data_center/app/adminapi/logic/user/UserLogic.php

92 lines
3.9 KiB
PHP
Raw Normal View History

2023-09-18 09:11:13 +08:00
<?php
namespace app\adminapi\logic\user;
use app\common\logic\BaseLogic;
use app\common\model\systems\System;
2023-09-18 09:11:13 +08:00
use app\common\model\user\User;
use app\common\model\user\UserBalance;
use app\common\model\user\UserIntegral;
2023-11-17 11:44:51 +08:00
use think\facade\Db;
2023-09-18 09:11:13 +08:00
class UserLogic extends BaseLogic
{
//用户详情
public static function detail(int $userId): array
{
//获取用户信息
2023-11-17 11:44:51 +08:00
$field = ['id','phone','avatar','nickname','realname','status','gender','age','create_time'];
2023-09-18 09:11:13 +08:00
$user = User::field($field)->where(['id' => $userId])->findOrEmpty();
2023-09-19 15:39:19 +08:00
$user['gender_text'] = $user->gender_text;
$user['status_text'] = $user->status_text;
2023-11-17 11:44:51 +08:00
$user['app_list'] = Db::name('system_user')->alias('su')->leftJoin('dc_system s','su.app_id = s.app_id')->field(['s.id', 's.app_id', 's.name'])->select();
2023-09-18 09:11:13 +08:00
return $user->toArray();
}
//用户余额列表
public static function balanceList($params): array
{
2023-09-21 15:31:01 +08:00
$search = [];
2023-09-21 18:08:58 +08:00
if(isset($params['record_id']) && !empty($params['record_id'])){
2023-09-21 15:31:01 +08:00
$search[] = ['record_id','=',$params['record_id']];
}
2023-09-21 18:08:58 +08:00
if(isset($params['mark']) && !empty($params['mark'])){
2023-09-21 15:31:01 +08:00
$search[] = ['mark','like','%'.$params['mark'].'%'];
}
2023-09-21 18:08:58 +08:00
if(isset($params['appid']) && !empty($params['appid'])){
2023-09-21 15:31:01 +08:00
$app = System::field('app_id')->where('id',$params['appid'])->findOrEmpty();
if(!$app->isEmpty()){
$search[] = ['appid','=',$app['app_id']];
}
}
if(isset($params['pay_type']) && in_array($params['pay_type'],[0,1,2,3,4])){
$search[] = ['pay_type','=',$params['pay_type']];
}
//获取用户余额列表
$fields = 'id,record_id,amount,total_amount,type,pay_type,mark,appid,create_time';
2023-09-21 15:31:01 +08:00
$lists = UserBalance::field($fields)->where('user_id',$params['uid'])->where($search)->page($params['page_no'],$params['page_size'])->order('create_time desc')->select()->each(function($item){
$item['app'] = System::where('app_id',$item['appid'])->value('name');
$item['type_text'] = $item->type_text;
$item['pay_type_text'] = $item->pay_type_text;
unset($item['appid']);
})->toArray();
2023-09-21 15:31:01 +08:00
$count = UserBalance::field('id')->where('user_id',$params['uid'])->where($search)->count();
return [
'count' => $count,
'page_no' => $params['page_no'],
'page_size' => $params['page_size'],
'lists' => $lists
];
}
//用户积分列表
public static function integralList($params): array
{
2023-09-21 15:31:01 +08:00
$search = [];
2023-09-21 18:08:58 +08:00
if(isset($params['mark']) && !empty($params['mark'])){
2023-09-21 15:31:01 +08:00
$search[] = ['mark','like','%'.$params['mark'].'%'];
}
2023-09-21 18:08:58 +08:00
if(isset($params['appid']) && !empty($params['appid'])){
2023-09-21 15:31:01 +08:00
$app = System::field('app_id')->where('id',$params['appid'])->findOrEmpty();
if(!$app->isEmpty()){
$search[] = ['appid','=',$app['app_id']];
}
}
if(isset($params['type']) && in_array($params['type'],[0,1])){
$search[] = ['type','=',$params['type']];
}
//获取用户积分列表
$fields = 'id,record_id,amount,total_amount,type,mark,appid,create_time';
2023-09-21 15:31:01 +08:00
$lists = UserIntegral::field($fields)->where('user_id',$params['uid'])->where($search)->page($params['page_no'],$params['page_size'])->order('create_time desc')->select()->each(function($item){
$item['app'] = System::where('app_id',$item['appid'])->value('name');
$item['type_text'] = $item->type_text;
})->toArray();
2023-09-21 15:31:01 +08:00
$count = UserIntegral::field('id')->where('user_id',$params['uid'])->where($search)->count();
return [
'count' => $count,
'page_no' => $params['page_no'],
'page_size' => $params['page_size'],
'lists' => $lists
];
}
2023-09-18 09:11:13 +08:00
}