feat : driver
This commit is contained in:
@@ -11,11 +11,13 @@ declare(strict_types=1);
|
||||
namespace App\Service\Admin\User;
|
||||
|
||||
use App\Constants\Admin\UserCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Extend\StringUtil;
|
||||
use App\Lib\Crypto\CryptoFactory;
|
||||
use App\Model\AdminRole;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\DriverSequence;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -101,6 +103,17 @@ class EmployeeService extends BaseService
|
||||
|
||||
if (!$model->save()) throw new ErrException('账号添加失败');
|
||||
|
||||
//写入关联表
|
||||
$res = match ($model->role_id) {
|
||||
RoleCode::DRIVER =>
|
||||
(new DriverSequence)->insert([
|
||||
'driver_id' => $model->id,
|
||||
]),
|
||||
default => true,
|
||||
};
|
||||
|
||||
if (!$res) throw new ErrException('关联表添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
@@ -113,6 +126,7 @@ class EmployeeService extends BaseService
|
||||
$id = (int)$this->request->input('id');
|
||||
$name = $this->request->input('chinese_name');
|
||||
$account = $this->request->input('account');
|
||||
$roleId = $this->request->input('role_id', 0);
|
||||
|
||||
$info = $this->adminUserModel->getAdminInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
@@ -123,12 +137,29 @@ class EmployeeService extends BaseService
|
||||
if (!empty($oldName) && $oldName->id != $info->id) throw new ErrException('员工已存在');
|
||||
if (!empty($oldAccount) && $oldAccount->id != $info->id) throw new ErrException('账号已存在');
|
||||
|
||||
if ($info->role_id != $roleId) {
|
||||
//写入关联表
|
||||
$del = match ($info->role_id) {
|
||||
RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->delete(),
|
||||
default => true,
|
||||
};
|
||||
|
||||
$add = match ($roleId) {
|
||||
RoleCode::DRIVER => (new DriverSequence)->insert([
|
||||
'driver_id' => $info->id,
|
||||
]),
|
||||
default => true,
|
||||
};
|
||||
|
||||
if (!$del || !$add) throw new ErrException('关联表修改失败');
|
||||
}
|
||||
|
||||
$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);
|
||||
$info->role_id = $roleId;
|
||||
$info->city_id = $this->request->input('city_id', 0);
|
||||
$info->section_id = $this->request->input('section_id', 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user