From ad7eb11e9d98a4e757136639c0232fe5ca86b78d Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 22 Jan 2024 19:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E5=91=98=E5=B7=A5=E7=AE=A1=E7=90=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/store/service/StoreServiceDao.php | 51 ++++--- .../store/service/StoreServiceRepository.php | 76 ++++++++-- app/controller/api/store/merchant/Service.php | 134 ++++++++++++++++++ .../api/store/user/UserMerchant.php | 3 +- app/controller/api/user/User.php | 4 +- .../merchant/store/service/StoreService.php | 18 +-- route/api.php | 12 +- 7 files changed, 246 insertions(+), 52 deletions(-) create mode 100644 app/controller/api/store/merchant/Service.php diff --git a/app/common/dao/store/service/StoreServiceDao.php b/app/common/dao/store/service/StoreServiceDao.php index 8cec7d3..d92bb88 100644 --- a/app/common/dao/store/service/StoreServiceDao.php +++ b/app/common/dao/store/service/StoreServiceDao.php @@ -39,27 +39,36 @@ class StoreServiceDao extends BaseDao * @author xaboy * @day 2020/5/29 */ - public function search(array $where) - { - return StoreService::getDB()->where('is_del', 0)->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) { - $query->where('status', $where['status']); - })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) { - $query->whereLike('nickname', "%{$where['keyword']}%"); - })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) { - $query->where('mer_id', $where['mer_id']); - })->when(isset($where['customer']) && $where['customer'] !== '', function ($query) use ($where) { - $query->where('customer', $where['customer']); - })->when(isset($where['is_verify']) && $where['is_verify'] !== '', function ($query) use ($where) { - $query->where('is_verify', $where['is_verify']); - })->when(isset($where['is_goods']) && $where['is_goods'] !== '', function ($query) use ($where) { - $query->where('is_goods', $where['is_goods']); - })->when(isset($where['is_open']) && $where['is_open'] !== '', function ($query) use ($where) { - $query->where('is_open', $where['is_open']); - })->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) { - $query->where('uid', $where['uid']); - })->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) { - $query->where('service_id', $where['service_id']); - }); + public function search(array $where){ + return StoreService::getDB() + ->where('is_del',0) + ->when(isset($where['status']) && $where['status'] !== '',function($query) use ($where){ + $query->where('status',$where['status']); + }) + ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query) use ($where){ + $query->whereLike('nickname',"%{$where['keyword']}%"); + }) + ->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query) use ($where){ + $query->where('mer_id',$where['mer_id']); + }) + ->when(isset($where['customer']) && $where['customer'] !== '',function($query) use ($where){ + $query->where('customer',$where['customer']); + }) + ->when(isset($where['is_verify']) && $where['is_verify'] !== '',function($query) use ($where){ + $query->where('is_verify',$where['is_verify']); + }) + ->when(isset($where['is_goods']) && $where['is_goods'] !== '',function($query) use ($where){ + $query->where('is_goods',$where['is_goods']); + }) + ->when(isset($where['is_open']) && $where['is_open'] !== '',function($query) use ($where){ + $query->where('is_open',$where['is_open']); + }) + ->when(isset($where['uid']) && $where['uid'] !== '',function($query) use ($where){ + $query->where('uid',$where['uid']); + }) + ->when(isset($where['service_id']) && $where['service_id'] !== '',function($query) use ($where){ + $query->where('service_id',$where['service_id']); + }); } public function getService($uid, $merId = null) diff --git a/app/common/repositories/store/service/StoreServiceRepository.php b/app/common/repositories/store/service/StoreServiceRepository.php index b5a00be..adcca66 100644 --- a/app/common/repositories/store/service/StoreServiceRepository.php +++ b/app/common/repositories/store/service/StoreServiceRepository.php @@ -84,6 +84,7 @@ class StoreServiceRepository extends BaseRepository Elm::switches('is_verify', '开启核销', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), Elm::switches('is_user', '客户管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), Elm::switches('staff_manage', '员工管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), + Elm::switches('qr_code_show', '推广二维码', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8), Elm::switches('notify', '订单通知', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(8)->control([ [ 'value' => 1, @@ -159,24 +160,54 @@ class StoreServiceRepository extends BaseRepository $service = $this->dao->getRandService($merId); if ($service) return $service; } - public function getServices($uid, array $where = [],$is_sys = 1) - { - $order = $is_sys ? 'ASC' : 'DESC'; + // 获取当前用户的员工信息 + public function getServices($uid, array $where = [],$is_sys = 1){ $where['uid'] = $uid; - $list = $this->search($where)->with(['merchant' => function ($query) { - $query->field('mer_id,mer_avatar,mer_name'); - }])->order('mer_id '.$order)->select()->hidden(['pwd'])->toArray(); - $config = systemConfig(['site_logo', 'site_name']); - foreach ($list as &$item){ - if ($item['mer_id'] == 0) { - $item['merchant'] = [ - 'mer_avatar' => $config['site_logo'], - 'mer_name' => $config['site_name'], - 'mer_id' => 0, - ]; + $list = $this->dao->getSearch([]) + ->hasWhere('merchant',function($query){ + $query->where('is_del', 0); + }) + ->where('StoreService.is_del',0) + ->where('StoreService.mer_id',$is_sys == 1 ? '=' : '>',0) + ->when(isset($where['is_verify']) && $where['is_verify'] !== '',function($query) use ($where){ + $query->where('StoreService.is_verify',$where['is_verify']); + }) + ->when(isset($where['customer']) && $where['customer'] !== '',function($query) use ($where){ + $query->where('StoreService.customer',$where['customer']); + }) + ->when(isset($where['is_goods']) && $where['is_goods'] !== '',function($query) use ($where){ + $query->where('StoreService.is_goods',$where['is_goods']); + }) + ->when(isset($where['is_open']) && $where['is_open'] !== '',function($query) use ($where){ + $query->where('StoreService.is_open',$where['is_open']); + }) + ->when(isset($where['uid']) && $where['uid'] !== '',function($query) use ($where){ + $query->where('StoreService.uid',$where['uid']); + }) + ->with([ + 'merchant' => function($query){ + $query->field('mer_id,mer_avatar,mer_name'); + } + ]) + ->order('StoreService.mer_id DESC') + ->select() + ->hidden(['pwd']) + ->toArray(); + // 是否处理总平台客服信息 + if($is_sys == 1){ + $config = systemConfig(['site_logo','site_name']); + foreach($list as &$item){ + if($item['mer_id'] == 0){ + $item['merchant'] = [ + 'mer_avatar' => $config['site_logo'], + 'mer_name' => $config['site_name'], + 'mer_id' => 0, + ]; + } } + unset($item); } - unset($item); + return $list; } public function createToken(StoreService $admin) @@ -311,6 +342,21 @@ class StoreServiceRepository extends BaseRepository return $this->dao->update($id, $data); } + /** + * Common: 删除信息 + * Author: wu-hui + * Time: 2024/01/22 15:56 + * @param int $id + * @param int $merId + * @return int + * @throws DbException + */ + public function deleteInfo(int $id,int $merId){ + if (!$this->dao->merExists($merId, $id)) throw new ValidateException('数据不存在!'); + + return $this->dao->delete($id); + } + } diff --git a/app/controller/api/store/merchant/Service.php b/app/controller/api/store/merchant/Service.php new file mode 100644 index 0000000..3316711 --- /dev/null +++ b/app/controller/api/store/merchant/Service.php @@ -0,0 +1,134 @@ +repository = $repository; + $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : NULL; + } + /** + * Common: 获取员工列表 + * Author: wu-hui + * Time: 2024/01/22 14:58 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function lst(){ + $params = $this->request->params(['keyword','mer_id']); + [$page, $limit] = $this->getPage(); + $data = $this->repository->getList($params, $page, $limit); + + return app('json')->success($data); + } + /** + * Common: 编辑信息 + * Author: wu-hui + * Time: 2024/01/22 18:43 + * @param StoreServiceValidate $validate + * @return mixed + * @throws \think\db\exception\DbException + */ + public function editInfo(StoreServiceValidate $validate){ + // 参数获取 + $params = $this->checkParams($validate); + $serviceId = (int)$params['service_id']; + unset($params['service_id']); + // 操作 + if($serviceId > 0) $this->repository->updateInfo((int)$serviceId, $params); + else $this->repository->createInfo($params); + + return app('json')->success('操作成功'); + } + /** + * Common: 编辑参数获取 + * Author: wu-hui + * Time: 2024/01/22 17:39 + * @param StoreServiceValidate $validate + * @return array + */ + public function checkParams(StoreServiceValidate $validate){ + // 参数获取 + $data = $this->request->params([ + ['mer_id',0], + ['service_id',0], + ['uid',[]], + 'nickname', + 'account', + 'pwd', + 'confirm_pwd', + 'is_open', + ['status',0], + 'customer', + 'is_verify', + 'is_goods', + 'is_user', + 'staff_manage', + 'notify', + 'avatar', + 'phone', + ['sort',0] + ]); + if(is_array(json_decode($data['uid'], true))) $data['uid'] = json_decode($data['uid'], true); + // 是否编辑 + if((int)$data['service_id'] > 0) $validate->update(); + $validate->check($data); + if ($data['pwd'] && $data['pwd'] != $data['confirm_pwd']) { + throw new ValidateException('员工密码与确认密码不一致'); + } + $data['uid'] = $data['uid']['id']; + unset($data['confirm_pwd']); + return $data; + } + /** + * Common: 获取用户信息 + * Author: wu-hui + * Time: 2024/01/22 18:34 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function staffInfo(){ + $id = $this->request->param('service_id'); + $service = $this->repository->getWith($id,[ + 'user' => function($query){ + $query->field('avatar,uid'); + } + ])->toArray(); + if($service['user'] ?? null){ + $service['uid'] = ['id' => $service['uid'], 'src' => $service['user']['avatar'] ?: $service['avatar']]; + }else{ + unset($service['uid']); + } + unset($service['user'], $service['pwd']); + + return app('json')->success($service); + } + /** + * Common: 删除员工信息 + * Author: wu-hui + * Time: 2024/01/22 15:56 + * @return mixed + * @throws \think\db\exception\DbException + */ + public function delInfo(){ + $params = $this->request->params(['service_id','mer_id']); + $this->repository->deleteInfo((int)$params['service_id'], (int)$params['mer_id']); + + return app('json')->success('删除成功'); + } + +} diff --git a/app/controller/api/store/user/UserMerchant.php b/app/controller/api/store/user/UserMerchant.php index bc583b4..5c95adf 100644 --- a/app/controller/api/store/user/UserMerchant.php +++ b/app/controller/api/store/user/UserMerchant.php @@ -46,8 +46,9 @@ class UserMerchant extends BaseController{ * @return mixed */ public function getList($merId){ - $where = $this->request->params(['nickname']); + $where = $this->request->params(['nickname','default_consume_id']); $where['mer_id'] = $merId; + if((int)$where['default_consume_id'] > 0) $where['uids'] = [$where['default_consume_id']] ?? []; [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->getList($where, $page, $limit)); diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 97e5e87..bf258b5 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -528,7 +528,9 @@ class User extends BaseController $uid = $this->user->uid; $where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1]]); $is_sys = $this->request->param('is_sys'); - return app('json')->success(app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys)); + $list = app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys); + + return app('json')->success($list); } public function memberInfo() diff --git a/app/controller/merchant/store/service/StoreService.php b/app/controller/merchant/store/service/StoreService.php index 5f8d1f8..b65d930 100644 --- a/app/controller/merchant/store/service/StoreService.php +++ b/app/controller/merchant/store/service/StoreService.php @@ -172,18 +172,12 @@ class StoreService extends BaseController return app('json')->success('修改成功'); } - /** - * @param $id - * @return mixed - * @throws DbException - * @author xaboy - * @day 2020/5/29 - */ - public function delete($id) - { - if (!$this->repository->merExists($this->request->merId(), $id)) - return app('json')->fail('数据不存在'); - $this->repository->delete($id); + + // 删除员工信息 + public function delete($id){ + $merId = $this->request->merId(); + $this->repository->deleteInfo((int)$id, (int)$merId); + return app('json')->success('删除成功'); } diff --git a/route/api.php b/route/api.php index 236c6f9..dc2ff40 100644 --- a/route/api.php +++ b/route/api.php @@ -369,10 +369,19 @@ Route::group('api/', function () { })->prefix('api.user.'); + // 员工管理 + Route::group('staff', function () { + Route::get('staff_list', 'Service/lst');// 列表 + Route::get('staff_edit', 'Service/editInfo');// 编辑 + Route::get('staff_del', 'Service/delInfo');// 删除 + Route::get('staff_info', 'Service/staffInfo');// 删除 + + })->prefix('api.store.merchant.'); + + })->middleware(UserTokenMiddleware::class, true); - //非强制登录 Route::group(function () { // 商品兑换 @@ -573,7 +582,6 @@ Route::group('api/', function () { })->prefix('api.Diy'); })->middleware(UserTokenMiddleware::class, false); - //微信支付回调 Route::any('notice/wechat_pay', 'api.Common/wechatNotify')->name('wechatNotify'); //微信支付回调