WokerTask/app/adminapi/lists/user/UserLists.php

133 lines
4.1 KiB
PHP
Raw Normal View History

2023-12-27 14:06:33 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\user;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\enum\user\UserTerminalEnum;
use app\common\lists\ListsExcelInterface;
2024-01-23 17:26:00 +08:00
use app\common\logic\ShopRequestLogic;
2023-12-27 14:06:33 +08:00
use app\common\model\Company;
use app\common\model\contract\Contract;
use app\common\model\user\User;
2023-12-29 18:49:41 +08:00
use app\common\model\user\UserRole;
2023-12-27 14:06:33 +08:00
use think\facade\Db;
/**
* 用户列表
* Class UserLists
* @package app\adminapi\lists\user
*/
class UserLists extends BaseAdminDataLists implements ListsExcelInterface
{
/**
* @notes 搜索条件
* @return array
* @author 段誉
* @date 2022/9/22 15:50
*/
public function setSearch(): array
{
2024-01-24 09:21:15 +08:00
return [
'=' => ['keyword', 'create_time_start', 'create_time_end', 'province', 'city', 'area', 'street', 'village']
];
2023-12-27 14:06:33 +08:00
}
/**
* @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
{
2024-01-23 17:26:00 +08:00
$field = "id,id contract,sn,nickname,sex,avatar,account,mobile,channel,create_time,admin_id,company_id,street,street as street_name,is_contract,group_id,invite_code";
2023-12-27 14:06:33 +08:00
2024-01-24 09:21:15 +08:00
$lists = User::where($this->searchWhere)
2023-12-29 18:49:41 +08:00
->append(['role_name'])
2023-12-27 14:06:33 +08:00
->with(['company'])
2023-12-29 18:49:41 +08:00
->withAttr('role_name', function ($value, $data){
$role = UserRole::where('id', $data['group_id'])->find();
return $role? $role['name']: "";
})
2023-12-27 14:06:33 +08:00
->limit($this->limitOffset, $this->limitLength)
->field($field)
->order('id desc')
->select()
->toArray();
foreach ($lists as &$item) {
$item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']);
2024-01-23 17:26:00 +08:00
$inviteUserStatistics = ShopRequestLogic::getInviteUserInfo(['promotion_code' => $item['invite_code']]);
$item['register_num'] = $inviteUserStatistics['data']['user_count'];
// $data['merchant_num'] = $inviteUserStatistics['data']['merchant_count'];
$item['trade_amount'] = Db::name('user_invite_first_order_log')->where('user_id', $item['id'])->sum('order_money');
2023-12-27 14:06:33 +08:00
}
return $lists;
}
/**
* @notes 获取数量
* @return int
* @author 段誉
* @date 2022/9/22 15:51
*/
public function count(): int
{
2024-01-24 09:21:15 +08:00
return User::where($this->searchWhere)->count();
2023-12-27 14:06:33 +08:00
}
/**
* @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' => '注册来源',
2024-01-23 17:26:00 +08:00
'role_name' => '用户角色',
'register_num' => '成功邀请人数',
'trade_amount' => '总计首单金额',
2023-12-27 14:06:33 +08:00
'create_time' => '注册时间',
];
}
}