Files

132 lines
4.0 KiB
PHP

<?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;
use app\common\model\user\User;
use app\common\service\user\UserAccountTypeService;
/**
* 用户列表
* 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
{
$allowSearch = ['keyword', 'channel', 'create_time_start', 'create_time_end'];
if (($this->params['account_scope'] ?? '') === UserAccountTypeService::SCOPE_SYSTEM) {
$allowSearch = array_diff($allowSearch, ['channel']);
}
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
{
$field = "id,sn,nickname,sex,avatar,account,mobile,channel,user_money,user_points,create_time";
$lists = $this->buildQuery()
->limit($this->limitOffset, $this->limitLength)
->field($field)
->order('id desc')
->select()->toArray();
foreach ($lists as &$item) {
$accountType = UserAccountTypeService::resolveType($item);
$item = array_merge($item, $accountType);
$item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']);
}
return $lists;
}
/**
* @notes 获取数量
* @return int
* @author 段誉
* @date 2022/9/22 15:51
*/
public function count(): int
{
return $this->buildQuery()->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' => '手机号码',
'account_scope_desc' => '账号归属',
'account_type_desc' => '账号类型',
'channel' => '注册来源',
'create_time' => '注册时间',
];
}
protected function buildQuery()
{
$query = User::withSearch($this->setSearch(), $this->params);
$accountScope = (string) ($this->params['account_scope'] ?? '');
if ($accountScope === UserAccountTypeService::SCOPE_REGISTERED) {
$query->whereIn('channel', UserAccountTypeService::registeredChannels());
} elseif ($accountScope === UserAccountTypeService::SCOPE_SYSTEM) {
$query->whereNotIn('channel', UserAccountTypeService::registeredChannels());
}
return $query;
}
}