From 77d86ff27f4ba4ba8bbae810f7e8fb940ea9037e Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 22 Apr 2024 17:56:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=95=86=E6=88=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0=20-=20=E5=91=98=E5=B7=A5?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E9=99=90=E5=88=B6=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E7=94=B1=E5=85=A8=E7=B1=BB=E5=9E=8B=E5=95=86=E6=88=B7=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E8=B4=A6=E5=8F=B7=E5=94=AF=E4=B8=80=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=90=8C=E7=B1=BB=E5=9E=8B=E5=95=86=E6=88=B7=E5=91=98?= =?UTF-8?q?=E5=B7=A5=E8=B4=A6=E5=8F=B7=E5=94=AF=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/service/StoreServiceDao.php | 16 ++++++++++++---- .../store/service/StoreServiceRepository.php | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/common/dao/store/service/StoreServiceDao.php b/app/common/dao/store/service/StoreServiceDao.php index d92bb88..ed309a9 100644 --- a/app/common/dao/store/service/StoreServiceDao.php +++ b/app/common/dao/store/service/StoreServiceDao.php @@ -8,6 +8,7 @@ namespace app\common\dao\store\service; use app\common\dao\BaseDao; use app\common\model\store\service\StoreService; +use app\common\model\system\merchant\Merchant; use think\db\BaseQuery; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -87,10 +88,17 @@ class StoreServiceDao extends BaseDao * @author xaboy * @day 2020-03-30 */ - public function fieldExists($field, $value, ?int $except = null): bool - { - $query = ($this->getModel())::getDB()->where($field, $value)->where('is_del', 0); - if (!is_null($except)) $query->where($this->getPk(), '<>', $except); + public function fieldExists($field, $value, ?int $except = null, $merId = null): bool{ + $query = StoreService::getDB() + ->alias('ss') + ->join('merchant m', 'ss.mer_id = m.mer_id', 'LEFT') + ->when(!empty($merId),function($query) use ($merId){ + $merchantType = Merchant::getDB()->where('mer_id', $merId)->value('merchant_type'); + $query->where('merchant_type', $merchantType); + }) + ->where('ss.'.$field, $value) + ->where('ss.is_del', 0); + if (!is_null($except)) $query->where('ss.'.$this->getPk(), '<>', $except); return $query->count() > 0; } diff --git a/app/common/repositories/store/service/StoreServiceRepository.php b/app/common/repositories/store/service/StoreServiceRepository.php index 7ef9743..a242a92 100644 --- a/app/common/repositories/store/service/StoreServiceRepository.php +++ b/app/common/repositories/store/service/StoreServiceRepository.php @@ -389,7 +389,7 @@ class StoreServiceRepository extends BaseRepository public function createInfo($data){ // 内容校验 if($this->isService($data['uid'], 0, $data['mer_id'])) throw new ValidateException('该用户已绑定商户!'); - if($this->dao->fieldExists('account', $data['account'])) throw new ValidateException('账号已存在!'); + if($this->dao->fieldExists('account', $data['account'], null, $data['mer_id'])) throw new ValidateException('账号已存在!'); // 数据添加 $data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT); return $this->dao->create($data); @@ -407,7 +407,7 @@ class StoreServiceRepository extends BaseRepository // 内容校验 if (!$this->dao->merExists($data['mer_id'], $id)) throw new ValidateException('数据不存在!'); if($this->isService($data['uid'], $id, $data['mer_id'])) throw new ValidateException('该用户已绑定商户!'); - if($this->dao->fieldExists('account', $data['account'], $id)) throw new ValidateException('账号已存在!'); + if($this->dao->fieldExists('account', $data['account'], $id, $data['mer_id'])) throw new ValidateException('账号已存在!'); // 数据修改 if ($data['pwd']) $data['pwd'] = password_hash($data['pwd'], PASSWORD_BCRYPT); else unset($data['pwd']);