sunhao 5 years ago
parent
commit
c7447ea7c3

+ 2 - 1
app/Console/Commands/DayGrandTotal.php

@@ -38,10 +38,11 @@ class DayGrandTotal extends Command {
38 38
         //总投入
39 39
         $data['throw_cost'] = CustTotal::where('is_del',0)->where('dtime','<',$_end)->sum('total_cost');
40 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();
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, sum(refund_price) as refund_fee'))->where('is_del',0)->where('createTime','<',$_end)->where('cost', '>', 0)->first();
42 42
         $data['goods_cost'] = $order->goods_cost;
43 43
         $data['freight_cost'] = $order->freight_cost;
44 44
         $data['aftersale_cost'] = $order->aftersale_cost;
45
+        $data['refund_fee'] = $order->refund_fee;
45 46
         $data['order_count'] = $order->order_count;
46 47
         $data['order_amount'] = $order->order_amount;
47 48
         $data['cust_count'] = $order->cust_count;

+ 4 - 2
app/Http/Controllers/Admin/StatisticsController.php

@@ -4573,10 +4573,11 @@ class StatisticsController extends Controller
4573 4573
             //总投入
4574 4574
             $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
4575 4575
             //订单信息
4576
-            $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('cost', '>', 0)->first();
4576
+            $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, sum(refund_price) as refund_fee'))->where('is_del',0)->where('cost', '>', 0)->first();
4577 4577
             $data['goods_cost'] = $order->goods_cost;
4578 4578
             $data['freight_cost'] = $order->freight_cost;
4579 4579
             $data['aftersale_cost'] = $order->aftersale_cost;
4580
+            $data['refund_fee'] = $order->refund_fee;
4580 4581
             $data['order_count'] = $order->order_count;
4581 4582
             $data['order_amount'] = $order->order_amount;
4582 4583
             $data['cust_count'] = $order->cust_count;
@@ -4623,10 +4624,11 @@ class StatisticsController extends Controller
4623 4624
         //总投入
4624 4625
         $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
4625 4626
         //订单信息
4626
-        $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('cost', '>', 0)->first();
4627
+        $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, sum(refund_price) as refund_fee'))->where('is_del',0)->where('cost', '>', 0)->first();
4627 4628
         $data['goods_cost'] = $order->goods_cost;
4628 4629
         $data['freight_cost'] = $order->freight_cost;
4629 4630
         $data['aftersale_cost'] = $order->aftersale_cost;
4631
+        $data['refund_fee'] = $order->refund_fee;
4630 4632
         $data['order_count'] = $order->order_count;
4631 4633
         $data['order_amount'] = $order->order_amount;
4632 4634
         $data['cust_count'] = $order->cust_count;

+ 41 - 0
app/Http/Controllers/Api/TemplateController.php

@@ -18,6 +18,9 @@ use App\TemplatesSalers;
18 18
 use App\TemplatesSourceSalers;
19 19
 use App\Admin;
20 20
 use App\TemplatesLog;
21
+use App\CustTotal;
22
+use App\CustDetail;
23
+use App\Order;
21 24
 use Illuminate\Support\Facades\Hash;
22 25
 use Illuminate\Support\Facades\DB;
23 26
 
@@ -111,4 +114,42 @@ class TemplateController extends Controller {
111 114
         return self::returnValue([]);
112 115
     }
113 116
 
117
+    /**
118
+     * 每日累计汇总数据
119
+     */
120
+    public function dayGrandTotal(Request $request){
121
+        $days = (int)$request->input('days');
122
+        if(!$days){
123
+            $days = 7;
124
+        }
125
+        $stime = date('Y-m-d', strtotime('-'.$days.' day'));
126
+        $data = array();
127
+       
128
+        //今日数据实时计算
129
+        $idate = date('Y-m-d');
130
+        $data['idate'] = $idate;
131
+        //总投入
132
+        $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
133
+        //订单信息
134
+        $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, sum(refund_price) as refund_fee'))->where('is_del',0)->where('cost', '>', 0)->first();
135
+        $data['goods_cost'] = $order->goods_cost;
136
+        $data['freight_cost'] = $order->freight_cost;
137
+        $data['aftersale_cost'] = $order->aftersale_cost;
138
+        $data['refund_fee'] = $order->refund_fee;
139
+        $data['order_count'] = $order->order_count;
140
+        $data['order_amount'] = $order->order_amount;
141
+        $data['cust_count'] = $order->cust_count;
142
+        //加粉
143
+        $data['fan_count'] = CustDetail::where('is_del',0)->sum('fan_add');    
144
+        //毛利 = 总销售额-总商品成本-总运费-总售后
145
+        $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost;
146
+        
147
+        //查询历史数据
148
+        $result = DB::table('day_grand_total')->where('idate', '>', $stime)->orderBy('idate', 'desc')->get();
149
+        $result = json_decode(json_encode($result), true);        
150
+        $result  = array_merge([$data], $result);
151
+        
152
+        return self::returnValue(['data'=>$result]);
153
+    }
154
+
114 155
 }

+ 1 - 0
app/Http/routes.php

@@ -235,5 +235,6 @@ Route::group(['prefix' => 'api'], function() {
235 235
     //模板
236 236
     Route::get('/template/qrcode', 'Api\TemplateController@salerQrcode');
237 237
     Route::get('/template/addLongLog', 'Api\TemplateController@addLongLog');
238
+    Route::get('/dayGrandTotal', 'Api\TemplateController@dayGrandTotal');
238 239
 
239 240
 });