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']);