diff --git a/app/common/repositories/store/service/StoreServiceRepository.php b/app/common/repositories/store/service/StoreServiceRepository.php index 4b16f58..0a69a90 100644 --- a/app/common/repositories/store/service/StoreServiceRepository.php +++ b/app/common/repositories/store/service/StoreServiceRepository.php @@ -267,7 +267,7 @@ class StoreServiceRepository extends BaseRepository ->when($id > 0,function($query) use ($id){ $query->where('StoreService.service_id','<>',$id); })->count(); - + return $count > 0; } /** @@ -278,17 +278,33 @@ class StoreServiceRepository extends BaseRepository * @return \app\common\dao\BaseDao|\think\Model */ public function createInfo($data){ - // 判断当前用户是否已经成为员工 + // 内容校验 if($this->isService($data['uid'])) throw new ValidateException('该用户已绑定商户!'); if($this->dao->fieldExists('account', $data['account'])) throw new ValidateException('账号已存在!'); // 数据添加 $data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT); return $this->dao->create($data); } + /** + * Common: 修改信息 + * Author: wu-hui + * Time: 2024/01/22 10:43 + * @param $id + * @param $data + * @return int + * @throws DbException + */ + public function updateInfo($id,$data){ + // 内容校验 + if (!$this->dao->merExists($data['mer_id'], $id)) throw new ValidateException('数据不存在!'); + if($this->isService($data['uid'], $id)) throw new ValidateException('该用户已绑定商户!'); + if($this->dao->fieldExists('account', $data['account'], $id)) throw new ValidateException('账号已存在!'); + // 数据修改 + if ($data['pwd']) $data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT); + else unset($data['pwd']); - - - + return $this->dao->update($id, $data); + } } diff --git a/app/common/repositories/user/UserMerchantRepository.php b/app/common/repositories/user/UserMerchantRepository.php index 6bb78d8..7235d91 100644 --- a/app/common/repositories/user/UserMerchantRepository.php +++ b/app/common/repositories/user/UserMerchantRepository.php @@ -8,6 +8,7 @@ namespace app\common\repositories\user; use app\common\dao\user\UserMerchantDao; use app\common\repositories\BaseRepository; +use app\common\repositories\store\service\StoreServiceRepository; use FormBuilder\Factory\Elm; use think\facade\Db; use think\facade\Route; @@ -41,6 +42,9 @@ class UserMerchantRepository extends BaseRepository $item->label = count($item['label_id']) ? $make->labels($item['label_id'], $where['mer_id']) : []; $item->svip_endtime = date('Y-m-d H:i:s', strtotime("+100 year")); $item->merchant_integral = $integralMake->getMerIntegral((int)$item->uid,(int)$where['mer_id']); + // 当前用户是否已经绑定店员身份 + $item->is_store_service = (int)app()->make(StoreServiceRepository::class)->isService((int)$item->uid); + return $item; }); diff --git a/app/controller/merchant/store/service/StoreService.php b/app/controller/merchant/store/service/StoreService.php index c1286a6..d459f8c 100644 --- a/app/controller/merchant/store/service/StoreService.php +++ b/app/controller/merchant/store/service/StoreService.php @@ -146,30 +146,12 @@ class StoreService extends BaseController return app('json')->success(formToData($this->repository->updateForm($id))); } - /** - * @param $id - * @param StoreServiceValidate $validate - * @return mixed - * @throws DbException - * @author xaboy - * @day 2020/5/29 - */ - public function update($id, StoreServiceValidate $validate) - { + // 修改信息 + public function update($id, StoreServiceValidate $validate){ $data = $this->checkParams($validate, true); - if (!$this->repository->merExists($merId = $this->request->merId(), $id)) - return app('json')->fail('数据不存在'); - if ($this->repository->issetService($merId, $data['uid'], $id)) - return app('json')->fail('该用户已绑定员工'); - if ($this->repository->fieldExists('account', $data['account'], $id)) { - return app('json')->fail('账号已存在'); - } - if ($data['pwd']) { - $data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT); - } else { - unset($data['pwd']); - } - $this->repository->update($id, $data); + $data['mer_id'] = $this->request->merId(); + $this->repository->updateInfo($id, $data); + return app('json')->success('修改成功'); }