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