sunhao 5 years ago
parent
commit
55c349573d
1 changed files with 5 additions and 2 deletions
  1. 5 2
      app/Http/Controllers/Admin/StatisticsController.php

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

570
             if($etime) $query->where('dtime', '<=', $etime);
570
             if($etime) $query->where('dtime', '<=', $etime);
571
         })->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->offset($offset)->limit($pageSize)->get();
571
         })->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->offset($offset)->limit($pageSize)->get();
572
         $result = json_decode(json_encode($result),true);
572
         $result = json_decode(json_encode($result),true);
573
+        $end_time = date('Y-m-d');
573
         foreach($result as $k=>&$v){
574
         foreach($result as $k=>&$v){
574
             #进粉成本
575
             #进粉成本
575
             $v['cost_fan'] = $v['total_fan_add']>0? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
576
             $v['cost_fan'] = $v['total_fan_add']>0? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
594
              //当日加粉
595
              //当日加粉
595
             $phones = DB::table('customers')->where('fanTime', $v['dtime'])->lists('phone');
596
             $phones = DB::table('customers')->where('fanTime', $v['dtime'])->lists('phone');
596
             #当日加粉订单总计:
597
             #当日加粉订单总计:
598
+            #截止昨天           
597
             $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost, sum(freight_cost) as freight_cost'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->where(function($query) use($team_id){
599
             $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost, sum(freight_cost) as freight_cost'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->where(function($query) use($team_id){
598
                 if($team_id>0) $query->where('team_id', $team_id);
600
                 if($team_id>0) $query->where('team_id', $team_id);
599
-            })->first();
601
+            })->where('createTime','<',$end_time)->first();
600
             #当日新粉成单:            
602
             #当日新粉成单:            
601
             $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where(function($query) use($team_id){
603
             $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where(function($query) use($team_id){
602
                 if($team_id>0) $query->where('team_id', $team_id);
604
                 if($team_id>0) $query->where('team_id', $team_id);
650
             if($etime) $query->where('dtime', '<=', $etime);
652
             if($etime) $query->where('dtime', '<=', $etime);
651
         })->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->get();
653
         })->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->get();
652
         $result = json_decode(json_encode($result),true);
654
         $result = json_decode(json_encode($result),true);
655
+        $end_time = date('Y-m-d');
653
         foreach($result as $k=>&$v){
656
         foreach($result as $k=>&$v){
654
             #进粉成本
657
             #进粉成本
655
             $v['cost_fan'] = $v['total_fan_add']>0? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
658
             $v['cost_fan'] = $v['total_fan_add']>0? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
667
             #当日订单数、销售额
670
             #当日订单数、销售额
668
             $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
671
             $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
669
                 if($team_id>0) $query->where('team_id', $team_id);
672
                 if($team_id>0) $query->where('team_id', $team_id);
670
-            })->first();
673
+            })->where('createTime','<',$end_time)->first();
671
             $v['order_count'] = $order->order_count;
674
             $v['order_count'] = $order->order_count;
672
             $v['order_amount'] = $order->order_amount;
675
             $v['order_amount'] = $order->order_amount;
673
 
676