cqp 2 сар өмнө
parent
commit
fedc3d5163

+ 44 - 6
app/Service/StatisticsService.php

@@ -2636,13 +2636,34 @@ class StatisticsService extends Service
             ->where('province_code', $province_code)
             ->select('city_code','type','customer_id','title','customer_from','car_type','consulting_product_new_title','enter_time','contact_info')
             ->get()->toArray();
+        $detail = CustomerReportDepart::where('del_time',0)
+            ->whereIn('customer_id',array_unique(array_column($list,'customer_id')))
+            ->where('type',CustomerReportDepart::type_one)
+            ->select('customer_id','top_depart_id')
+            ->get()->toArray();
+        $detail_map = [];
+        foreach ($detail as $value){
+            $detail_map[$value['customer_id']][] = $value['top_depart_id'];
+        }
+        $depart = Depart::whereIn('id',array_unique(array_column($detail,'top_depart_id')))
+            ->pluck('title','id')
+            ->toArray();
 
         $map = [];
         foreach ($list as $value) {
             if(empty($value['city_code']) && $first_city != $city_code) continue;
+            $depart_title = "";
+            if(isset($detail_map[$value['customer_id']])){
+                foreach ($detail_map[$value['customer_id']] as $val){
+                    $t = $depart[$val];
+                    if(! $t) continue;
+                    $depart_title .= $t . ',';
+                }
+            }
+            $depart_title = rtrim($depart_title,',');
             $tmp = [
-                'customer_id' => $value['customer_id'],
-                'title' => $value['customer_id'],
+                'depart_title' => $depart_title,
+                'title' => $value['title'],
                 'customer_from' => $value['customer_from'],
                 'car_type' => $value['car_type'],
                 'consulting_product_new_title' => $value['consulting_product_new_title'],
@@ -2696,12 +2717,13 @@ class StatisticsService extends Service
             ->get()->toArray();
         $detail_array = array_column($detail,'customer_id');
 
+        $depart = Depart::where('id',$top_depart_id)->value('title');
         $map = [];
         foreach ($list as $value) {
             if(in_array($value['customer_id'], $detail_array)){
                 $tmp = [
-                    'customer_id' => $value['customer_id'],
-                    'title' => $value['customer_id'],
+                    'depart_title' => $depart,
+                    'title' => $value['title'],
                     'customer_from' => $value['customer_from'],
                     'car_type' => $value['car_type'],
                     'consulting_product_new_title' => $value['consulting_product_new_title'],
@@ -2768,25 +2790,41 @@ class StatisticsService extends Service
             ->whereIn('customer_id',array_unique(array_column($list,'customer_id')))
             ->select('customer_id','man_id','type','top_depart_id')
             ->get()->toArray();
+
+        $detail_map = [];
         $detail_array = $man_map = [];
         foreach ($detail as $value){
             if($value['type'] == CustomerReportDepart::type_two){
 
             }elseif ($value['type'] == CustomerReportDepart::type_one && $value['top_depart_id'] == $top_depart_id){
+                $detail_map[$value['customer_id']][] = $value['top_depart_id'];
                 if(! in_array($value['customer_id'], $detail_array)) $detail_array[] = $value['customer_id'];
             }elseif ($value['type'] == CustomerReportDepart::type_three){
                 if($value['man_id'] == $man_id) $man_map[$value['customer_id']] = 1;
             }
         }
+        $depart = Depart::whereIn('id',array_unique(array_column($detail,'top_depart_id')))
+            ->pluck('title','id')
+            ->toArray();
 
         $map = [];
         foreach ($list as $value) {
             //这个客户是否属于当前这个门店
             if(in_array($value['customer_id'], $detail_array)){
+                $depart_title = "";
+                if(isset($detail_map[$value['customer_id']])){
+                    foreach ($detail_map[$value['customer_id']] as $val){
+                        $t = $depart[$val];
+                        if(! $t) continue;
+                        $depart_title .= $t . ',';
+                    }
+                }
+                $depart_title = rtrim($depart_title,',');
+
                 if(isset($man_map[$value['customer_id']])) {
                     $tmp = [
-                        'customer_id' => $value['customer_id'],
-                        'title' => $value['customer_id'],
+                        'depart_title' => $depart_title,
+                        'title' => $value['title'],
                         'customer_from' => $value['customer_from'],
                         'car_type' => $value['car_type'],
                         'consulting_product_new_title' => $value['consulting_product_new_title'],