Commit 7592749f by 朱继来

Merge branch 'zjl_perm_20191022'

parents a55d86e9 bf0e2d6d
......@@ -422,11 +422,23 @@ Class OrderController extends Controller
$map['is_new_order'] = $request->input('is_new_order', '');
$map['business_type'] = $request->input('business_type', '');
// 订单查看权限---交易员、客服、自营客服、自营内部采购
if (in_array($info['role'], [3, 4, 7, 12])) {
// 筛选自己的订单
$map['sale_id'] = $request->user->userId;
}
$perm = new PermController;
// 订单查看权限
if (strpos($info['role'], ',') !== false) { // 多角色情况下
$res = $perm->checkUserRoles($request, $info['role']);
if ($res) {
$info['role'] = $res['role_id'];
$res['sale_id'] && $map['sale_id'] = $res['sale_id'];
}
} else {
if (in_array($info['role'], Config('perm_args.kefu_order'))) { // 交易员、联营客服(线销一组、二组、三组客服)、自营客服、自营内部采购
$map['sale_id'] = $request->user->userId; // 筛选自己的订单
} else if (in_array($info['role'], Config('perm_args.manager_order'))) { // 线销一组、二组、三组主管(查看自己及其下组员的订单)
$map['sale_id'] = $perm->getGroupSalesId($request, $info['role']);
}
}
// 自营客服权限
if ($tid == 2 && $info['role'] == 6) {
......@@ -468,6 +480,18 @@ Class OrderController extends Controller
$perm = new PermController;
if ($tid == 1) {
// $search_joint_sales = Config('perm_args.search_joint_sales');
// if ($search_joint_sales) {
// $sale_list = [];
// foreach ($search_joint_sales as $v) {
// $role_name = array_keys(Config('perm_args.roles'), $v);
// $temp = $perm->getRoleUsers($request, $role_name[0]);
// }
// }
$manager = $perm->getRoleUsers($request, '经理');
$test = $perm->getRoleUsers($request, '测试');
$sales = $perm->getRoleUsers($request, '交易员');
......@@ -853,10 +877,15 @@ Class OrderController extends Controller
$tags = $request->input('tags', '');
// 联营
$joint_manager = $perm->getRoleUsers($request, '经理');
$joint_kefu = $perm->getRoleUsers($request, '客服');
$sale_list = $perm->getRoleUsers($request, '交易员');
$test = $perm->getRoleUsers($request, '测试');
$joint_manager = $perm->getRoleUsers($request, '经理');
$joint_in_charge_1 = $perm->getRoleUsers($request, '线销一组主管');
$joint_in_charge_2 = $perm->getRoleUsers($request, '线销二组主管');
$joint_in_charge_3 = $perm->getRoleUsers($request, '线销三组主管');
$joint_kefu_1 = $perm->getRoleUsers($request, '线销一组客服');
$joint_kefu_2 = $perm->getRoleUsers($request, '线销二组客服');
$joint_kefu_3 = $perm->getRoleUsers($request, '线销三组客服');
$sale_list = $perm->getRoleUsers($request, '交易员');
$test = $perm->getRoleUsers($request, '测试');
$self_manager = $self_kefu = '';
......@@ -867,19 +896,47 @@ Class OrderController extends Controller
$self_kefu = array_merge($self_assistant, $self_kefu);
}
$info['joint_manager'] = $this->filterLeave($joint_manager);
$info['joint_kefu'] = $this->filterLeave($joint_kefu);
$info['sale_list'] = $this->filterLeave($sale_list);
$info['test'] = $this->filterLeave($test);
$info['self_manager'] = $this->filterLeave($self_manager);
$info['self_kefu'] = $this->filterLeave($self_kefu);
$info['sale_id'] = $request->user->userId;
$info['role'] = $perm->getUserRole($request);
$info['joint_manager'] = $this->filterLeave($joint_manager);
$joint_in_charge_1 = $this->filterLeave($joint_in_charge_1);
$joint_in_charge_2 = $this->filterLeave($joint_in_charge_2);
$joint_in_charge_3 = $this->filterLeave($joint_in_charge_3);
$info['joint_in_charge'] = $this->remove_duplicate(array_merge($joint_in_charge_1, $joint_in_charge_2, $joint_in_charge_3));
$info['joint_kefu_1'] = $this->filterLeave($joint_kefu_1);
$info['joint_kefu_2'] = $this->filterLeave($joint_kefu_2);
$info['joint_kefu_3'] = $this->filterLeave($joint_kefu_3);
$info['sale_list'] = $this->filterLeave($sale_list);
$info['test'] = $this->filterLeave($test);
$info['self_manager'] = $this->filterLeave($self_manager);
$info['self_kefu'] = $this->filterLeave($self_kefu);
$info['sale_id'] = $request->user->userId;
$info['role'] = $perm->getUserRole($request);
return view('detail', $info);
}
// 二维数组去重
public function remove_duplicate($array)
{
$result = array();
foreach ($array as $key => $value) {
$has = false;
foreach($result as $val){
if($val->userId == $value->userId){
$has = true;
break;
}
}
if(!$has) $result[] = $value;
}
return $result;
}
// 去掉已离职人员
public function filterLeave(&$data)
{
......
......@@ -8,22 +8,6 @@
class PermController extends Controller
{
protected $roles = [
'管理员' => 1,
'经理' => 2,
'交易员' => 3,
'客服' => 4,
'测试' => 5,
'京东自营' => 6,
'自营客服' => 7,
'运营助理' => 8,
'财务' => 9,
'自营客服主管' => 10,
'自营客服主管助理' => 11,
'自营内部采购' => 12,
'尽调' => 13,
];
// 检查用户是否具有系统访问权限
public function checkAccess($request)
{
......@@ -56,9 +40,7 @@
$uid = $request->user->userId;
$email = $request->user->email;
if ($email == 'admin@ichunt.com') {
return 1;
}
if ($email == 'admin@ichunt.com') return 1;
// 根据域名查询系统业务ID
$business = $this->getBusinessInfo();
......@@ -69,26 +51,26 @@
// 权限系统配置的管理帐号
$adminAccount = json_decode($business->admin, true);
if (in_array($email, $adminAccount)) {
return 1;
}
if (in_array($email, $adminAccount)) return 1;
// 根据用户ID和业务ID查看角色
$userPerm = DB::table('t_user_perm')->where(['userId' => $uid, 'bid' => $bid])->first();
if (empty($userPerm)) {
return 0;
} else {
if ($userPerm->roles == 'null') return 0;
$role = json_decode($userPerm->roles, true);
foreach ($role as $v) {
$department = DB::table('t_role_perm')->where(['roleId' => $v, 'bid' => $bid])->first();
return in_array($department->name, array_keys($this->roles)) ? array_get($this->roles, $department->name) : 0;
}
}
if (empty($userPerm)) return 0;
if ($userPerm->roles == 'null') return 0; // 没有选择角色
$role = json_decode($userPerm->roles, true);
$user_role = []; // 当前用户拥有的角色值
foreach ($role as $v) {
$department = DB::table('t_role_perm')->where(['roleId' => $v, 'bid' => $bid])->first();
$user_role[] = in_array($department->name, array_keys(Config('perm_args.roles'))) ? array_get(Config('perm_args.roles'), $department->name) : 0;
}
return count($role) > 1 ? implode(',', $user_role) : implode('', $user_role); // 多角色用逗号拼接
}
return 0;
......@@ -224,4 +206,83 @@
return array_values($menus);
}
// 获取主管及其下对应组员的sale_id
public function getGroupSalesId($request, $role_id)
{
$sale_id = [];
// 主管ID
$manager_role_name = array_keys(Config('perm_args.roles'), $role_id);
if (!$manager_role_name) {
$manager_sales = $this->getRoleUsers($request, $manager_role_name[0]);
if ($manager_sales) {
foreach ($manager_sales as $v) {
$sale_id[] = $v->userId;
}
}
}
// 线销主管对应的客服
$manager_to_kefu = Config('perm_args.manager_to_kefu');
if (!in_array($role_id, array_keys($manager_to_kefu))) return 0;
$sub_id = $manager_to_kefu[$role_id];
$role_name = array_keys(Config('perm_args.roles'), $sub_id);
if (!$role_name) return 0;
$sales = $this->getRoleUsers($request, $role_name[0]);
if ($sales) {
foreach ($sales as $v) {
$sale_id[] = $v->userId;
}
}
return $sale_id;
}
/**
* 多角色情况下
* 1.若存在管理员、经理、测试角色,则返回角色
* 2.若存在线销主管,则查询其下客服
* 3.其他情况暂不考虑
* @param [type] $request [description]
* @param [type] $role_id [description]
* @return [type] [description]
*/
public function checkUserRoles($request, $role_id)
{
$data = [];
$roles = explode(',', $role_id);
$master = array_intersect($roles, Config('perm_args.check_all_order')); // 交集,是否能查看所有订单
if ($master) {
$data['role_id'] = min($master); // 设置最小值的角色 (因为系统页面都是单角色判断)
$data['sale_id'] = 0;
return $data;
}
$intersect = array_intersect($roles, Config('perm_args.manager_order')); // 交集,获取线销主管
if ($intersect) {
$data['role_id'] = min($intersect); // 设置最小值的角色
foreach ($intersect as $v) {
$sale_ids[] = $this->getGroupSalesId($request, $v);
}
$arr = array_reduce($sale_ids, 'array_merge', array()); // 转一维数组
$data['sale_id'] = array_merge(array_unique($arr)); // 去重后,再重新索引
}
return $data;
}
}
\ No newline at end of file
<?php
return [
// 用户角色
'roles' => [
'管理员' => 1,
'经理' => 2,
'交易员' => 3,
'客服' => 4,
'测试' => 5,
'京东自营' => 6,
'自营客服' => 7,
'运营助理' => 8,
'财务' => 9,
'自营客服主管' => 10,
'自营客服主管助理' => 11,
'自营内部采购' => 12,
'尽调' => 13,
'线销一组主管' => 14,
'线销一组客服' => 15,
'线销二组主管' => 16,
'线销二组客服' => 17,
'线销三组主管' => 18,
'线销三组客服' => 19,
],
// 线销主管 =》 线销客服
'manager_to_kefu' => [
14 => 15,
16 => 17,
18 => 19,
],
// 筛选自己的订单
'kefu_order' => [3, 4, 7, 12, 15, 17, 19],
// 主管角色,查看自己及其组员订单
'manager_order' => [14, 16, 18],
// 查看所有订单角色
'check_all_order' => [1, 2, 5],
// 审单时权限 (用于调价权限 changeOrder.blade.php)
'is_manager_perm' => [1, 2, 10, 11, 14, 16, 18],
// 筛选业务员 -- 联营
'search_joint_sales' => [3, 4, 5, 14, 15, 16, 17, 18, 19],
// 筛选业务员 -- 自营
'search_self_sales' => [5, 7, 10, 11, 12],
];
......@@ -498,8 +498,8 @@
@include('detail.addGoods')
<script>
var is_manager = "{{ $role == 1 || $role == 2 || $role == 10 || $role == 11 ? true : false }}";
var is_manager = "{{ in_array($role, Config('perm_args.is_manager_perm')) ? true : false }}";
var isNewClient = "{{isset($isNewClient) ? $isNewClient : 0}}";
// var order_amount = "{{$order_info['order_amount']}}";
var currency = "{{$order_info['currency']}}"; // 币种
......
......@@ -27,18 +27,69 @@
</tr>
@endif
@if (!empty($joint_kefu))
@if (!empty($joint_in_charge))
<tr>
<td class="check-table-title">联营客服:</td>
<td>
<ul>
@foreach ($joint_kefu as $key => $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}"/><span>{{$vo->name}}</span></label></li>
@endif
@endforeach
<table class="table table-bordered table-hover">
<tr>
<td width="10%">主管:</td>
<td>
<ul>
@foreach ($joint_in_charge as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}"/><span>{{$vo->name}}</span></label></li>
@endif
@endforeach
</ul>
</td>
</tr>
<tr>
<td>线销一组:</td>
<td>
<ul>
@foreach ($joint_kefu_1 as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}"/><span>{{$vo->name}}</span></label></li>
@endif
@endforeach
</ul>
</td>
</tr>
<tr>
<td>线销二组:</td>
<td>
<ul>
@foreach ($joint_kefu_2 as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}"/><span>{{$vo->name}}</span></label></li>
@endif
@endforeach
</ul>
</td>
</tr>
<tr>
<td>线销三组:</td>
<td>
<ul>
@foreach ($joint_kefu_3 as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}"/><span>{{$vo->name}}</span></label></li>
@endif
@endforeach
</ul>
</td>
</tr>
</table>
</ul>
</td>
</tr>
......@@ -49,7 +100,7 @@
<td class="check-table-title">交易员:</td>
<td>
<ul>
@foreach ($sale_list as $key => $vo)
@foreach ($sale_list as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
......@@ -67,7 +118,7 @@
<td>
<ul>
@foreach ($self_manager as $k => $v)
@foreach ($self_manager as $v)
@if ($v->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$v->userId}}" checked /><span>{{$v->name}}</span></label></li>
@else
......@@ -84,7 +135,7 @@
<td class="check-table-title">自营客服:</td>
<td>
<ul>
@foreach ($self_kefu as $key => $vo)
@foreach ($self_kefu as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
......@@ -101,7 +152,7 @@
<td class="check-table-title">测试:</td>
<td>
<ul>
@foreach ($test as $key => $vo)
@foreach ($test as $vo)
@if ($vo->userId == $order_info['sale_id'])
<li><label><input type="radio" name="sale_id" value="{{$vo->userId}}" checked /><span>{{$vo->name}}</span></label></li>
@else
......@@ -114,7 +165,7 @@
@endif
<!-- 查看权限:当前推送人 或 管理员、经理、测试、运营助理 或 自营客服主管 -->
@if ($sale_id == $order_info['sale_id'] || (in_array($role, [1, 2, 5, 8]) || in_array($role, [1, 10]) ))
@if ($sale_id == $order_info['sale_id'] || in_array($role, [1, 2, 5, 8, 10, 11, 14, 16, 18]))
<tr>
<td class="check-table-title">备注信息:</td>
<td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment