|
@@ -33,8 +33,12 @@ class Admin extends Apic
|
|
|
parent::_initialize();
|
|
|
$this->model = model('Admin');
|
|
|
|
|
|
- $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
|
|
|
- $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
|
|
|
+ $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());//下级管理员
|
|
|
+ $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());//下级角色组
|
|
|
+
|
|
|
+ /*dump($this->childrenAdminIds);
|
|
|
+ dump($this->childrenGroupIds);
|
|
|
+ exit;*/
|
|
|
|
|
|
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
|
|
|
|
|
@@ -88,12 +92,11 @@ class Admin extends Apic
|
|
|
}
|
|
|
|
|
|
$list = Db::name('pc_admin')
|
|
|
- ->where('company_id',$this->auth->company_id)
|
|
|
+ ->where('company_id',$this->auth->company_id) //多此一举
|
|
|
->where('id', 'in', $this->childrenAdminIds)
|
|
|
->field(['password', 'salt', 'token'], true)
|
|
|
->order('id', 'asc')
|
|
|
- ->autopage()
|
|
|
- ->select();
|
|
|
+ ->paginate();
|
|
|
|
|
|
foreach ($list as $k => &$v) {
|
|
|
$v['avatar'] = localpath_to_netpath($v['avatar']);
|
|
@@ -103,7 +106,8 @@ class Admin extends Apic
|
|
|
}
|
|
|
unset($v);
|
|
|
|
|
|
- $this->success(1,$list);
|
|
|
+ $result = array("total" => $list->total(), "list" => $list->items());
|
|
|
+ $this->success(1,$result);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -176,6 +180,10 @@ class Admin extends Apic
|
|
|
}
|
|
|
|
|
|
$row['groupids'] = $groupids;
|
|
|
+
|
|
|
+ unset($row['password']);
|
|
|
+ unset($row['salt']);
|
|
|
+
|
|
|
$this->success(1,$row);
|
|
|
}
|
|
|
|
|
@@ -185,59 +193,73 @@ class Admin extends Apic
|
|
|
public function edit()
|
|
|
{
|
|
|
$ids = input('id',0);
|
|
|
- if ($this->request->isPost()) {
|
|
|
- $this->token();
|
|
|
- $params = $this->request->post("row/a");
|
|
|
- if ($params) {
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- if ($params['password']) {
|
|
|
- if (!Validate::is($params['password'], '\S{6,30}')) {
|
|
|
- exception(__("Please input correct password"));
|
|
|
- }
|
|
|
- $params['salt'] = Random::alnum();
|
|
|
- $params['password'] = $this->auth->getEncryptPassword($params['password'], $params['salt']);
|
|
|
- } else {
|
|
|
- unset($params['password'], $params['salt']);
|
|
|
- }
|
|
|
- //这里需要针对username和email做唯一验证
|
|
|
- $adminValidate = \think\Loader::validate('Admin');
|
|
|
- $adminValidate->rule([
|
|
|
- 'username' => 'require|regex:\w{3,30}|unique:PcAdmin,username,' . $row->id,
|
|
|
- 'email' => 'require|email|unique:PcAdmin,email,' . $row->id,
|
|
|
- 'mobile' => 'regex:1[3-9]\d{9}|unique:PcAdmin,mobile,' . $row->id,
|
|
|
- 'password' => 'regex:\S{32}',
|
|
|
- ]);
|
|
|
- $result = $row->validate('Admin.edit')->save($params);
|
|
|
- if ($result === false) {
|
|
|
- exception($row->getError());
|
|
|
- }
|
|
|
+ $row = $this->model->get(['id' => $ids]);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ if (!in_array($row->id, $this->childrenAdminIds)) {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ 'username' => input('username',''),//手机号
|
|
|
+ 'nickname' => input('nickname',''),//姓名
|
|
|
+ 'password' => input('password',''),//密码
|
|
|
+ 'gonghao' => input('gonghao',''), //工号
|
|
|
+ ];
|
|
|
+ $group_id = input('group_id',0);
|
|
|
+ if(empty($group_id)){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if ($params['password']) {
|
|
|
+ if (!Validate::is($params['password'], '\S{6,30}')) {
|
|
|
+ exception(__("Please input correct password"));
|
|
|
+ }
|
|
|
+ $params['salt'] = Random::alnum();
|
|
|
+ $params['password'] = $this->auth->getEncryptPassword($params['password'], $params['salt']);
|
|
|
+ } else {
|
|
|
+ unset($params['password'], $params['salt']);
|
|
|
+ }
|
|
|
+ $params['mobile'] = $params['username'];
|
|
|
+ //这里需要针对username和email做唯一验证
|
|
|
+ $adminValidate = \think\Loader::validate('Admin');
|
|
|
+ $adminValidate->rule([
|
|
|
+ 'mobile' => 'require|regex:1\d{10}|unique:PcAdmin,mobile,' . $row->id,
|
|
|
+ 'username' => 'require|regex:1\d{10}|unique:PcAdmin,username,' . $row->id,
|
|
|
+ 'password' => 'regex:\S{32}',
|
|
|
+ ]);
|
|
|
+ $result = $row->validate('Admin.edit')->save($params);
|
|
|
+ if ($result === false) {
|
|
|
+ exception($row->getError());
|
|
|
+ }
|
|
|
|
|
|
- // 先移除所有权限
|
|
|
- model('AuthGroupAccess')->where('uid', $row->id)->delete();
|
|
|
+ // 先移除所有权限
|
|
|
+ model('AuthGroupAccess')->where('uid', $row->id)->delete();
|
|
|
|
|
|
- $group = $this->request->post("group/a");
|
|
|
+ $group = [$group_id];
|
|
|
|
|
|
- // 过滤不允许的组别,避免越权
|
|
|
- $group = array_intersect($this->childrenGroupIds, $group);
|
|
|
- if (!$group) {
|
|
|
- exception(__('The parent group exceeds permission limit'));
|
|
|
- }
|
|
|
+ // 过滤不允许的组别,避免越权
|
|
|
+ $group = array_intersect($this->childrenGroupIds, $group);
|
|
|
+ if (!$group) {
|
|
|
+ exception(__('The parent group exceeds permission limit'));
|
|
|
+ }
|
|
|
|
|
|
- $dataset = [];
|
|
|
- foreach ($group as $value) {
|
|
|
- $dataset[] = ['uid' => $row->id, 'group_id' => $value];
|
|
|
- }
|
|
|
- model('AuthGroupAccess')->saveAll($dataset);
|
|
|
- Db::commit();
|
|
|
- } catch (\Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- $this->success();
|
|
|
+ $dataset = [];
|
|
|
+ foreach ($group as $value) {
|
|
|
+ $dataset[] = ['uid' => $row->id, 'group_id' => $value];
|
|
|
}
|
|
|
- $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ model('AuthGroupAccess')->saveAll($dataset);
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
}
|
|
|
+ $this->success();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|