update:后台添加用户接口,用户角色下拉列表接口,公司下拉列表接口

This commit is contained in:
chenbo 2023-10-10 16:33:46 +08:00
parent 024c437337
commit 5eb6d22c08
5 changed files with 83 additions and 0 deletions

View File

@ -18,6 +18,7 @@ use app\adminapi\lists\user\UserLists;
use app\adminapi\logic\user\UserLogic;
use app\adminapi\validate\user\AdjustUserMoney;
use app\adminapi\validate\user\UserValidate;
use app\common\logic\CompanyLogic;
use think\facade\Db;
use think\facade\Request;
use app\common\logic\contract\ContractLogic;
@ -55,6 +56,15 @@ class UserController extends BaseAdminController
return $this->success('', $detail);
}
public function add()
{
$params = $this->request->param();
$re = UserLogic::addUser($params);
if ($re) {
return $this->success('添加成功');
}
return $this->fail(UserLogic::getError());
}
/**
* @notes 编辑用户信息
@ -111,4 +121,9 @@ class UserController extends BaseAdminController
return $this->fail(ContractLogic::getError());
}
}
public function getCompanyList()
{
return $this->data(CompanyLogic::getList());
}
}

View File

@ -104,5 +104,10 @@ class UserRoleController extends BaseAdminController
return $this->data($result);
}
public function getList()
{
$list = UserRoleLogic::getList();
return $this->data($list);
}
}

View File

@ -20,6 +20,8 @@ use app\common\logic\BaseLogic;
use app\common\model\contract\Contract;
use app\common\model\dict\DictData;
use app\common\model\user\User;
use app\common\service\ConfigService;
use think\facade\Config;
use think\facade\Db;
/**
@ -122,4 +124,53 @@ class UserLogic extends BaseLogic
}
}
public static function addUser($params)
{
// 手机号已被使用
$mobileUser = User::where(['account' => $params['account']])->find();
if (!empty($mobileUser)) {
self::setError('手机号已被注册');
return false;
}
$count = User::where('company_id', $params['company_id'])->count();
$value = DictData::where('id', 28)->value('value');
if ($count >= $value) {
self::setError('你创建的账号已达上限');
return false;
}
$userSn = User::createUserSn();
$passwordSalt = Config::get('project.unique_identification');
$password = create_password(123456, $passwordSalt);
if ($params['avatar'] != '') {
$avatar = $params['avatar'];
} else {
$avatar = ConfigService::get('default_image', 'user_avatar');
}
$group_id = $params['group_id'];
User::create([
'sn' => $userSn,
'avatar' => $avatar,
'is_captain' => $group_id == 2? 1: 0,
'nickname' => $params['nickname'],
'account' => $params['account'],
'mobile' => $params['account'],
'id_card' => $params['id_card'],
'password' => $password,
'channel' => 0,
'sex' => $params['sex'],
'province' => $params['province'],
'city' => $params['city'],
'area' => $params['area'],
'street' => $params['street'],
'village' => $params['village'],
'brigade' => $params['brigade'],
'address' => $params['address'],
'qualification' => json_encode($params['qualification']),
'company_id' => $params['company_id'],
'group_id' => $group_id,
]);
return true;
}
}

View File

@ -424,5 +424,10 @@ class CompanyLogic extends BaseLogic
$model->party_b = $companyId;
$model->save();
return $model->id;
}
public static function getList()
{
return Company::field(['id', 'company_name', 'province', 'city', 'area', 'street', 'village', 'brigade'])->select()->toArray();
}
}

View File

@ -109,4 +109,11 @@ class UserRoleLogic extends BaseLogic
{
return UserRole::findOrEmpty($params['id'])->toArray();
}
public static function getList()
{
return UserRole::order(['id' => 'desc'])->field(['id', 'name'])
->select()
->toArray();
}
}