3 Commits 5a73b1f8b3 ... b40478d9da

Author SHA1 Message Date
  yb b40478d9da 转到访调整 1 month ago
  yb c8e866321d Merge branch 'master' into custom_manager 1 month ago
  yb 25ec5f2aca 外渠人员功能调整 1 month ago

+ 2 - 2
app/admin/service/consultant/ConsultantService.php

@@ -112,7 +112,7 @@ class ConsultantService
         }
         $type = 2;
         if (!empty($params['type'])) {
-            if (in_array($params['type'], [1,2,3])) {
+            if (in_array($params['type'], [1,2,3,4])) {
                 $type = $params['type'];
                 if ($type != 1) {
                     $params['relation_user_id'] = null;
@@ -179,7 +179,7 @@ class ConsultantService
         }
         $type = 2;
         if (!empty($params['type'])) {
-            if (in_array($params['type'], [1,2,3])) {
+            if (in_array($params['type'], [1,2,3,4])) {
                 $type = $params['type'];
                 if ($type != 1) {
                     $params['relation_user_id'] = null;

+ 43 - 38
app/admin/service/consultant/CustomService.php

@@ -81,16 +81,16 @@ class CustomService
             }];
         }
         if (!empty($params['consultant_name'])) {
-            $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")
-                ->where('mobile', 'like', "%{$params['consultant_name']}%")
+            $consultantIds = Consultant::orWhere('name', 'like', "%{$params['consultant_name']}%")
+                ->orWhere('mobile', 'like', "%{$params['consultant_name']}%")
                 ->pluck('id')->toArray();
             $where[] = [function($query) use ($consultantIds) {
                 $query->whereIn('consultant_id', $consultantIds);
             }];
         }
         if (!empty($params['report_name'])) {
-            $consultantIds = Consultant::where('name', 'like', "%{$params['report_name']}%")
-                ->where('mobile', 'like', "%{$params['report_name']}%")
+            $consultantIds = Consultant::orWhere('name', 'like', "%{$params['report_name']}%")
+                ->orWhere('mobile', 'like', "%{$params['report_name']}%")
                 ->pluck('id')->toArray();
             $where[] = [function($query) use ($consultantIds) {
                 $query->whereIn('report_consultant_id', $consultantIds);
@@ -856,6 +856,8 @@ class CustomService
                 return json_fail('客户已经存在');
             }
         }
+        //查询顾问的团队信息
+        $deptId = Consultant::where('id', $params['consultant_id'])->value('dept_id');
         $result = false;
         Db::beginTransaction();
         try {
@@ -869,6 +871,7 @@ class CustomService
                 //更新到访保护期时间
                 $info->visit_time = time();
             }
+            $info->dept_id = $deptId ?? 0;
             $info->consultant_id = $params['consultant_id'];
             $info->check_time = time();
             $info->check_admin_id = $adminId;
@@ -1053,47 +1056,49 @@ class CustomService
             $returnData = [];
             $genderData = ['', '男', '女'];
             $typeData = ['', '来电', '来访'];
-            $currentStatusData = [-1 => '无效客户', 1 => '已来电', 2 => '已到访', 3 => '已缴费', 4 => '已成交'];
+            $currentStatusData = [-1 => '报备失败', 1 => '已报备', 2 => '已到访', 3 => '已缴费', 4 => '已成交'];
+            $textConfig = self::config();
+            //合并数组并去重
+            $type1 = $textConfig['visit_type']['type1'] ?? [];
+            $type2 = $textConfig['visit_type']['type2'] ?? [];
+            $textTypeKeys = [];
+            foreach ($type1 as $k1 => $v1) {
+                $textTypeKeys[$k1] = $v1;
+            }
+            foreach ($type2 as $k2 => $v2) {
+                $textTypeKeys[$k2] = $v2;
+            }
             foreach ($list as &$item) {
                 $visitTime = $item->visit_time;
                 $visitTimeStamp = strtotime($visitTime);
                 $diff = ($visitTimeStamp + $diffNums) - $currentTime;
                 $currentStatus = $item->current_status;//当前状态
                 $checkStatus = $item->check_status;//审核状态
-                if ($checkStatus == 1) {
-                    $currentStatusText = '待审核';
-                }
-                if ($checkStatus == -1) {
-                    $currentStatusText = '已失效';
-                }
-                if ($checkStatus == 2) {
-                    //审核通过
-                    if ($currentStatus > 1) {
-                        $currentStatusText = $currentStatusData[$currentStatus] ?? '';
-                    }
-                    if ($currentStatus == 1) {
-                        if ($diff > 0) {
-                            $currentStatusText = $currentStatusData[$currentStatus] ?? '';
-                        } else {
-                            $currentStatusText = '已失效';
-                        }
-                    }
-                    if ($currentStatus == -1) {
-                        $currentStatusText = '无效客户';
-                    }
+                if ($diff <= 0 && $checkStatus == 2 && $currentStatus > 1) {
+                    $currentStatusText = '公池';
+                } else {
+                    $currentStatusText = $currentStatusData[$item->current_status] ?? '';
                 }
+                $ageRangeText = $item->age_range > 0 ? $textConfig['age_range'][$item->age_range - 1] ?? '' : '';
+                $levelText = $item->level > 0 ? $textConfig['level'][$item->level - 1] ?? '' : '';
+                $regionText = $item->region > 0 ? $textConfig['region'][$item->region - 1] ?? '' : '';
+                $visitTypeText = $textTypeKeys[$item->visit_type] ?? '';
+
                 $returnData[] = [
-                    'name' => $item->name,
-                    'mobile' => $item->mobile,
+                    'name' => $item->name, //客户姓名
+                    'mobile' => $item->mobile, //客户电话
                     'mask_mobile' => self::handlePhone($item->mobile),
-                    'gender' => $genderData[$item->gender] ?? '',
-                    'type' => $typeData[$item->type] ?? '',
-                    'consultant_name' => $consultantKeys[$item->consultant_id]['name'] ?? '',
-                    'consultant_mobile' => $consultantKeys[$item->consultant_id]['mobile'] ?? '',
-                    'team_name' => TeamService::getTeamName($teamKeys, $item->dept_id),
+                    'gender' => $genderData[$item->gender] ?? '', //客户性别
+                    "report_consultant_name" => $consultantKeys[$item->report_consultant_id]['name'] ?? '', //报备人
+                    'consultant_name' => $consultantKeys[$item->consultant_id]['name'] ?? '', //健康顾问
+                    'team_name' => TeamService::getTeamName($teamKeys, $item->dept_id), //所属团队
                     'current_status' => $currentStatusText, //当前状态
-                    'visit_time' => $item->visit_time,
-                    'created_at' => date('Y-m-d H:i:s',strtotime($item->created_at))
+                    'visit_time' => $item->visit_time, //到访时间
+                    "age_range" => $ageRangeText, //年龄区间
+                    "level" => $levelText, //客户等级
+                    "region" => $regionText, //所在区域
+                    "visit_type" => $visitTypeText, //来源
+                    'created_at' => date('Y-m-d H:i:s', strtotime($item->created_at)) //报备时间
                 ];
             }
             return json_success('请求成功', $returnData);
@@ -1294,9 +1299,9 @@ class CustomService
                                 'create_consultant_id' => $reportConsultantId,
                                 'dept_id' => $deptId ?? 0,
                                 'belong_status' => 1,
-                                'current_status' => 2,
-                                'check_status' => 2,
-                                'check_note' => '导入的客户信息,无审核人员',
+                                'current_status' => 1,
+                                'check_status' => 1,
+                                'check_note' => '',
                                 'type' => 1,
                                 'visit_time' => strtotime($val[0]),
                                 'created_at' => strtotime($val[0])

+ 24 - 6
app/wechat/service/CustomService.php

@@ -66,11 +66,21 @@ class CustomService
                 $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 == 4) {
+                $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)")
+                        ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2)");
+                }];
+            } 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) {
             //团队下所有的
@@ -97,9 +107,14 @@ class CustomService
                 $query->orWhere('consultant_id', $consultantId)->orWhere('report_consultant_id', $consultantId);
             }];
             $whereFollow[] = ['consultant_id', '=', $consultantId];
-        } else {
+        } else if ($type == 3){
             //所有团队的
 
+        } else if ($type == 4) {
+            //查询渠道人员
+            $where[] = [function($query) use ($consultantId) {
+                $query->orWhere('consultant_id', $consultantId)->orWhere('report_consultant_id', $consultantId);
+            }];
         }
         if (!empty($params['search_type'])) {
             $searchType = $params['search_type'];
@@ -736,6 +751,8 @@ class CustomService
             }
         }
         $consultantId = $params['consultant_id'];
+        //查询顾问的团队信息
+        $deptId = Consultant::where('id', $params['consultant_id'])->value('dept_id');
         $result = false;
         Db::beginTransaction();
         try {
@@ -744,6 +761,7 @@ class CustomService
                 //拒绝录入拒绝理由
                 $info->check_note = $params['note'] ?? '无拒绝理由';
             }
+            $info->dept_id = $deptId ?? 0;
             $info->consultant_id = $consultantId;
             $info->current_status = $checkStatus;
             $info->check_time = time();

+ 32 - 10
app/wechat/service/UserService.php

@@ -345,10 +345,26 @@ class UserService
         } else if ($userInfo->type == 3) {
             //判客账户
             $ids = Consultant::pluck('id')->toArray();
+        } else if ($userInfo->type == 4) {
+            //外渠账号
+            $ids[] = $userId;
         }
         return $ids;
     }
 
+    /**
+     * Notes: 获取用户类型
+     * User: yb
+     * Date: 2024/9/13
+     * Time: 13:57
+     * @return mixed
+     */
+    public static function getUserType()
+    {
+        $userId = JwtToken::getCurrentId();
+        return Consultant::where('id', $userId)->value('type');
+    }
+
     /**
      * Notes: 首页统计分析
      * User: yb
@@ -361,6 +377,7 @@ class UserService
         $userIds = self::getIds();
         $currentTime = time();
         $diffNums = CustomService::DIFF_TIME;
+        $userType = self::getUserType();
 
         $whereFollow = [
             [function($query) use ($userIds) {
@@ -371,12 +388,14 @@ class UserService
         $where[] = [function($query) use ($userIds) {
             $query->orWhereIn('consultant_id', $userIds)->orWhereIn('report_consultant_id', $userIds);
         }];
-        $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)")
-                ->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);
-        }];
+        if ($userType != 4) {
+            $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)")
+                    ->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);
+            }];
+        }
         //客户总量
         $customNums = MarketCustomer::where($where)->count();
         if (!empty($params['time'])) {
@@ -470,16 +489,19 @@ class UserService
         $diffNums = CustomService::DIFF_TIME;
         //统计客户总数
         $userIds = self::getIds();
+        $userType = self::getUserType();
         $where = [
             [function($query) use ($userIds) {
                 $query->whereIn('consultant_id', $userIds);
-            }],
-            [function($query) use ($diffNums, $currentTime){
+            }]
+        ];
+        if ($userType != 4) {
+            $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)");
-            }]
-        ];
+            }];
+        }
         $whereTrend = [];
         if (!empty($params['type'])) {
             $whereTrend[] = ['current_status', '=', $params['type']];