Compare commits

...

3 Commits

Author SHA1 Message Date
weiz 93ee31c9ee Merge pull request 'zhangwei' (#4) from zhangwei into master
Reviewed-on: #4
2023-09-19 16:48:36 +08:00
unknown e4f6a62b16 用户余额列表、积分列表接口 2023-09-19 16:47:40 +08:00
unknown 42af6df23e update 2023-09-19 15:39:19 +08:00
8 changed files with 191 additions and 25 deletions

View File

@ -5,6 +5,8 @@ namespace app\adminapi\controller\user;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\user\UserLists;
use app\adminapi\logic\user\UserLogic;
use app\common\validate\user\UserBalanceValidate;
use app\common\validate\user\UserIntegralValidate;
use app\common\validate\user\UserValidate;
use think\response\Json;
@ -23,4 +25,22 @@ class UserController extends BaseAdminController
$detail = UserLogic::detail($params['id']);
return $this->success('', $detail);
}
// 获取用户余额列表
public function balance(): Json
{
//获取参数
$params = (new UserBalanceValidate())->get()->goCheck('list');
$data = UserLogic::balanceList($params);
return $this->success('', $data);
}
// 获取用户积分列表
public function integral():Json
{
//获取参数
$params = (new UserIntegralValidate())->get()->goCheck('list');
$data = UserLogic::integralList($params);
return $this->success('', $data);
}
}

View File

@ -12,27 +12,26 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['user_status'],
'%like%' => ['user_account','user_nickname','user_phone'],
'=' => ['status'],
'%like%' => ['nick_name','phone'],
];
}
// 获取用户列表
public function lists(): array
{
$field = "id,user_avatar,user_account,user_nickname,user_phone,user_gender,user_status,create_time";
$lists = User::field($field)->where($this->searchWhere)->where('user_status','<>',2)
$field = "id,phone,avatar,nick_name,real_name,id_card,gender,age,total_balance,total_integral,status,create_time";
return User::field($field)->where($this->searchWhere)->where('status','<>',2)
->limit($this->limitOffset, $this->limitLength)
->order('id desc')->select()->each(function($item){
$item['user_status_text'] = $item->user_status_text;
$item['user_gender_text'] = $item->user_gender_text;
$item['status_text'] = $item->status_text;
$item['gender_text'] = $item->gender_text;
})->toArray();
return $lists;
}
// 获取数量
public function count(): int
{
return User::field('id')->where($this->searchWhere)->where('user_status','<>',2)->count();
return User::field('id')->where($this->searchWhere)->where('status','<>',2)->count();
}
}

View File

@ -3,17 +3,73 @@
namespace app\adminapi\logic\user;
use app\common\logic\BaseLogic;
use app\common\model\systems\System;
use app\common\model\user\User;
use app\common\model\user\UserBalance;
use app\common\model\user\UserIntegral;
class UserLogic extends BaseLogic
{
//用户详情
public static function detail(int $userId): array
{
$field = ['id','user_phone','user_avatar','user_name','user_gender','user_age','user_status','user_last_login_time','user_last_login_ip','create_time'];
//获取用户信息
$field = ['id','phone','avatar','nick_name','real_name','id_card','gender','age','total_balance','total_integral','province','city','area','street','village','brigade','address','status','last_login_time','last_login_ip','create_time'];
$user = User::field($field)->where(['id' => $userId])->findOrEmpty();
$user['user_gender_text'] = $user->user_gender_text;
$user['user_status_text'] = $user->user_status_text;
$user['address'] = $user->province_text.$user->city_text.$user->area_text.$user->street_text.$user->village_text.$user->brigade_text.$user->address;
$user['gender_text'] = $user->gender_text;
$user['status_text'] = $user->status_text;
//获取用户余额列表
$user['balance_list'] = UserBalance::field('id,record_id,amount,total_amount,type,pay_type,mark,appid,create_time')->where('user_id',$userId)->limit(10)->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();
//获取用户积分列表
$user['integral_list'] = UserIntegral::field('id,record_id,amount,total_amount,type,mark,appid,create_time')->where('user_id',$userId)->limit(10)->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();
unset($user['province'],$user['city'],$user['area'],$user['street'],$user['village'],$user['brigade']);
return $user->toArray();
}
//用户余额列表
public static function balanceList($params): array
{
//获取用户余额列表
$fields = 'id,record_id,amount,total_amount,type,pay_type,mark,appid,create_time';
$lists = UserBalance::field($fields)->where('user_id',$params['uid'])->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();
$count = UserBalance::field('id')->where('user_id',$params['uid'])->count();
return [
'count' => $count,
'page_no' => $params['page_no'],
'page_size' => $params['page_size'],
'lists' => $lists
];
}
//用户积分列表
public static function integralList($params): array
{
//获取用户积分列表
$fields = 'id,record_id,amount,total_amount,type,mark,appid,create_time';
$lists = UserIntegral::field($fields)->where('user_id',$params['uid'])->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();
$count = UserIntegral::field('id')->where('user_id',$params['uid'])->count();
return [
'count' => $count,
'page_no' => $params['page_no'],
'page_size' => $params['page_size'],
'lists' => $lists
];
}
}

View File

@ -3,22 +3,76 @@
namespace app\common\model\user;
use app\common\model\BaseModel;
use think\facade\Db;
class User extends BaseModel
{
protected $name = 'user';
// 获取用户状态
public function getUserStatusTextAttr($value,$data): string
public function getStatusTextAttr($value,$data): string
{
$user_status = [0=>'正常',1=>'冻结',2=>'删除'];
return $user_status[$data['user_status']];
$status = [0=>'正常',1=>'冻结',2=>'删除'];
return $status[$data['status']];
}
// 获取用户性别
public function getUserGenderTextAttr($value,$data): string
public function getGenderTextAttr($value,$data): string
{
$user_gender = [0=>'男',1=>'女',2=>'未知'];
return $user_gender[$data['user_gender']];
$gender = [0=>'男',1=>'女',2=>'未知'];
return $gender[$data['gender']];
}
public function getProvinceTextAttr($value,$data): string {
$data = Db::name('geo_province')->where('province_code',$data['province'])->findOrEmpty();
if(empty($data)){
return '';
}
return $data['province_name'];
}
public function getCityTextAttr($value,$data): string {
$data = Db::name('geo_city')->where('city_code',$data['city'])->findOrEmpty();
if(empty($data)){
return '';
}
return $data['city_name'];
}
public function getAreaTextAttr($value,$data): string {
$data = Db::name('geo_area')->where('area_code',$data['area'])->findOrEmpty();
if(empty($data)){
return '';
}
return $data['area_name'];
}
public function getStreetTextAttr($value,$data): string {
$data = Db::name('geo_street')->where('street_code',$data['street'])->findOrEmpty();
if(empty($data)){
return '';
}
return $data['street_name'];
}
public function getVillageTextAttr($value,$data): string {
$data = Db::name('geo_village')->where('village_code',$data['village'])->findOrEmpty();
if(empty($data)){
return '';
}
return $data['village_name'];
}
public function getBrigadeTextAttr($value,$data): string {
$data = Db::name('geo_brigade')->where('id',$data['brigade'])->findOrEmpty();
if(empty($data)){
return '';
}
return $data['brigade_name'];
}
public function getLastLoginTimeAttr($value): string
{
return date('Y-m-d H:i:s',$value);
}
}

View File

@ -16,7 +16,7 @@ class UserBalance extends BaseModel
public function getPayTypeTextAttr($value,$data): string
{
$pay_type = [ 0=>'微信支付', 2=>'支付宝支付', 3=>'银行卡支付', 4=>'余额支付', 5=>'其他'];
$pay_type = [ 0=>'微信支付', 1=>'支付宝支付', 2=>'银行卡支付', 3=>'余额支付', 4=>'其他'];
return $pay_type[$data['pay_type']];
}
}

View File

@ -12,8 +12,11 @@ class UserBalanceValidate extends BaseValidate
'record_table' => 'require',
'amount' => 'require|float|gt:0',
'type' => 'require|in:0,1',
'pay_type' => 'require|in:0,1,2,3,4,5',
'pay_type' => 'require|in:0,1,2,3,4',
'mark' => 'require',
'uid' => 'require',
'page_no' => 'require|number|gt:0',
'page_size' => 'require|number|gt:0'
];
protected $message = [
@ -28,8 +31,20 @@ class UserBalanceValidate extends BaseValidate
'pay_type.require' => '请选择支付方式',
'pay_type.in' => '支付方式值错误',
'mark.require' => '请填写金额变更具体详情',
'uid.require' => '缺少用户id',
'page_no.require' => '缺少分页页码',
'page_no.number' => '分页页码数据格式错误',
'page_no.gt' => '分页页码必须大于0',
'page_size.require' => '缺少分页条数',
'page_size.number' => '分页条数数据格式错误',
'page_size.gt' => '分页条数必须大于0',
];
public function sceneList(): UserBalanceValidate
{
return $this->only(['uid','page_no','page_size']);
}
public function sceneAdd(): UserBalanceValidate
{
return $this->only(['record_id','record_table','amount','type','pay_type','mark']);

View File

@ -13,20 +13,35 @@ class UserIntegralValidate extends BaseValidate
'amount' => 'require|float|gt:0',
'type' => 'require|in:0,1',
'mark' => 'require',
'uid' => 'require',
'page_no' => 'require|number|gt:0',
'page_size' => 'require|number|gt:0'
];
protected $message = [
'id.require' => '缺少数据主键',
'record_id.require' => '请填写本地记录id',
'record_table.require' => '请填写本地记录表名',
'amount.require' => '请填写金额',
'amount.float' => '金额数据格式错误',
'amount.gt' => '金额必须大于零',
'type.require' => '请选择金额变更类型',
'type.in' => '金额变更类型值错误',
'mark.require' => '请填写金额变更具体详情',
'amount.require' => '请填写积分数目',
'amount.float' => '积分数目数据格式错误',
'amount.gt' => '积分数目必须大于零',
'type.require' => '请选择积分数目变更类型',
'type.in' => '积分数目变更类型值错误',
'mark.require' => '请填写积分数目变更具体详情',
'uid.require' => '缺少用户id',
'page_no.require' => '缺少分页页码',
'page_no.number' => '分页页码数据格式错误',
'page_no.gt' => '分页页码必须大于0',
'page_size.require' => '缺少分页条数',
'page_size.number' => '分页条数数据格式错误',
'page_size.gt' => '分页条数必须大于0',
];
public function sceneList(): UserIntegralValidate
{
return $this->only(['uid','page_no','page_size']);
}
public function sceneAdd(): UserIntegralValidate
{
return $this->only(['record_id','record_table','amount','type','mark']);

View File

@ -9,6 +9,7 @@ use app\common\validate\BaseValidate;
class UserValidate extends BaseValidate
{
protected $rule = [
'id' => 'require',
'phone' => 'require|mobile|unique:user',
'code' => 'require',
'age' => 'number|gt:0',
@ -24,6 +25,7 @@ class UserValidate extends BaseValidate
];
protected $message = [
'id.require' => '请选择用户',
'phone.require' => '请输入手机号码',
'phone.mobile' => '请输入正确的手机号码',
'phone.unique' => '该手机号码已注册',
@ -42,6 +44,11 @@ class UserValidate extends BaseValidate
'brigade.number' => '小组编码值错误',
];
public function sceneDetail(): UserValidate
{
return $this->only(['id']);
}
public function sceneChangeMobile(): UserValidate
{
return $this->only(['phone','code']);