feat : user
This commit is contained in:
@@ -10,10 +10,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin;
|
||||
|
||||
use App\Constants\Admin\UserCode;
|
||||
use App\Exception\AdminException;
|
||||
use App\Extend\StringUtil;
|
||||
use App\Lib\Crypto\CryptoFactory;
|
||||
use App\Model\AdminUser;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class EmployeeService extends BaseService
|
||||
{
|
||||
@@ -24,12 +28,27 @@ class EmployeeService extends BaseService
|
||||
#[Inject]
|
||||
protected AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* 注入加密工厂
|
||||
* @var CryptoFactory $cryptoFactory
|
||||
*/
|
||||
#[Inject]
|
||||
protected CryptoFactory $cryptoFactory;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function add()
|
||||
/**
|
||||
* 添加
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(): array
|
||||
{
|
||||
$name = $this->request->input('chinese_name');
|
||||
$account = $this->request->input('account');
|
||||
@@ -40,34 +59,60 @@ class EmployeeService extends BaseService
|
||||
if (!empty($oldName) && !empty($oldAccount)) throw new AdminException('账号或者员工已存在');
|
||||
|
||||
$salt = StringUtil::randStr(6);
|
||||
$defaultPassword = config('system.admin_default_password');
|
||||
|
||||
$model = new AdminUser();
|
||||
|
||||
$model->username = $account;
|
||||
$model->chinese_name = $name;
|
||||
$model->salt =
|
||||
$model->salt = $salt;
|
||||
$model->password = $this->cryptoFactory->cryptoClass('admin-password',$defaultPassword,$salt)->encrypt();
|
||||
$model->status = $this->request->input('status', 1);
|
||||
$model->avatar = $this->request->input('avatar',0);
|
||||
$model->role_id = $this->request->input('role_id', 0);
|
||||
|
||||
|
||||
$model->save();
|
||||
if (!$model->save()) throw new AdminException('账号添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
/**
|
||||
* 删除
|
||||
* @return array
|
||||
*/
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
|
||||
if (empty($info)) throw new AdminException('员工不存在');
|
||||
|
||||
$info->is_del = UserCode::DISABLE;
|
||||
|
||||
if (!$info->save()) throw new AdminException('账号删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function get()
|
||||
/**
|
||||
* 详情
|
||||
* @return array
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
return $this->return->success();
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
|
||||
if (empty($info)) throw new AdminException('员工不存在');
|
||||
|
||||
return $this->return->success('success', ['info' => $info->toArray()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user