|
@@ -24,74 +24,53 @@ class AdminUser extends Auth{
|
|
|
* 列表页
|
|
|
*
|
|
|
* */
|
|
|
- public function index(Model $Model){
|
|
|
- $mp = [];
|
|
|
- $session = session('userRule');
|
|
|
- if ($session){
|
|
|
- $mp[] = ['admin_rule.company_id','=',$session['company_id']];
|
|
|
- if ($session['business_id']){
|
|
|
- $mp[] = ['admin_rule.business_id','=',$session['business_id']];
|
|
|
- }
|
|
|
- }
|
|
|
- if(!in_array(admin('uid'), explode(',', config('administrator')))){
|
|
|
- $mp['admin_rule.type'] = 1;
|
|
|
+ public function index(Model $Model,Business $Business,Company $Company){
|
|
|
+ // 查询数据
|
|
|
+ $map = [];
|
|
|
+ // 当前登录用户角色数据
|
|
|
+ $session = session('userRule') ? session('userRule') : ['menu_type'=>0,'company_id'=>1,'business_id'=>0];
|
|
|
+ // 非超管
|
|
|
+ if( !in_array(admin('uid'), explode(',', config('administrator'))) ){
|
|
|
+ // 规格条件
|
|
|
+ $map[] = ['admin_rule.type','=',1];
|
|
|
+ $map[] = ['admin_rule.company_id','=',$session['company_id']];
|
|
|
+ if ($session['business_id']) $map[] = ['admin_rule.business_id','=',$session['business_id']];
|
|
|
}
|
|
|
// 查询系统用户
|
|
|
- $list = $Model::query();
|
|
|
- if($mp) $list->join('admin_rule','admin_rule.admin_uid','=','admin.uid');
|
|
|
- $list = $list->where($mp)
|
|
|
- ->orderByDesc('admin.uid')
|
|
|
- ->paginate(config('page_num',10));
|
|
|
+ $list = $Model->query()->join('admin_rule','admin_rule.admin_uid','=','admin.uid','LEFT')->where($map)->orderByDesc('admin.uid')->paginate(config('page_num',10));
|
|
|
// 循环处理
|
|
|
foreach ($list as $key => $value) {
|
|
|
// 获取分组名
|
|
|
- $group = DB::table('auth_group')
|
|
|
+ $group = DB::table('auth_group')
|
|
|
->join('auth_group_access','auth_group_access.group_id','=','auth_group.id')
|
|
|
->where([['auth_group_access.user_uid','=',$value['uid']]])
|
|
|
->pluck('auth_group.title')->toArray();
|
|
|
- if (in_array($value['uid'],explode(',',config('administrator')))) $group[] = '超管';
|
|
|
+ // 返回结果
|
|
|
+ if ( in_array($value['uid'],explode(',',config('administrator'))) ) $group[] = '超管';
|
|
|
// 切成字符串
|
|
|
- $value['title'] = implode('、', $group);
|
|
|
+ $value['title'] = implode('、', $group);
|
|
|
//获取用户角色
|
|
|
- $rule = DB::table('admin_rule')->where('admin_uid',$value['uid'])->first();
|
|
|
- $rule_title = '';
|
|
|
- if ($rule){
|
|
|
- switch ($rule['menu_type']){
|
|
|
- case 1:
|
|
|
- $rule_title = '商户';
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- $rule_title = '店铺';
|
|
|
- break;
|
|
|
- }
|
|
|
- if ($rule['menu_type'] == 1){
|
|
|
- if ($rule['data_type'] == 1){
|
|
|
- $rule_title = '商户普通员工';
|
|
|
- }elseif ($rule['data_type'] == 2){
|
|
|
- $rule_title = '商户代表';
|
|
|
- }
|
|
|
- }elseif ($rule['menu_type'] == 2){
|
|
|
- if ($rule['data_type'] == 1){
|
|
|
- $rule_title = '店铺普通员工';
|
|
|
- }elseif ($rule['data_type'] == 2){
|
|
|
- $rule_title = '店铺推广员';
|
|
|
- }
|
|
|
- }
|
|
|
+ $rule = DB::table('admin_rule')->where('admin_uid',$value['uid'])->first();
|
|
|
+ // 角色标题
|
|
|
+ $rule_title = '';
|
|
|
+ // 角色标题
|
|
|
+ if ( $rule ) {
|
|
|
+ if( $rule['menu_type'] == 1 && $rule['data_type'] == 1 ) $rule_title = '商户普通员工';
|
|
|
+ if( $rule['menu_type'] == 1 && $rule['data_type'] == 2 ) $rule_title = '商户代表';
|
|
|
+ if( $rule['menu_type'] == 2 && $rule['data_type'] == 1 ) $rule_title = '店铺普通员工';
|
|
|
+ if( $rule['menu_type'] == 2 && $rule['data_type'] == 2 ) $rule_title = '店铺推广员';
|
|
|
}
|
|
|
- $value['rule_title'] = $rule_title;
|
|
|
- $value['business_name'] = '';
|
|
|
- if ($value['business_id']){
|
|
|
- $value['business_name'] = Business::query()->where('id', $value['business_id'])->value('name');
|
|
|
- }
|
|
|
- $value['company_name'] = Company::query()->where('id', $value['company_id'])->value('name');
|
|
|
+ $value['rule_title'] = $rule_title;
|
|
|
+ $value['business_name'] = $value['business_id'] ? (string)$Business->getOne($value['business_id'] ,'name') : '';
|
|
|
+ $value['company_name'] = $value['company_id'] ? $Company->getOne($value['company_id'],'name') : '';
|
|
|
// 重组
|
|
|
- $list[$key] = $value;
|
|
|
+ $list[$key] = $value;
|
|
|
}
|
|
|
// 分配数据
|
|
|
$this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
|
|
|
$this->assign('list',$list);
|
|
|
// 加载模板
|
|
|
- return $this->fetch();
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -110,14 +89,13 @@ class AdminUser extends Auth{
|
|
|
$data['password'] = request('password','');
|
|
|
$data['password'] = md5($data['password']);
|
|
|
$dataType = request('data_type',1);
|
|
|
+ $groups = (array) request('groups',[]);
|
|
|
// 角色数据
|
|
|
$ruleData = ['menu_type'=>1,'data_type'=>$dataType,'type'=>1,'company_id'=>1,'business_id'=>0];
|
|
|
// 修改数据
|
|
|
if( $session['menu_type'] ) $ruleData['menu_type'] = $session['menu_type'];
|
|
|
if( $session['company_id'] ) $ruleData['company_id'] = $session['company_id'];
|
|
|
if( $session['business_id'] ) $ruleData['business_id'] = $session['business_id'];
|
|
|
- // 所属权限组
|
|
|
- $groups = (array) request('groups',[]);
|
|
|
// 开启事务
|
|
|
DB::beginTransaction();
|
|
|
// 写入数据表
|
|
@@ -161,37 +139,24 @@ class AdminUser extends Auth{
|
|
|
// 告知结果
|
|
|
return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
|
|
|
}
|
|
|
- $whereGroup = [];
|
|
|
+ // 查询条件
|
|
|
+ $map = [];
|
|
|
// 如果不是超管 查询当前用户所属组
|
|
|
- $administrator = explode(',', config('administrator'));
|
|
|
- /*if(!in_array(admin('uid'),$administrator)){
|
|
|
- //用户所属组
|
|
|
- $gsGroup = DB::table('auth_group_access')->where(['user_uid'=>admin('uid')])->pluck('group_id')->toArray();
|
|
|
- //用户所属组 上级
|
|
|
- $upGroup = DB::table('auth_group')->whereIn('id',$gsGroup)->pluck('group_pid')->toArray();
|
|
|
- //用户所属组的下级
|
|
|
- $groupLower = DB::table('auth_group')->whereIn('group_pid',$gsGroup)->pluck('id')->toArray();
|
|
|
- //var_dump($groupLower);
|
|
|
- $whereGroup = array_merge($upGroup,$gsGroup,$groupLower);
|
|
|
- }*/
|
|
|
- $where = [];
|
|
|
- if(!in_array(admin('uid'),$administrator)){
|
|
|
- if($session && $session['menu_type'] ) $where['menu_type'] = $session['menu_type'];
|
|
|
- if($session && $session['company_id'] ) $where['company_id'] = $session['company_id'];
|
|
|
- if($session && $session['business_id'] ) $where['business_id'] = $session['business_id'];
|
|
|
- $where['type'] = 1;
|
|
|
+ if(!in_array(admin('uid'),explode(',', config('administrator')))){
|
|
|
+ $map[] = ['type','=',1];
|
|
|
+ if($session && $session['menu_type'] ) $map[] = [['menu_type'],'=',$session['menu_type']];
|
|
|
+ if($session && $session['company_id'] ) $map[] = [$map['company_id'],'=',$session['company_id']];
|
|
|
+ if($session && $session['business_id'] ) $map[] = [$map['business_id'],'=',$session['business_id']];
|
|
|
}
|
|
|
// 查询用户组
|
|
|
- $query = DB::table('auth_group');
|
|
|
- if($where) $query->where($where);
|
|
|
- $group = $query->whereNotIn('id',explode(',',config('CUSTOM_GROUP')))->select(['id','title'])->get()->toArray();
|
|
|
+ $group = DB::table('auth_group')->where($map)->select(['id','title'])->get()->toArray();
|
|
|
// 错误告知
|
|
|
- if( !$group ) $this->error('请先添加用户组');
|
|
|
+ if( !$group ) $this->error('请先添加用户组');
|
|
|
// 分配数据
|
|
|
$this->assign('group',$group);
|
|
|
$this->assign('crumbs','新增');
|
|
|
// 加载模板
|
|
|
- return $this->fetch();
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -202,13 +167,10 @@ class AdminUser extends Auth{
|
|
|
// 接收参数
|
|
|
$uid = request('uid',0);
|
|
|
// 查询用户
|
|
|
- $oldData = $Model
|
|
|
- ->join('admin_rule','admin_rule.admin_uid','=','admin.uid')
|
|
|
- ->where(['uid'=>$uid])
|
|
|
- ->select('admin.*','admin_rule.data_type','admin_rule.menu_type')
|
|
|
- ->first();
|
|
|
+ $oldData = $Model->query()->join('admin_rule','admin_rule.admin_uid','=','admin.uid','LEFT')->where(['uid'=>$uid])->first();
|
|
|
// 当前登录用户角色数据
|
|
|
$session = session('userRule') ? session('userRule') : ['menu_type'=>0,'company_id'=>0,'business_id'=>0];
|
|
|
+ // 修改提交
|
|
|
if(request()->isMethod('post')){
|
|
|
// 验证参数
|
|
|
$request->scene('edit')->validate();
|
|
@@ -216,18 +178,18 @@ class AdminUser extends Auth{
|
|
|
$data['username'] = request('username','');
|
|
|
$data['phone'] = request('phone','');
|
|
|
$dataType = request('data_type',1);
|
|
|
+ $groups = (array) request('groups',[]);
|
|
|
// 角色数据
|
|
|
$ruleData = $AdminRule::query()->where([['admin_uid','=',$uid]])->first(['id','admin_uid','menu_type','data_type','type','company_id','business_id']);
|
|
|
// 如果不存在的话
|
|
|
- $ruleData = $ruleData ? $ruleData->toArray() : ['admin_uid'=>$uid,'menu_type'=>1,'data_type'=>$dataType,'type'=>1,'company_id'=>1,'business_id'=>0];
|
|
|
+ $ruleData = $ruleData ? $ruleData->toArray() : ['admin_uid'=>$uid,'menu_type'=>0,'data_type'=>$dataType,'type'=>1,'company_id'=>1,'business_id'=>0];
|
|
|
// 修改数据
|
|
|
+ if( $dataType ) $ruleData['data_type'] = $dataType;
|
|
|
if( $session['menu_type'] ) $ruleData['menu_type'] = $session['menu_type'];
|
|
|
if( $session['company_id'] ) $ruleData['company_id'] = $session['company_id'];
|
|
|
if( $session['business_id'] ) $ruleData['business_id'] = $session['business_id'];
|
|
|
// 密码
|
|
|
$password = request('password','');
|
|
|
- // 所属权限组
|
|
|
- $groups = (array) request('groups',[]);
|
|
|
// 如果用户不存在
|
|
|
if( !$oldData ) return json_send(['code'=>'error','msg'=>'用户不存在']);
|
|
|
// 不能修改超管的账号
|
|
@@ -279,31 +241,17 @@ class AdminUser extends Auth{
|
|
|
// 告知结果
|
|
|
return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
|
|
|
}
|
|
|
- //$whereGroup = [];
|
|
|
+ // 查询条件
|
|
|
+ $map = [];
|
|
|
// 如果不是超管 查询当前用户所属组
|
|
|
- $administrator = explode(',', config('administrator'));
|
|
|
- /*if(!in_array(admin('uid'),$administrator)){
|
|
|
- // 用户所属组
|
|
|
- $gsGroup = DB::table('auth_group_access')->where(['user_uid'=>admin('uid')])->pluck('group_id')->toArray();
|
|
|
- // 用户所属组 上级
|
|
|
- $upGroup = DB::table('auth_group')->whereIn('id',$gsGroup)->pluck('group_pid')->toArray();
|
|
|
- // 用户所属组的下级
|
|
|
- $groupLower = DB::table('auth_group')->whereIn('group_pid',$gsGroup)->pluck('id')->toArray();
|
|
|
- // 下属组
|
|
|
- $whereGroup = array_merge($upGroup,$gsGroup,$groupLower);
|
|
|
- }*/
|
|
|
- $where = [];
|
|
|
- if(!in_array(admin('uid'),$administrator)){
|
|
|
- if($session && $session['menu_type'] ) $where['menu_type'] = $session['menu_type'];
|
|
|
- if($session && $session['company_id'] ) $where['company_id'] = $session['company_id'];
|
|
|
- if($session && $session['business_id'] ) $where['business_id'] = $session['business_id'];
|
|
|
- $where['type'] = 1;
|
|
|
+ if(!in_array(admin('uid'),explode(',', config('administrator')))){
|
|
|
+ $map[] = ['type','=',1];
|
|
|
+ if($session && $session['menu_type'] ) $map[] = [['menu_type'],'=',$session['menu_type']];
|
|
|
+ if($session && $session['company_id'] ) $map[] = [$map['company_id'],'=',$session['company_id']];
|
|
|
+ if($session && $session['business_id'] ) $map[] = [$map['business_id'],'=',$session['business_id']];
|
|
|
}
|
|
|
// 查询用户组
|
|
|
- $query = DB::table('auth_group');
|
|
|
- if($where) $query->where($where);
|
|
|
- // 获取
|
|
|
- $group = $query->whereNotIn('id',explode(',',config('CUSTOM_GROUP')))->select(['id','title'])->get()->toArray();
|
|
|
+ $group = DB::table('auth_group')->where($map)->select(['id','title'])->get()->toArray();
|
|
|
// 错误告知
|
|
|
if( !$group ) return $this->error('请先添加用户组');
|
|
|
// 错误告知
|
|
@@ -330,7 +278,7 @@ class AdminUser extends Auth{
|
|
|
$this->assign('breadcrumb2','操作记录');
|
|
|
$this->assign('list',$list);
|
|
|
// 加载模板
|
|
|
- return $this->fetch();
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|