فهرست منبع

移交客户时识别是否从公池中移交

yb 8 ماه پیش
والد
کامیت
49e445fa05
2فایلهای تغییر یافته به همراه62 افزوده شده و 18 حذف شده
  1. 7 5
      app/admin/service/consultant/CustomService.php
  2. 55 13
      app/wechat/service/CustomService.php

+ 7 - 5
app/admin/service/consultant/CustomService.php

@@ -645,7 +645,7 @@ class CustomService
                 $query->whereIn('consultant_id', $consultantIds);
             }];
         }
-        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time'])->get();
+        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time','check_status','current_status'])->get();
         if (!$customList->isEmpty()) {
             foreach ($customList as$item) {
                 $logsInertData[] = [
@@ -674,10 +674,12 @@ class CustomService
                 if ($currentConsultantId != 0) {
                     //移交至指定顾问
                     //判断一下是否到了到访的过期时间,如果过期了就更新到访时间,没过期时间就不变
-                    $visitTime = $item->visit_time;
-                    $diff = strtotime($visitTime) + $diffTime - time();
-                    if ($diff <= 0) {
-                        $item->visit_time = time();
+                    if ($item->check_status == 2 && $item->current_status == 2) {
+                        $visitTime = $item->visit_time;
+                        $diff = strtotime($visitTime) + $diffTime - time();
+                        if ($diff <= 0) {
+                            $item->visit_time = time();
+                        }
                     }
                 } else {
                     //移交至其他团队

+ 55 - 13
app/wechat/service/CustomService.php

@@ -58,14 +58,20 @@ class CustomService
         $type = $consultantInfo->type;
         $currentTime = time();
         $diffNums = self::DIFF_TIME;
-        $where = [
-            [function($query) use ($diffNums, $currentTime){
-            $query->orWhereRaw("check_status IN (-1, 1)")
-                ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
-                ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
-        }]
-        ];
+        $where = [];
         $whereFollow = [];
+        if (!empty($params['belong_status'])) {
+            //团队权限
+            $where[] = [function($query) use ($diffNums, $currentTime){
+                $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
+            }];
+        } else {
+            $where[] = [function($query) use ($diffNums, $currentTime){
+                $query->orWhereRaw("check_status IN (-1, 1)")
+                    ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
+                    ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
+            }];
+        }
         if ($type == 1) {
             //团队下所有的
             $deptIds = TeamService::getIds($deptId);
@@ -95,11 +101,39 @@ class CustomService
             //所有团队的
 
         }
-        if (!empty($params['custom'])) {
-            $keywords = $params['custom'];
-            $where[] = [function($query) use ($keywords) {
-                $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
-            }];
+        if (!empty($params['search_type'])) {
+            $searchType = $params['search_type'];
+            // 1 = 仅搜索客户
+            if ($searchType == 1) {
+                if (!empty($params['custom'])) {
+                    $keywords = $params['custom'];
+                    $where[] = [function($query) use ($keywords) {
+                        $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%");
+                    }];
+                }
+            } else {
+                if (!empty($params['custom'])) {
+                    $keywords = $params['custom'];
+                    $consultantIds = Consultant::orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")->pluck('id')->toArray();
+                    if ($searchType == 2) {
+                        $searchKey = 'consultant_id';
+                    } else {
+                        $searchKey = 'report_consultant_id';
+                    }
+                    $where[] = [function($query) use ($consultantIds, $searchKey) {
+                        $query->orWhereIn($searchKey, $consultantIds);
+                    }];
+                }
+            }
+        } else {
+            if (!empty($params['custom'])) {
+                $keywords = $params['custom'];
+                $consultantIds = Consultant::orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")->pluck('id')->toArray();
+                $where[] = [function($query) use ($keywords, $consultantIds) {
+                    $query->orWhere('name', 'like', "%{$keywords}%")->orWhere('mobile', 'like', "%{$keywords}%")
+                        ->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
+                }];
+            }
         }
         if (!empty($params['report_status'])) {
             if ($params['report_status'] == 1) {
@@ -587,7 +621,7 @@ class CustomService
         if (!empty($consultantId)) {
             $whereCustom[] = ['consultant_id', '=', $consultantId];
         }
-        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id'])->get();
+        $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time','check_status','current_status'])->get();
         if (!$customList->isEmpty()) {
             foreach ($customList as$item) {
                 $logsInertData[] = [
@@ -609,10 +643,18 @@ class CustomService
         if (empty($logsInertData)) {
             return json_fail('移交记录不能为空');
         }
+        $diffTime = self::DIFF_TIME;
         Db::beginTransaction();
         $result = false;
         try {
             foreach ($customList as $item) {
+                if ($item->check_status == 2 && $item->current_status == 2) {
+                    $visitTime = $item->visit_time;
+                    $diff = strtotime($visitTime) + $diffTime - time();
+                    if ($diff <= 0) {
+                        $item->visit_time = time();
+                    }
+                }
                 $item->consultant_id = $currentConsultantId;
                 $item->dept_id = $currentDeptId;
                 $item->save();