cxfoot/modules/admin/models/UserListForm.php
2023-10-27 14:25:12 +08:00

207 lines
7.7 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-11-5
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\admin\models;
use app\models\User;
use app\models\UserLogoutReview;
use app\models\UserOauth;
use app\models\SysAdmin;
use yii\data\Pagination;
use app\components\EncryptHelper;
use app\components\SiteHelper;
use app\components\Utils;
class UserListForm extends AdminModel
{
public $keywords;
public $page;
public $limit;
public $is_admin;
public $status;
public function rules()
{
return [
[['keywords',], 'trim'],
[['keywords',], 'string'],
[['page', 'limit', 'is_admin', 'status',], 'integer'],
[['page'], 'default', 'value' => 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.type' => 0,
'u.is_delete' => 0,
])
->andWhere(['!=','u.id',1])
// ->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,u.is_view');
$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;
}
//查询除admin账号外的所有用户
public function search_user()
{
if(!$this->validate()){
return $this->getModelError();
}
$mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null;
$query = User::find()->alias('u')
->where(['!=','u.id',1])
->andWhere([
'u.is_delete' => 0
])
->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,
])
->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;
}
public function logout_review()
{
$mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null;
$query = UserLogoutReview::find()->alias('ulr')
->select('ulr.*,u.nickname,u.real_name,u.avatar_url,u.mobile_prefix,u.mobile_phone,u.id as user_id')
->leftJoin(['u' => User::tableName()],'ulr.user_id=u.id')
->where([
'ulr.is_delete' => 0,
])
->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([
'ulr.status' => $this->status,
]);
$count = $query->count();
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['ulr.created_at' => SORT_DESC])->asArray()->all();
foreach ($list as $index => $item){
$item['status_cn'] = UserLogoutReview::getStatus($item['status']);
$item['created_at_cn'] = date("Y/m/d H:i",$item['created_at']);
$item['mobile_phone'] = empty($item['mobile_phone']) ? '' : EncryptHelper::decryptMobilePhone($item['mobile_phone']);
if(empty($item['mobile_phone'])){
$item['mobile_phone'] = ' -- ';
}
$item['nickname'] = "[{$item['user_id']}]".$item['nickname'];
//脱敏
if(!empty($item['real_name']) && $item['nickname'] != $item['real_name']){
$item['nickname'] .= '--'.$item['real_name'];
}
$list[$index] = $item;
}
$data = [];
$data['code'] = 0;
$data['msg'] = 'ok';
$data['data'] = $list;
$data['count'] = $count;
return $data;
}
}