| 
					
				 | 
			
			
				@@ -72,28 +72,29 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!empty($params['report_status'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($params['report_status'] == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //待审核 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $where[] = ['check_status', '=', 1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $where[] = ['check_status', '=', 2]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if ($params['report_status'] == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //已报备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $where[] = [function($query) use ($diffNums, $currentTime) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else if ($params['report_status'] == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //已锁定 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $where[] = [function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $query->whereIn('current_status', [2,3,4]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else if ($params['report_status'] == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //已失效 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $where[] = [function($query) use ($diffNums, $currentTime){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $where[] = ['check_status', '=', $params['report_status']]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            if ($params['report_status'] == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                //待审核 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $where[] = ['check_status', '=', 1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $where[] = ['check_status', '=', 2]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            if ($params['report_status'] == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                //已报备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $where[] = [function($query) use ($diffNums, $currentTime) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } else if ($params['report_status'] == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                //已锁定 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $where[] = [function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    $query->whereIn('current_status', [2,3,4]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } else if ($params['report_status'] == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                //已失效 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $where[] = [function($query) use ($diffNums, $currentTime){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!empty($params['consultant_name'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")->pluck('id'); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -131,9 +132,13 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!empty($params['current_status'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $currentStatus = $params['current_status']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $where[] = [function($query) use ($currentStatus){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $query->where('current_status', '=', $currentStatus)->where('check_status', '=', 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ($currentStatus == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $where[] = ['current_status', '=', $currentStatus]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $where[] = [function($query) use ($currentStatus){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $query->where('current_status', '=', $currentStatus)->where('check_status', '<>', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!empty($params['consultant_id'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $where[] = ['consultant_id', '=', $params['consultant_id']]; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -203,6 +208,24 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $where[] = ['level', '=', ($params['level'] + 1)]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!empty($params['belong_status'])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $belongStatus = $params['belong_status']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ($belongStatus == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //未流入公池 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $where[] = ['belong_status', '=', 1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $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)"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //已经流入公池 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $where[] = [function($query) use ($diffNums, $currentTime){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return $where; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -303,6 +326,7 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'check_status' => 1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'visit_time' => $params['visit_time'] ?? null, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'note' => $params['note'] ?? '', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'belong_status' => 1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'current_status' => $params['current_status'] ?? null, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'created_at' => time() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ]; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -533,15 +557,21 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static function moveCustom($params) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $userId = JwtToken::getCurrentId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $currentConsultantId = $params['consultant_id']; //当前顾问 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $moveType = $params['move_type'] ?? 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if ($moveType == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $currentDeptId = $params['dept_id']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $currentConsultantId = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $currentConsultantId = $params['consultant_id'] ?? 0; //当前顾问 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $consultantInfo = Consultant::firstWhere(['id' => $currentConsultantId]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (empty($consultantInfo)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return json_fail('顾问不存在'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $currentDeptId = $consultantInfo->dept_id; //当前部门 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $consultantIds = $params['move_consultant_id'] ?? []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $customIds = $params['move_market_customer_id'] ?? []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $note = $params['note'] ?? ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $consultantInfo = Consultant::firstWhere(['id' => $currentConsultantId]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (empty($consultantInfo)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return json_fail('顾问不存在'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $currentDeptId = $consultantInfo->dept_id; //当前部门 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $logsInertData  = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $now = time(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $whereCustom = []; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -580,6 +610,13 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $result = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             foreach ($customList as $item) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if ($currentConsultantId != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //移交至指定顾问 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $item->visit_time = time(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //移交至其他团队 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    $item->visit_time = time() - self::DIFF_TIME; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $item->consultant_id = $currentConsultantId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $item->dept_id = $currentDeptId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $item->save(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -682,16 +719,26 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $query->whereBetween('created_at', $createdDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $paginator = MarketCustomerLogs::with(['custom', 'beforeMan', 'currentMan', 'opBackPerson', 'opFrontPerson']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ->whereHas('custom', function ($query) use ($whereCustom) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $query->where($whereCustom); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ->whereHas('currentMan', function ($query) use ($whereCurrent) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $query->where($whereCurrent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ->whereHas('beforeMan', function ($query) use ($whereBefore) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $query->where($whereBefore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $paginator = MarketCustomerLogs::with(['custom' => function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->select('id', 'name', 'mobile'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }, 'beforeMan' => function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->select('id', 'name', 'mobile'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }, 'currentMan' => function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->select('id', 'name', 'mobile'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }, 'beforeDept' => function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->select('dept_id', 'dept_name'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }, 'currentDept' => function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->select('dept_id', 'dept_name'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            ->whereHas('custom', function ($query) use ($whereCustom) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $query->where($whereCustom); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            ->whereHas('currentMan', function ($query) use ($whereCurrent) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $query->where($whereCurrent); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            ->whereHas('beforeMan', function ($query) use ($whereBefore) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                $query->where($whereBefore); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ->where($where) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ->orderBy('created_at', 'desc') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ->paginate($limit, '*', 'page', $page); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -731,7 +778,7 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $status = $info->check_status; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ($status != 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return json_fail('客户不是待审核状态'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return json_fail('客户不是待转到访状态'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $mobile = $info->mobile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ($checkStatus == 2) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -743,10 +790,15 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Db::beginTransaction(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $info->check_status = $checkStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $info->current_status = $checkStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if ($checkStatus == -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //拒绝录入拒绝理由 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $info->check_note = $params['note'] ?? '无拒绝理由'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if ($checkStatus == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //更新到访保护期时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $info->visit_time = time(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $info->check_time = time(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $info->check_admin_id = $adminId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $result = $info->save(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -757,7 +809,7 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ['check_status', '=', 1], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ['id', '<>', $customId] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1,'check_note' => '客户已经被其他顾问报备']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                MarketCustomer::where($where)->update(['check_time' => time(),'check_status' => -1, 'current_status' => -1,'check_note' => '客户已经被其他登记']); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Db::commit(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }catch (BusinessException|\Exception $e){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -765,9 +817,9 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return json_fail($e->getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ($result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return json_success('审核成功'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return json_success('操作成功'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return json_fail('审核失败'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return json_fail('操作失败'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -786,14 +838,18 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $where = self::commonSearch($params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //客户总数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $total = MarketCustomer::where($where)->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //待审核 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $checkTotal = MarketCustomer::where($where)->where('check_status', 1)->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //公池客户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $pubTotal = MarketCustomer::where($where)->where([[function($query){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $diffNums = self::DIFF_TIME; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->orWhereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }]])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //已报备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $reportTotal = MarketCustomer::where($where)->where( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $checkTotal = MarketCustomer::where($where)->where('check_status', 1)->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //已到访 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $visitTotal = MarketCustomer::where($where)->where( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             [[function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $currentTime = time(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 $diffNums = self::DIFF_TIME; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0) AND current_status = 1 AND check_status = 2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $query->whereRaw("((visit_time + {$diffNums}) - UNIX_TIMESTAMP() > 0) AND current_status = 2 AND check_status = 2")->where('belong_status', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }]] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         )->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //已来电 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -801,31 +857,35 @@ class CustomService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $query->where('check_status', '=', 2)->where('current_status', '=', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }]])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //已到访 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        $visitTotal = MarketCustomer::where($where)->where([[function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $query->where('check_status', '=', 2)->where('current_status', '=', 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }]])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        $visitTotal = MarketCustomer::where($where)->where([[function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            $query->where('check_status', '=', 2)->where('current_status', '=', 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        }]])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //已缴费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $payTotal = MarketCustomer::where($where)->where([[function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $query->where('check_status', '=', 2)->where('current_status', '=', 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->where('check_status', '=', 2)->where('current_status', '=', 3)->where('belong_status', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }]])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //已成交 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $dealTotal = MarketCustomer::where($where)->where([[function($query) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $query->where('check_status', '=', 2)->where('current_status', '=', 4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $query->where('check_status', '=', 2)->where('current_status', '=', 4)->where('belong_status', 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }]])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //已到访 + 已缴费 + 已成交 / 客户总数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //已缴费 + 已成交 / 客户总数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //报备失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $failTotal = MarketCustomer::where($where)->where('current_status', -1)->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $rant = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if ($total > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            $rant = $payTotal + $dealTotal / $total; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $rant = ($payTotal + $dealTotal) / $total; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $rant = sprintf('%.2f', $rant); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         $data = [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'total' => $total, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'pub_total' => $pubTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'check_total' => $checkTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            'report_total' => $reportTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'report_total' => 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'mobile_total' => $mobileTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'visit_total' => $visitTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'pay_total' => $payTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'deal_total' => $dealTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            'fail_total' => $failTotal, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             'rant' => $rant, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return json_success('请求成功', $data); 
			 |