341 lines
13 KiB
PHP
341 lines
13 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,ListsSearchInterface,ListsExtendInterface};
|
||
use app\common\model\user\{User,UserInfo,UserMineRecord};
|
||
use app\common\model\finance\{RechargeRecord,WithdrawRecord};
|
||
|
||
|
||
/**
|
||
* 用户列表
|
||
* Class UserLists
|
||
* @package app\adminapi\lists\user
|
||
*/
|
||
class UserLists extends BaseAdminDataLists implements ListsExcelInterface,ListsSearchInterface,ListsExtendInterface
|
||
{
|
||
|
||
/**
|
||
* @notes 设置搜索条件
|
||
* @return \string[][]
|
||
* @author bd
|
||
* @date 2024/01/31 14:07
|
||
*/
|
||
public function setSearch(): array
|
||
{
|
||
return [
|
||
'=' => ['u.sn','u.is_open','u.is_agent','u.country_code','u.register_ip','u.login_ip'],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @notes 搜索条件
|
||
* @author 段誉
|
||
* @date 2023/2/24 16:08
|
||
*/
|
||
public function queryWhere()
|
||
{
|
||
$where = [];
|
||
// 用户编号
|
||
if (!empty($this->params['user_info'])) {
|
||
$where[] = ['u.sn|u.account|u.mobile', '=', $this->params['user_info']];
|
||
}
|
||
|
||
// 会员等级
|
||
if (!empty($this->params['member_id'])) {
|
||
$where[] = ['umr.member_id', '=', $this->params['member_id']];
|
||
}
|
||
|
||
// 邮箱地址
|
||
if (!empty($this->params['email'])) {
|
||
$where[] = ['ui.email', '=', $this->params['email']];
|
||
}
|
||
|
||
// 邮箱认证
|
||
if (!empty($this->params['auth_email'])) {
|
||
$where[] = ['ui.auth_email', '=', $this->params['auth_email']];
|
||
}
|
||
|
||
// 下单时间
|
||
if (!empty($this->params['create_time_start']) && !empty($this->params['create_time_end'])) {
|
||
$time = [strtotime($this->params['create_time_start']), strtotime($this->params['create_time_end'])];
|
||
$where[] = ['u.create_time', 'between', $time];
|
||
}
|
||
|
||
return $where;
|
||
}
|
||
|
||
|
||
/**
|
||
* @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
|
||
{
|
||
$where = " 1 = 1 ";
|
||
|
||
|
||
// 金额范围
|
||
if (!empty($this->params['recharge_withdraw_min'])) {
|
||
$recharge_withdraw_min = $this->params['recharge_withdraw_min'];
|
||
$where .= " AND u.total_recharge - u.total_withdraw >= $recharge_withdraw_min ";
|
||
}
|
||
|
||
// 金额范围
|
||
if (!empty($this->params['recharge_withdraw_max'])) {
|
||
$recharge_withdraw_max = $this->params['recharge_withdraw_max'];
|
||
$where .= " AND u.total_recharge - u.total_withdraw <= $recharge_withdraw_max ";
|
||
}
|
||
|
||
$field = "u.id,u.sn,u.nickname,u.sex,u.avatar,u.account,u.mobile,u.country_code,u.auto_member,u.is_lh,u.is_transfer,u.is_sn,u.is_open,u.is_agent,u.agent_name,u.channel,u.user_money,u.user_point,u.total_recharge,u.total_withdraw,u.total_income_invest,u.total_invest,u.total_income_mine,u.create_time,u.register_ip,u.register_isp,u.remark2,u.login_ip,u.login_time";
|
||
$field .= ',ui.email,ui.auth_email';
|
||
|
||
$join_table = "user_info t";
|
||
$join_require = 't.user_id = u.id';
|
||
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
|
||
$join_table = "user_relation_agent ur";
|
||
$join_require = 'u.id = ur.user_id';
|
||
|
||
$user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
|
||
$parent_id = 0;
|
||
if (!$user->isEmpty()) $parent_id = $user['id'];
|
||
|
||
$where .= " AND ur.parent_id = $parent_id ";
|
||
|
||
if(isset($this->params['level']) && $this->params['level'] !=""){
|
||
$level = $this->params['level'];
|
||
$where .= " AND ur.level = $level ";
|
||
}
|
||
$field .= ',ur.level';
|
||
}
|
||
$lists = User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->field($field)
|
||
->append(['team_num','team_recharge','team_withdraw','item_num','today_item_num','vip_name','unused_money','team_report','team_top','register_ip_num','login_ip_num','register_country','mine'])
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->limit($this->limitOffset, $this->limitLength)
|
||
->order('u.id desc')
|
||
->select()
|
||
->toArray();
|
||
|
||
foreach ($lists as &$item) {
|
||
$item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']);
|
||
|
||
$item['recharge_withdraw'] = round($item['total_recharge'] - $item['total_withdraw'], 2);
|
||
|
||
if(isset($item['level']) && isset($item['team_top']['level'])){
|
||
$item['team_top']['level'] = $item['level'];
|
||
}
|
||
}
|
||
|
||
return $lists;
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取数量
|
||
* @return int
|
||
* @author 段誉
|
||
* @date 2022/9/22 15:51
|
||
*/
|
||
public function count(): int
|
||
{
|
||
$where = " 1 = 1 ";
|
||
|
||
// 金额范围
|
||
if (!empty($this->params['recharge_withdraw_min'])) {
|
||
$recharge_withdraw_min = $this->params['recharge_withdraw_min'];
|
||
$where .= " AND u.total_recharge - u.total_withdraw >= $recharge_withdraw_min ";
|
||
}
|
||
|
||
// 金额范围
|
||
if (!empty($this->params['recharge_withdraw_max'])) {
|
||
$recharge_withdraw_max = $this->params['recharge_withdraw_max'];
|
||
$where .= " AND u.total_recharge - u.total_withdraw <= $recharge_withdraw_max ";
|
||
}
|
||
|
||
$join_table = "user_info t";
|
||
$join_require = 't.user_id = u.id';
|
||
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
|
||
$join_table = "user_relation_agent ur";
|
||
$join_require = 'u.id = ur.user_id';
|
||
|
||
$user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
|
||
$parent_id = 0;
|
||
if (!$user->isEmpty()) $parent_id = $user['id'];
|
||
|
||
$where .= " AND ur.parent_id = $parent_id ";
|
||
|
||
if(isset($this->params['level']) && $this->params['level'] !=""){
|
||
$level = $this->params['level'];
|
||
$where .= " AND ur.level = $level ";
|
||
}
|
||
}
|
||
|
||
|
||
return User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->count();
|
||
}
|
||
|
||
public function extend(): array
|
||
{
|
||
$where = " 1 = 1 ";
|
||
|
||
// 金额范围
|
||
if (!empty($this->params['recharge_withdraw_min'])) {
|
||
$recharge_withdraw_min = $this->params['recharge_withdraw_min'];
|
||
$where .= " AND u.total_recharge - u.total_withdraw >= $recharge_withdraw_min ";
|
||
}
|
||
|
||
// 金额范围
|
||
if (!empty($this->params['recharge_withdraw_max'])) {
|
||
$recharge_withdraw_max = $this->params['recharge_withdraw_max'];
|
||
$where .= " AND u.total_recharge - u.total_withdraw <= $recharge_withdraw_max ";
|
||
}
|
||
|
||
$join_table = "user_info t";
|
||
$join_require = 't.user_id = u.id';
|
||
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
|
||
$join_table = "user_relation_agent ur";
|
||
$join_require = 'u.id = ur.user_id';
|
||
|
||
$user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
|
||
$parent_id = 0;
|
||
if (!$user->isEmpty()) $parent_id = $user['id'];
|
||
|
||
$where .= " AND ur.parent_id = $parent_id ";
|
||
|
||
if(isset($this->params['level']) && $this->params['level'] !=""){
|
||
$level = $this->params['level'];
|
||
$where .= " AND ur.level = $level ";
|
||
}
|
||
}
|
||
|
||
$total_recharge = User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->sum('u.total_recharge');
|
||
|
||
$total_withdraw = User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->sum('u.total_withdraw');
|
||
|
||
$total_money = User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->sum('u.user_money');
|
||
|
||
$recharge_ing = User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->join('recharge_record rr', 'u.id = rr.user_id')
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->where($where)
|
||
->where(['rr.status' => 0])
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->sum('rr.amount');
|
||
|
||
$withdraw_ing = User::alias('u')
|
||
->join('user_info ui', 'u.id = ui.user_id')
|
||
->join($join_table, $join_require)
|
||
->join('withdraw_record wr', 'u.id = wr.user_id')
|
||
->leftjoin('user_member_record umr', 'u.id = umr.user_id')
|
||
->where($where)
|
||
->where(['wr.status' => 0])
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->sum('wr.amount');
|
||
|
||
return [
|
||
'total_money' => round($total_money, 2),
|
||
'total_recharge' => round($total_recharge, 2),
|
||
'total_withdraw' => round($total_withdraw, 2),
|
||
'recharge_withdraw' => round($total_recharge - $total_withdraw, 2),
|
||
'recharge_ing' => round($recharge_ing, 2),
|
||
'withdraw_ing' => round($withdraw_ing, 2),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @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' => '用户ID',
|
||
'country_code' => '国家区号',
|
||
'account' => '手机号',
|
||
'sn' => '邀请码',
|
||
'email' => '邮箱',
|
||
'vip_name' => '会员等级',
|
||
'level_top_account' => '一代',
|
||
'level_level' => '用户层级',
|
||
'team_level1' => '推广情况(1级)',
|
||
'team_level2' => '推广情况(2级)',
|
||
'team_level3' => '推广情况(3级)',
|
||
'total_recharge' => '总充值',
|
||
'total_withdraw' => '总提现',
|
||
'recharge_withdraw' => '充提差',
|
||
'channel' => '注册来源',
|
||
'create_time' => '注册时间',
|
||
];
|
||
}
|
||
|
||
} |