|
@@ -20,109 +20,6 @@ class CheckWx
|
|
|
*/
|
|
|
public function handle($request, Closure $next)
|
|
|
{
|
|
|
- $data=$request->all();
|
|
|
|
|
|
- if (!isset($data['openid'])) return response()->json(['code'=> 202,'msg'=>'缺少openid','data'=>null]);
|
|
|
- $openid = $data['openid'];
|
|
|
- //校验openid是否绑定
|
|
|
- $employee = new WxEmployee();
|
|
|
- $employee = $employee->where('openid',$openid)->first();
|
|
|
- if (empty($employee)) return response()->json(['code'=> 202,'msg'=>'用户授权信息不存在!','data'=>null]);
|
|
|
- $employee = $employee->toArray();
|
|
|
- if (empty($employee['mobile'])) return response()->json(['code'=> 202,'msg'=>'用户手机信息不存在!','data'=>null]);
|
|
|
- if (empty($employee['employee_id'])) {
|
|
|
- //找到对应的账号
|
|
|
- $emp = Employee::where('del_time',0)
|
|
|
- ->where('mobile',$employee['mobile'])
|
|
|
- ->where('state',Employee::USE)
|
|
|
- ->select('id')
|
|
|
- ->first();
|
|
|
- if(empty($emp)) return response()->json(['code'=> 202,'msg'=>'用户手机信息未匹配到系统账号,请录入手机号!','data'=>null]);
|
|
|
- $emp = $emp->toArray();
|
|
|
- WxEmployee::where('id',$employee['id'])->update(['employee_id' => $emp['id']]);
|
|
|
- $employee['employee_id'] = $emp['id'];
|
|
|
- }
|
|
|
-
|
|
|
- //当前请求接口
|
|
|
- $uri = $request->path();
|
|
|
- //不需要校验是否绑定账号的接口
|
|
|
- $url = config('nocheck');
|
|
|
-
|
|
|
- if(in_array($uri,$url)){
|
|
|
- $request->userData = new Employee();
|
|
|
- }else{
|
|
|
- $employee_id = $employee['employee_id'];
|
|
|
- if(empty($employee_id)) return response()->json(['code'=> 202,'msg'=>'用户未绑定账号!','data'=>null]);
|
|
|
- //校验用户
|
|
|
- $service = new WxEmployeeService();
|
|
|
- $checkResult = $service->checkWxUser($employee_id);
|
|
|
- list($state, $data) = $checkResult;
|
|
|
- if(! $state) return response()->json(['code'=> 202,'msg'=>$data,'data'=>null]);
|
|
|
-
|
|
|
- //人员角色
|
|
|
- $data['role'] = EmployeeService::getPersonRole($employee_id);
|
|
|
- //角色里所有菜单权限
|
|
|
- $data['role_authority'] = EmployeeService::getPersonRoleQx($data['role']);
|
|
|
- //角色里特殊的按钮
|
|
|
- $data['special_button'] = EmployeeService::getSpecialButton($data['role'],$employee_id);
|
|
|
-
|
|
|
- //当前门店
|
|
|
- $userSetTopDepartId = $request->input('userSetTopDepartId');
|
|
|
- if(empty($userSetTopDepartId)) return response()->json(['code'=>202,'msg'=>'当前门店信息缺失','data'=>null]);
|
|
|
-
|
|
|
- $return = EmployeeService::getLoginDepart($employee_id, $userSetTopDepartId);
|
|
|
- //所属部门
|
|
|
- $data['rule_depart'] = $return[0] ?? [];
|
|
|
- //顶级公司
|
|
|
- $data['depart_top'] = $return[1] ?? [];
|
|
|
- $top = array_column($data['depart_top'],'depart_id');
|
|
|
- if(! in_array($userSetTopDepartId, $top)) return response()->json(['code'=>202,'msg'=>'当前门店不在权限内,请重新选择!','data'=>null]);
|
|
|
- //部门对应的顶级公司
|
|
|
- $data['depart_map'] = $return[2] ?? [];
|
|
|
- //权限范围内的部门以及公司
|
|
|
- $data['depart_range'] = $return[3] ?? [];
|
|
|
- //是否有所有的部门权限
|
|
|
- $data['is_all_depart'] = $return[4] ?? 0;
|
|
|
- //总公司
|
|
|
- $data['head'] = $return[5] ?? [];
|
|
|
- //当前部门
|
|
|
- $data['depart_select'] = $return[6] ?? [];
|
|
|
- //是否库存校验(默认校验)
|
|
|
- $my_top = $data['depart_top'][0] ?? [];
|
|
|
- $is_check_stock = empty($my_top['is_stock']) ? ProductInventorySet::type_one : $my_top['is_stock'];
|
|
|
- $data['is_check_stock'] = $is_check_stock;
|
|
|
-
|
|
|
- $query = config('morequery');
|
|
|
- $url = $request->path();
|
|
|
-
|
|
|
- //菜单ID
|
|
|
- $menu = $query['menu'] ?? [];
|
|
|
- if(isset($menu[$url])){
|
|
|
- $param = $menu[$url];
|
|
|
- if(is_array($param)){
|
|
|
- $key = $param['key'];
|
|
|
- $get = $request->input($key);
|
|
|
- $menu_id = $param['array'][$get] ?? 0;
|
|
|
- }else{
|
|
|
- $menu_id = $param ?? 0;
|
|
|
- }
|
|
|
- $request->merge(['menu_id' => $menu_id]);
|
|
|
- }
|
|
|
-
|
|
|
- $menu2 = $query['is_list_search'] ?? [];
|
|
|
- if(in_array($url, $menu2)) {
|
|
|
- if(! empty($data['is_list_search']) && ! empty($request->is_list_search)){//列表页呈现
|
|
|
- $request->merge(['get_my_top_depart_data' => 0]);
|
|
|
- }else{//建单据选择
|
|
|
- $request->merge(['get_my_top_depart_data' => 1]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $request->merge(['from_wx' => 1]);
|
|
|
-
|
|
|
- $request->userData = $data;
|
|
|
- }
|
|
|
-
|
|
|
- return $next($request);
|
|
|
}
|
|
|
}
|