From 8515960d83fd81d4ef176f40d54cb67918ddc6b2 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 6 Jun 2024 15:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=97=E5=91=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/lists/StoreStaffLists.php | 67 +++++++++++ app/common/logic/SystemStoreStaffLogic.php | 54 +++++++++ .../model/system_store/SystemStoreStaff.php | 16 ++- app/store/controller/StaffController.php | 106 +++++++++++++++++- 4 files changed, 237 insertions(+), 6 deletions(-) create mode 100644 app/common/lists/StoreStaffLists.php diff --git a/app/common/lists/StoreStaffLists.php b/app/common/lists/StoreStaffLists.php new file mode 100644 index 000000000..dcc4c0669 --- /dev/null +++ b/app/common/lists/StoreStaffLists.php @@ -0,0 +1,67 @@ +when(!empty($this->request->adminInfo['store_id']), function ($query) { + $query->where('store_id', '=', $this->request->adminInfo['store_id']); + }) + ->when(!empty($this->params['keyword']), function ($query) { + $query->where('staff_name|account|phone', 'like', "%{$this->params['keyword']}%"); + }) + ->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 SystemStoreStaff::when(!empty($this->request->adminInfo['store_id']), function ($query) { + $query->where('store_id', '=', $this->request->adminInfo['store_id']); + }) + ->when(!empty($this->params['keyword']), function ($query) { + $query->where('staff_name|account|phone', 'like', "%{$this->params['keyword']}%"); + }) + ->count(); + } + +} diff --git a/app/common/logic/SystemStoreStaffLogic.php b/app/common/logic/SystemStoreStaffLogic.php index ddce0e347..94ed3501e 100644 --- a/app/common/logic/SystemStoreStaffLogic.php +++ b/app/common/logic/SystemStoreStaffLogic.php @@ -3,6 +3,8 @@ namespace app\common\logic; use app\common\model\system_store\SystemStoreStaff; +use app\common\service\FileService; +use Webman\Config; class SystemStoreStaffLogic extends BaseLogic { @@ -12,4 +14,56 @@ class SystemStoreStaffLogic extends BaseLogic return SystemStoreStaff::where($where)->field($field)->select()->toArray(); } + public function add($params) + { + try { + $model = new SystemStoreStaff(); + $model->setAttrs($params); + $model->store_id = request()->adminInfo['store_id']; + $passwordSalt = Config::get('project.unique_identification'); + $model->pwd = create_password($params['pwd'], $passwordSalt); + $defaultAvatar = config('project.default_image.admin_avatar'); + $model->avatar = !empty($model['avatar']) ? FileService::setFileUrl($model['avatar']) : $defaultAvatar; + $model->save(); + } catch (\Exception $exception) { + throw new \Exception($exception->getMessage()); + } + } + + public function edit($id, $params) + { + try { + $model = SystemStoreStaff::find($id); + if (empty($model)) { + throw new \Exception('数据不存在'); + } + $model->setAttrs($params); + $model->save(); + } catch (\Exception $exception) { + throw new \Exception($exception->getMessage()); + } + } + + public function delete($id) + { + try { + $model = SystemStoreStaff::find($id); + if (empty($model)) { + throw new \Exception('数据不存在'); + } + $model->delete(); + } catch (\Exception $exception) { + throw new \Exception($exception->getMessage()); + } + } + + public function detail($id) + { + $model = SystemStoreStaff::find($id); + if (empty($model)) { + throw new \Exception('数据不存在'); + } + return $model->toArray(); + } + } diff --git a/app/common/model/system_store/SystemStoreStaff.php b/app/common/model/system_store/SystemStoreStaff.php index 277418c45..d6919b59a 100644 --- a/app/common/model/system_store/SystemStoreStaff.php +++ b/app/common/model/system_store/SystemStoreStaff.php @@ -4,6 +4,7 @@ namespace app\common\model\system_store; use app\common\model\BaseModel; +use app\common\service\FileService; use think\model\concern\SoftDelete; @@ -18,5 +19,16 @@ class SystemStoreStaff extends BaseModel protected $name = 'system_store_staff'; protected $deleteTime = 'delete_time'; - -} \ No newline at end of file + /** + * @notes 头像获取器 - 头像路径添加域名 + * @param $value + * @return string + * @author Tab + * @date 2021/7/13 11:35 + */ + public function getAvatarAttr($value) + { + return empty($value) ? FileService::getFileUrl(config('project.default_image.admin_avatar')) : FileService::getFileUrl(trim($value, '/')); + } + +} diff --git a/app/store/controller/StaffController.php b/app/store/controller/StaffController.php index 7958a5eaa..ac4cb9194 100644 --- a/app/store/controller/StaffController.php +++ b/app/store/controller/StaffController.php @@ -2,6 +2,8 @@ namespace app\store\controller; +use app\common\controller\Definitions; +use app\common\lists\StoreStaffLists; use app\common\logic\SystemStoreStaffLogic; use hg\apidoc\annotation as ApiDoc; @@ -15,19 +17,115 @@ class StaffController extends BaseAdminController ApiDoc\Method('GET'), ApiDoc\NotHeaders(), ApiDoc\Author('中国队长'), + ApiDoc\Query(name: 'keyword', type: 'string', require: false, desc: '店员名称/手机号/账号'), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(ref: [Definitions::class, "page"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'id', 'type' => 'int'], ['name' => 'staff_name', 'desc' => '店员名称', 'type' => 'string'], ['name' => 'avatar', 'desc' => '头像', 'type' => 'string'], ['name' => 'account', 'desc' => '账号', 'type' => 'string'], ['name' => 'phone', 'desc' => '手机号', 'type' => 'string'], - ['name' => 'is_admin', 'desc' => '是否是管理员', 'type' => 'string'], - ['name' => 'is_manager', 'desc' => '是否是店长', 'type' => 'string'], + ['name' => 'is_admin', 'desc' => '是否是管理员,1是,0不是', 'type' => 'int'], + ['name' => 'is_manager', 'desc' => '是否是店长,1是,0不是', 'type' => 'int'], ]), ] - public function lists(SystemStoreStaffLogic $staffLogic) + public function lists() { - return $this->data($staffLogic->listByWhere(['store_id' => $this->request->adminInfo['store_id'], 'status' => 1], 'id,staff_name,avatar,account,phone,is_admin,is_manager')); + return $this->dataLists(new StoreStaffLists()); + } + + #[ + ApiDoc\Title('添加'), + ApiDoc\url('/store/staff/add'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Param(name: 'account', type: 'string', require: true, desc: '账号'), + ApiDoc\Param(name: 'pwd', type: 'string', require: true, desc: '密码'), + ApiDoc\Param(name: 'avatar', type: 'string', require: true, desc: '头像'), + ApiDoc\Param(name: 'staff_name', type: 'string', require: true, desc: '店员名称'), + ApiDoc\Param(name: 'phone', type: 'string', require: true, desc: '手机号'), + ApiDoc\Param(name: 'verify_status', type: 'string', require: true, desc: '核销开关,1开启,0关闭'), + ApiDoc\Param(name: 'order_status', type: 'string', require: true, desc: '订单状态,1开启,0关闭'), + ApiDoc\Param(name: 'is_manager', type: 'string', require: true, desc: '是否是店长,1是,0不是'), + ApiDoc\Param(name: 'status', type: 'string', require: true, desc: '状态,1启用,0禁用'), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function add(SystemStoreStaffLogic $staffLogic) + { + $params = $this->request->post(); + $staffLogic->add($params); + return $this->success('操作成功', [], 1, 1); + } + + #[ + ApiDoc\Title('编辑'), + ApiDoc\url('/store/staff/edit'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Query(name: 'id', type: 'int', require: true, desc: 'id'), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Param(name: 'account', type: 'string', require: true, desc: '账号'), + ApiDoc\Param(name: 'pwd', type: 'string', require: true, desc: '密码'), + ApiDoc\Param(name: 'avatar', type: 'string', require: true, desc: '头像'), + ApiDoc\Param(name: 'staff_name', type: 'string', require: true, desc: '店员名称'), + ApiDoc\Param(name: 'phone', type: 'string', require: true, desc: '手机号'), + ApiDoc\Param(name: 'verify_status', type: 'string', require: true, desc: '核销开关,1开启,0关闭'), + ApiDoc\Param(name: 'order_status', type: 'string', require: true, desc: '订单状态,1开启,0关闭'), + ApiDoc\Param(name: 'is_manager', type: 'string', require: true, desc: '是否是店长,1是,0不是'), + ApiDoc\Param(name: 'status', type: 'string', require: true, desc: '状态,1启用,0禁用'), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function edit(SystemStoreStaffLogic $staffLogic) + { + $id = $this->request->get('id'); + $params = $this->request->post(); + $staffLogic->edit($id, $params); + return $this->success('操作成功', [], 1, 1); + } + + #[ + ApiDoc\Title('删除'), + ApiDoc\url('/store/staff/delete'), + ApiDoc\Method('POST'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(name: 'id', type: 'int', require: true, desc: 'id'), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function delete(SystemStoreStaffLogic $staffLogic) + { + $id = $this->request->get('id'); + $staffLogic->delete($id); + return $this->success('操作成功', [], 1, 1); + } + + #[ + ApiDoc\Title('详情'), + ApiDoc\url('/store/staff/detail'), + ApiDoc\Method('GET'), + ApiDoc\NotHeaders(), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(name: 'id', type: 'int', require: true, desc: 'id'), + ApiDoc\ResponseSuccess("data", type: "array", children: [ + ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], + ['name' => 'account', 'desc' => '账号', 'type' => 'string'], + ['name' => 'avatar', 'desc' => '头像', 'type' => 'string'], + ['name' => 'staff_name', 'desc' => '店员名称', 'type' => 'string'], + ['name' => 'phone', 'desc' => '手机号', 'type' => 'string'], + ['name' => 'verify_status', 'desc' => '核销开关,1开启,0关闭', 'type' => 'int'], + ['name' => 'order_status', 'desc' => '订单状态,1开启,0关闭', 'type' => 'int'], + ['name' => 'is_admin', 'desc' => '是否管理员,1是,0不是', 'type' => 'int'], + ['name' => 'is_manager', 'desc' => '是否是店长,1是,0不是', 'type' => 'int'], + ['name' => 'status', 'desc' => '状态,1启用,0禁用', 'type' => 'int'], + ]), + ] + public function detail(SystemStoreStaffLogic $staffLogic) + { + $id = $this->request->get('id'); + $data = $staffLogic->detail($id); + return $this->data($data); } }