model = model('Admin'); $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true); $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); Tree::instance()->init($groupList); $groupdata = []; if ($this->auth->isSuperAdmin()) { $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); foreach ($result as $k => $v) { $groupdata[$v['id']] = $v['name']; } } else { $result = []; $groups = $this->auth->getGroups(); foreach ($groups as $m => $n) { $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id'])); $temp = []; foreach ($childlist as $k => $v) { $temp[$v['id']] = $v['name']; } $result[__($n['name'])] = $temp; } $groupdata = $result; } $this->view->assign('groupdata', $groupdata); $this->assignconfig("admin", ['id' => $this->auth->id]); } /** * 查看, controller/auth/admin.php 只改了返回值 */ public function index() { if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $childrenGroupIds = $this->childrenGroupIds; $groupName = AuthGroup::where('id', 'in', $childrenGroupIds) ->column('id,name'); $authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds) ->field('uid,group_id') ->select(); $adminGroupName = []; foreach ($authGroupList as $k => $v) { if (isset($groupName[$v['group_id']])) { $adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']]; } } $groups = $this->auth->getGroups(); foreach ($groups as $m => $n) { $adminGroupName[$this->auth->id][$n['id']] = $n['name']; } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $type = $this->request->get("type", ''); $admin_ids = []; if ($type == 'customer_service') { $type_id = $this->request->get("type_id", 0); // 查询客服列表,,找到当前客服 type_id $customerServices = CustomerService::select(); $currentCustomerService = null; if ($type_id) { foreach ($customerServices as $key => $customerService) { if ($customerService['id'] == $type_id) { $currentCustomerService = $customerService; } } } $admin_ids = array_unique(array_column($customerServices, 'admin_id')); if ($currentCustomerService) { foreach ($admin_ids as $key => $admin_id) { if ($admin_id == $currentCustomerService['admin_id']) { unset($admin_ids[$key]); // 当前客服的 admin 也要查出来 } } } } $total = $this->model ->where($where) ->where('id', 'in', $this->childrenAdminIds) ->where('id', 'not in', $admin_ids) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->where('id', 'in', $this->childrenAdminIds) ->where('id', 'not in', $admin_ids) ->field(['password', 'salt', 'token'], true) ->order($sort, $order) ->limit($offset, $limit) ->select(); foreach ($list as $k => &$v) { $groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : []; $v['groups'] = implode(',', array_keys($groups)); $v['groups_text'] = implode(',', array_values($groups)); } unset($v); $result = array("total" => $total, "rows" => $list); return $this->success('操作成功', null, $result); } return $this->view->fetch(); } }