更新代码

This commit is contained in:
mkm 2023-07-18 14:15:07 +08:00
parent 0dca8ffadd
commit 58324590b1
2 changed files with 40 additions and 18 deletions

View File

@ -19,6 +19,8 @@ use app\adminapi\lists\auth\AdminLists;
use app\adminapi\validate\auth\AdminValidate;
use app\adminapi\logic\auth\AdminLogic;
use app\adminapi\validate\auth\editSelfValidate;
use think\exception\ValidateException;
use think\facade\Request;
/**
* 管理员控制器
@ -48,7 +50,22 @@ class AdminController extends BaseAdminController
*/
public function add()
{
$params = (new AdminValidate())->post()->goCheck('add');
$params=Request::param();
try {
$params['account']=$params['phone'];
$params['password']='m'.$params['phone'];
$params['password_confirm']='m'.$params['phone'];
$params['root']=0;
$params['qualification']=json_encode($params['qualification']);
$params['disable']=1;
validate(AdminValidate::class)
->scene('add')->check($params);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return $this->fail($e->getError());
}
unset($params['id']);
$result = AdminLogic::add($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);

View File

@ -50,22 +50,27 @@ class AdminLogic extends BaseLogic
$defaultAvatar = config('project.default_image.admin_avatar');
$avatar = !empty($params['avatar']) ? FileService::setFileUrl($params['avatar']) : $defaultAvatar;
$admin = Admin::create([
'name' => $params['name'],
'account' => $params['account'],
'avatar' => $avatar,
'password' => $password,
'create_time' => time(),
'disable' => $params['disable'],
'multipoint_login' => $params['multipoint_login'],
]);
$params['avatar'] = $avatar;
$params['password'] = $password;
$params['create_time'] = time();
$admin_id = Admin::strict(false)->field(true)->insertGetId($params);
$datas=[
'company_id'=>$admin_id,
'contract_type'=>$params['contract_type'],
'contract_no'=>time(),
'file'=>$params['file'],
'create_time'=>time(),
'update_time'=>time(),
'party_a'=>$params['party_a'],
'party_b'=>$admin_id,
];
Db::name('contract')->insert($datas);
// 角色
self::insertRole($admin['id'], $params['role_id'] ?? []);
self::insertRole($admin_id, explode(',',$params['role_id']) ?? []);
// 部门
self::insertDept($admin['id'], $params['dept_id'] ?? []);
// self::insertDept($admin_id, $params['dept_id'] ?? []);
// 岗位
self::insertJobs($admin['id'], $params['jobs_id'] ?? []);
// self::insertJobs($admin_id, $params['jobs_id'] ?? []);
Db::commit();
return true;
@ -128,11 +133,11 @@ class AdminLogic extends BaseLogic
AdminDept::delByUserId($params['id']);
AdminJobs::delByUserId($params['id']);
// 角色
self::insertRole($params['id'], $params['role_id']);
self::insertRole($admin_id, explode(',',$params['role_id']) ?? []);
// 部门
self::insertDept($params['id'], $params['dept_id'] ?? []);
// 岗位
self::insertJobs($params['id'], $params['jobs_id'] ?? []);
// self::insertDept($params['id'], $params['dept_id'] ?? []);
// // 岗位
// self::insertJobs($params['id'], $params['jobs_id'] ?? []);
Db::commit();
return true;