From d8bcc4f4c49ca0bca160a845fa763c4db7374713 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 1 Apr 2026 15:59:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F-=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86-=E4=BC=98=E5=8C=96password=E5=92=8Cuuid=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/game/User.php | 141 ++++++++++++++++++++++ web/src/views/backend/game/user/index.vue | 10 +- 2 files changed, 150 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/game/User.php b/app/admin/controller/game/User.php index 6c21763..b92e9a3 100644 --- a/app/admin/controller/game/User.php +++ b/app/admin/controller/game/User.php @@ -31,6 +31,147 @@ class User extends Backend return null; } + /** + * 添加(重写:password 使用 Admin 同款加密;uuid 由 username+channel_id 生成) + * @throws Throwable + */ + protected function _add(): Response + { + if ($this->request && $this->request->method() === 'POST') { + $data = $this->request->post(); + if (!$data) { + return $this->error(__('Parameter %s can not be empty', [''])); + } + + $data = $this->applyInputFilter($data); + $data = $this->excludeFields($data); + + $password = $data['password'] ?? null; + if (!is_string($password) || trim($password) === '') { + return $this->error(__('Parameter %s can not be empty', ['password'])); + } + $data['password'] = hash_password($password); + + $username = $data['username'] ?? ''; + $channelId = $data['channel_id'] ?? ($data['game_channel_id'] ?? null); + if (!is_string($username) || trim($username) === '' || $channelId === null || $channelId === '') { + return $this->error(__('Parameter %s can not be empty', ['username/channel_id'])); + } + $data['uuid'] = md5(trim($username) . '|' . $channelId); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $data[$this->dataLimitField] = $this->auth->id; + } + + $result = false; + $this->model->startTrans(); + try { + if ($this->modelValidate) { + $validate = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + if (class_exists($validate)) { + $validate = new $validate(); + if ($this->modelSceneValidate) { + $validate->scene('add'); + } + $validate->check($data); + } + } + $result = $this->model->save($data); + $this->model->commit(); + } catch (Throwable $e) { + $this->model->rollback(); + return $this->error($e->getMessage()); + } + if ($result !== false) { + return $this->success(__('Added successfully')); + } + return $this->error(__('No rows were added')); + } + + return $this->error(__('Parameter error')); + } + + /** + * 编辑(重写:password 使用 Admin 同款加密;uuid 由 username+channel_id 生成) + * @throws Throwable + */ + protected function _edit(): Response + { + $pk = $this->model->getPk(); + $id = $this->request ? ($this->request->post($pk) ?? $this->request->get($pk)) : null; + $row = $this->model->find($id); + if (!$row) { + return $this->error(__('Record not found')); + } + + $dataLimitAdminIds = $this->getDataLimitAdminIds(); + if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) { + return $this->error(__('You have no permission')); + } + + if ($this->request && $this->request->method() === 'POST') { + $data = $this->request->post(); + if (!$data) { + return $this->error(__('Parameter %s can not be empty', [''])); + } + + $data = $this->applyInputFilter($data); + $data = $this->excludeFields($data); + + if (array_key_exists('password', $data)) { + $password = $data['password']; + if (!is_string($password) || trim($password) === '') { + unset($data['password']); + } else { + $data['password'] = hash_password($password); + } + } + + $nextUsername = array_key_exists('username', $data) ? $data['username'] : $row['username']; + $nextChannelId = null; + if (array_key_exists('channel_id', $data)) { + $nextChannelId = $data['channel_id']; + } elseif (array_key_exists('game_channel_id', $data)) { + $nextChannelId = $data['game_channel_id']; + } else { + $nextChannelId = $row['channel_id'] ?? $row['game_channel_id'] ?? null; + } + + if (is_string($nextUsername) && trim($nextUsername) !== '' && $nextChannelId !== null && $nextChannelId !== '') { + $data['uuid'] = md5(trim($nextUsername) . '|' . $nextChannelId); + } + + $result = false; + $this->model->startTrans(); + try { + if ($this->modelValidate) { + $validate = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + if (class_exists($validate)) { + $validate = new $validate(); + if ($this->modelSceneValidate) { + $validate->scene('edit'); + } + $data[$pk] = $row[$pk]; + $validate->check($data); + } + } + $result = $row->save($data); + $this->model->commit(); + } catch (Throwable $e) { + $this->model->rollback(); + return $this->error($e->getMessage()); + } + if ($result !== false) { + return $this->success(__('Update successful')); + } + return $this->error(__('No rows updated')); + } + + return $this->success('', [ + 'row' => $row + ]); + } + /** * 查看 * @throws Throwable diff --git a/web/src/views/backend/game/user/index.vue b/web/src/views/backend/game/user/index.vue index 8f86a00..a02e308 100644 --- a/web/src/views/backend/game/user/index.vue +++ b/web/src/views/backend/game/user/index.vue @@ -55,7 +55,15 @@ const baTable = new baTableClass( sortable: false, operator: 'LIKE', }, - { label: t('game.user.uuid'), prop: 'uuid', align: 'center', operatorPlaceholder: t('Fuzzy query'), sortable: false, operator: 'LIKE' }, + { + label: t('game.user.uuid'), + prop: 'uuid', + align: 'center', + showOverflowTooltip: true, + operatorPlaceholder: t('Fuzzy query'), + sortable: false, + operator: 'LIKE', + }, { label: t('game.user.phone'), prop: 'phone', align: 'center', operatorPlaceholder: t('Fuzzy query'), sortable: false, operator: 'LIKE' }, { label: t('game.user.coin'), prop: 'coin', align: 'center', sortable: false, operator: 'RANGE' }, {