Skip to content

Commit

Permalink
Fixed : Fixed BUG editing for users and characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLeeAreemm committed Jan 8, 2023
1 parent 1e3b974 commit 18f9273
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
10 changes: 3 additions & 7 deletions app/controller/admin/AdminRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@ public function add(): Json
{
$param = input();
$param['create_time'] = time();
$roles_arr = json_decode($this->request->param('role_auth'), true);
$arr = [];
foreach ($roles_arr as $value) {
$arr[] = $value['id'];
}
$param['role_auth'] = implode(',', $arr);
$start = Model::create($param);
$roles_arr = $this->request->param('role_auth');
$param['role_auth'] = implode(',', $roles_arr);
$start = Model::create($param);

if (!$start) {
return $this->send(ErrorCode::DB_DATA_ADD_FAILE, [], '新增失败');
Expand Down
13 changes: 4 additions & 9 deletions app/controller/admin/AdminUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,24 @@ public function add(): Json
if ($account_exist){
return $this->send(ErrorCode::DB_DATA_ALREADY_EXIST, [], '该账号已存在');
}

$role_auth = json_decode($param['role_auth'], true);
$role_auth = $param['role_auth'];
$role_id = [];
$auth = [];

foreach ($param as $key => $val) {
if (!Str::startsWith($key, 'u_role')) {
continue;
}
$role_id[] = $val;
}
foreach ($role_auth as $value) {
$auth[] = $value['id'];
}


$data = [
'u_name' => $param['u_name'],
'u_account' => $param['u_account'],
'p_u_id' => $this->who['u_id'],
'u_password' => md5($param['u_password']),
'role_id' => implode(',', $role_id),
'u_auth' => implode(',', $auth),
'u_auth' => implode(',', $role_auth),
'create_time' => date('Y-m-d H:i:s'),
];
$userModel = new Model();
Expand Down Expand Up @@ -236,13 +232,12 @@ public function edit()

$data = [
'u_name' => $param['u_name'],
'u_password' => md5($param['u_password']),
'u_account' => $param['u_account'],
'role_id' => implode(',', $role_id),
'u_auth' => implode(',', $role_auth),
'update_time' => date('Y-m-d H:i:s'),
];
if ($users->u_password !== $param['u_password'] && !empty($param['u_password'])){
if (!empty($param['u_password']) && md5($users->u_password) !== md5($param['u_password'])){
$data['u_password'] = md5($param['u_password']);
}
$res = $users->save($data);
Expand Down

0 comments on commit 18f9273

Please sign in to comment.