Browse Source

汇总roi脚本

sunhao 5 years ago
parent
commit
f517ee83f0
2 changed files with 80 additions and 0 deletions
  1. 79 0
      app/Console/Commands/RoiTotal.php
  2. 1 0
      app/Console/Kernel.php

+ 79 - 0
app/Console/Commands/RoiTotal.php

@@ -0,0 +1,79 @@
1
+<?php 
2
+namespace App\Console\Commands;
3
+
4
+use Illuminate\Console\Command;
5
+use DB;
6
+use App\CustTotal;
7
+use App\CustDetail;
8
+class RoiTotal extends Command {
9
+
10
+    protected $signature = 'RoiTotal';
11
+
12
+    /**
13
+     * The console command description.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $description = '汇总roi';
18
+
19
+
20
+    public function handle()
21
+    {
22
+        $this->RoiTotal();
23
+    }
24
+    public function RoiTotal(){
25
+        $timeArr = array(
26
+            1 => '-7 day',
27
+            2 => '-15 day',
28
+            3 => '-30 day',
29
+            4 => '-45 day',
30
+            5 => '-60 day',
31
+        );
32
+        for($i=1;$i<6;$i++){
33
+            $stime = date('Y-m-d', strtotime($timeArr[$i]));   
34
+            $etime = $date = date('Y-m-d');
35
+            //计算date i天内的roi    
36
+            $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add'))->where('is_del',0)->where('dtime', $stime)->first();
37
+
38
+            $result = json_decode(json_encode($result), true);           
39
+            
40
+            $data = array();
41
+            $data['ad_time'] = $stime;  
42
+            $data['type'] = $i;            
43
+            //新粉收入
44
+            //当日加粉
45
+            $phones = DB::table('customers')->where('fanTime', $stime)->lists('phone');
46
+            #当日加粉15日订单总计:
47
+            $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, count(distinct(receiverMobile)) as cust_count'))->whereIn('receiverMobile', $phones)->where('createTime', '>=', $stime)->where('createTime', '<', $etime)->where('is_del', 0)->first();
48
+            #当日新粉成单:            
49
+            $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $stime)->where('createTime','<=', $stime.' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->first();
50
+           
51
+            // 1.当日新粉成单数
52
+            $data['new_fan_order_count'] = $new_order->order_count;
53
+            // 2.当日新粉成交额 
54
+            $data['new_fan_order_amount'] = $new_order->order_amount;
55
+            // 3.当日粉丝总成交额
56
+            $data['order_amount'] = $order->order_amount;
57
+            // 15日总单数
58
+            $data['order_count'] = $order->order_count;
59
+
60
+            $data['cust_count'] = $order->cust_count;
61
+            $data['fan_count'] = CustDetail::where('dtime', $stime)->where('is_del', 0)->sum('fan_add');
62
+            $data['gzh_count'] = $result['total_fan_add'];
63
+            $data['cost'] = $result['total_cost'];
64
+            //插入数据
65
+            $res = $this->insertData($data);
66
+            
67
+        }
68
+  
69
+    }
70
+
71
+    /**
72
+     * @param idate:统计日期 rate:成单率 date:昨日
73
+     *
74
+     */
75
+    public function insertData($data){        
76
+        return DB::table('roi_total')->insert($data);
77
+    }
78
+
79
+}

+ 1 - 0
app/Console/Kernel.php

@@ -35,6 +35,7 @@ class Kernel extends ConsoleKernel {
35 35
         'App\Console\Commands\SyncCustSaler',
36 36
         'App\Console\Commands\DayGrandTotal',
37 37
         'App\Console\Commands\AfreshOrderCost',
38
+        'App\Console\Commands\RoiTotal',
38 39
 
39 40
         
40 41
     ];