This commit is contained in:
unknown 2023-09-19 15:39:19 +08:00
parent 087e72abef
commit 42af6df23e
5 changed files with 84 additions and 16 deletions

View File

@ -23,4 +23,9 @@ class UserController extends BaseAdminController
$detail = UserLogic::detail($params['id']); $detail = UserLogic::detail($params['id']);
return $this->success('', $detail); return $this->success('', $detail);
} }
// 用户余额列表
public function balanceLists() {
}
} }

View File

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

@ -10,10 +10,12 @@ class UserLogic extends BaseLogic
//用户详情 //用户详情
public static function detail(int $userId): array 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::field($field)->where(['id' => $userId])->findOrEmpty();
$user['user_gender_text'] = $user->user_gender_text; $user['address'] = $user->province_text.$user->city_text.$user->area_text.$user->street_text.$user->village_text.$user->brigade_text.$user->address;
$user['user_status_text'] = $user->user_status_text; $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(); return $user->toArray();
} }
} }

View File

@ -3,22 +3,76 @@
namespace app\common\model\user; namespace app\common\model\user;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use think\facade\Db;
class User extends BaseModel class User extends BaseModel
{ {
protected $name = 'user'; protected $name = 'user';
// 获取用户状态 // 获取用户状态
public function getUserStatusTextAttr($value,$data): string public function getStatusTextAttr($value,$data): string
{ {
$user_status = [0=>'正常',1=>'冻结',2=>'删除']; $status = [0=>'正常',1=>'冻结',2=>'删除'];
return $user_status[$data['user_status']]; return $status[$data['status']];
} }
// 获取用户性别 // 获取用户性别
public function getUserGenderTextAttr($value,$data): string public function getGenderTextAttr($value,$data): string
{ {
$user_gender = [0=>'男',1=>'女',2=>'未知']; $gender = [0=>'男',1=>'女',2=>'未知'];
return $user_gender[$data['user_gender']]; 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

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