all(); $config = []; $config['model'] = $this->modelClass; switch ($scene) { case 'index': // ====== view_scope:仅 user_id=73 生效,最高优先级,覆盖下方业务id默认值与角色范围逻辑 ====== $viewScope = $p['view_scope'] ?? ''; if ($request->user->uid == 73 && in_array($viewScope, ['all', 'self'], true)) { if ($viewScope === 'self') { $config['where']['salesperson_id'] = $request->user->uid; // 只看自己(含自己草稿) } else { // 'all':自己和别人的,排除草稿(approval_status=0) $config['where']['approval_status'] = ['>=', 1]; } $config['where']['is_final'] = $p['is_final'] ?? 0; if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; foreach (['pi_no', 'order_no', 'customer_snapshot'] as $col) { $config['orWhere'][] = [$col, 'like', $k]; } } $config['order']['id'] = 'desc'; break; // 最高优先级:跳过下方业务id默认值与角色范围逻辑 } // ====== ====== 筛选 ====== ====== // 业务id if (isset($p['salesperson_id']) && $p['salesperson_id']) { $config['where']['salesperson_id'] = $p['salesperson_id']; } else { $config['where']['salesperson_id'] = $request->user->uid; } // 初、终版 $config['where']['is_final'] = $p['is_final'] ?? 0; // 关键字 if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; foreach (['pi_no', 'order_no', 'customer_snapshot'] as $col) { $config['orWhere'][] = [$col, 'like', $k]; } } $config['order']['id'] = 'desc'; $user_role_id = UserRoles::where('user_id', $request->user->uid)->pluck('role_id')->toArray(); //$roles_id = array_intersect([1,6], $request->user->role_ids); $roles_id = array_intersect([1,5,6], $user_role_id); if (count($roles_id) != 0){ // if(in_array(4, $request->user->role_ids)){ //业务主管 // $report = User::where('report_to',$request->user->uid)->pluck('id')->toArray(); // $report = array_merge($report, [$request->user->uid]); // $config['where']['salesperson_id'] = ['in',$report]; // } else //内勤分组的人可以看到自己分组的备货单 if (in_array(5,$roles_id)){ //内勤 $userGroupMember = UserGroupMembers::where('user_id',$request->user->uid) ->where('is_leader',1) ->first(); if($userGroupMember){ $report = UserGroupMembers::where('group_id',$userGroupMember->group_id) ->pluck('user_id') ->toArray(); $config['where']['salesperson_id'] = ['in',$report]; $config['where']['approval_status'] = ['>=',1]; }else{ //内勤没有负责的组时 $config['where']['salesperson_id'] = $request->user->uid; } } elseif (in_array(1,$roles_id)) { //超管可以看所有的 //$config['where']['approval_status'] = ['>=',1]; $config['orWhere'][] = ['approval_status','>=',1]; $config['orWhere'][] = ['salesperson_id','=',$request->user->uid]; unset($config['where']['salesperson_id']); }else{ $config['where']['salesperson_id'] = $request->user->uid; } } break; case 'print': case 'approval': $config['where']['id'] = $p['id']; break; case 'detail': case 'show': $config['where']['id'] = $p['id']; $config['with'][] = 'items'; $config['with'][] = 'items.options'; $config['with'][] = 'items.moneyValues'; $config['with'][] = 'accounts'; $config['with'][] = 'moneyValues'; $config['with'][] = 'salesperson'; $config['with'][] = 'files'; break; case 'store': break; case 'update': $config['where']['id'] = $p['id']; break; case 'destroy': $config['where']['id'] = $p['id']; break; } return $config; } /** * 最终审批 */ public function serviceUltimateApproval(Request $request) { $config = $this->buildQueryConfig($request, 'detail'); $item = $this->logicShow($config); // 检查是否至少有一个车辆填写了vin $hasVin = false; foreach ($item->items as $k => $v) { if ($v->vin !== '') { $hasVin = true; break; } } // 如果没有任何车辆填写vin,则抛出异常 if (!$hasVin) { throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核'); } $this->logicUpdateBy($config, [ 'approval_status' => 1 ]); $this->startApproval($item); return $this->postProcess('UltimateApproval', $item); } }