From 61c50f9169379858a73c076b6b8486bacf83d9b0 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Sat, 1 Jun 2024 16:07:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0store=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/controller/BaseAdminController.php | 22 ++ app/store/controller/DownloadController.php | 38 ++ app/store/controller/LoginController.php | 59 +++ app/store/controller/UploadController.php | 44 +++ app/store/controller/WorkbenchController.php | 37 ++ app/store/controller/auth/AdminController.php | 127 +++++++ app/store/controller/auth/MenuController.php | 134 +++++++ app/store/controller/auth/RoleController.php | 118 ++++++ .../store_order/StoreOrderController.php | 95 +++++ .../store_product/StoreProductController.php | 95 +++++ .../StoreProductAttrValueController.php | 95 +++++ app/store/lists/BaseAdminDataLists.php | 39 ++ app/store/lists/auth/AdminLists.php | 206 +++++++++++ app/store/lists/auth/MenuLists.php | 58 +++ app/store/lists/auth/RoleLists.php | 93 +++++ .../lists/store_order/StoreOrderLists.php | 65 ++++ .../lists/store_product/StoreProductLists.php | 69 ++++ .../StoreProductAttrValueLists.php | 65 ++++ .../StoreProductUnitLists.php | 65 ++++ app/store/logic/LoginLogic.php | 95 +++++ app/store/logic/WorkbenchLogic.php | 198 ++++++++++ app/store/logic/auth/AdminLogic.php | 340 ++++++++++++++++++ app/store/logic/auth/AuthLogic.php | 105 ++++++ app/store/logic/auth/MenuLogic.php | 184 ++++++++++ app/store/logic/auth/RoleLogic.php | 170 +++++++++ .../logic/store_order/StoreOrderLogic.php | 94 +++++ .../logic/store_product/StoreProductLogic.php | 148 ++++++++ .../StoreProductAttrValueLogic.php | 94 +++++ app/store/middleware/AuthMiddleware.php | 63 ++++ app/store/middleware/InitMiddleware.php | 35 ++ app/store/middleware/LoginMiddleware.php | 65 ++++ app/store/service/AdminTokenService.php | 116 ++++++ app/store/validate/LoginValidate.php | 85 +++++ app/store/validate/auth/AdminValidate.php | 168 +++++++++ app/store/validate/auth/MenuValidate.php | 195 ++++++++++ app/store/validate/auth/RoleValidate.php | 119 ++++++ app/store/validate/auth/editSelfValidate.php | 71 ++++ .../store_order/StoreOrderValidate.php | 82 +++++ .../store_product/StoreProductValidate.php | 84 +++++ .../StoreProductAttrValueValidate.php | 82 +++++ 40 files changed, 4117 insertions(+) create mode 100644 app/store/controller/BaseAdminController.php create mode 100644 app/store/controller/DownloadController.php create mode 100644 app/store/controller/LoginController.php create mode 100644 app/store/controller/UploadController.php create mode 100644 app/store/controller/WorkbenchController.php create mode 100644 app/store/controller/auth/AdminController.php create mode 100644 app/store/controller/auth/MenuController.php create mode 100644 app/store/controller/auth/RoleController.php create mode 100644 app/store/controller/store_order/StoreOrderController.php create mode 100644 app/store/controller/store_product/StoreProductController.php create mode 100644 app/store/controller/store_product_attr_value/StoreProductAttrValueController.php create mode 100644 app/store/lists/BaseAdminDataLists.php create mode 100644 app/store/lists/auth/AdminLists.php create mode 100644 app/store/lists/auth/MenuLists.php create mode 100644 app/store/lists/auth/RoleLists.php create mode 100644 app/store/lists/store_order/StoreOrderLists.php create mode 100644 app/store/lists/store_product/StoreProductLists.php create mode 100644 app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php create mode 100644 app/store/lists/store_product_unit/StoreProductUnitLists.php create mode 100644 app/store/logic/LoginLogic.php create mode 100644 app/store/logic/WorkbenchLogic.php create mode 100644 app/store/logic/auth/AdminLogic.php create mode 100644 app/store/logic/auth/AuthLogic.php create mode 100644 app/store/logic/auth/MenuLogic.php create mode 100644 app/store/logic/auth/RoleLogic.php create mode 100644 app/store/logic/store_order/StoreOrderLogic.php create mode 100644 app/store/logic/store_product/StoreProductLogic.php create mode 100644 app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php create mode 100644 app/store/middleware/AuthMiddleware.php create mode 100644 app/store/middleware/InitMiddleware.php create mode 100644 app/store/middleware/LoginMiddleware.php create mode 100644 app/store/service/AdminTokenService.php create mode 100644 app/store/validate/LoginValidate.php create mode 100644 app/store/validate/auth/AdminValidate.php create mode 100644 app/store/validate/auth/MenuValidate.php create mode 100644 app/store/validate/auth/RoleValidate.php create mode 100644 app/store/validate/auth/editSelfValidate.php create mode 100644 app/store/validate/store_order/StoreOrderValidate.php create mode 100644 app/store/validate/store_product/StoreProductValidate.php create mode 100644 app/store/validate/store_product_attr_value/StoreProductAttrValueValidate.php diff --git a/app/store/controller/BaseAdminController.php b/app/store/controller/BaseAdminController.php new file mode 100644 index 000000000..94454d6d5 --- /dev/null +++ b/app/store/controller/BaseAdminController.php @@ -0,0 +1,22 @@ +request->adminInfo) && $this->request->adminInfo) { + $this->adminInfo = $this->request->adminInfo; + $this->adminId = $this->request->adminInfo['admin_id']; + } + } +} diff --git a/app/store/controller/DownloadController.php b/app/store/controller/DownloadController.php new file mode 100644 index 000000000..4560923dd --- /dev/null +++ b/app/store/controller/DownloadController.php @@ -0,0 +1,38 @@ +get('file'); + + //通过文件缓存的key获取文件储存的路径 + $exportCache = new ExportCache(); + $fileInfo = $exportCache->getFile($fileKey); + + if (empty($fileInfo)) { + return JsonService::fail('下载文件不存在'); + } + + //下载前删除缓存 + Cache::delete($fileKey); + + return response()->download($fileInfo['src'] . $fileInfo['name'],$fileInfo['name']); + } +} diff --git a/app/store/controller/LoginController.php b/app/store/controller/LoginController.php new file mode 100644 index 000000000..975ad139d --- /dev/null +++ b/app/store/controller/LoginController.php @@ -0,0 +1,59 @@ +post()->goCheck(); + $params['is_admin']=$this->request->post('is_admin',1); + return $this->data((new LoginLogic())->login($params)); + } + + /** + * @notes 退出登录 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/7/8 00:36 + */ + public function logout() + { + //退出登录情况特殊,只有成功的情况,也不需要token验证 + (new LoginLogic())->logout($this->adminInfo); + return $this->success(); + } +} diff --git a/app/store/controller/UploadController.php b/app/store/controller/UploadController.php new file mode 100644 index 000000000..770e8dbad --- /dev/null +++ b/app/store/controller/UploadController.php @@ -0,0 +1,44 @@ +request->post('cid', 0); + $result = UploadService::image($cid); + return $this->success('上传成功', $result); + } catch (Exception $e) { + return $this->fail($e->getMessage()); + } + } + + /** + * @notes 上传视频 + * @author 乔峰 + * @date 2021/12/29 16:27 + */ + public function video() + { + try { + $cid = $this->request->post('cid', 0); + $result = UploadService::video($cid); + return $this->success('上传成功', $result); + } catch (Exception $e) { + return $this->fail($e->getMessage()); + } + } +} diff --git a/app/store/controller/WorkbenchController.php b/app/store/controller/WorkbenchController.php new file mode 100644 index 000000000..97339367c --- /dev/null +++ b/app/store/controller/WorkbenchController.php @@ -0,0 +1,37 @@ +data($result); + } +} diff --git a/app/store/controller/auth/AdminController.php b/app/store/controller/auth/AdminController.php new file mode 100644 index 000000000..2f8739e28 --- /dev/null +++ b/app/store/controller/auth/AdminController.php @@ -0,0 +1,127 @@ +dataLists(new AdminLists()); + } + + + /** + * @notes 添加管理员 + * @author 乔峰 + * @date 2021/12/29 10:21 + */ + public function add() + { + $params = (new AdminValidate())->post()->goCheck('add'); + $result = AdminLogic::add($params); + if (true === $result) { + return $this->success('操作成功', [], 1, 1); + } + return $this->fail(AdminLogic::getError()); + } + + + /** + * @notes 编辑管理员 + * @author 乔峰 + * @date 2021/12/29 11:03 + */ + public function edit() + { + $params = (new AdminValidate())->post()->goCheck('edit'); + $result = AdminLogic::edit($params); + if (true === $result) { + return $this->success('操作成功', [], 1, 1); + } + return $this->fail(AdminLogic::getError()); + } + + + /** + * @notes 删除管理员 + * @author 乔峰 + * @date 2021/12/29 11:03 + */ + public function delete() + { + $params = (new AdminValidate())->post()->goCheck('delete'); + $result = AdminLogic::delete($params); + if (true === $result) { + return $this->success('操作成功', [], 1, 1); + } + return $this->fail(AdminLogic::getError()); + } + + + /** + * @notes 查看管理员详情 + * @author 乔峰 + * @date 2021/12/29 11:07 + */ + public function detail() + { + $params = (new AdminValidate())->goCheck('detail'); + $result = AdminLogic::detail($params); + return $this->data($result); + } + + + /** + * @notes 获取当前管理员信息 + * @author 乔峰 + * @date 2021/12/31 10:53 + */ + public function mySelf() + { + $result = AdminLogic::detail(['id' => $this->adminId], 'auth'); + return $this->data($result); + } + + + /** + * @notes 编辑超级管理员信息 + * @author 乔峰 + * @date 2022/4/8 17:54 + */ + public function editSelf() + { + $params = (new editSelfValidate())->post()->goCheck('', ['admin_id' => $this->adminId]); + $result = AdminLogic::editSelf($params); + return $this->success('操作成功', [], 1, 1); + } + +} diff --git a/app/store/controller/auth/MenuController.php b/app/store/controller/auth/MenuController.php new file mode 100644 index 000000000..9e62d599d --- /dev/null +++ b/app/store/controller/auth/MenuController.php @@ -0,0 +1,134 @@ +adminId); + return $this->data($result); + } + + + /** + * @notes 获取菜单列表 + * @author 乔峰 + * @date 2022/6/29 17:23 + */ + public function lists() + { + return $this->dataLists(new MenuLists()); + } + + + /** + * @notes 菜单详情 + * @author 乔峰 + * @date 2022/6/30 10:07 + */ + public function detail() + { + $params = (new MenuValidate())->goCheck('detail'); + return $this->data(MenuLogic::detail($params)); + } + + + /** + * @notes 添加菜单 + * @author 乔峰 + * @date 2022/6/30 10:07 + */ + public function add() + { + $params = (new MenuValidate())->post()->goCheck('add'); + MenuLogic::add($params); + return $this->success('操作成功', [], 1, 1); + } + + + /** + * @notes 编辑菜单 + * @author 乔峰 + * @date 2022/6/30 10:07 + */ + public function edit() + { + $params = (new MenuValidate())->post()->goCheck('edit'); + MenuLogic::edit($params); + return $this->success('操作成功', [], 1, 1); + } + + + /** + * @notes 删除菜单 + * @author 乔峰 + * @date 2022/6/30 10:07 + */ + public function delete() + { + $params = (new MenuValidate())->post()->goCheck('delete'); + MenuLogic::delete($params); + return $this->success('操作成功', [], 1, 1); + } + + + /** + * @notes 更新状态 + * @author 乔峰 + * @date 2022/7/6 17:04 + */ + public function updateStatus() + { + $params = (new MenuValidate())->post()->goCheck('status'); + MenuLogic::updateStatus($params); + return $this->success('操作成功', [], 1, 1); + } + + + /** + * @notes 获取菜单数据 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2022/10/13 11:03 + */ + public function all() + { + $result = MenuLogic::getAllData(); + return $this->data($result); + } + + +} diff --git a/app/store/controller/auth/RoleController.php b/app/store/controller/auth/RoleController.php new file mode 100644 index 000000000..88713a89b --- /dev/null +++ b/app/store/controller/auth/RoleController.php @@ -0,0 +1,118 @@ +dataLists(new RoleLists()); + } + + + /** + * @notes 添加权限 + * @author 乔峰 + * @date 2021/12/29 11:49 + */ + public function add() + { + $params = (new RoleValidate())->post()->goCheck('add'); + $res = RoleLogic::add($params); + if (true === $res) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(RoleLogic::getError()); + } + + + /** + * @notes 编辑角色 + * @author 乔峰 + * @date 2021/12/29 14:18 + */ + public function edit() + { + $params = (new RoleValidate())->post()->goCheck('edit'); + $res = RoleLogic::edit($params); + if (true === $res) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(RoleLogic::getError()); + } + + + /** + * @notes 删除角色 + * @author 乔峰 + * @date 2021/12/29 14:18 + */ + public function delete() + { + $params = (new RoleValidate())->post()->goCheck('del'); + RoleLogic::delete($params['id']); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 查看角色详情 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/12/29 14:18 + */ + public function detail() + { + $params = (new RoleValidate())->goCheck('detail'); + $detail = RoleLogic::detail($params['id']); + return $this->data($detail); + } + + + /** + * @notes 获取角色数据 + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2022/10/13 10:39 + */ + public function all() + { + $result = RoleLogic::getAllData(); + return $this->data($result); + } + +} diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php new file mode 100644 index 000000000..64f1609b2 --- /dev/null +++ b/app/store/controller/store_order/StoreOrderController.php @@ -0,0 +1,95 @@ +dataLists(new StoreOrderLists()); + } + + + /** + * @notes 添加订单列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function add() + { + $params = (new StoreOrderValidate())->post()->goCheck('add'); + $result = StoreOrderLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreOrderLogic::getError()); + } + + + /** + * @notes 编辑订单列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function edit() + { + $params = (new StoreOrderValidate())->post()->goCheck('edit'); + $result = StoreOrderLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreOrderLogic::getError()); + } + + + /** + * @notes 删除订单列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function delete() + { + $params = (new StoreOrderValidate())->post()->goCheck('delete'); + StoreOrderLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取订单列表详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 16:02 + */ + public function detail() + { + $params = (new StoreOrderValidate())->goCheck('detail'); + $result = StoreOrderLogic::detail($params); + return $this->data($result); + } + + +} diff --git a/app/store/controller/store_product/StoreProductController.php b/app/store/controller/store_product/StoreProductController.php new file mode 100644 index 000000000..72f547074 --- /dev/null +++ b/app/store/controller/store_product/StoreProductController.php @@ -0,0 +1,95 @@ +dataLists(new StoreProductLists()); + } + + + /** + * @notes 添加商品列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function add() + { + $params = (new StoreProductValidate())->post()->goCheck('add'); + $result = StoreProductLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreProductLogic::getError()); + } + + + /** + * @notes 编辑商品列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function edit() + { + $params = (new StoreProductValidate())->post()->goCheck('edit'); + $result = StoreProductLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreProductLogic::getError()); + } + + + /** + * @notes 删除商品列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function delete() + { + $params = (new StoreProductValidate())->post()->goCheck('delete'); + StoreProductLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品列表详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function detail() + { + $params = (new StoreProductValidate())->goCheck('detail'); + $result = StoreProductLogic::detail($params); + return $this->data($result); + } + + +} diff --git a/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php b/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php new file mode 100644 index 000000000..dfb51cb65 --- /dev/null +++ b/app/store/controller/store_product_attr_value/StoreProductAttrValueController.php @@ -0,0 +1,95 @@ +dataLists(new StoreProductAttrValueLists()); + } + + + /** + * @notes 添加商品属性值 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function add() + { + $params = (new StoreProductAttrValueValidate())->post()->goCheck('add'); + $result = StoreProductAttrValueLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreProductAttrValueLogic::getError()); + } + + + /** + * @notes 编辑商品属性值 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function edit() + { + $params = (new StoreProductAttrValueValidate())->post()->goCheck('edit'); + $result = StoreProductAttrValueLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreProductAttrValueLogic::getError()); + } + + + /** + * @notes 删除商品属性值 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function delete() + { + $params = (new StoreProductAttrValueValidate())->post()->goCheck('delete'); + StoreProductAttrValueLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品属性值详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 14:10 + */ + public function detail() + { + $params = (new StoreProductAttrValueValidate())->goCheck('detail'); + $result = StoreProductAttrValueLogic::detail($params); + return $this->data($result); + } + + +} diff --git a/app/store/lists/BaseAdminDataLists.php b/app/store/lists/BaseAdminDataLists.php new file mode 100644 index 000000000..e3ae4f7f5 --- /dev/null +++ b/app/store/lists/BaseAdminDataLists.php @@ -0,0 +1,39 @@ +adminInfo = $this->request->adminInfo; + $this->adminId = $this->request->adminId; + } + + +} diff --git a/app/store/lists/auth/AdminLists.php b/app/store/lists/auth/AdminLists.php new file mode 100644 index 000000000..df53a646b --- /dev/null +++ b/app/store/lists/auth/AdminLists.php @@ -0,0 +1,206 @@ + '账号', + 'name' => '名称', + 'role_name' => '角色', + 'dept_name' => '部门', + 'create_time' => '创建时间', + 'login_time' => '最近登录时间', + 'login_ip' => '最近登录IP', + 'disable_desc' => '状态', + ]; + } + + + /** + * @notes 设置导出文件名 + * @return string + * @author 乔峰 + * @date 2021/12/29 10:08 + */ + public function setFileName(): string + { + return '管理员列表'; + } + + + /** + * @notes 设置搜索条件 + * @return \string[][] + * @author 乔峰 + * @date 2021/12/29 10:07 + */ + public function setSearch(): array + { + return [ + '%like%' => ['name', 'account'], + ]; + } + + + /** + * @notes 设置支持排序字段 + * @return string[] + * @author 乔峰 + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['create_time' => 'create_time', 'id' => 'id']; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @author 乔峰 + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['id' => 'desc']; + } + + /** + * @notes 查询条件 + * @return array + * @author 乔峰 + * @date 2022/11/29 11:33 + */ + public function queryWhere() + { + $where = []; + if (isset($this->params['role_id']) && $this->params['role_id'] != '') { + $adminIds = AdminRole::where('role_id', $this->params['role_id'])->column('admin_id'); + if (!empty($adminIds)) { + $where[] = ['id', 'in', $adminIds]; + } + } + return $where; + } + + + /** + * @notes 获取管理列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/12/29 10:05 + */ + public function lists(): array + { + $field = [ + 'id', 'name', 'account', 'create_time', 'disable', 'root', + 'login_time', 'login_ip', 'multipoint_login', 'avatar' + ]; + + $adminLists = Admin::field($field) + ->where($this->searchWhere) + ->where($this->queryWhere()) + ->limit($this->limitOffset, $this->limitLength) + ->order($this->sortOrder) + ->append(['role_id', 'dept_id', 'jobs_id', 'disable_desc']) + ->select() + ->toArray(); + + // 角色数组('角色id'=>'角色名称') + $roleLists = SystemRole::column('name', 'id'); + // 部门列表 + $deptLists = Dept::column('name', 'id'); + // 岗位列表 + // $jobsLists = Jobs::column('name', 'id'); + + //管理员列表增加角色名称 + foreach ($adminLists as $k => $v) { + $roleName = ''; + if ($v['root'] == 1) { + $roleName = '系统管理员'; + } else { + foreach ($v['role_id'] as $roleId) { + $roleName .= $roleLists[$roleId] ?? ''; + $roleName .= '/'; + } + } + + $deptName = ''; + foreach ($v['dept_id'] as $deptId) { + $deptName .= $deptLists[$deptId] ?? ''; + $deptName .= '/'; + } + + $jobsName = ''; + foreach ($v['jobs_id'] as $jobsId) { + $jobsName .= $jobsLists[$jobsId] ?? ''; + $jobsName .= '/'; + } + + $adminLists[$k]['role_name'] = trim($roleName, '/'); + $adminLists[$k]['dept_name'] = trim($deptName, '/'); + $adminLists[$k]['jobs_name'] = trim($jobsName, '/'); + } + + return $adminLists; + } + + /** + * @notes 获取数量 + * @return int + * @author 乔峰 + * @date 2021/7/13 00:52 + */ + public function count(): int + { + return Admin::where($this->searchWhere) + ->where($this->queryWhere()) + ->count(); + } + + public function extend() + { + return []; + } +} diff --git a/app/store/lists/auth/MenuLists.php b/app/store/lists/auth/MenuLists.php new file mode 100644 index 000000000..aa86ffb90 --- /dev/null +++ b/app/store/lists/auth/MenuLists.php @@ -0,0 +1,58 @@ + 'desc', 'id' => 'asc']) + ->select() + ->toArray(); + return linear_to_tree($lists, 'children'); + } + + + /** + * @notes 获取菜单数量 + * @return int + * @author 乔峰 + * @date 2022/6/29 16:41 + */ + public function count(): int + { + return SystemMenu::count(); + } + +} diff --git a/app/store/lists/auth/RoleLists.php b/app/store/lists/auth/RoleLists.php new file mode 100644 index 000000000..de42e1205 --- /dev/null +++ b/app/store/lists/auth/RoleLists.php @@ -0,0 +1,93 @@ + '角色名称', + 'desc' => '备注', + 'create_time' => '创建时间' + ]; + } + + /** + * @notes 导出表名 + * @return string + * @author Tab + * @date 2021/9/22 18:52 + */ + public function setFileName(): string + { + return '角色表'; + } + + /** + * @notes 角色列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author cjhao + * @date 2021/8/25 18:00 + */ + public function lists(): array + { + $lists = SystemRole::with(['role_menu_index']) + ->field('id,name,desc,sort,create_time') + ->limit($this->limitOffset, $this->limitLength) + ->order(['sort' => 'desc', 'id' => 'desc']) + ->select() + ->toArray(); + + foreach ($lists as $key => $role) { + //使用角色的人数 + $lists[$key]['num'] = AdminRole::where('role_id', $role['id'])->count(); + $menuId = array_column($role['role_menu_index'], 'menu_id'); + $lists[$key]['menu_id'] = $menuId; + unset($lists[$key]['role_menu_index']); + } + + return $lists; + } + + /** + * @notes 总记录数 + * @return int + * @author Tab + * @date 2021/7/13 11:26 + */ + public function count(): int + { + return SystemRole::count(); + } +} diff --git a/app/store/lists/store_order/StoreOrderLists.php b/app/store/lists/store_order/StoreOrderLists.php new file mode 100644 index 000000000..9a1fcf9ea --- /dev/null +++ b/app/store/lists/store_order/StoreOrderLists.php @@ -0,0 +1,65 @@ + ['order_id', 'pay_type'], + ]; + } + + + /** + * @notes 获取订单列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:02 + */ + public function lists(): array + { + return StoreOrder::where($this->searchWhere) + ->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取订单列表数量 + * @return int + * @author admin + * @date 2024/05/31 16:02 + */ + public function count(): int + { + return StoreOrder::where($this->searchWhere)->count(); + } + +} diff --git a/app/store/lists/store_product/StoreProductLists.php b/app/store/lists/store_product/StoreProductLists.php new file mode 100644 index 000000000..252a93561 --- /dev/null +++ b/app/store/lists/store_product/StoreProductLists.php @@ -0,0 +1,69 @@ + ['store_name', 'cate_id'], + ]; + } + + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function lists(): array + { + return StoreProduct::where($this->searchWhere) + ->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); + $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function count(): int + { + return StoreProduct::where($this->searchWhere)->count(); + } +} diff --git a/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php b/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php new file mode 100644 index 000000000..c0b68ea81 --- /dev/null +++ b/app/store/lists/store_product_attr_value/StoreProductAttrValueLists.php @@ -0,0 +1,65 @@ + ['product_id'], + ]; + } + + + /** + * @notes 获取商品属性值列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 14:10 + */ + public function lists(): array + { + return StoreProductAttrValue::where($this->searchWhere) + ->field(['id', 'product_id']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取商品属性值数量 + * @return int + * @author admin + * @date 2024/05/31 14:10 + */ + public function count(): int + { + return StoreProductAttrValue::where($this->searchWhere)->count(); + } + +} diff --git a/app/store/lists/store_product_unit/StoreProductUnitLists.php b/app/store/lists/store_product_unit/StoreProductUnitLists.php new file mode 100644 index 000000000..6eadc7156 --- /dev/null +++ b/app/store/lists/store_product_unit/StoreProductUnitLists.php @@ -0,0 +1,65 @@ + ['name'], + ]; + } + + + /** + * @notes 获取计量单位列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 15:50 + */ + public function lists(): array + { + return StoreProductUnit::where($this->searchWhere) + ->field(['id', 'name', 'is_bulk', 'py', 'number', 'data']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取计量单位数量 + * @return int + * @author admin + * @date 2024/05/31 15:50 + */ + public function count(): int + { + return StoreProductUnit::where($this->searchWhere)->count(); + } + +} diff --git a/app/store/logic/LoginLogic.php b/app/store/logic/LoginLogic.php new file mode 100644 index 000000000..a0c522e8b --- /dev/null +++ b/app/store/logic/LoginLogic.php @@ -0,0 +1,95 @@ +find(); + if($params['is_admin'] == 0 &&$admin){ + $auth_shop=Db::name('user_auth_shop')->where(['admin_id'=>$admin['id'],'status'=>1,'apply_status'=>1,'type'=>2])->find(); + if(!$auth_shop){ + throw new MyBusinessException('该账户没有权限'); + } + } + if($admin &&$params['is_admin'] == 1){ + $role_find=AdminRole::where('admin_id',$admin['id'])->where('role_id',1)->find(); + if($role_find) throw new MyBusinessException('请使用供应商后台登录'); + } + //用户表登录信息更新 + $admin->login_time = $time; + $admin->login_ip = request()->getLocalIp(); + $admin->save(); + //设置token + $adminInfo = AdminTokenService::setToken($admin->id, $params['terminal'], $admin->multipoint_login); + + //返回登录信息 + $avatar = $admin->avatar ? $admin->avatar : Config::get('project.default_image.admin_avatar'); + $avatar = FileService::getFileUrl($avatar); + return [ + 'name' => $adminInfo['name'], + 'avatar' => $avatar, + 'role_name' => $adminInfo['role_name'], + 'token' => $adminInfo['token'], + ]; + } + + + /** + * @notes 退出登录 + * @param $adminInfo + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/7/5 14:34 + */ + public function logout($adminInfo) + { + //token不存在,不注销 + if (!isset($adminInfo['token'])) { + return false; + } + //设置token过期 + return AdminTokenService::expireToken($adminInfo['token']); + } +} diff --git a/app/store/logic/WorkbenchLogic.php b/app/store/logic/WorkbenchLogic.php new file mode 100644 index 000000000..66948b847 --- /dev/null +++ b/app/store/logic/WorkbenchLogic.php @@ -0,0 +1,198 @@ + self::versionInfo(), + // 今日数据 + 'today' => self::today(), + // 常用功能 + 'menu' => self::menu(), + // 近15日访客数 + 'visitor' => self::visitor(), + // 服务支持 + 'support' => self::support() + ]; + } + + + /** + * @notes 常用功能 + * @return array[] + * @author 乔峰 + * @date 2021/12/29 16:40 + */ + public static function menu(): array + { + return [ + [ + 'name' => '管理员', + 'image' => FileService::getFileUrl(config('project.default_image.menu_admin')), + 'url' => '/permission/admin' + ], + [ + 'name' => '角色管理', + 'image' => FileService::getFileUrl(config('project.default_image.menu_role')), + 'url' => '/permission/role' + ], + [ + 'name' => '部门管理', + 'image' => FileService::getFileUrl(config('project.default_image.menu_dept')), + 'url' => '/organization/department' + ], + [ + 'name' => '素材中心', + 'image' => FileService::getFileUrl(config('project.default_image.menu_file')), + 'url' => '/material/index' + ], + [ + 'name' => '菜单权限', + 'image' => FileService::getFileUrl(config('project.default_image.menu_auth')), + 'url' => '/permission/menu' + ], + [ + 'name' => '网站信息', + 'image' => FileService::getFileUrl(config('project.default_image.menu_web')), + 'url' => '/setting/website/information' + ], + ]; + } + + + /** + * @notes 版本信息 + * @return array + * @author 乔峰 + * @date 2021/12/29 16:08 + */ + public static function versionInfo(): array + { + return [ + 'version' => config('project.version'), + 'website' => config('project.website.url'), + 'name' => ConfigService::get('website', 'name'), + 'based' => 'vue3.x、ElementUI、MySQL', + 'channel' => [ + 'website' => 'https://gitee.com/MuZJun/gather-admin.git', + 'gitee' => 'https://gitee.com/MuZJun/gather-vue.git', + ] + ]; + } + + + /** + * @notes 今日数据 + * @return int[] + * @author 乔峰 + * @date 2021/12/29 16:15 + */ + public static function today(): array + { + return [ + 'time' => date('Y-m-d H:i:s'), + // 今日销售额 + 'today_sales' => 100, + // 总销售额 + 'total_sales' => 1000, + + // 今日访问量 + 'today_visitor' => 10, + // 总访问量 + 'total_visitor' => 100, + + // 今日新增用户量 + 'today_new_user' => 30, + // 总用户量 + 'total_new_user' => 3000, + + // 订单量 (笔) + 'order_num' => 12, + // 总订单量 + 'order_sum' => 255 + ]; + } + + + /** + * @notes 访问数 + * @return array + * @author 乔峰 + * @date 2021/12/29 16:57 + */ + public static function visitor(): array + { + $num = []; + $date = []; + for ($i = 0; $i < 15; $i++) { + $where_start = strtotime("- " . $i . "day"); + $date[] = date('Y/m/d', $where_start); + $num[$i] = rand(0, 100); + } + + return [ + 'date' => $date, + 'list' => [ + ['name' => '访客数', 'data' => $num] + ] + ]; + } + + + /** + * @notes 服务支持 + * @return array[] + * @author 乔峰 + * @date 2022/7/18 11:18 + */ + public static function support() + { + return [ + [ + 'image' => FileService::getFileUrl(config('project.default_image.qq_group')), + 'title' => '官方公众号', + 'desc' => '关注官方公众号', + ], + [ + 'image' => FileService::getFileUrl(config('project.default_image.customer_service')), + 'title' => '添加企业客服微信', + 'desc' => '想了解更多请添加客服', + ] + ]; + } + +} diff --git a/app/store/logic/auth/AdminLogic.php b/app/store/logic/auth/AdminLogic.php new file mode 100644 index 000000000..174fd8c8d --- /dev/null +++ b/app/store/logic/auth/AdminLogic.php @@ -0,0 +1,340 @@ + $params['name'], + 'account' => $params['account'], + 'avatar' => $avatar, + 'password' => $password, + 'create_time' => time(), + 'disable' => $params['disable'], + 'multipoint_login' => $params['multipoint_login'], + ]); + + // 角色 + self::insertRole($admin['id'], $params['role_id'] ?? []); + // 部门 + self::insertDept($admin['id'], $params['dept_id'] ?? []); + // 岗位 + self::insertJobs($admin['id'], $params['jobs_id'] ?? []); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑管理员 + * @param array $params + * @return bool + * @author 乔峰 + * @date 2021/12/29 10:43 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + // 基础信息 + $data = [ + 'id' => $params['id'], + 'name' => $params['name'], + 'account' => $params['account'], + 'disable' => $params['disable'], + 'multipoint_login' => $params['multipoint_login'] + ]; + + // 头像 + $data['avatar'] = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : ''; + + // 密码 + if (!empty($params['password'])) { + $passwordSalt = Config::get('project.unique_identification'); + $data['password']=create_password($params['password'], $passwordSalt); + // $data['password'] = password_hash($params['password'],PASSWORD_DEFAULT); + } + + // 禁用或更换角色后.设置token过期 + $roleId = AdminRole::where('admin_id', $params['id'])->column('role_id'); + $editRole = false; + if (!empty(array_diff_assoc($roleId, $params['role_id']))) { + $editRole = true; + } + + if ($params['disable'] == 1 || $editRole) { + $tokenArr = AdminSession::where('admin_id', $params['id'])->select()->toArray(); + foreach ($tokenArr as $token) { + self::expireToken($token['token']); + } + } + + Admin::update($data); + (new AdminAuthCache($params['id']))->clearAuthCache(); + + // 删除旧的关联信息 + AdminRole::delByUserId($params['id']); + AdminDept::delByUserId($params['id']); + AdminJobs::delByUserId($params['id']); + // 角色 + self::insertRole($params['id'], $params['role_id']); + // 部门 + self::insertDept($params['id'], $params['dept_id'] ?? []); + // 岗位 + self::insertJobs($params['id'], $params['jobs_id'] ?? []); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除管理员 + * @param array $params + * @return bool + * @author 乔峰 + * @date 2021/12/29 10:45 + */ + public static function delete(array $params): bool + { + Db::startTrans(); + try { + $admin = Admin::findOrEmpty($params['id']); + if ($admin->root == YesNoEnum::YES) { + throw new \Exception("超级管理员不允许被删除"); + } + Admin::destroy($params['id']); + + //设置token过期 + $tokenArr = AdminSession::where('admin_id', $params['id'])->select()->toArray(); + foreach ($tokenArr as $token) { + self::expireToken($token['token']); + } + (new AdminAuthCache($params['id']))->clearAuthCache(); + + // 删除旧的关联信息 + AdminRole::delByUserId($params['id']); + AdminDept::delByUserId($params['id']); + AdminJobs::delByUserId($params['id']); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 过期token + * @param $token + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/12/29 10:46 + */ + public static function expireToken($token): bool + { + $adminSession = AdminSession::where('token', '=', $token) + ->with('admin') + ->find(); + + if (empty($adminSession)) { + return false; + } + + $time = time(); + $adminSession->expire_time = $time; + $adminSession->update_time = $time; + $adminSession->save(); + + return (new AdminTokenCache())->deleteAdminInfo($token); + } + + + /** + * @notes 查看管理员详情 + * @param $params + * @return array + * @author 乔峰 + * @date 2021/12/29 11:07 + */ + public static function detail($params, $action = 'detail'): array + { + $admin = Admin::field([ + 'id', 'account', 'name', 'disable', 'root', + 'multipoint_login', 'avatar', + ])->findOrEmpty($params['id'])->toArray(); + + if ($action == 'detail') { + return $admin; + } + + $result['user'] = $admin; + // 当前管理员角色拥有的菜单 + $result['menu'] = MenuLogic::getMenuByAdminId($params['id']); + // 当前管理员橘色拥有的按钮权限 + $result['permissions'] = AuthLogic::getBtnAuthByRoleId($admin); + return $result; + } + + + /** + * @notes 编辑超级管理员 + * @param $params + * @return Admin + * @author 乔峰 + * @date 2022/4/8 17:54 + */ + public static function editSelf($params) + { + $data = [ + 'id' => $params['admin_id'], + 'name' => $params['name'], + 'avatar' => FileService::setFileUrl($params['avatar']), + ]; + + if (!empty($params['password'])) { + $passwordSalt = Config::get('project.unique_identification'); + $data['password']=create_password($params['password'], $passwordSalt); + // $data['password'] = password_hash($params['password'],PASSWORD_DEFAULT); + } + + return Admin::update($data); + } + + + /** + * @notes 新增角色 + * @param $adminId + * @param $roleIds + * @throws \Exception + * @author 乔峰 + * @date 2022/11/25 14:23 + */ + public static function insertRole($adminId, $roleIds) + { + if (!empty($roleIds)) { + // 角色 + $roleData = []; + foreach ($roleIds as $roleId) { + $roleData[] = [ + 'admin_id' => $adminId, + 'role_id' => $roleId, + ]; + } + (new AdminRole())->saveAll($roleData); + } + } + + + /** + * @notes 新增部门 + * @param $adminId + * @param $deptIds + * @throws \Exception + * @author 乔峰 + * @date 2022/11/25 14:22 + */ + public static function insertDept($adminId, $deptIds) + { + // 部门 + if (!empty($deptIds)) { + $deptData = []; + foreach ($deptIds as $deptId) { + $deptData[] = [ + 'admin_id' => $adminId, + 'dept_id' => $deptId + ]; + } + (new AdminDept())->saveAll($deptData); + } + } + + + /** + * @notes 新增岗位 + * @param $adminId + * @param $jobsIds + * @throws \Exception + * @author 乔峰 + * @date 2022/11/25 14:22 + */ + public static function insertJobs($adminId, $jobsIds) + { + // 岗位 + if (!empty($jobsIds)) { + $jobsData = []; + foreach ($jobsIds as $jobsId) { + $jobsData[] = [ + 'admin_id' => $adminId, + 'jobs_id' => $jobsId + ]; + } + (new AdminJobs())->saveAll($jobsData); + } + } + +} diff --git a/app/store/logic/auth/AuthLogic.php b/app/store/logic/auth/AuthLogic.php new file mode 100644 index 000000000..602d50714 --- /dev/null +++ b/app/store/logic/auth/AuthLogic.php @@ -0,0 +1,105 @@ +where([ + ['is_disable', '=', 0], + ['perms', '<>', ''] + ]) + ->column('perms'); + } + + + /** + * @notes 获取当前管理员角色按钮权限 + * @param $roleId + * @return mixed + * @author 乔峰 + * @date 2022/7/1 16:10 + */ + public static function getBtnAuthByRoleId($admin) + { + if ($admin['root']) { + return ['*']; + } + + $menuId = SystemRoleMenu::whereIn('role_id', $admin['role_id']) + ->column('menu_id'); + + $where[] = ['is_disable', '=', 0]; + $where[] = ['perms', '<>', '']; + + $roleAuth = SystemMenu::distinct(true) + ->where('id', 'in', $menuId) + ->where($where) + ->column('perms'); + + $allAuth = SystemMenu::distinct(true) + ->where($where) + ->column('perms'); + + $hasAllAuth = array_diff($allAuth, $roleAuth); + if (empty($hasAllAuth)) { + return ['*']; + } + + return $roleAuth; + } + + + /** + * @notes 获取管理员角色关联的菜单id(菜单,权限) + * @param int $adminId + * @return array + * @author 乔峰 + * @date 2022/7/1 15:56 + */ + public static function getAuthByAdminId(int $adminId): array + { + $roleIds = AdminRole::where('admin_id', $adminId)->column('role_id'); + $menuId = SystemRoleMenu::whereIn('role_id', $roleIds)->column('menu_id'); + + return SystemMenu::distinct(true) + ->where([ + ['is_disable', '=', 0], + ['perms', '<>', ''], + ['id', 'in', array_unique($menuId)], + ]) + ->column('perms'); + } +} diff --git a/app/store/logic/auth/MenuLogic.php b/app/store/logic/auth/MenuLogic.php new file mode 100644 index 000000000..b18c7e102 --- /dev/null +++ b/app/store/logic/auth/MenuLogic.php @@ -0,0 +1,184 @@ +column('menu_id'); + $where[] = ['id', 'in', $roleMenu]; + } + + $menu = SystemMenu::where($where) + ->order(['sort' => 'desc', 'id' => 'asc']) + ->select(); + + return linear_to_tree($menu, 'children'); + } + + + /** + * @notes 添加菜单 + * @param array $params + * @return SystemMenu|\think\Model + * @author 乔峰 + * @date 2022/6/30 10:06 + */ + public static function add(array $params) + { + return SystemMenu::create([ + 'pid' => $params['pid'], + 'type' => $params['type'], + 'name' => $params['name'], + 'icon' => $params['icon'] ?? '', + 'sort' => $params['sort'], + 'perms' => $params['perms'] ?? '', + 'paths' => $params['paths'] ?? '', + 'component' => $params['component'] ?? '', + 'selected' => $params['selected'] ?? '', + 'params' => $params['params'] ?? '', + 'is_cache' => $params['is_cache'], + 'is_show' => $params['is_show'], + 'is_disable' => $params['is_disable'], + ]); + } + + + /** + * @notes 编辑菜单 + * @param array $params + * @return SystemMenu + * @author 乔峰 + * @date 2022/6/30 10:07 + */ + public static function edit(array $params) + { + return SystemMenu::update([ + 'id' => $params['id'], + 'pid' => $params['pid'], + 'type' => $params['type'], + 'name' => $params['name'], + 'icon' => $params['icon'] ?? '', + 'sort' => $params['sort'], + 'perms' => $params['perms'] ?? '', + 'paths' => $params['paths'] ?? '', + 'component' => $params['component'] ?? '', + 'selected' => $params['selected'] ?? '', + 'params' => $params['params'] ?? '', + 'is_cache' => $params['is_cache'], + 'is_show' => $params['is_show'], + 'is_disable' => $params['is_disable'], + ]); + } + + + /** + * @notes 详情 + * @param $params + * @return array + * @author 乔峰 + * @date 2022/6/30 9:54 + */ + public static function detail($params) + { + return SystemMenu::findOrEmpty($params['id'])->toArray(); + } + + + /** + * @notes 删除菜单 + * @param $params + * @author 乔峰 + * @date 2022/6/30 9:47 + */ + public static function delete($params) + { + // 删除菜单 + SystemMenu::destroy($params['id']); + // 删除角色-菜单表中 与该菜单关联的记录 + SystemRoleMenu::where(['menu_id' => $params['id']])->delete(); + } + + + /** + * @notes 更新状态 + * @param array $params + * @return SystemMenu + * @author 乔峰 + * @date 2022/7/6 17:02 + */ + public static function updateStatus(array $params) + { + return SystemMenu::update([ + 'id' => $params['id'], + 'is_disable' => $params['is_disable'] + ]); + } + + + /** + * @notes 全部数据 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2022/10/13 11:03 + */ + public static function getAllData() + { + $data = SystemMenu::where(['is_disable' => YesNoEnum::NO]) + ->field('id,pid,name') + ->order(['sort' => 'desc', 'id' => 'desc']) + ->select() + ->toArray(); + + return linear_to_tree($data, 'children'); + } + +} diff --git a/app/store/logic/auth/RoleLogic.php b/app/store/logic/auth/RoleLogic.php new file mode 100644 index 000000000..e0113d50b --- /dev/null +++ b/app/store/logic/auth/RoleLogic.php @@ -0,0 +1,170 @@ + $params['name'], + 'desc' => $params['desc'] ?? '', + 'sort' => $params['sort'] ?? 0, + ]); + + $data = []; + foreach ($menuId as $item) { + if (empty($item)) { + continue; + } + $data[] = [ + 'role_id' => $role['id'], + 'menu_id' => $item, + ]; + } + (new SystemRoleMenu)->insertAll($data); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::$error = $e->getMessage(); + return false; + } + } + + + /** + * @notes 编辑角色 + * @param array $params + * @return bool + * @author 乔峰 + * @date 2021/12/29 14:16 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $menuId = !empty($params['menu_id']) ? $params['menu_id'] : []; + + SystemRole::update([ + 'id' => $params['id'], + 'name' => $params['name'], + 'desc' => $params['desc'] ?? '', + 'sort' => $params['sort'] ?? 0, + ]); + + if (!empty($menuId)) { + SystemRoleMenu::where(['role_id' => $params['id']])->delete(); + $data = []; + foreach ($menuId as $item) { + $data[] = [ + 'role_id' => $params['id'], + 'menu_id' => $item, + ]; + } + (new SystemRoleMenu)->insertAll($data); + } + + (new AdminAuthCache())->deleteTag(); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::$error = $e->getMessage(); + return false; + } + } + + /** + * @notes 删除角色 + * @param int $id + * @return bool + * @author 乔峰 + * @date 2021/12/29 14:16 + */ + public static function delete(int $id) + { + SystemRole::destroy(['id' => $id]); + (new AdminAuthCache())->deleteTag(); + return true; + } + + + /** + * @notes 角色详情 + * @param int $id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/12/29 14:17 + */ + public static function detail(int $id): array + { + $detail = SystemRole::field('id,name,desc,sort')->find($id); + $authList = $detail->roleMenuIndex()->select()->toArray(); + $menuId = array_column($authList, 'menu_id'); + $detail['menu_id'] = $menuId; + return $detail->toArray(); + } + + + /** + * @notes 角色数据 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2022/10/13 10:39 + */ + public static function getAllData() + { + return SystemRole::order(['sort' => 'desc', 'id' => 'desc']) + ->select() + ->toArray(); + } + + +} diff --git a/app/store/logic/store_order/StoreOrderLogic.php b/app/store/logic/store_order/StoreOrderLogic.php new file mode 100644 index 000000000..f8808002c --- /dev/null +++ b/app/store/logic/store_order/StoreOrderLogic.php @@ -0,0 +1,94 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑订单列表 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 16:02 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreOrder::where('id', $params['id'])->update([ + + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除订单列表 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 16:02 + */ + public static function delete(array $params): bool + { + return StoreOrder::destroy($params['id']); + } + + + /** + * @notes 获取订单列表详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 16:02 + */ + public static function detail($params): array + { + return StoreOrder::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/app/store/logic/store_product/StoreProductLogic.php b/app/store/logic/store_product/StoreProductLogic.php new file mode 100644 index 000000000..1dd27998d --- /dev/null +++ b/app/store/logic/store_product/StoreProductLogic.php @@ -0,0 +1,148 @@ + $params['store_name'], + 'image' => $params['image'], + 'bar_code' => $params['bar_code'] ?? '', + 'cate_id' => $params['cate_id'], + 'unit' => $params['unit'], + 'stock' => $params['stock'], + 'cost' => $params['cost'], + 'purchase' => $params['purchase'], + 'rose' => $params['rose'], + ]; + $rose_price = bcmul($params['cost'], $params['rose'], 2); + $data['price'] = bcadd($params['cost'], $rose_price, 2); + $res = StoreProduct::create($data); + StoreProductAttrValue::create([ + "bar_code" => $params["bar_code"] ?? '', + "image" => $params["image"] ?? '', + "cost" => $params['cost'], + "purchase" => $params['purchase'], + "unit" => $params["unit"], + "price" => $data['price'], + "stock" => $params['stock'], + "product_id" => $res['id'], + "unique" => setUnique($res['id'], '', 0), + 'sales' => 0, + ]); + StoreCategory::where('id', $params['cate_id'])->inc('three')->update(); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + $StoreProduct = StoreProduct::where('id', $params['id'])->find(); + try { + if ($StoreProduct['cate_id'] != $params['cate_id']) { + StoreCategory::where('id', $params['cate_id'])->inc('three')->update(); + StoreCategory::where('id', $StoreProduct['cate_id'])->dec('three')->update(); + } + StoreProduct::where('id', $params['id'])->update([ + 'store_name' => $params['store_name'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function delete(array $params): bool + { + return StoreProduct::destroy($params['id']); + } + + + /** + * @notes 获取商品列表详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function detail($params): array + { + return StoreProduct::findOrEmpty($params['id'])->toArray(); + } + + /** + * 更新商品分类 + */ + public static function updateGoodsclass($id, $type = 0) + { + $pid = StoreCategory::where('id', $id)->value('pid'); + if ($pid) { + $goodsclass = StoreCategory::where('id', $pid)->field('pid,children')->find(); + if ($goodsclass) { + if (count($goodsclass['children']) >= 1) { + if (!in_array($id, $goodsclass['children'])) { + $arr = $goodsclass['children']; + array_push($arr, $id); + StoreCategory::where('id', $pid)->update(['children' => $arr]); + if ($goodsclass['pid'] != 0 && $type == 0) { + self::updateGoodsclass($pid, 1); + } + } + } + } + } + } +} diff --git a/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php b/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php new file mode 100644 index 000000000..2520412a2 --- /dev/null +++ b/app/store/logic/store_product_attr_value/StoreProductAttrValueLogic.php @@ -0,0 +1,94 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑商品属性值 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 14:10 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreProductAttrValue::where('id', $params['id'])->update([ + + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除商品属性值 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 14:10 + */ + public static function delete(array $params): bool + { + return StoreProductAttrValue::destroy($params['id']); + } + + + /** + * @notes 获取商品属性值详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 14:10 + */ + public static function detail($params): array + { + return StoreProductAttrValue::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/app/store/middleware/AuthMiddleware.php b/app/store/middleware/AuthMiddleware.php new file mode 100644 index 000000000..f72999a6b --- /dev/null +++ b/app/store/middleware/AuthMiddleware.php @@ -0,0 +1,63 @@ +controllerObject->isNotNeedLogin()) { + return $handler($request); + } + + //系统默认超级管理员,无需权限验证 + if (1 === $request->adminInfo['root']) { + return $handler($request); + } + + $adminAuthCache = new AdminAuthCache($request->adminInfo['admin_id']); + + // 当前访问路径 + $accessUri = strtolower($request->controller . '/' . $request->action); + // 全部路由 + $allUri = $this->formatUrl($adminAuthCache->getAllUri()); + + // 判断该当前访问的uri是否存在,不存在无需验证 + if (!in_array($accessUri, $allUri)) { + return $handler($request); + } + + // 当前管理员拥有的路由权限 + $AdminUris = $adminAuthCache->getAdminUri() ?? []; + $AdminUris = $this->formatUrl($AdminUris); + + if (in_array($accessUri, $AdminUris)) { + return $handler($request); + } + return JsonService::fail('权限不足,无法访问或操作'); + } + + /** + * @notes 格式化URL + * @param array $data + * @return array|string[] + * @author 乔峰 + * @date 2022/7/7 15:39 + */ + public function formatUrl(array $data) + { + return array_map(function ($item) { + return strtolower(Str::camel($item)); + }, $data); + } +} diff --git a/app/store/middleware/InitMiddleware.php b/app/store/middleware/InitMiddleware.php new file mode 100644 index 000000000..fd19b0aae --- /dev/null +++ b/app/store/middleware/InitMiddleware.php @@ -0,0 +1,35 @@ +controller); + $controllerClass = new $controller; + if (($controllerClass instanceof BaseAdminController) === false) { + throw new ControllerExtendException($controller, '404'); + } + } catch (ClassNotFoundException $e) { + throw new HttpException(404, 'controller not exists:' . $e->getClass()); + } + + //创建控制器对象 + $request->controllerObject = new $controller; + + return $handler($request); + } +} diff --git a/app/store/middleware/LoginMiddleware.php b/app/store/middleware/LoginMiddleware.php new file mode 100644 index 000000000..95998a2a5 --- /dev/null +++ b/app/store/middleware/LoginMiddleware.php @@ -0,0 +1,65 @@ +header('token'); +// $controller = str_replace('.', '\\', $request->controller); + //判断接口是否免登录 + $isNotNeedLogin = $request->controllerObject->isNotNeedLogin(); + + //不直接判断$isNotNeedLogin结果,使不需要登录的接口通过,为了兼容某些接口可以登录或不登录访问 + if (empty($token) && !$isNotNeedLogin) { + //没有token并且该地址需要登录才能访问 + return JsonService::fail('请求参数缺token', [], 0, 0); + } + + $adminInfo = (new AdminTokenCache())->getAdminInfo($token); + if (empty($adminInfo) && !$isNotNeedLogin) { + //token过期无效并且该地址需要登录才能访问 + return JsonService::fail('登录超时,请重新登录', [], -1); + } + + //token临近过期,自动续期 + if ($adminInfo) { + //获取临近过期自动续期时长 + $beExpireDuration = Config::get('project.admin_token.be_expire_duration'); + //token续期 + if (time() > ($adminInfo['expire_time'] - $beExpireDuration)) { + $result = AdminTokenService::overtimeToken($token); + //续期失败(数据表被删除导致) + if (empty($result)) { + return JsonService::fail('登录过期', [], -1); + } + } + } + + //给request赋值,用于控制器 + $request->adminInfo = $adminInfo; + $request->adminId = $adminInfo['admin_id'] ?? 0; + $request->supplierId = $adminInfo['supplier_id'] ?? 0; + + return $handler($request); + } +} diff --git a/app/store/service/AdminTokenService.php b/app/store/service/AdminTokenService.php new file mode 100644 index 000000000..0041efce6 --- /dev/null +++ b/app/store/service/AdminTokenService.php @@ -0,0 +1,116 @@ +find(); + + //获取token延长过期的时间 + $expireTime = $time + Config::get('project.admin_token.expire_duration'); + + $adminTokenCache = new AdminTokenCache(); + + //token处理 + if ($adminSession) { + if ($adminSession->expire_time < $time || $multipointLogin === 0) { + //清空缓存 + $adminTokenCache->deleteAdminInfo($adminSession->token); + //如果token过期或账号设置不支持多处登录,更新token + $adminSession->token = create_token($adminId); + } + $adminSession->expire_time = $expireTime; + $adminSession->update_time = $time; + + $adminSession->save(); + } else { + //找不到在该终端的token记录,创建token记录 + $adminSession = AdminSession::create([ + 'admin_id' => $adminId, + 'terminal' => $terminal, + 'token' => create_token($adminId), + 'expire_time' => $expireTime + ]); + } + + return $adminTokenCache->setAdminInfo($adminSession->token); + } + + /** + * @notes 延长token过期时间 + * @param $token + * @return array|false|mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/7/5 14:25 + */ + public static function overtimeToken($token) + { + $time = time(); + $adminSession = AdminSession::where('token', '=', $token)->findOrEmpty(); + if ($adminSession->isEmpty()) { + return false; + } + //延长token过期时间 + $adminSession->expire_time = $time + Config::get('project.admin_token.expire_duration'); + $adminSession->update_time = $time; + $adminSession->save(); + return (new AdminTokenCache())->setAdminInfo($adminSession->token); + } + + /** + * @notes 设置token为过期 + * @param $token + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/7/5 14:31 + */ + public static function expireToken($token) + { + $adminSession = AdminSession::where('token', '=', $token) + ->with('admin') + ->findOrEmpty(); + + if ($adminSession->isEmpty()) { + return false; + } + + //当支持多处登录的时候,服务端不注销 + if ($adminSession->admin->multipoint_login === 1) { + return false; + } + + $time = time(); + $adminSession->expire_time = $time; + $adminSession->update_time = $time; + $adminSession->save(); + + return (new AdminTokenCache())->deleteAdminInfo($token); + } +} diff --git a/app/store/validate/LoginValidate.php b/app/store/validate/LoginValidate.php new file mode 100644 index 000000000..c94e79553 --- /dev/null +++ b/app/store/validate/LoginValidate.php @@ -0,0 +1,85 @@ + 'require|in:' . AdminTerminalEnum::PC . ',' . AdminTerminalEnum::MOBILE, + 'account' => 'require', + 'password' => 'require|password', + ]; + + protected $message = [ + 'account.require' => '请输入账号', + 'password.require' => '请输入密码' + ]; + + /** + * @notes @notes 密码验证 + * @param $password + * @param $other + * @param $data + * @return bool|string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/7/2 14:00 + */ + public function password($password, $other, $data) + { + // 登录限制 + $config = [ + 'login_restrictions' => ConfigService::get('admin_login', 'login_restrictions'), + 'password_error_times' => ConfigService::get('admin_login', 'password_error_times'), + 'limit_login_time' => ConfigService::get('admin_login', 'limit_login_time'), + ]; + + $adminAccountSafeCache = new AdminAccountSafeCache(); + if ($config['login_restrictions'] == 1) { + $adminAccountSafeCache->count = $config['password_error_times']; + $adminAccountSafeCache->minute = $config['limit_login_time']; + } + + //后台账号安全机制,连续输错后锁定,防止账号密码暴力破解 + if ($config['login_restrictions'] == 1 && !$adminAccountSafeCache->isSafe()) { + new MyBusinessException('密码连续' . $adminAccountSafeCache->count . '次输入错误,请' . $adminAccountSafeCache->minute . '分钟后重试'); + } + + $adminInfo = Admin::where('account', '=', $data['account']) + ->field(['password,disable']) + ->findOrEmpty(); + + if ($adminInfo->isEmpty()) { + return '账号不存在'; + } + + if ($adminInfo['disable'] === 1) { + return '账号已禁用'; + } + + if (empty($adminInfo['password'])) { + $adminAccountSafeCache->record(); + return '账号不存在'; + } + $passwordSalt = Config::get('project.unique_identification'); + if ($adminInfo['password'] !== create_password($password, $passwordSalt)) { + $adminAccountSafeCache->record(); + return '密码错误'; + } + + $adminAccountSafeCache->relieve(); + return true; + } +} diff --git a/app/store/validate/auth/AdminValidate.php b/app/store/validate/auth/AdminValidate.php new file mode 100644 index 000000000..fe26e58d7 --- /dev/null +++ b/app/store/validate/auth/AdminValidate.php @@ -0,0 +1,168 @@ + 'require|checkAdmin', + 'account' => 'require|length:1,32|unique:'.Admin::class, + 'name' => 'require|length:1,16|unique:'.Admin::class, + 'password' => 'require|length:6,32|edit', + 'password_confirm' => 'requireWith:password|confirm', + 'role_id' => 'require', + 'disable' => 'require|in:0,1|checkAbleDisable', + 'multipoint_login' => 'require|in:0,1', + ]; + + protected $message = [ + 'id.require' => '管理员id不能为空', + 'account.require' => '账号不能为空', + 'account.length' => '账号长度须在1-32位字符', + 'account.unique' => '账号已存在', + 'password.require' => '密码不能为空', + 'password.length' => '密码长度须在6-32位字符', + 'password_confirm.requireWith' => '确认密码不能为空', + 'password_confirm.confirm' => '两次输入的密码不一致', + 'name.require' => '名称不能为空', + 'name.length' => '名称须在1-16位字符', + 'name.unique' => '名称已存在', + 'role_id.require' => '请选择角色', + 'disable.require' => '请选择状态', + 'disable.in' => '状态值错误', + 'multipoint_login.require' => '请选择是否支持多处登录', + 'multipoint_login.in' => '多处登录状态值为误', + ]; + + /** + * @notes 添加场景 + * @return AdminValidate + * @author 乔峰 + * @date 2021/12/29 15:46 + */ + public function sceneAdd() + { + return $this->remove(['password', 'edit']) + ->remove('id', 'require|checkAdmin') + ->remove('disable', 'checkAbleDisable'); + } + + /** + * @notes 详情场景 + * @return AdminValidate + * @author 乔峰 + * @date 2021/12/29 15:46 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + /** + * @notes 编辑场景 + * @return AdminValidate + * @author 乔峰 + * @date 2021/12/29 15:47 + */ + public function sceneEdit() + { + return $this->remove('password', 'require|length') + ->append('id', 'require|checkAdmin'); + } + + + /** + * @notes 删除场景 + * @return AdminValidate + * @author 乔峰 + * @date 2021/12/29 15:47 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + + /** + * @notes 编辑情况下,检查是否填密码 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @author 乔峰 + * @date 2021/12/29 10:19 + */ + public function edit($value, $rule, $data) + { + if (empty($data['password']) && empty($data['password_confirm'])) { + return true; + } + $len = strlen($value); + if ($len < 6 || $len > 32) { + return '密码长度须在6-32位字符'; + } + return true; + } + + + /** + * @notes 检查指定管理员是否存在 + * @param $value + * @return bool|string + * @author 乔峰 + * @date 2021/12/29 10:19 + */ + public function checkAdmin($value) + { + $admin = Admin::findOrEmpty($value); + if ($admin->isEmpty()) { + return '管理员不存在'; + } + return true; + } + + + /** + * @notes 禁用校验 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @author 乔峰 + * @date 2022/8/11 9:59 + */ + public function checkAbleDisable($value, $rule, $data) + { + $admin = Admin::findOrEmpty($data['id']); + if ($admin->isEmpty()) { + return '管理员不存在'; + } + + if ($value && $admin['root']) { + return '超级管理员不允许被禁用'; + } + return true; + } + +} diff --git a/app/store/validate/auth/MenuValidate.php b/app/store/validate/auth/MenuValidate.php new file mode 100644 index 000000000..e0990e692 --- /dev/null +++ b/app/store/validate/auth/MenuValidate.php @@ -0,0 +1,195 @@ + 'require', + 'pid' => 'require|checkPid', + 'type' => 'require|in:M,C,A', + 'name' => 'require|length:1,30|checkUniqueName', + 'icon' => 'max:100', + 'sort' => 'require|egt:0', + 'perms' => 'max:100', + 'paths' => 'max:200', + 'component' => 'max:200', + 'selected' => 'max:200', + 'params' => 'max:200', + 'is_cache' => 'require|in:0,1', + 'is_show' => 'require|in:0,1', + 'is_disable' => 'require|in:0,1', + ]; + + + protected $message = [ + 'id.require' => '参数缺失', + 'pid.require' => '请选择上级菜单', + 'type.require' => '请选择菜单类型', + 'type.in' => '菜单类型参数值错误', + 'name.require' => '请填写菜单名称', + 'name.length' => '菜单名称长度需为1~30个字符', + 'icon.max' => '图标名称不能超过100个字符', + 'sort.require' => '请填写排序', + 'sort.egt' => '排序值需大于或等于0', + 'perms.max' => '权限字符不能超过100个字符', + 'paths.max' => '路由地址不能超过200个字符', + 'component.max' => '组件路径不能超过200个字符', + 'selected.max' => '选中菜单路径不能超过200个字符', + 'params.max' => '路由参数不能超过200个字符', + 'is_cache.require' => '请选择缓存状态', + 'is_cache.in' => '缓存状态参数值错误', + 'is_show.require' => '请选择显示状态', + 'is_show.in' => '显示状态参数值错误', + 'is_disable.require' => '请选择菜单状态', + 'is_disable.in' => '菜单状态参数值错误', + ]; + + + /** + * @notes 添加场景 + * @return MenuValidate + * @author 乔峰 + * @date 2022/6/29 18:26 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 详情场景 + * @return MenuValidate + * @author 乔峰 + * @date 2022/6/29 18:27 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return MenuValidate + * @author 乔峰 + * @date 2022/6/29 18:27 + */ + public function sceneDelete() + { + return $this->only(['id']) + ->append('id', 'checkAbleDelete'); + } + + + /** + * @notes 更新状态场景 + * @return MenuValidate + * @author 乔峰 + * @date 2022/7/6 17:04 + */ + public function sceneStatus() + { + return $this->only(['id', 'is_disable']); + } + + + /** + * @notes 校验菜单名称是否已存在 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @author 乔峰 + * @date 2022/6/29 18:24 + */ + protected function checkUniqueName($value, $rule, $data) + { + if ($data['type'] != 'M') { + return true; + } + $where[] = ['type', '=', $data['type']]; + $where[] = ['name', '=', $data['name']]; + + if (!empty($data['id'])) { + $where[] = ['id', '<>', $data['id']]; + } + + $check = SystemMenu::where($where)->findOrEmpty(); + + if (!$check->isEmpty()) { + return '菜单名称已存在'; + } + + return true; + } + + + /** + * @notes 是否有子级菜单 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @author 乔峰 + * @date 2022/6/30 9:40 + */ + protected function checkAbleDelete($value, $rule, $data) + { + $hasChild = SystemMenu::where(['pid' => $value])->findOrEmpty(); + if (!$hasChild->isEmpty()) { + //return '存在子菜单,不允许删除'; + } + + // 已绑定角色菜单不可以删除 + $isBindRole = SystemRole::hasWhere('roleMenuIndex', ['menu_id' => $value])->findOrEmpty(); + if (!$isBindRole->isEmpty()) { + //return '已分配菜单不可删除'; + } + + return true; + } + + + /** + * @notes 校验上级 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @author 乔峰 + * @date 2022/6/30 9:51 + */ + protected function checkPid($value, $rule, $data) + { + if (!empty($data['id']) && $data['id'] == $value) { + return '上级菜单不能选择自己'; + } + return true; + } + +} diff --git a/app/store/validate/auth/RoleValidate.php b/app/store/validate/auth/RoleValidate.php new file mode 100644 index 000000000..1ab836206 --- /dev/null +++ b/app/store/validate/auth/RoleValidate.php @@ -0,0 +1,119 @@ + 'require|checkRole', + 'name' => 'require|max:64|unique:' . SystemRole::class . ',name', + 'menu_id' => 'array', + ]; + + protected $message = [ + 'id.require' => '请选择角色', + 'name.require' => '请输入角色名称', + 'name.max' => '角色名称最长为16个字符', + 'name.unique' => '角色名称已存在', + 'menu_id.array' => '权限格式错误' + ]; + + /** + * @notes 添加场景 + * @return RoleValidate + * @author 乔峰 + * @date 2021/12/29 15:47 + */ + public function sceneAdd() + { + return $this->only(['name', 'menu_id']); + } + + /** + * @notes 详情场景 + * @return RoleValidate + * @author 乔峰 + * @date 2021/12/29 15:47 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + /** + * @notes 删除场景 + * @return RoleValidate + * @author 乔峰 + * @date 2021/12/29 15:48 + */ + public function sceneDel() + { + return $this->only(['id']) + ->append('id', 'checkAdmin'); + } + + + /** + * @notes 验证角色是否存在 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/12/29 15:48 + */ + public function checkRole($value, $rule, $data) + { + if (!SystemRole::find($value)) { + return '角色不存在'; + } + return true; + } + + + + /** + * @notes 验证角色是否被使用 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 乔峰 + * @date 2021/12/29 15:49 + */ + public function checkAdmin($value, $rule, $data) + { + if (Admin::where(['role_id' => $value])->find()) { + return '有管理员在使用该角色,不允许删除'; + } + return true; + } + +} diff --git a/app/store/validate/auth/editSelfValidate.php b/app/store/validate/auth/editSelfValidate.php new file mode 100644 index 000000000..1566e6e41 --- /dev/null +++ b/app/store/validate/auth/editSelfValidate.php @@ -0,0 +1,71 @@ + 'require|length:1,16', + 'avatar' => 'require', + 'password_old' => 'length:6,32', + 'password' => 'length:6,32|checkPassword', + 'password_confirm' => 'requireWith:password|confirm', + ]; + + + protected $message = [ + 'name.require' => '请填写名称', + 'name.length' => '名称须在1-16位字符', + 'avatar.require' => '请选择头像', + 'password_now.length' => '密码长度须在6-32位字符', + 'password_confirm.requireWith' => '确认密码不能为空', + 'password_confirm.confirm' => '两次输入的密码不一致', + ]; + + + /** + * @notes 校验密码 + * @param $value + * @param $rule + * @param $data + * @return bool|string + * @author 乔峰 + * @date 2022/4/8 17:40 + */ + public function checkPassword($value, $rule, $data) + { + if (empty($data['password_old'])) { + return '请填写当前密码'; + } + + $admin = Admin::findOrEmpty($data['admin_id']); + if (!password_verify($data['password_old'],$admin['password'])) { + return '当前密码错误'; + } + + return true; + } + +} diff --git a/app/store/validate/store_order/StoreOrderValidate.php b/app/store/validate/store_order/StoreOrderValidate.php new file mode 100644 index 000000000..3e7eeec4e --- /dev/null +++ b/app/store/validate/store_order/StoreOrderValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return StoreOrderValidate + * @author admin + * @date 2024/05/31 16:02 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return StoreOrderValidate + * @author admin + * @date 2024/05/31 16:02 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return StoreOrderValidate + * @author admin + * @date 2024/05/31 16:02 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreOrderValidate + * @author admin + * @date 2024/05/31 16:02 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} diff --git a/app/store/validate/store_product/StoreProductValidate.php b/app/store/validate/store_product/StoreProductValidate.php new file mode 100644 index 000000000..67dff6945 --- /dev/null +++ b/app/store/validate/store_product/StoreProductValidate.php @@ -0,0 +1,84 @@ + 'require', + 'store_name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'store_name' => '商品名称', + ]; + + + /** + * @notes 添加场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneAdd() + { + return $this->only(['store_name']); + } + + + /** + * @notes 编辑场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneEdit() + { + return $this->only(['id','store_name']); + } + + + /** + * @notes 删除场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} diff --git a/app/store/validate/store_product_attr_value/StoreProductAttrValueValidate.php b/app/store/validate/store_product_attr_value/StoreProductAttrValueValidate.php new file mode 100644 index 000000000..8f9c577d3 --- /dev/null +++ b/app/store/validate/store_product_attr_value/StoreProductAttrValueValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductAttrValueValidate + * @author admin + * @date 2024/05/31 14:10 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +}