feat: 修改UserLists类以支持更多搜索字段
This commit is contained in:
parent
1fdedb2bc7
commit
f08fcc575c
@ -12,8 +12,9 @@ use app\common\model\user\User;
|
|||||||
use app\common\model\user\UserAddress;
|
use app\common\model\user\UserAddress;
|
||||||
use app\common\model\vip_flow\VipFlow;
|
use app\common\model\vip_flow\VipFlow;
|
||||||
use support\Db;
|
use support\Db;
|
||||||
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
|
||||||
class UserLists extends BaseAdminDataLists implements ListsExcelInterface
|
class UserLists extends BaseAdminDataLists implements ListsExcelInterface,ListsSearchInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @notes 搜索条件
|
* @notes 搜索条件
|
||||||
@ -23,8 +24,11 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
|
|||||||
*/
|
*/
|
||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
$allowSearch = ['keyword', 'channel', 'create_time_start', 'create_time_end','store_id','user_ship'];
|
return [
|
||||||
return array_intersect(array_keys($this->params), $allowSearch);
|
'=' => ['store_id','user_ship','is_disable'],
|
||||||
|
'%like%' => ['account','mobile'],
|
||||||
|
'%pipe_like%' => ['nickname'=>'nickname|real_name'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,28 +43,15 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
$params = $this->params;
|
|
||||||
$where = [];
|
|
||||||
if(isset($params['nickname']) && $params['nickname'] != ''){
|
|
||||||
$where[] = ['real_name|nickname','like','%'.$params['nickname'].'%'];
|
|
||||||
}
|
|
||||||
if(isset($params['account']) && $params['account'] != ''){
|
|
||||||
$where[] = ['account','like','%'.$params['account'].'%'];
|
|
||||||
}
|
|
||||||
if(isset($params['mobile']) && $params['mobile'] != ''){
|
|
||||||
$where[] = ['mobile','like','%'.$params['mobile'].'%'];
|
|
||||||
}
|
|
||||||
if(isset($params['is_disable']) && $params['is_disable'] != ''){
|
|
||||||
$where[] = ['is_disable','=', $params['is_disable']];
|
|
||||||
}
|
|
||||||
$field = "id,nickname,real_name,sex,avatar,account,mobile,channel,create_time,purchase_funds,user_ship,
|
$field = "id,nickname,real_name,sex,avatar,account,mobile,channel,create_time,purchase_funds,user_ship,
|
||||||
label_id,integral,now_money,total_recharge_amount";
|
label_id,integral,now_money,total_recharge_amount";
|
||||||
$lists = User::withSearch($this->setSearch(), $this->params)->where($where)
|
$lists = User::where($this->searchWhere)
|
||||||
->with(['user_ship','user_label'])
|
->with(['user_ship','user_label'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->field($field)
|
->field($field)
|
||||||
->order('id desc')
|
->order('id desc')
|
||||||
->select()->each(function($data){
|
->select()
|
||||||
|
->each(function($data){
|
||||||
$data['sex_text'] = $data->sex_text;
|
$data['sex_text'] = $data->sex_text;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
foreach ($lists as &$item) {
|
foreach ($lists as &$item) {
|
||||||
@ -115,21 +106,8 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
$params = $this->params;
|
|
||||||
$where = [];
|
return User::where($this->searchWhere)->count();
|
||||||
if(isset($params['nickname']) && $params['nickname'] != ''){
|
|
||||||
$where[] = ['nickname','like','%'.$params['nickname'].'%'];
|
|
||||||
}
|
|
||||||
if(isset($params['account']) && $params['account'] != ''){
|
|
||||||
$where[] = ['account','like','%'.$params['account'].'%'];
|
|
||||||
}
|
|
||||||
if(isset($params['mobile']) && $params['mobile'] != ''){
|
|
||||||
$where[] = ['mobile','like','%'.$params['mobile'].'%'];
|
|
||||||
}
|
|
||||||
if(isset($params['is_disable']) && $params['is_disable'] != ''){
|
|
||||||
$where[] = ['is_disable','=', $params['is_disable']];
|
|
||||||
}
|
|
||||||
return User::withSearch($this->setSearch(), $this->params)->where($where)->count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user