schema = [ 'id' => 'number', 'account' => 'string', 'nickname' => 'string', 'password' => 'string', 'token' => 'string', 'delete_time' => 'number', 'create_time' => 'number', 'update_time' => 'number' ]; } public function access() { return self::hasOne(AuthGroupAccessModel::class,'admin_id','id'); } public function department() { return self::hasOne(DepartmentModel::class,'id','department_id'); } public function loadByLogin($username, $password) { return $this->where([ ['account|id|mobile', '=', $username], ['password', '=', $password], ['is_delete', '=',0] ])->find(); } public function refreshToken($adminId,$token) { return $this->where([ ['id', '=',$adminId], ['is_delete', '=',0] ])->update(['token' => $token]); } /** * @param array $params * @return \think\Paginator * @throws \think\db\exception\DbException */ public function findByPaginate(array $params) { $where = [ ['erp_admin.is_delete', '=', 0], ]; $access_where = [ ['is_delete', '=', 0] ]; if(isset($params['group_id']) && $params['group_id'] > 0) array_push($access_where,['group_id', '=', $params['group_id']]); if(isset($params['department_id']) && $params['department_id'] > 0) array_push($where, ['erp_admin.department_id', '=', $params['department_id']]); return $this->where($where) ->with(['access','access.group', 'department']) ->hasWhere('access', $access_where) ->hasWhere('department') ->order('create_time','desc') ->paginate(['list_rows' => 10, "query" => $params]); } public function doesItExist($account) { $customer = $this->where([ ["account", '=',$account], ["is_delete", '=', 0], ])->find(); return $customer; } public function findById($id) { return $this->where('id',$id)->with(['access','access.group','department'])->find(); } public function findAdmins($store_id, $text) { $where = [ ['is_delete', '=', 0] ]; if($text != null) { array_push($where, ['id|nickname','like', '%'.$text.'%']); } return $this ->where($where) ->where("FIND_IN_SET('{$store_id}', store_ids)") ->limit(50) ->order('id', 'desc') ->select(); } public function findAll() { return $this->where('is_delete', 0) ->where('store_ids',"NOT NULL") ->select(); } }