|
@@ -4552,10 +4552,102 @@ class StatisticsController extends Controller
|
4552
|
4552
|
$filename = 'xiaoshoufugou_'.date('Y-m-d_H').'.xlsx';
|
4553
|
4553
|
return Order::export_excel($result, $filename, $indexKey, $title);
|
4554
|
4554
|
}
|
|
4555
|
+
|
|
4556
|
+ /**
|
|
4557
|
+ * 每日累计汇总数据
|
|
4558
|
+ */
|
|
4559
|
+ public function dayGrandTotal(Request $request){
|
|
4560
|
+ $page = (int)$request->input('page');
|
|
4561
|
+ $pageSize = 20;
|
|
4562
|
+ if($page<=0){
|
|
4563
|
+ $page = 1;
|
|
4564
|
+ }
|
|
4565
|
+
|
|
4566
|
+ $data = array();
|
|
4567
|
+ if($page == 1){
|
|
4568
|
+ $pageSize = $pageSize - 1;
|
|
4569
|
+ $offset = ($page-1) * $pageSize;
|
|
4570
|
+ //今日数据实时计算
|
|
4571
|
+ $idate = date('Y-m-d');
|
|
4572
|
+ $data['idate'] = $idate;
|
|
4573
|
+ //总投入
|
|
4574
|
+ $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
|
|
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();
|
|
4577
|
+ $data['goods_cost'] = $order->goods_cost;
|
|
4578
|
+ $data['freight_cost'] = $order->freight_cost;
|
|
4579
|
+ $data['aftersale_cost'] = $order->aftersale_cost;
|
|
4580
|
+ $data['order_count'] = $order->order_count;
|
|
4581
|
+ $data['order_amount'] = $order->order_amount;
|
|
4582
|
+ $data['cust_count'] = $order->cust_count;
|
|
4583
|
+ //加粉
|
|
4584
|
+ $data['fan_count'] = CustDetail::where('is_del',0)->sum('fan_add');
|
|
4585
|
+ //毛利 = 总销售额-总商品成本-总运费-总售后
|
|
4586
|
+ $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost;
|
|
4587
|
+ }else{
|
|
4588
|
+ $offset = ($page-1) * $pageSize - 1;
|
|
4589
|
+ }
|
|
4590
|
+ //查询历史数据
|
|
4591
|
+ $count = DB::table('day_grand_total')->count();
|
|
4592
|
+ $count = $count + 1;
|
|
4593
|
+ $result = DB::table('day_grand_total')->orderBy('idate', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
4594
|
+ $result = json_decode(json_encode($result), true);
|
|
4595
|
+ if($page == 1){
|
|
4596
|
+ $result = array_merge([$data], $result);
|
|
4597
|
+ }
|
|
4598
|
+
|
|
4599
|
+ if ($count > 1) {
|
|
4600
|
+ // 总页数
|
|
4601
|
+ $pages = ceil($count/$pageSize);
|
|
4602
|
+ }else{
|
|
4603
|
+ // 总页数
|
|
4604
|
+ $pages = 1;
|
|
4605
|
+ }
|
|
4606
|
+
|
|
4607
|
+ return view('statistics/dayGrandTotal', ['result' =>$result,
|
|
4608
|
+ 'page' =>$page,
|
|
4609
|
+ 'count' =>$count,
|
|
4610
|
+ 'pages' =>$pages,
|
|
4611
|
+ ]);
|
|
4612
|
+ }
|
|
4613
|
+
|
|
4614
|
+ /**
|
|
4615
|
+ * 每日累计汇总数据导出
|
|
4616
|
+ */
|
|
4617
|
+ public function dayGrandTotal_export(Request $request){
|
|
4618
|
+
|
|
4619
|
+ $data = array();
|
|
4620
|
+ //今日数据实时计算
|
|
4621
|
+ $idate = date('Y-m-d');
|
|
4622
|
+ $data['idate'] = $idate;
|
|
4623
|
+ //总投入
|
|
4624
|
+ $data['throw_cost'] = CustTotal::where('is_del',0)->sum('total_cost');
|
|
4625
|
+ //订单信息
|
|
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
|
+ $data['goods_cost'] = $order->goods_cost;
|
|
4628
|
+ $data['freight_cost'] = $order->freight_cost;
|
|
4629
|
+ $data['aftersale_cost'] = $order->aftersale_cost;
|
|
4630
|
+ $data['order_count'] = $order->order_count;
|
|
4631
|
+ $data['order_amount'] = $order->order_amount;
|
|
4632
|
+ $data['cust_count'] = $order->cust_count;
|
|
4633
|
+ //加粉
|
|
4634
|
+ $data['fan_count'] = CustDetail::where('is_del',0)->sum('fan_add');
|
|
4635
|
+ //毛利 = 总销售额-总商品成本-总运费-总售后
|
|
4636
|
+ $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost;
|
|
4637
|
+
|
|
4638
|
+ $result = DB::table('day_grand_total')->orderBy('idate', 'desc')->get();
|
|
4639
|
+ $result = json_decode(json_encode($result), true);
|
|
4640
|
+ $result = array_merge([$data], $result);
|
|
4641
|
+
|
|
4642
|
+ $indexKey = ['idate','throw_cost','cust_count','order_count','order_amount','goods_cost', 'freight_cost', 'aftersale_cost', 'profit'];
|
|
4643
|
+ $title = ['汇总日期', '总投放', '总客户数', '总下单数', '总销售额', '总货品成本', '总运费成本', '总售后', '总毛利'];
|
|
4644
|
+ $filename = 'huizongshuj_'.date('Y-m-d_H').'.xlsx';
|
|
4645
|
+ return Order::export_excel($result, $filename, $indexKey, $title);
|
|
4646
|
+ }
|
4555
|
4647
|
|
4556
|
4648
|
}
|
4557
|
4649
|
|
4558
|
|
-
|
|
4650
|
+
|
4559
|
4651
|
|
4560
|
4652
|
|
4561
|
4653
|
|