multi-store/app/admin/lists/user/UserLists.php
2024-06-20 11:41:14 +08:00

140 lines
4.2 KiB
PHP

<?php
namespace app\admin\lists\user;
use app\admin\lists\BaseAdminDataLists;
use app\common\enum\user\UserTerminalEnum;
use app\common\enum\YesNoEnum;
use app\common\lists\ListsExcelInterface;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\common\model\vip_flow\VipFlow;
class UserLists extends BaseAdminDataLists implements ListsExcelInterface
{
/**
* @notes 搜索条件
* @return array
* @author 乔峰
* @date 2022/9/22 15:50
*/
public function setSearch(): array
{
$allowSearch = ['keyword', 'channel', 'create_time_start', 'create_time_end'];
return array_intersect(array_keys($this->params), $allowSearch);
}
/**
* @notes 获取用户列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 乔峰
* @date 2022/9/22 15:50
*/
public function lists(): array
{
$params = $this->params;
$where = [];
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']];
}
$field = "id,nickname,real_name,sex,avatar,account,mobile,channel,create_time,purchase_funds,user_ship,
label_id,integral";
$lists = User::withSearch($this->setSearch(), $this->params)->where($where)
->with(['user_ship','user_label'])
->limit($this->limitOffset, $this->limitLength)
->field($field)
->order('id desc')
->select()->each(function($data){
$data['sex_text'] = $data->sex_text;
})->toArray();
foreach ($lists as &$item) {
$item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']);
$item['user_address'] = UserAddress::where([
'uid'=>$item['id'],'is_default'=>YesNoEnum::YES
])->value('detail');
if($item['vip_name']== null){
$item['vip_name'] = '普通会员';
}
if($item['label_name']== null){
$item['label_name'] = '无';
}
$item['return_money'] = VipFlow::
where(['user_id'=>$item['id'],'status'=>0])
->sum('number')??0;
}
return $lists;
}
/**
* @notes 获取数量
* @return int
* @author 乔峰
* @date 2022/9/22 15:51
*/
public function count(): int
{
$params = $this->params;
$where = [];
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();
}
/**
* @notes 导出文件名
* @return string
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
return '用户列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
return [
'sn' => '用户编号',
'nickname' => '用户昵称',
'account' => '账号',
'mobile' => '手机号码',
'channel' => '注册来源',
'create_time' => '注册时间',
];
}
}