cqp hai 1 mes
pai
achega
594fb35fe0
Modificáronse 1 ficheiros con 62 adicións e 63 borrados
  1. 62 63
      app/Console/Commands/CustomerFromThreePlatForm.php

+ 62 - 63
app/Console/Commands/CustomerFromThreePlatForm.php

@@ -5,7 +5,8 @@ namespace App\Console\Commands;
 use App\Model\BasicType;
 use App\Model\Customer;
 use App\Model\CustomerInfo;
-use App\Model\Depart;
+use App\Model\CustomerRemain;
+use App\Model\DepartWithDHF;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\DB;
 
@@ -48,16 +49,24 @@ class CustomerFromThreePlatForm extends Command
             ->where('type',BasicType::type_10)
             ->select('id','title')
             ->get()->toArray();
+        $dhf = DepartWithDHF::from('depart_with_dhf as a')
+            ->join('depart as b','b.id','a.top_depart_id')
+            ->where('a.del_time',0)
+            ->where('b.del_time',0)
+            ->select('a.top_depart_id','a.clueSourceId','b.notify_id')
+            ->get()->toArray();
+        $dhf_map = array_column($dhf,null,'clueSourceId');
+
         \App\Model\CustomerFromThreePlatForm::where("del_time",0)
             ->where("customerName","<>","")
             ->orderBy('id')
             ->select('id','crt_time','city','actionType','acquireTime','clueType','product','wechat','clueId','transformType','clueSource','clueSourceId','customerName','platform','ipLocationCity','phone','isRepeatClue','flowType','fromUserId')
-            ->chunkById(20, function ($data) use($basic){
+            ->chunkById(20, function ($data) use($basic,$dhf_map){
                 // 开启事务
-                DB::transaction(function () use ($data,$basic) {
+                DB::transaction(function () use ($data,$basic,$dhf_map) {
                     $dataArray = $data->toArray();
                     $nowStamp = time();
-                    list($main, $main_detail, $fail) = $this->processingData($dataArray, $nowStamp,$basic);
+                    list($main, $main_detail, $fail, $main_detail2, $main_detail3) = $this->processingData($dataArray, $nowStamp,$basic,$dhf_map);
                     $c_third_platform_id = array_column($main,'c_third_platform_id');
 
                     if (! empty($main) ) {
@@ -70,12 +79,39 @@ class CustomerFromThreePlatForm extends Command
                         foreach ($main_detail as $id => $value){
                             if(isset($map[$id])){
                                 foreach ($value as $v){
-                                    $v['customer_id'] = $map[$id] ?? 0;
+                                    $v['customer_id'] = $map[$id];
                                     $insert_detail[] = $v;
                                 }
                             }
                         }
                         if(! empty($insert_detail)) CustomerInfo::insert($insert_detail);
+
+                        if(! empty($main_detail2)){
+                            $insert_detail_2 = [];
+                            foreach ($main_detail2 as $id => $value){
+                                if(isset($map[$id])){
+                                    foreach ($value as $v){
+                                        $v['customer_id'] = $map[$id];
+                                        $insert_detail_2[] = $v;
+                                    }
+                                }
+                            }
+                            if(! empty($insert_detail_2)) CustomerInfo::insert($insert_detail_2);
+                        }
+
+                        if(! empty($main_detail3)){
+                            $insert_detail_3 = [];
+                            foreach ($main_detail3 as $id => $value){
+                                if(isset($map[$id])){
+                                    foreach ($value as $v){
+                                        $v['customer_id'] = $map[$id];
+                                        $insert_detail_3[] = $v;
+                                    }
+                                }
+                            }
+                            if(! empty($insert_detail_3)) CustomerRemain::insert($insert_detail_3);
+                        }
+
                         echo '更新完成' . PHP_EOL;
                     }
 
@@ -92,64 +128,12 @@ class CustomerFromThreePlatForm extends Command
         echo '任务结束--------end---------------';
     }
 
-    private function processingData2($data,$time, $basic,$top_depart_id){
-        $return = $return1 = $return2 = [];
-
-        $search = $info_phone = $info_wechat = [];
-        foreach ($data as $value){
-            //同样的客户信息只保留最后一次的id
-            if(! empty($value['phone'])) {
-                $info_phone[$value['phone']] = $value['id'];
-                $search[] = $value['phone'];
-            }
-            if(! empty($value['wechat'])) {
-                $info_wechat[$value['wechat']] = $value['id'];
-                $search[] = $value['wechat'];
-            }
-        }
-
-        $contact = CustomerInfo::from('customer_info as a')
-            ->join('customer as b','b.id','a.customer_id')
-            ->where('a.del_time',0)
-            ->where('b.del_time',0)
-            ->where('b.top_depart_id',$top_depart_id)
-            ->whereIn('a.contact_info', $search)
-            ->pluck('a.contact_info')
-            ->toArray();
-
-        //result 1 联系方式数据库中已存在失败 2 联系方式重复传递失败 3
-        foreach ($data as $value){
-            if(! empty($value['phone'])){
-                if(in_array($value['phone'], $contact)){
-                    $return2[] = [
-                        'id' => $value['id'],
-                        'result' => 1
-                    ];
-                }else{
-                    $tmp_id = $info_phone[$value['phone']] ?? 0;
-                    if($tmp_id != $value['id']){
-                        $return2[] = [
-                            'id' => $value['id'],
-                            'result' => 2
-                        ];
-                    }
-                }
-            }
-            if(! empty($value['wechat']) && in_array($value['wechat'], $contact)){
-                $return2[] = [
-                    'id' => $value['id'],
-                    'result' => 1
-                ];
-                continue;
-            }
-
-        }
-    }
-
-    private function processingData($data, $time,$basic)
+    private function processingData($data, $time,$basic,$dhf_map)
     {
-        $return = []; // 成功数据
-        $return_detail = []; // 成功数据
+        $return = []; // 客户主表
+        $return_detail = []; // 客户联系方式
+        $return_detail2 = []; // 客户负责人
+        $return_detail3 = []; // 客户负责人提醒
         $fail   = []; // 失败数据(含 result 标记)
         $basic_map = array_column($basic,'title','id');
 
@@ -266,10 +250,25 @@ class CustomerFromThreePlatForm extends Command
                         'type' => CustomerInfo::type_one
                     ];
                 }
+                $setting = $dhf_map[$value['clueSourceId']] ?? [];
+                if(! empty($setting['notify_id']) && ! empty($setting['top_depart_id'])){
+                    $return_detail2[$id][] = [
+                        'customer_id' => 0,
+                        'data_id' => $setting['notify_id'],
+                        'crt_time' => $time,
+                        'type' => CustomerInfo::type_two
+                    ];
+                    $return_detail3[$id][] = [
+                        'customer_id' => 0,
+                        'fp' => $setting['top_depart_id'],
+                        'fz' => $setting['notify_id'],
+                        'crt_time' => $time,
+                    ];
+                }
             }
         }
 
-        return [$return, $return_detail, $fail];
+        return [$return, $return_detail, $fail, $return_detail2, $return_detail3];
     }
 
 }