|
@@ -0,0 +1,57 @@
|
|
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
|
+use App\Order;
|
|
9
|
+class DayGrandTotal extends Command {
|
|
10
|
+
|
|
11
|
+ protected $signature = 'DayGrandTotal';
|
|
12
|
+
|
|
13
|
+ /**
|
|
14
|
+ * The console command description.
|
|
15
|
+ *
|
|
16
|
+ * @var string
|
|
17
|
+ */
|
|
18
|
+ protected $description = '每日汇总投放,成本,毛利等数据';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+ public function handle()
|
|
22
|
+ {
|
|
23
|
+ $this->dayGrandTotal();
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+ public function dayGrandTotal(){
|
|
28
|
+ $_end = date('Y-m-d');
|
|
29
|
+ $data = array();
|
|
30
|
+ $idate = date('Y-m-d', strtotime('-1 day'));
|
|
31
|
+ //查看是否已有数据
|
|
32
|
+ $if_e = DB::table('day_grand_total')->where('idate', $idate)->first();
|
|
33
|
+ if(!empty($if_e)){
|
|
34
|
+ echo "\n日期:".$idate." 已存在";
|
|
35
|
+ return false;
|
|
36
|
+ }
|
|
37
|
+ $data['idate'] = $idate;
|
|
38
|
+ //总投入
|
|
39
|
+ $data['throw_cost'] = CustTotal::where('is_del',0)->where('dtime','<',$_end)->sum('total_cost');
|
|
40
|
+ //订单信息
|
|
41
|
+ $order = Order::select(DB::raw('sum(cost) as goods_cost, sum(freight_cost) as freight_cost, sum(aftersale_fee) as aftersale_cost, count(1) as order_count, sum(receivedAmount) as order_amount, count(distinct(receiverMobile)) as cust_count'))->where('is_del',0)->where('createTime','<',$_end)->where('cost', '>', 0)->first();
|
|
42
|
+ $data['goods_cost'] = $order->goods_cost;
|
|
43
|
+ $data['freight_cost'] = $order->freight_cost;
|
|
44
|
+ $data['aftersale_cost'] = $order->aftersale_cost;
|
|
45
|
+ $data['order_count'] = $order->order_count;
|
|
46
|
+ $data['order_amount'] = $order->order_amount;
|
|
47
|
+ $data['cust_count'] = $order->cust_count;
|
|
48
|
+ //加粉
|
|
49
|
+ $data['fan_count'] = CustDetail::where('is_del',0)->where('dtime','<',$_end)->sum('fan_add');
|
|
50
|
+ //毛利 = 总销售额-总商品成本-总运费-总售后
|
|
51
|
+ $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost;
|
|
52
|
+
|
|
53
|
+ $res = DB::table('day_grand_total')->insert($data);
|
|
54
|
+ echo "\n日期:".$idate." 插入结果:".$res;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+}
|