From 64fb6d81c526c26b9f5e0534651f4162a9a27c35 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 18 Mar 2026 19:20:45 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=A7=AF=E5=88=86=E5=95=86=E5=9F=8E]=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/mall/User.php | 196 ++++++++++++++++++ app/common/model/MallUser.php | 31 +++ app/common/validate/MallUser.php | 25 +++ web/src/lang/backend/en/mall/user.ts | 15 ++ web/src/lang/backend/zh-cn/mall/user.ts | 15 ++ web/src/views/backend/mall/user/index.vue | 80 +++++++ web/src/views/backend/mall/user/popupForm.vue | 82 ++++++++ 7 files changed, 444 insertions(+) create mode 100644 app/admin/controller/mall/User.php create mode 100644 app/common/model/MallUser.php create mode 100644 app/common/validate/MallUser.php create mode 100644 web/src/lang/backend/en/mall/user.ts create mode 100644 web/src/lang/backend/zh-cn/mall/user.ts create mode 100644 web/src/views/backend/mall/user/index.vue create mode 100644 web/src/views/backend/mall/user/popupForm.vue diff --git a/app/admin/controller/mall/User.php b/app/admin/controller/mall/User.php new file mode 100644 index 0000000..92464f2 --- /dev/null +++ b/app/admin/controller/mall/User.php @@ -0,0 +1,196 @@ +model = new \app\common\model\MallUser(); + } + + /** + * 查看 + */ + public function index(Request $request): Response + { + $response = $this->initializeBackend($request); + if ($response !== null) { + return $response; + } + + if ($request->get('select') || $request->post('select')) { + $this->_select(); + return $this->success(); + } + + list($where, $alias, $limit, $order) = $this->queryBuilder(); + $res = $this->model + ->withoutField('password') + ->withJoin($this->withJoinTable, $this->withJoinType) + ->visible(['admin' => ['username']]) + ->alias($alias) + ->where($where) + ->order($order) + ->paginate($limit); + + return $this->success('', [ + 'list' => $res->items(), + 'total' => $res->total(), + 'remark' => get_route_remark(), + ]); + } + + /** + * 添加(密码加密) + */ + public function add(Request $request): Response + { + $response = $this->initializeBackend($request); + if ($response !== null) { + return $response; + } + + if ($request->method() !== 'POST') { + return $this->error(__('Parameter error')); + } + + $data = $request->post(); + if (!$data) { + return $this->error(__('Parameter %s can not be empty', [''])); + } + + $passwd = $data['password'] ?? ''; + if (empty($passwd)) { + return $this->error(__('Parameter %s can not be empty', [__('Password')])); + } + + $data = $this->applyInputFilter($data); + $data = $this->excludeFields($data); + + $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); + if ($result !== false && $passwd) { + $this->model->resetPassword((int) $this->model->id, $passwd); + } + $this->model->commit(); + } catch (Throwable $e) { + $this->model->rollback(); + return $this->error($e->getMessage()); + } + + return $result !== false ? $this->success(__('Added successfully')) : $this->error(__('No rows were added')); + } + + /** + * 编辑(密码可选更新) + */ + public function edit(Request $request): Response + { + $response = $this->initializeBackend($request); + if ($response !== null) { + return $response; + } + + $pk = $this->model->getPk(); + $id = $request->post($pk) ?? $request->get($pk); + $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 ($request->method() === 'POST') { + $data = $request->post(); + if (!$data) { + return $this->error(__('Parameter %s can not be empty', [''])); + } + + if (!empty($data['password'])) { + $this->model->resetPassword((int) $row->id, $data['password']); + } + + $data = $this->applyInputFilter($data); + $data = $this->excludeFields($data); + + $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'); + } + $validate->check(array_merge($data, [$pk => $row[$pk]])); + } + } + $result = $row->save($data); + $this->model->commit(); + } catch (Throwable $e) { + $this->model->rollback(); + return $this->error($e->getMessage()); + } + + return $result !== false ? $this->success(__('Update successful')) : $this->error(__('No rows updated')); + } + + unset($row['password']); + $row['password'] = ''; + return $this->success('', ['row' => $row]); + } + + /** + * 删除 + */ + public function del(Request $request): Response + { + $response = $this->initializeBackend($request); + if ($response !== null) { + return $response; + } + return $this->_del(); + } +} diff --git a/app/common/model/MallUser.php b/app/common/model/MallUser.php new file mode 100644 index 0000000..15299bb --- /dev/null +++ b/app/common/model/MallUser.php @@ -0,0 +1,31 @@ +belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id'); + } + + /** + * 重置密码(加密存储) + */ + public function resetPassword(int $id, string $newPassword): bool + { + return $this->where(['id' => $id])->update(['password' => hash_password($newPassword)]) !== false; + } +} \ No newline at end of file diff --git a/app/common/validate/MallUser.php b/app/common/validate/MallUser.php new file mode 100644 index 0000000..845f967 --- /dev/null +++ b/app/common/validate/MallUser.php @@ -0,0 +1,25 @@ + 'require', + 'phone' => 'require', + ]; + + protected $message = [ + 'username.require' => '用户名不能为空', + 'phone.require' => '手机号不能为空', + ]; + + protected $scene = [ + 'add' => ['username', 'phone'], + 'edit' => ['username', 'phone'], + ]; +} diff --git a/web/src/lang/backend/en/mall/user.ts b/web/src/lang/backend/en/mall/user.ts new file mode 100644 index 0000000..3d67d60 --- /dev/null +++ b/web/src/lang/backend/en/mall/user.ts @@ -0,0 +1,15 @@ +export default { + id: 'id', + username: 'username', + phone: 'phone', + password: 'password', + score: 'score', + daily_claim: 'daily_claim', + daily_claim_use: 'daily_claim_use', + available_for_withdrawal: 'available_for_withdrawal', + admin_id: 'admin_id', + admin__username: 'username', + create_time: 'create_time', + update_time: 'update_time', + 'quick Search Fields': 'id', +} diff --git a/web/src/lang/backend/zh-cn/mall/user.ts b/web/src/lang/backend/zh-cn/mall/user.ts new file mode 100644 index 0000000..1326d8d --- /dev/null +++ b/web/src/lang/backend/zh-cn/mall/user.ts @@ -0,0 +1,15 @@ +export default { + id: 'ID', + username: '用户名', + phone: '手机号', + password: '密码', + score: '积分', + daily_claim: '每日限额', + daily_claim_use: '每日限额(已使用)', + available_for_withdrawal: '可提现金额', + admin_id: '归属管理员', + admin__username: '用户名', + create_time: '创建时间', + update_time: '修改时间', + 'quick Search Fields': 'ID', +} diff --git a/web/src/views/backend/mall/user/index.vue b/web/src/views/backend/mall/user/index.vue new file mode 100644 index 0000000..1110acd --- /dev/null +++ b/web/src/views/backend/mall/user/index.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/web/src/views/backend/mall/user/popupForm.vue b/web/src/views/backend/mall/user/popupForm.vue new file mode 100644 index 0000000..3d5ab52 --- /dev/null +++ b/web/src/views/backend/mall/user/popupForm.vue @@ -0,0 +1,82 @@ + + + + +