sunhao 5 years ago
parent
commit
8766fc275c
2 changed files with 39 additions and 0 deletions
  1. 38 0
      app/Console/Commands/SyncCustSaler.php
  2. 1 0
      app/Console/Kernel.php

+ 38 - 0
app/Console/Commands/SyncCustSaler.php

@@ -0,0 +1,38 @@
1
+<?php 
2
+namespace App\Console\Commands;
3
+
4
+use Illuminate\Console\Command;
5
+use DB;
6
+class SyncCustSaler extends Command {
7
+
8
+    protected $signature = 'SyncCustSaler';
9
+
10
+    /**
11
+     * The console command description.
12
+     *
13
+     * @var string
14
+     */
15
+    protected $description = '同步客户第一次下单销售';
16
+
17
+
18
+    public function handle()
19
+    {
20
+        $this->SyncCustSaler();
21
+    }
22
+    public function SyncCustSaler(){
23
+        $customers = DB::table('customers')->select('id', 'phone')->where('phone','>','')->get();
24
+        $customers = json_decode(json_encode($customers), true);
25
+        foreach($customers as $k=>$v){
26
+            $order = DB::table('order')->select('admin_id')->where('receiverMobile', $v['phone'])->orderBy('id', 'asc')->first();
27
+            if(empty($order)){
28
+                echo "\n".$v['phone']." 失败,未找到订单:";
29
+                continue;
30
+            }
31
+            $admin_id = $order->admin_id;
32
+            $res = DB::table('customers')->where('id', $v['id'])->update(['admin_id'=>$admin_id]);
33
+            echo "\n".$v['phone']." 结果:".$res;
34
+        }
35
+    }
36
+
37
+
38
+}

+ 1 - 0
app/Console/Kernel.php

@@ -32,6 +32,7 @@ class Kernel extends ConsoleKernel {
32 32
         'App\Console\Commands\SyncMjWarehouse',
33 33
         'App\Console\Commands\SyncOrderToMj',
34 34
         'App\Console\Commands\DisRoiByDay60',
35
+        'App\Console\Commands\SyncCustSaler',
35 36
 
36 37
         
37 38
     ];