sunhao 5 years ago
parent
commit
86def84acc

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

@@ -51,7 +51,13 @@ class DayGrandTotal extends Command {
51 51
         $data['fan_count'] = CustDetail::where('is_del',0)->where('dtime','<',$_end)->where('dtime','>=',$_start)->sum('fan_add');    
52 52
         //毛利 = 总销售额-总商品成本-总运费-总售后
53 53
         $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost - $data['throw_cost'] + $order->refund_fee;
54
-   
54
+        //总新粉单数            
55
+        $new_order = Order::select(DB::raw('count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->where('order.createTime','<',$_end)->where('order.createTime','>=',$_start)->first();
56
+        $data['new_order_count'] = $new_order->order_count;
57
+        //总老粉单数
58
+        $data['old_order_count'] = $data['order_count'] - $data['new_order_count'];
59
+        //总复购订单
60
+        $data['fugou_order_count'] = $data['order_count'] - $data['cust_count'];
55 61
         $res = DB::table('day_grand_total')->insert($data);
56 62
         echo "\n日期:".$idate." 插入结果:".$res;
57 63
     }

+ 21 - 1
app/Http/Controllers/Admin/StatisticsController.php

@@ -4586,6 +4586,15 @@ class StatisticsController extends Controller
4586 4586
             //毛利 = 总销售额-总商品成本-总运费-总售后
4587 4587
             $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost - $data['throw_cost'] + $order->refund_fee;
4588 4588
             $data['roi'] = $data['throw_cost']>0?  round($order->order_amount / $data['throw_cost'], 4) * 100 .'%' : '';
4589
+            //总新粉单数            
4590
+            $new_order = Order::select(DB::raw('count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->where('order.createTime','>=',$_start)->first();
4591
+            $data['new_order_count'] = $new_order->order_count;
4592
+            //总老粉单数
4593
+            $data['old_order_count'] = $data['order_count'] - $data['new_order_count'];
4594
+            //总复购订单
4595
+            $data['fugou_order_count'] = $data['order_count'] - $data['cust_count'];
4596
+            //总复购率
4597
+            $data['fugou_rate'] = $data['cust_count']>0 ? round($data['fugou_order_count'] / $data['cust_count'], 4) : '';
4589 4598
         }else{
4590 4599
             $offset = ($page-1) * $pageSize - 1;
4591 4600
         }
@@ -4596,6 +4605,7 @@ class StatisticsController extends Controller
4596 4605
         $result = json_decode(json_encode($result), true);
4597 4606
         foreach($result as $k=>&$v){
4598 4607
             $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) * 100 .'%' : '';
4608
+            $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
4599 4609
         }
4600 4610
         if($page == 1){
4601 4611
             $result  = array_merge([$data], $result);
@@ -4641,11 +4651,21 @@ class StatisticsController extends Controller
4641 4651
         //毛利 = 总销售额-总商品成本-总运费-总售后
4642 4652
         $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost - $data['throw_cost'] + $order->refund_fee;
4643 4653
         $data['roi'] = $data['throw_cost']>0?  round($order->order_amount / $data['throw_cost'], 4) * 100 .'%' : '';
4644
-       
4654
+        //总新粉单数            
4655
+        $new_order = Order::select(DB::raw('count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->where('order.createTime','>=',$_start)->first();
4656
+        $data['new_order_count'] = $new_order->order_count;
4657
+        //总老粉单数
4658
+        $data['old_order_count'] = $data['order_count'] - $data['new_order_count'];
4659
+        //总复购订单
4660
+        $data['fugou_order_count'] = $data['order_count'] - $data['cust_count'];
4661
+        //总复购率
4662
+        $data['fugou_rate'] = $data['cust_count']>0 ? round($data['fugou_order_count'] / $data['cust_count'], 4) : '';
4663
+
4645 4664
         $result = DB::table('day_grand_total')->orderBy('idate', 'desc')->get();
4646 4665
         $result = json_decode(json_encode($result), true); 
4647 4666
         foreach($result as $k=>&$v){
4648 4667
             $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) * 100 .'%' : '';
4668
+            $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
4649 4669
         }  
4650 4670
         $result  = array_merge([$data], $result);
4651 4671
 

+ 10 - 1
app/Http/Controllers/Api/TemplateController.php

@@ -144,13 +144,22 @@ class TemplateController extends Controller {
144 144
         //毛利 = 总销售额-总商品成本-总运费-总售后
145 145
         $data['profit'] = $order->order_amount - $order->goods_cost - $order->freight_cost - $order->aftersale_cost - $data['throw_cost'] + $order->refund_fee;
146 146
         $data['roi'] = $data['throw_cost']>0?  round($order->order_amount / $data['throw_cost'], 4) : '';
147
-        
147
+        //总新粉单数            
148
+        $new_order = Order::select(DB::raw('count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->where('order.createTime','>=',$_start)->first();
149
+        $data['new_order_count'] = $new_order->order_count;
150
+        //总老粉单数
151
+        $data['old_order_count'] = $data['order_count'] - $data['new_order_count'];
152
+        //总复购订单
153
+        $data['fugou_order_count'] = $data['order_count'] - $data['cust_count'];
154
+        //总复购率
155
+        $data['fugou_rate'] = $data['cust_count']>0 ? round($data['fugou_order_count'] / $data['cust_count'], 4) : '';
148 156
         //查询历史数据
149 157
         $result = DB::table('day_grand_total')->where('idate', '>', $stime)->orderBy('idate', 'desc')->get();
150 158
         $result = json_decode(json_encode($result), true); 
151 159
         foreach($result as $k=>&$v){
152 160
             unset($v['fan_count']);
153 161
             $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) : '';
162
+            $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
154 163
         }       
155 164
         $result  = array_merge([$data], $result);
156 165