feat : user
This commit is contained in:
@@ -35,12 +35,22 @@ class EmployeeService extends BaseService
|
||||
#[Inject]
|
||||
protected CryptoFactory $cryptoFactory;
|
||||
|
||||
public function handle()
|
||||
/**
|
||||
* @var array|string[]
|
||||
*/
|
||||
private array $filed = ['id','username','avatar','chinese_name','mobile','status','last_login_ip','last_login_time','role_id'];
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
|
||||
$list = $this->adminUserModel->where('is_del',UserCode::ENABLE)->paginate($limit,$this->filed)->toArray();
|
||||
|
||||
return $this->return->success();
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,6 +74,7 @@ class EmployeeService extends BaseService
|
||||
$model = new AdminUser();
|
||||
|
||||
$model->username = $account;
|
||||
$model->mobile = $account;
|
||||
$model->chinese_name = $name;
|
||||
$model->salt = $salt;
|
||||
$model->password = $this->cryptoFactory->cryptoClass('admin-password',$defaultPassword,$salt)->encrypt();
|
||||
@@ -76,8 +87,33 @@ class EmployeeService extends BaseService
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
/**
|
||||
* 修改
|
||||
* @return array
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$name = $this->request->input('chinese_name');
|
||||
$account = $this->request->input('account');
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
if (empty($info)) throw new AdminException('数据不存在');
|
||||
|
||||
$oldAccount = $this->adminUserModel->getAdminInfoByAccount($account);
|
||||
$oldName = $this->adminUserModel->getAdminInfoByName($name);
|
||||
|
||||
if (!empty($oldName) && $oldName->id != $info->id) throw new AdminException('员工已存在');
|
||||
if (!empty($oldAccount) && $oldAccount->id != $info->id) throw new AdminException('账号已存在');
|
||||
|
||||
$info->username = $account;
|
||||
$info->mobile = $account;
|
||||
$info->chinese_name = $name;
|
||||
$info->status = $this->request->input('status', 1);
|
||||
$info->avatar = $this->request->input('avatar',0);
|
||||
$info->role_id = $this->request->input('role_id', 0);
|
||||
|
||||
if (!$info->save()) throw new AdminException('账号修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -90,6 +126,8 @@ class EmployeeService extends BaseService
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
if ($this->adminId == $id) throw new AdminException('不可删除自己');
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
|
||||
if (empty($info)) throw new AdminException('员工不存在');
|
||||
@@ -109,10 +147,34 @@ class EmployeeService extends BaseService
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
$info = $this->adminUserModel->where('id', $id)->where('is_del',UserCode::ENABLE)->first($this->filed);
|
||||
|
||||
if (empty($info)) throw new AdminException('员工不存在');
|
||||
|
||||
return $this->return->success('success', ['info' => $info->toArray()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function resetPassword(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
|
||||
if (empty($info)) throw new AdminException('员工不存在');
|
||||
|
||||
$salt = StringUtil::randStr(6);
|
||||
$defaultPassword = config('system.admin_default_password');
|
||||
|
||||
$info->salt = $salt;
|
||||
$info->password = $this->cryptoFactory->cryptoClass('admin-password',$defaultPassword,$salt)->encrypt();
|
||||
|
||||
if (!$info->save()) throw new AdminException('密码重置失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user