feat : admin bind user_id
This commit is contained in:
@@ -9,7 +9,8 @@ use Hyperf\Database\Model\Builder;
|
|||||||
use Hyperf\DbConnection\Model\Model;
|
use Hyperf\DbConnection\Model\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
|
* @property int $bind_user_id
|
||||||
* @property string $username
|
* @property string $username
|
||||||
* @property string $password
|
* @property string $password
|
||||||
* @property string $salt
|
* @property string $salt
|
||||||
@@ -43,7 +44,7 @@ class AdminUser extends Model
|
|||||||
/**
|
/**
|
||||||
* The attributes that should be cast to native types.
|
* The attributes that should be cast to native types.
|
||||||
*/
|
*/
|
||||||
protected array $casts = ['id' => 'integer', 'avatar' => 'integer', 'status' => 'integer', 'is_del' => 'integer', 'role_id' => 'integer'];
|
protected array $casts = ['id' => 'integer', 'avatar' => 'integer', 'status' => 'integer', 'is_del' => 'integer', 'role_id' => 'integer','bind_user_id' => 'integer'];
|
||||||
|
|
||||||
const CREATED_AT = 'create_time';
|
const CREATED_AT = 'create_time';
|
||||||
|
|
||||||
@@ -76,6 +77,15 @@ class AdminUser extends Model
|
|||||||
return $this->where('id', $id)->where('is_del',UserCode::IS_NO_DEL)->first();
|
return $this->where('id', $id)->where('is_del',UserCode::IS_NO_DEL)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $userId
|
||||||
|
* @return \Hyperf\Database\Model\Model|Builder|null
|
||||||
|
*/
|
||||||
|
public function getAdminInfoByBindUserId(int $userId): \Hyperf\Database\Model\Model|Builder|null
|
||||||
|
{
|
||||||
|
return $this->where('bind_user_id', $userId)->where('is_del',UserCode::IS_NO_DEL)->first();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有数据
|
* 获取所有数据
|
||||||
* @param array $ids
|
* @param array $ids
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use App\Model\AdminRole;
|
|||||||
use App\Model\AdminUser;
|
use App\Model\AdminUser;
|
||||||
use App\Model\Chef;
|
use App\Model\Chef;
|
||||||
use App\Model\DriverSequence;
|
use App\Model\DriverSequence;
|
||||||
|
use App\Model\User;
|
||||||
use App\Model\WarehouseKeeper;
|
use App\Model\WarehouseKeeper;
|
||||||
use App\Service\Admin\BaseService;
|
use App\Service\Admin\BaseService;
|
||||||
use App\Service\ServiceTrait\Admin\RoleMembersTrait;
|
use App\Service\ServiceTrait\Admin\RoleMembersTrait;
|
||||||
@@ -43,6 +44,13 @@ class EmployeeService extends BaseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected AdminRole $adminRoleModel;
|
protected AdminRole $adminRoleModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected User $userModel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入加密工厂
|
* 注入加密工厂
|
||||||
* @var CryptoFactory $cryptoFactory
|
* @var CryptoFactory $cryptoFactory
|
||||||
@@ -90,6 +98,12 @@ class EmployeeService extends BaseService
|
|||||||
|
|
||||||
if (!empty($oldName) && !empty($oldAccount)) throw new ErrException('账号或者员工已存在');
|
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);
|
$salt = StringUtil::randStr(6);
|
||||||
$defaultPassword = config('system.admin_default_password');
|
$defaultPassword = config('system.admin_default_password');
|
||||||
|
|
||||||
@@ -104,6 +118,7 @@ class EmployeeService extends BaseService
|
|||||||
$model->avatar = $this->request->input('avatar',0);
|
$model->avatar = $this->request->input('avatar',0);
|
||||||
$model->role_id = $this->request->input('role_id', 0);
|
$model->role_id = $this->request->input('role_id', 0);
|
||||||
$model->city_id = $this->request->input('city_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);
|
// $model->section_id = $this->request->input('section_id', 0);
|
||||||
|
|
||||||
if (!$model->save()) throw new ErrException('账号添加失败');
|
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($oldName) && $oldName->id != $info->id) throw new ErrException('员工已存在');
|
||||||
if (!empty($oldAccount) && $oldAccount->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) {
|
if ($info->role_id != $roleId) {
|
||||||
//写入关联表
|
//写入关联表
|
||||||
$del = match ($info->role_id) {
|
$del = match ($info->role_id) {
|
||||||
@@ -171,6 +193,7 @@ class EmployeeService extends BaseService
|
|||||||
$info->avatar = $this->request->input('avatar',0);
|
$info->avatar = $this->request->input('avatar',0);
|
||||||
$info->role_id = $roleId;
|
$info->role_id = $roleId;
|
||||||
$info->city_id = $this->request->input('city_id', 0);
|
$info->city_id = $this->request->input('city_id', 0);
|
||||||
|
$info->bind_user_id = $bindUserId;
|
||||||
// $info->section_id = $this->request->input('section_id', 0);
|
// $info->section_id = $this->request->input('section_id', 0);
|
||||||
|
|
||||||
if (!$info->save()) throw new ErrException('账号修改失败');
|
if (!$info->save()) throw new ErrException('账号修改失败');
|
||||||
|
|||||||
Reference in New Issue
Block a user