| 
									
										
										
										
											2021-11-18 17:57:04 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace app\model; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use think\facade\Db; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Member extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public const STATUS_NORMAL  = 1;//正常
 | 
					
						
							|  |  |  |     public const STATUS_DISABLE = 0;//禁用
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 18:11:50 +08:00
										 |  |  |     public const ANENT_ROLE_ID = 2;//角色id 2 为代理商
 | 
					
						
							| 
									
										
										
										
											2021-11-18 17:57:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function getList($limit = 40) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::alias('m') | 
					
						
							|  |  |  |             ->leftjoin('auth_group g', 'g.id=m.group_id') | 
					
						
							|  |  |  |             ->field('m.id,m.username,m.login_time,m.group_id,g.title') | 
					
						
							|  |  |  |             ->order('m.id', 'asc') | 
					
						
							|  |  |  |             ->paginate($limit); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取所有代理商 | 
					
						
							|  |  |  |      * */ | 
					
						
							|  |  |  |     public static  function getAgentAll(){ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $subQuery = Db::name('member') | 
					
						
							|  |  |  |             ->field('id,business_code,nickname') | 
					
						
							| 
									
										
										
										
											2021-11-25 18:11:50 +08:00
										 |  |  |             ->whereRaw('(find_in_set("'.Member::ANENT_ROLE_ID .'", roles))') | 
					
						
							| 
									
										
										
										
											2021-11-18 17:57:04 +08:00
										 |  |  |             ->buildSql(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        return Db::table($subQuery . ' a') | 
					
						
							|  |  |  |             ->join("business b" ,"a.business_code = b.code") | 
					
						
							|  |  |  |            ->field("a.*") | 
					
						
							|  |  |  |             ->order('a.id', 'desc') | 
					
						
							|  |  |  |             ->select(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 根据角色分组返回用户 | 
					
						
							|  |  |  |      * @param  int  $groupId  角色分组ID | 
					
						
							|  |  |  |      * @param  int  $limit  每页数量 | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function getListByGroup($groupId, $limit = 40) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::alias('m') | 
					
						
							|  |  |  |             ->leftjoin('auth_group g', 'g.id=m.group_id') | 
					
						
							|  |  |  |             ->field('m.id,m.username,m.login_time,m.group_id,g.title') | 
					
						
							|  |  |  |             ->where('m.group_id', '=', $groupId) | 
					
						
							|  |  |  |             ->order('m.id', 'asc') | 
					
						
							|  |  |  |             ->paginate($limit); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //根据用户名获取管理账号
 | 
					
						
							|  |  |  |     public static function getByUserName($username) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::where('username', trim($username)) | 
					
						
							|  |  |  |             ->findOrEmpty() | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //根据ID获取管理账户和相关权限
 | 
					
						
							|  |  |  |     public static function getMemberAndRulesByID($memberId) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::alias('m') | 
					
						
							|  |  |  |             ->join('auth_group g', 'm.group_id = g.id', 'LEFT') | 
					
						
							|  |  |  |             ->field('m.group_id,g.rules') | 
					
						
							|  |  |  |             ->where('m.id', $memberId) | 
					
						
							|  |  |  |             ->findOrEmpty() | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function updateCates($id, $cates) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $cates = implode(',', $cates); | 
					
						
							|  |  |  |         $data  = ['cates' => $cates]; | 
					
						
							|  |  |  |         self::updateById($id, $data); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |