sunhao лет назад: 5
Родитель
Сommit
8dfa274cc4

+ 66 - 0
app/Console/Commands/DayGrandRoiHistory.php

@@ -0,0 +1,66 @@
1
+<?php 
2
+namespace App\Console\Commands;
3
+
4
+use Illuminate\Console\Command;
5
+use DB;
6
+
7
+class DayGrandRoiHistory extends Command {
8
+
9
+    protected $signature = 'DayGrandRoiHistory';
10
+
11
+    /**
12
+     * The console command description.
13
+     *
14
+     * @var string
15
+     */
16
+    protected $description = '每日汇总投放,成本,毛利等数据';
17
+
18
+
19
+    public function handle()
20
+    {
21
+        $this->DayGrandRoiHistory();
22
+    }
23
+
24
+    
25
+    public function DayGrandRoiHistory(){
26
+        $result = DB::table('day_grand_total')->select('id','idate')->get();
27
+        $result = json_decode(json_encode($result), true);
28
+        foreach($result as $k=>$v){
29
+            //7 - 60 roi汇总
30
+            $s7 = $v['idate']. ' -7 day';
31
+            $date = date('Y-m-d', strtotime($s7));
32
+            $data['cost7'] = DB::table('roi_total')->where('type', 1)->where('ad_time', '<=', $date)->sum('cost');
33
+            $data['order_count7'] = DB::table('roi_total')->where('type', 1)->where('ad_time', '<=', $date)->sum('order_count');
34
+            $data['order_amount7'] = DB::table('roi_total')->where('type', 1)->where('ad_time', '<=', $date)->sum('order_amount');
35
+
36
+            $s15 = $v['idate']. ' -15 day';
37
+            $date = date('Y-m-d', strtotime($s15));
38
+            $data['cost15'] = DB::table('roi_total')->where('type', 2)->where('ad_time', '<=', $date)->sum('cost');
39
+            $data['order_count15'] = DB::table('roi_total')->where('type', 2)->where('ad_time', '<=', $date)->sum('order_count');
40
+            $data['order_amount15'] = DB::table('roi_total')->where('type', 2)->where('ad_time', '<=', $date)->sum('order_amount');
41
+
42
+            $s30 = $v['idate']. ' -30 day';
43
+            $date = date('Y-m-d', strtotime($s30));
44
+            $data['cost30'] = DB::table('roi_total')->where('type', 3)->where('ad_time', '<=', $date)->sum('cost');
45
+            $data['order_count30'] = DB::table('roi_total')->where('type', 3)->where('ad_time', '<=', $date)->sum('order_count');
46
+            $data['order_amount30'] = DB::table('roi_total')->where('type', 3)->where('ad_time', '<=', $date)->sum('order_amount');
47
+
48
+            $s45 = $v['idate']. ' -45 day';
49
+            $date = date('Y-m-d', strtotime($s45));
50
+            $data['cost45'] = DB::table('roi_total')->where('type', 4)->where('ad_time', '<=', $date)->sum('cost');
51
+            $data['order_count45'] = DB::table('roi_total')->where('type', 4)->where('ad_time', '<=', $date)->sum('order_count');
52
+            $data['order_amount45'] = DB::table('roi_total')->where('type', 4)->where('ad_time', '<=', $date)->sum('order_amount');
53
+
54
+            $s60 = $v['idate']. ' -60 day';
55
+            $date = date('Y-m-d', strtotime($s60));
56
+            $data['cost60'] = DB::table('roi_total')->where('type', 5)->where('ad_time', '<=', $date)->sum('cost');
57
+            $data['order_count60'] = DB::table('roi_total')->where('type', 5)->where('ad_time', '<=', $date)->sum('order_count');
58
+            $data['order_amount60'] = DB::table('roi_total')->where('type', 5)->where('ad_time', '<=', $date)->sum('order_amount');
59
+
60
+            $res = DB::table('day_grand_total')->where('id', $v['id'])->update($data);
61
+            echo "\n日期:".$v['idate']." 更新结果:".$res;
62
+        }
63
+        
64
+    }
65
+
66
+}

+ 21 - 0
app/Console/Commands/DayGrandTotal.php

@@ -58,6 +58,27 @@ class DayGrandTotal extends Command {
58 58
         $data['old_order_count'] = $data['order_count'] - $data['new_order_count'];
59 59
         //总复购订单
60 60
         $data['fugou_order_count'] = $data['order_count'] - $data['cust_count'];
61
+
62
+        //7 - 60 roi汇总
63
+        $data['cost7'] = DB::table('roi_total')->where('type', 1)->sum('cost');
64
+        $data['order_count7'] = DB::table('roi_total')->where('type', 1)->sum('order_count');
65
+        $data['order_amount7'] = DB::table('roi_total')->where('type', 1)->sum('order_amount');
66
+
67
+        $data['cost15'] = DB::table('roi_total')->where('type', 2)->sum('cost');
68
+        $data['order_count15'] = DB::table('roi_total')->where('type', 2)->sum('order_count');
69
+        $data['order_amount15'] = DB::table('roi_total')->where('type', 2)->sum('order_amount');
70
+
71
+        $data['cost30'] = DB::table('roi_total')->where('type', 3)->sum('cost');
72
+        $data['order_count30'] = DB::table('roi_total')->where('type', 3)->sum('order_count');
73
+        $data['order_amount30'] = DB::table('roi_total')->where('type', 3)->sum('order_amount');
74
+
75
+        $data['cost45'] = DB::table('roi_total')->where('type', 4)->sum('cost');
76
+        $data['order_count45'] = DB::table('roi_total')->where('type', 4)->sum('order_count');
77
+        $data['order_amount45'] = DB::table('roi_total')->where('type', 4)->sum('order_amount');
78
+
79
+        $data['cost60'] = DB::table('roi_total')->where('type', 5)->sum('cost');
80
+        $data['order_count60'] = DB::table('roi_total')->where('type', 5)->sum('order_count');
81
+        $data['order_amount60'] = DB::table('roi_total')->where('type', 5)->sum('order_amount');
61 82
         $res = DB::table('day_grand_total')->insert($data);
62 83
         echo "\n日期:".$idate." 插入结果:".$res;
63 84
     }

+ 1 - 0
app/Console/Kernel.php

@@ -37,6 +37,7 @@ class Kernel extends ConsoleKernel {
37 37
         'App\Console\Commands\AfreshOrderCost',
38 38
         'App\Console\Commands\RoiTotal',
39 39
         'App\Console\Commands\RoiTotalHistory',
40
+        'App\Console\Commands\DayGrandRoiHistory',
40 41
 
41 42
         
42 43
     ];