1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $admin_user_ids = SysAdmin::find() ->where(['is_delete' => 0]) ->select('user_id')->column(); $mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null; $query = User::find()->alias('u') ->andWhere([ 'u.is_delete' => 0 ]) ->andWhere([ 'not in','u.type',[User::TYPE_STORE,User::TYPE_COACH] ]) ->andFilterWhere([ 'OR', ['LIKE', 'u.nickname', $this->keywords], ['LIKE', 'u.username', $this->keywords], ['LIKE', 'u.real_name', $this->keywords], ['LIKE', 'u.mobile_phone', $mobile_hash], ]) ->andFilterWhere([ 'u.status' => $this->status, ]); $cond = $this->is_admin == 0 ? "NOT IN" : "IN"; $query = $query->andWhere([ $cond, 'u.id', $admin_user_ids ]) ->select('u.id,u.username,u.nickname,u.avatar_url,u.mobile_phone,u.mobile_prefix,u.email,u.real_name,u.gender,u.birthday,u.status,u.created_at,u.updated_at'); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['u.created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['gender_cn'] = User::getGender($item['gender']); $item['status_cn'] = User::getStatus($item['status']); $item['created_at_cn'] = date("Y-m-d",$item['created_at']); $item['updated_at_cn'] = date("Y-m-d",$item['updated_at']); $item['mobile_phone'] = empty($item['mobile_phone']) ? '' : EncryptHelper::decryptMobilePhone($item['mobile_phone']); if(empty($item['mobile_phone'])){ $item['mobile_phone'] = ' -- '; } //脱敏 // $item['mobile_phone'] = $item['mobile_phone'] == null ? '--' : Utils::stringDesensitization($item['mobile_phone'], 3,4); $item['real_name'] = $item['real_name'] == null ? '--' : $item['real_name']; $list[$index] = $item; } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } }