修改:商户管理后台添加、编辑员工时判断用户是否已经成为员工

添加:商户用户输出信息添加该用户是否为员工
This commit is contained in:
wuhui_zzw 2024-01-22 11:02:42 +08:00
parent d17c7944ab
commit 1550d8bf6e
3 changed files with 30 additions and 28 deletions

View File

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

View File

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

View File

@ -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('修改成功');
}