feat : user
This commit is contained in:
@@ -19,6 +19,11 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
])]
|
||||
class EmployeeController
|
||||
{
|
||||
/**
|
||||
* @param EmployeeRequest $request
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[RequestMapping(path: "add", methods: "POST")]
|
||||
#[Scene(scene: "add")]
|
||||
public function add(EmployeeRequest $request)
|
||||
@@ -26,6 +31,10 @@ class EmployeeController
|
||||
return (new EmployeeService)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmployeeRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "edit", methods: "POST")]
|
||||
#[Scene(scene: "edit")]
|
||||
public function edit(EmployeeRequest $request)
|
||||
@@ -33,24 +42,48 @@ class EmployeeController
|
||||
return (new EmployeeService)->edit();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "del", methods: "POST")]
|
||||
/**
|
||||
* @param EmployeeRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "del", methods: "GET")]
|
||||
#[Scene(scene: "del")]
|
||||
public function delete(EmployeeRequest $request)
|
||||
{
|
||||
return (new EmployeeService)->delete();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "list", methods: "POST")]
|
||||
/**
|
||||
* @param EmployeeRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "list")]
|
||||
public function list(EmployeeRequest $request)
|
||||
{
|
||||
return (new EmployeeService)->handle();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "info", methods: "POST")]
|
||||
/**
|
||||
* @param EmployeeRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "info", methods: "GET")]
|
||||
#[Scene(scene: "info")]
|
||||
public function info(EmployeeRequest $request)
|
||||
{
|
||||
return (new EmployeeService)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmployeeRequest $request
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[RequestMapping(path: "reset_password", methods: "GET")]
|
||||
#[Scene(scene: "reset_password")]
|
||||
public function resetPassword(EmployeeRequest $request)
|
||||
{
|
||||
return (new EmployeeService)->resetPassword();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,6 @@ class EmployeeRequest extends FormRequest
|
||||
'del' => ['id'],
|
||||
'reset_password' => ['id'],
|
||||
'info' => ['id'],
|
||||
'list' => ['limit']
|
||||
'list' => ['limit'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -74,3 +74,39 @@ Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
role_id=3&role_name=测试&role_status=1&menu_ids=1,2,3,4,5,6,7&role_remark=测试
|
||||
|
||||
|
||||
|
||||
### 账号添加
|
||||
POST {{host}}/admin/employee/add
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
account=13632877013&status=1&role_id=1&chinese_name=测试
|
||||
|
||||
### 账号修改
|
||||
POST {{host}}/admin/employee/edit
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
id=2&account=13632877013&status=1&role_id=1&chinese_name=测试1
|
||||
|
||||
### 账号删除
|
||||
GET {{host}}/admin/employee/del?id=2
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 账号详情
|
||||
GET {{host}}/admin/employee/info?id=1
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 账号列表
|
||||
GET {{host}}/admin/employee/list?limit=10
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 账号重置密码
|
||||
GET {{host}}/admin/employee/reset_password?id=2
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
Reference in New Issue
Block a user