This commit is contained in:
weiz 2024-05-15 11:20:34 +08:00
parent bf8ea2a150
commit 0822795b7a
4 changed files with 50 additions and 14 deletions

View File

@ -57,8 +57,11 @@ class UserController extends BaseAdminController
*/
public function edit()
{
$params = (new UserValidate())->post()->goCheck('setInfo');
UserLogic::setUserInfo($params);
return $this->success('操作成功', [], 1, 1);
$params = (new UserValidate())->post()->goCheck('edit');
$result = UserLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(UserLogic::getError());
}
}

View File

@ -35,13 +35,26 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
*/
public function lists(): array
{
$params = $this->params;
$where = [];
if(isset($params['nickname']) && $params['nickname'] != ''){
$where[] = ['nickname','like','%'.$params['nickname'].'%'];
}
if(isset($params['account']) && $params['account'] != ''){
$where[] = ['account','like','%'.$params['account'].'%'];
}
if(isset($params['mobile']) && $params['mobile'] != ''){
$where[] = ['mobile','like','%'.$params['mobile'].'%'];
}
if(isset($params['is_disable']) && $params['is_disable'] != ''){
$where[] = ['is_disable','=', $params['is_disable']];
}
$field = "id,nickname,real_name,sex,avatar,account,mobile,channel,create_time";
$lists = User::withSearch($this->setSearch(), $this->params)
$lists = User::withSearch($this->setSearch(), $this->params)->where($where)
->limit($this->limitOffset, $this->limitLength)
->field($field)
->order('id desc')
->select()->toArray();
foreach ($lists as &$item) {
$item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']);
}
@ -58,7 +71,21 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
*/
public function count(): int
{
return User::withSearch($this->setSearch(), $this->params)->count();
$params = $this->params;
$where = [];
if(isset($params['nickname']) && $params['nickname'] != ''){
$where[] = ['nickname','like','%'.$params['nickname'].'%'];
}
if(isset($params['account']) && $params['account'] != ''){
$where[] = ['account','like','%'.$params['account'].'%'];
}
if(isset($params['mobile']) && $params['mobile'] != ''){
$where[] = ['mobile','like','%'.$params['mobile'].'%'];
}
if(isset($params['is_disable']) && $params['is_disable'] != ''){
$where[] = ['is_disable','=', $params['is_disable']];
}
return User::withSearch($this->setSearch(), $this->params)->where($where)->count();
}

View File

@ -75,15 +75,15 @@ class UserLogic extends BaseLogic
Db::startTrans();
try {
User::where('id', $params['id'])->update([
'avatar' => $params['avatar'],
'avatar' => $params['avatar'] ?? '',
'real_name' => $params['real_name'],
'nickname' => $params['nickname'],
'account' => $params['account'],
'password' => $params['password'],
'mobile' => $params['mobile'],
'sex' => $params['sex'],
'is_disable' => $params['is_disable'],
'user_money' => $params['user_money']
'password' => $params['password'] ?? '',
'mobile' => $params['mobile'] ?? '',
'sex' => $params['sex'] ?? 0,
'is_disable' => $params['is_disable'] ?? 0,
'user_money' => $params['user_money'] ?? 0
]);
Db::commit();

View File

@ -24,7 +24,10 @@ class UserValidate extends BaseValidate
'nickname' => 'require',
'account' => 'require',
'password' => 'require',
'mobile' => 'require',
'mobile' => 'require|mobile',
'is_disable' => 'in:0,1',
'sex' => 'in:i,2',
'user_money' => 'float'
];
@ -39,6 +42,9 @@ class UserValidate extends BaseValidate
'account' => '用户账号',
'password' => '用户密码',
'mobile' => '用户电话',
'is_disable' => '是否禁用',
'sex' => '用户性别',
'user_money' => '用户余额',
];
@ -62,7 +68,7 @@ class UserValidate extends BaseValidate
*/
public function sceneEdit()
{
return $this->only(['id','real_name','nickname','account','password','mobile']);
return $this->only(['id','real_name','nickname','account','password','mobile'])->remove('password','require');
}