留学万象
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

143 lines
5.1 KiB

<?php
namespace app\admin\controller\shopro;
use app\admin\model\AuthGroup;
use app\admin\model\AuthGroupAccess;
use app\admin\model\shopro\chat\CustomerService;
use app\common\controller\Backend;
use fast\Random;
use fast\Tree;
use think\Validate;
/**
* 管理员管理
*
* @icon fa fa-users
* @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
*/
class Admin extends Backend
{
/**
* @var \app\admin\model\Admin
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->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();
}
}