|
@@ -99,7 +99,7 @@ class CustomService
|
|
|
if (!empty($params['consultant_name'])) {
|
|
|
$consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")->pluck('id');
|
|
|
$where[] = [function($query) use ($consultantIds) {
|
|
|
- $query->whereIn('consultant_id', $consultantIds);
|
|
|
+ $query->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
|
|
|
}];
|
|
|
}
|
|
|
if (!empty($params['type'])) {
|
|
@@ -141,7 +141,10 @@ class CustomService
|
|
|
}
|
|
|
}
|
|
|
if (!empty($params['consultant_id'])) {
|
|
|
- $where[] = ['consultant_id', '=', $params['consultant_id']];
|
|
|
+ $consultantId = $params['consultant_id'];
|
|
|
+ $where[] = [function($query) use ($consultantId) {
|
|
|
+ $query->orWhere('consultant_id', $consultantId)->orWhere('report_consultant_id', $consultantId);
|
|
|
+ }];
|
|
|
}
|
|
|
if (!empty($params['custom'])) {
|
|
|
$keywords = $params['custom'];
|
|
@@ -252,14 +255,25 @@ class CustomService
|
|
|
$total = $paginator->total();
|
|
|
$items = $paginator->items();
|
|
|
if (!empty($items)) {
|
|
|
+ //查询顾问信息
|
|
|
$consultantKeys = [];
|
|
|
+ $reportConsultantIds = $paginator->pluck('report_consultant_id')->toArray();
|
|
|
$consultantIds = $paginator->pluck('consultant_id')->toArray();
|
|
|
- if (!empty($consultantIds)) {
|
|
|
- //去重
|
|
|
- $consultantIds = array_unique($consultantIds);
|
|
|
- //排序
|
|
|
- $consultantIds = array_values($consultantIds);
|
|
|
- //查询顾问信息
|
|
|
+ if (!empty($consultantIds) || !empty($reportConsultantIds)) {
|
|
|
+ if (!empty($consultantIds)) {
|
|
|
+ //去重
|
|
|
+ $consultantIds = array_unique($consultantIds);
|
|
|
+ //排序
|
|
|
+ $consultantIds = array_values($consultantIds);
|
|
|
+ }
|
|
|
+ if (!empty($reportConsultantIds)) {
|
|
|
+ //去重
|
|
|
+ $reportConsultantIds = array_unique($reportConsultantIds);
|
|
|
+ //排序
|
|
|
+ $reportConsultantIds = array_values($reportConsultantIds);
|
|
|
+ }
|
|
|
+ $consultantIds = array_merge($consultantIds, $reportConsultantIds);
|
|
|
+
|
|
|
$consultantList = Consultant::whereIn('id', $consultantIds)->select(['id', 'name', 'mobile'])->get();
|
|
|
if (!$consultantList->isEmpty()) {
|
|
|
foreach ($consultantList->toArray() as $consultantItem) {
|
|
@@ -267,6 +281,9 @@ class CustomService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
$teamKeys = TeamService::getItemKeys();
|
|
|
foreach ($items as &$item) {
|
|
|
$visitTime = $item->visit_time;
|
|
@@ -275,6 +292,8 @@ class CustomService
|
|
|
$item->diff_nums = ($diff > 0) ? $diff : 0;
|
|
|
$item->consultant_name = $consultantKeys[$item->consultant_id]['name'] ?? '';
|
|
|
$item->consultant_mobile = $consultantKeys[$item->consultant_id]['mobile'] ?? '';
|
|
|
+ $item->report_consultant_name = $consultantKeys[$item->report_consultant_id]['name'] ?? '';
|
|
|
+ $item->report_consultant_mobile = $consultantKeys[$item->report_consultant_id]['mobile'] ?? '';
|
|
|
$item->team_name = TeamService::getTeamName($teamKeys, $item->dept_id);
|
|
|
$item->mask_mobile = self::handlePhone($item->mobile);
|
|
|
}
|
|
@@ -301,16 +320,18 @@ class CustomService
|
|
|
return json_fail('客户已经登记过了');
|
|
|
}
|
|
|
//查询顾问信息
|
|
|
- $consultantId = $params['consultant_id'];
|
|
|
- $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
|
|
|
+ $reportConsultantId = $params['report_consultant_id'];
|
|
|
+ $consultantInfo = Consultant::firstWhere(['id' => $reportConsultantId]);
|
|
|
if (empty($consultantInfo)) {
|
|
|
- return json_fail('顾问信息不存在');
|
|
|
+ return json_fail('报备顾问信息不存在');
|
|
|
}
|
|
|
$deptId = $consultantInfo->dept_id;
|
|
|
$insertData = [
|
|
|
'name' => $params['name'],
|
|
|
'mobile' => $mobile,
|
|
|
- 'consultant_id' => $consultantId,
|
|
|
+ 'consultant_id' => 0,
|
|
|
+ 'create_consultant_id' => $reportConsultantId,
|
|
|
+ 'report_consultant_id' => $reportConsultantId,
|
|
|
'dept_id' => $deptId,
|
|
|
'gender' => $params['gender'] ?? null,
|
|
|
'visit_type' => $params['visit_type'] ?? null,
|
|
@@ -799,6 +820,7 @@ class CustomService
|
|
|
//更新到访保护期时间
|
|
|
$info->visit_time = time();
|
|
|
}
|
|
|
+ $info->consultant_id = $params['consultant_id'];
|
|
|
$info->check_time = time();
|
|
|
$info->check_admin_id = $adminId;
|
|
|
$result = $info->save();
|
|
@@ -1041,4 +1063,72 @@ class CustomService
|
|
|
{
|
|
|
return substr_replace($val, '****', 3, 4);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Notes: 判客指定顾问
|
|
|
+ * User: yb
|
|
|
+ * Date: 2024/9/5
|
|
|
+ * Time: 15:50
|
|
|
+ * @param $params
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * Notes: 指定顾问
|
|
|
+ * User: yb
|
|
|
+ * Date: 2024/9/5
|
|
|
+ * Time: 12:52
|
|
|
+ * @param $params
|
|
|
+ */
|
|
|
+ public static function appoint($params)
|
|
|
+ {
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ return json_fail('请选择客户');
|
|
|
+ }
|
|
|
+ if (empty($params['report_consultant_id'])) {
|
|
|
+ return json_fail('请选择指定顾问');
|
|
|
+ }
|
|
|
+ $userId = JwtToken::getCurrentId();
|
|
|
+ $relationUserId = $userId;
|
|
|
+ $customId = $params['id'];
|
|
|
+ $reportConsultantId = $params['report_consultant_id'];
|
|
|
+ $customInfo = MarketCustomer::firstWhere(['id' => $customId]);
|
|
|
+ if (empty($customInfo)) {
|
|
|
+ return json_fail('客户信息不存在');
|
|
|
+ }
|
|
|
+ $consultantInfo = Consultant::firstWhere(['id' => $reportConsultantId]);
|
|
|
+ if (empty($consultantInfo)) {
|
|
|
+ return json_fail('顾问信息不存在');
|
|
|
+ }
|
|
|
+ $currentDeptId = $consultantInfo->dept_id; //当前部门
|
|
|
+ $now = time();
|
|
|
+ $logData = [
|
|
|
+ 'market_customer_id' => $customId,
|
|
|
+ 'consultant_id' => $reportConsultantId,
|
|
|
+ 'dept_id' => $currentDeptId,
|
|
|
+ 'before_consultant_id' => $customInfo->report_consultant_id,
|
|
|
+ 'before_dept_id' => $customInfo->dept_id,
|
|
|
+ 'note' => $params['note'] ?? '判客指定报备顾问',
|
|
|
+ 'change_user_id' => $relationUserId,
|
|
|
+ 'change_consultant_id' => 0,
|
|
|
+ 'created_at' => $now
|
|
|
+ ];
|
|
|
+ Db::beginTransaction();
|
|
|
+ $result = false;
|
|
|
+ try {
|
|
|
+ $customInfo->report_consultant_id = $reportConsultantId;
|
|
|
+ $customInfo->dept_id = $currentDeptId;
|
|
|
+ $result = $customInfo->save();
|
|
|
+ MarketCustomerLogs::insert($logData);
|
|
|
+ Db::commit();
|
|
|
+ }catch (BusinessException|\Exception $e) {
|
|
|
+ Db::rollBack();
|
|
|
+ return json_fail($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result) {
|
|
|
+ return json_success('指定成功');
|
|
|
+ } else {
|
|
|
+ return json_fail('指定失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|