fmtRequest($request); $requestMap = $request['map'] ?: []; # getCount是代办事项传来的参数,代办事项不需要使用场景 $sceneMap = []; $partMap = []; $teamMap = $requestMap['team_id']; //团队成员 高级筛选 if ($teamMap) { $partMap = advancedQueryFormatForTeam($teamMap, 'customer_check', ''); unset($requestMap['team_id']); $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; } else { $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; } // 权限 $readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read'); $updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update'); $deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete'); //排序 if ($order_type && $order_field) { $order = $fieldModel->getOrderByFormtype('crm_customer_check', 'customer_check', $order_field, $order_type); } else { $order = 'customer_check.update_time desc'; } # 待办事项查询参数 $dealtWhere = []; if (!empty($customerCheckIdArray)) $dealtWhere['customer_check.customer_check_id'] = ['in', $customerCheckIdArray]; $dataCount = db('crm_customer_check') ->alias('customer_check') ->join('__CRM_CUSTOMER__ customer', 'customer_check.customer_check_id = customer.customer_id', 'LEFT') ->where($map)->where($partMap)->where($dealtWhere)->count('customer_check_id'); if (!empty($getCount) && $getCount == 1) { $data['dataCount'] = !empty($dataCount) ? $dataCount : 0; return $data; } $indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ?: array('name'); // 列表展示字段 $userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); // 人员类型 $structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); // 部门类型 # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) $temporaryField = str_replace('_name', '', $order_field); if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { $order_field = $temporaryField; } $customerField = ''; foreach ($indexField as $k => $v) { $customerField = 'customer.'.$v; } $list = db('crm_customer_check') ->alias('customer_check') ->join('__CRM_CUSTOMER__ customer', 'customer_check.customer_id = customer.customer_id', 'LEFT') ->where($map) ->where($partMap) ->where($dealtWhere) ->limit($request['offset'], $request['length']) ->field('customer_check.*,customer.name as name,'.$customerField) ->orderRaw($order) ->select(); foreach ($list as $k => $v) { $list[$k]['customer_id_info']['customer_id'] = $v['customer_id']; $list[$k]['customer_id_info']['name'] = $v['customer_name']; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : ''; //权限 $roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read'); $rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update'); $permission = []; $is_read = 0; $is_update = 0; $is_delete = 0; if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1; if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1; if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1; $permission['is_read'] = $is_read; $permission['is_update'] = $is_update; $permission['is_delete'] = $is_delete; $list[$k]['permission'] = $permission; # 日期 $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null; # 系统字段 负责人部门 zjf 20210726 $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name']; } $data = []; $data['list'] = $list ?: []; $data['dataCount'] = $dataCount ?: 0; return $data; } /** * 创建客户捞取审批信息 * @param * @return */ public function createData($param) { $createData = []; foreach ($param['customer_id'] as $key => $value) { $createData[$key]['customer_id'] = $value; $createData[$key]['check_status'] = $param['check_status'] ?? 0; $createData[$key]['flow_id'] = $param['flow_id'] ?? 0; $createData[$key]['order_id'] = $param['order_id'] ?? 0; $createData[$key]['check_user_id'] = $param['check_user_id'] ?? 0; $createData[$key]['flow_user_id'] = $param['flow_user_id'] ?? 0; $createData[$key]['user_id'] = $param['user_id'] ?? 0; $createData[$key]['create_user_id'] = $param['user_id'] ?? 0; $createData[$key]['owner_user_id'] = $param['user_id'] ?? 0; } $this->startTrans(); try { $data = $this->saveAll($createData); $this->commit(); } catch (\Exception $e) { $this->error = '领取失败'; $this->rollback(); return false; } foreach ($data as $k => $v) { //站内信 $send_user_id = stringToArray($param['check_user_id']); if ($send_user_id && empty($param['check_status'])) { (new Message())->send( Message::CUSTOMER_CHECK_TO_DO, [ 'title' => $param['name'], 'action_id' => $v['customer_check_id'] ], $send_user_id ); } $data = []; $data['customer_check_id'] = $v['customer_check_id']; echo $v['customer_check_id']; # 创建待办事项的关联数据 $checkUserIds = db('crm_customer_check')->where('customer_check_id', $data['customer_check_id'])->value('check_user_id'); $checkUserIdArray = stringToArray($checkUserIds); $dealtData = []; foreach ($checkUserIdArray as $kk => $vv) { $dealtData[] = [ 'types' => 'crm_customer_check', 'types_id' => $data['customer_check_id'], 'user_id' => $vv ]; } if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); } } }