feat : admin bind user_id
This commit is contained in:
@@ -19,6 +19,7 @@ use App\Model\AdminRole;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Chef;
|
||||
use App\Model\DriverSequence;
|
||||
use App\Model\User;
|
||||
use App\Model\WarehouseKeeper;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Admin\RoleMembersTrait;
|
||||
@@ -43,6 +44,13 @@ class EmployeeService extends BaseService
|
||||
#[Inject]
|
||||
protected AdminRole $adminRoleModel;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
#[Inject]
|
||||
protected User $userModel;
|
||||
|
||||
|
||||
/**
|
||||
* 注入加密工厂
|
||||
* @var CryptoFactory $cryptoFactory
|
||||
@@ -90,6 +98,12 @@ class EmployeeService extends BaseService
|
||||
|
||||
if (!empty($oldName) && !empty($oldAccount)) throw new ErrException('账号或者员工已存在');
|
||||
|
||||
$bindUserId = $this->request->input('bind_user_id', 0);
|
||||
if ($bindUserId > 0) {
|
||||
$oldBindUserId = $this->adminUserModel->getAdminInfoByBindUserId($bindUserId);
|
||||
if (!empty($oldBindUserId)) throw new ErrException('绑定用户已存在');
|
||||
}
|
||||
|
||||
$salt = StringUtil::randStr(6);
|
||||
$defaultPassword = config('system.admin_default_password');
|
||||
|
||||
@@ -104,6 +118,7 @@ class EmployeeService extends BaseService
|
||||
$model->avatar = $this->request->input('avatar',0);
|
||||
$model->role_id = $this->request->input('role_id', 0);
|
||||
$model->city_id = $this->request->input('city_id', 0);
|
||||
$model->bind_user_id = $bindUserId;
|
||||
// $model->section_id = $this->request->input('section_id', 0);
|
||||
|
||||
if (!$model->save()) throw new ErrException('账号添加失败');
|
||||
@@ -143,6 +158,13 @@ class EmployeeService extends BaseService
|
||||
if (!empty($oldName) && $oldName->id != $info->id) throw new ErrException('员工已存在');
|
||||
if (!empty($oldAccount) && $oldAccount->id != $info->id) throw new ErrException('账号已存在');
|
||||
|
||||
$bindUserId = $this->request->input('bind_user_id', 0);
|
||||
if ($bindUserId > 0) {
|
||||
$oldBindUserId = $this->adminUserModel->getAdminInfoByBindUserId($bindUserId);
|
||||
if (!empty($oldBindUserId) && $info->bind_user_id != $oldBindUserId) throw new ErrException('绑定用户已存在');
|
||||
}
|
||||
|
||||
|
||||
if ($info->role_id != $roleId) {
|
||||
//写入关联表
|
||||
$del = match ($info->role_id) {
|
||||
@@ -171,6 +193,7 @@ class EmployeeService extends BaseService
|
||||
$info->avatar = $this->request->input('avatar',0);
|
||||
$info->role_id = $roleId;
|
||||
$info->city_id = $this->request->input('city_id', 0);
|
||||
$info->bind_user_id = $bindUserId;
|
||||
// $info->section_id = $this->request->input('section_id', 0);
|
||||
|
||||
if (!$info->save()) throw new ErrException('账号修改失败');
|
||||
|
||||
Reference in New Issue
Block a user