|
@@ -56,17 +56,6 @@ class UseradminController extends Controller
|
|
|
Helper::ok($data);
|
|
Helper::ok($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 角色下拉列表获取
|
|
|
|
|
- * @return void
|
|
|
|
|
- */
|
|
|
|
|
- public function actionGetRoleSelect()
|
|
|
|
|
- {
|
|
|
|
|
- $cri = DbCriteria::simpleCompare([])->setSelect('id, name');
|
|
|
|
|
- $data = DB::getListWithCriteria('role', $cri);
|
|
|
|
|
- Helper::ok($data['records']??[]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public function actionUserList()
|
|
public function actionUserList()
|
|
|
{
|
|
{
|
|
|
$name = Helper::getPostString('name');
|
|
$name = Helper::getPostString('name');
|
|
@@ -81,38 +70,54 @@ class UseradminController extends Controller
|
|
|
$cri = DbCriteria::simpleCompareWithPage($filters)
|
|
$cri = DbCriteria::simpleCompareWithPage($filters)
|
|
|
->setAlias('u')
|
|
->setAlias('u')
|
|
|
->setDebugUntil('234', '-1')
|
|
->setDebugUntil('234', '-1')
|
|
|
- ->setSelect('u.id, u.username, r.name as role_name, u.status, u.sex, u.phone, u.create_date, u.avatar, u.update_date')
|
|
|
|
|
|
|
+ ->setSelect('u.id, u.username, r.name as role_name, u.status, u.role_id, u.sex, u.phone, u.create_date, u.avatar, u.update_date, u.company_ids, u.school_ids')
|
|
|
->setJoin('left join wx_role r on u.role_id = r.id')
|
|
->setJoin('left join wx_role r on u.role_id = r.id')
|
|
|
->setOrder('id desc');
|
|
->setOrder('id desc');
|
|
|
$data = DB::getListWithCriteria('useradmin', $cri);
|
|
$data = DB::getListWithCriteria('useradmin', $cri);
|
|
|
if (!empty($data['records'])) {
|
|
if (!empty($data['records'])) {
|
|
|
- $data['records'] = array_map(function ($item) {
|
|
|
|
|
|
|
+ $schools = Helper::arrayColumn(
|
|
|
|
|
+ DB::getListWithCriteria('school', DbCriteria::simpleCompare([])->setSelect('id, name')),
|
|
|
|
|
+ 'name',
|
|
|
|
|
+ 'id'
|
|
|
|
|
+ );
|
|
|
|
|
+ $companys = Helper::arrayColumn(
|
|
|
|
|
+ DB::getListWithCriteria('company', DbCriteria::simpleCompare([])->setSelect('id, name')),
|
|
|
|
|
+ 'name',
|
|
|
|
|
+ 'id'
|
|
|
|
|
+ );
|
|
|
|
|
+ $data['records'] = array_map(function ($item) use ($schools, $companys) {
|
|
|
$item['avatar'] = Helper::getImageUrl($item['avatar']);
|
|
$item['avatar'] = Helper::getImageUrl($item['avatar']);
|
|
|
|
|
+ $item['company_ids'] = $item['company_ids'] ? array_map(function ($item) {return (int)$item;}, explode(',', $item['company_ids'])) : [];
|
|
|
|
|
+ $item['school_ids'] = $item['school_ids'] ? array_map(function ($item) {return (int)$item;}, explode(',', $item['school_ids'])) : [];
|
|
|
|
|
+ $item['company_names'] = array_map(function ($item) use ($companys) {
|
|
|
|
|
+ if (isset($companys[$item])) return $companys[$item];
|
|
|
|
|
+ }, $item['company_ids']);
|
|
|
|
|
+ $item['school_names'] = array_map(function ($item) use ($schools) {
|
|
|
|
|
+ if (isset($schools[$item])) return $schools[$item];
|
|
|
|
|
+ }, $item['school_ids']);
|
|
|
return $item;
|
|
return $item;
|
|
|
}, $data['records']);
|
|
}, $data['records']);
|
|
|
}
|
|
}
|
|
|
Helper::ok($data);
|
|
Helper::ok($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function actionGetSelectList()
|
|
|
|
|
- {
|
|
|
|
|
- $data = DB::getListWithCriteria('useradmin', DbCriteria::simpleCompare(['id' => '!=1', 'status' => 1])->setSelect('id, username as name'));
|
|
|
|
|
- Helper::ok($data['records']);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public function actionSaveRoleAuth()
|
|
public function actionSaveRoleAuth()
|
|
|
{
|
|
{
|
|
|
$id = Helper::getPostInt('id');
|
|
$id = Helper::getPostInt('id');
|
|
|
$leaf_ids = Helper::getArrParam($_POST, 'leaf_ids', 'array_int', []);
|
|
$leaf_ids = Helper::getArrParam($_POST, 'leaf_ids', 'array_int', []);
|
|
|
$half_Leaf_ids = Helper::getArrParam($_POST, 'half_Leaf_ids', 'array_int', []);
|
|
$half_Leaf_ids = Helper::getArrParam($_POST, 'half_Leaf_ids', 'array_int', []);
|
|
|
if ($id < 0 || !$leaf_ids) {
|
|
if ($id < 0 || !$leaf_ids) {
|
|
|
- return Helper::error('参数错误');
|
|
|
|
|
|
|
+ Helper::error('参数错误');
|
|
|
}
|
|
}
|
|
|
$info = [
|
|
$info = [
|
|
|
'auth_ids' => implode(',', Helper::concatArray($half_Leaf_ids, $leaf_ids)),
|
|
'auth_ids' => implode(',', Helper::concatArray($half_Leaf_ids, $leaf_ids)),
|
|
|
'show_ids' => $leaf_ids ? implode(',', $leaf_ids) : '',
|
|
'show_ids' => $leaf_ids ? implode(',', $leaf_ids) : '',
|
|
|
];
|
|
];
|
|
|
DB::updateById('role', $info, $id);
|
|
DB::updateById('role', $info, $id);
|
|
|
|
|
+ $users = DB::getListWithCriteria('useradmin', DbCriteria::simpleCompare(['role_id' => $id])->setSelect('id'))?:[];
|
|
|
|
|
+ foreach ($users as $user) {
|
|
|
|
|
+ $this->clearAuth($user['id']);
|
|
|
|
|
+ }
|
|
|
Helper::ok();
|
|
Helper::ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -124,6 +129,8 @@ class UseradminController extends Controller
|
|
|
$phone = Helper::getPostString('phone');
|
|
$phone = Helper::getPostString('phone');
|
|
|
$sex = Helper::getPostInt('sex');
|
|
$sex = Helper::getPostInt('sex');
|
|
|
$role_id = Helper::getPostInt('role_id');
|
|
$role_id = Helper::getPostInt('role_id');
|
|
|
|
|
+ $company_ids = Helper::getArrParam($_POST, 'company_ids', 'array_int', []);
|
|
|
|
|
+ $school_ids = Helper::getArrParam($_POST, 'school_ids', 'array_int', []);
|
|
|
// username不能为空和重复
|
|
// username不能为空和重复
|
|
|
if (!$username) {
|
|
if (!$username) {
|
|
|
Helper::error('用户名不能为空');
|
|
Helper::error('用户名不能为空');
|
|
@@ -140,6 +147,8 @@ class UseradminController extends Controller
|
|
|
'phone' => $phone,
|
|
'phone' => $phone,
|
|
|
'sex' => $sex,
|
|
'sex' => $sex,
|
|
|
'role_id' => $role_id,
|
|
'role_id' => $role_id,
|
|
|
|
|
+ 'company_ids' => $company_ids ? implode(',', $company_ids) : '',
|
|
|
|
|
+ 'school_ids' => $school_ids ? implode(',', $school_ids) : '',
|
|
|
];
|
|
];
|
|
|
if (!$id) {
|
|
if (!$id) {
|
|
|
// 新增用户
|
|
// 新增用户
|
|
@@ -152,6 +161,7 @@ class UseradminController extends Controller
|
|
|
$info['password'] = md5($password);
|
|
$info['password'] = md5($password);
|
|
|
DB::addData('useradmin', $info);
|
|
DB::addData('useradmin', $info);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ $this->clearAuth($id);
|
|
|
DB::updateById('useradmin', $info, $id);
|
|
DB::updateById('useradmin', $info, $id);
|
|
|
}
|
|
}
|
|
|
Helper::ok();
|
|
Helper::ok();
|