修改:商户管理后台 - 员工账号限制修改,由全类型商户员工账号唯一修改为同类型商户员工账号唯一

This commit is contained in:
wuhui_zzw 2024-04-22 17:56:12 +08:00
parent bd08cda5d2
commit 77d86ff27f
2 changed files with 14 additions and 6 deletions

View File

@ -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;
}

View File

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