From 42af6df23e9fcce04de7c02c67a1c23145258de7 Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Tue, 19 Sep 2023 15:39:19 +0800 Subject: [PATCH] update --- .../controller/user/UserController.php | 5 ++ app/adminapi/lists/user/UserLists.php | 14 ++-- app/adminapi/logic/user/UserLogic.php | 8 ++- app/common/model/user/User.php | 66 +++++++++++++++++-- app/common/validate/user/UserValidate.php | 7 ++ 5 files changed, 84 insertions(+), 16 deletions(-) diff --git a/app/adminapi/controller/user/UserController.php b/app/adminapi/controller/user/UserController.php index 0743851f..9bd42785 100644 --- a/app/adminapi/controller/user/UserController.php +++ b/app/adminapi/controller/user/UserController.php @@ -23,4 +23,9 @@ class UserController extends BaseAdminController $detail = UserLogic::detail($params['id']); return $this->success('', $detail); } + + // 用户余额列表 + public function balanceLists() { + + } } \ No newline at end of file diff --git a/app/adminapi/lists/user/UserLists.php b/app/adminapi/lists/user/UserLists.php index 98e7bdc6..ef777376 100644 --- a/app/adminapi/lists/user/UserLists.php +++ b/app/adminapi/lists/user/UserLists.php @@ -12,20 +12,20 @@ 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"; + $lists = 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; } @@ -33,6 +33,6 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface // 获取数量 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(); } } \ No newline at end of file diff --git a/app/adminapi/logic/user/UserLogic.php b/app/adminapi/logic/user/UserLogic.php index f8a85dd5..362bb1ec 100644 --- a/app/adminapi/logic/user/UserLogic.php +++ b/app/adminapi/logic/user/UserLogic.php @@ -10,10 +10,12 @@ 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; + unset($user['province'],$user['city'],$user['area'],$user['street'],$user['village'],$user['brigade']); return $user->toArray(); } } \ No newline at end of file diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index abf90b4f..fb062193 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -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); } } \ No newline at end of file diff --git a/app/common/validate/user/UserValidate.php b/app/common/validate/user/UserValidate.php index cac9e510..88b78a76 100644 --- a/app/common/validate/user/UserValidate.php +++ b/app/common/validate/user/UserValidate.php @@ -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']);