Browse Source

地域roi总计

sunhao 5 years ago
parent
commit
a651c3a0b9

+ 25 - 42
app/Http/Controllers/Admin/StatisticsController.php

@@ -1536,6 +1536,9 @@ class StatisticsController extends Controller
1536 1536
             'order_amount' => 0,
1537 1537
             'roi' => 0,
1538 1538
             'conversion_times' => 0,
1539
+            'new_order_count' => 0,
1540
+            'new_order_amount' => 0,
1541
+            'new_roi' => 0,
1539 1542
         ];
1540 1543
 
1541 1544
         //投入
@@ -1558,6 +1561,11 @@ class StatisticsController extends Controller
1558 1561
         $total_data['order_count'] = $order->order_count;
1559 1562
         $total_data['order_amount'] = $order->order_amount;
1560 1563
         $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1564
+        #总新粉成单:            
1565
+        $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, 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)->whereIn('receiverMobile', $phones)->first();
1566
+        $total_data['new_order_count'] = $new_order->order_count;
1567
+        $total_data['new_order_amount'] = $new_order->order_amount;
1568
+        $total_data['new_roi'] = $total_data['cost']>0 ? round($total_data['new_order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1561 1569
 
1562 1570
         return view('statistics/districtRoi', ['result' =>$result,
1563 1571
             'page'              =>$page,
@@ -1623,6 +1631,9 @@ class StatisticsController extends Controller
1623 1631
             'order_amount' => 0,
1624 1632
             'roi' => 0,
1625 1633
             'conversion_times' => 0,
1634
+            'new_order_count' => 0,
1635
+            'new_order_amount' => 0,
1636
+            'new_roi' => 0,
1626 1637
         ];
1627 1638
 
1628 1639
         //投入
@@ -1646,6 +1657,12 @@ class StatisticsController extends Controller
1646 1657
         $total_data['order_amount'] = $order->order_amount;
1647 1658
         $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1648 1659
 
1660
+        #总新粉成单:            
1661
+        $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, 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)->whereIn('receiverMobile', $phones)->first();
1662
+        $total_data['new_order_count'] = $new_order->order_count;
1663
+        $total_data['new_order_amount'] = $new_order->order_amount;
1664
+        $total_data['new_roi'] = $total_data['cost']>0 ? round($total_data['new_order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1665
+
1649 1666
         $indexKey = ['ad_time','city','total_cost','conversion_times','new_fan_count','new_order_count','new_order_amount','new_roi','order_count','order_amount','total_roi'];
1650 1667
         $title = ['日期', '城市', '投放成本', '加粉数', '新粉数量', '新粉成单数', '新粉收入', '新粉ROI', '累计成单数', '累计收入', '累计ROI'];
1651 1668
         $filename = 'district_roi_'.date('Y-m-d_H').'.xlsx';
@@ -1697,13 +1714,13 @@ class StatisticsController extends Controller
1697 1714
             #订单总计:
1698 1715
             $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->first();
1699 1716
             
1700
-            #当日新粉成单:            
1701
-            $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['ad_time'])->where('createTime','<=', $v['ad_time'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->first();
1702
-            // 1.当日新粉成单数
1717
+            #汇总新粉成单:            
1718
+            $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, 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)->whereIn('receiverMobile', $phones)->first();
1719
+            // 1.新粉成单数
1703 1720
             $v['new_order_count'] = $new_order->order_count;
1704
-            // 2.当日新粉成交额 
1721
+            // 2.新粉成交额 
1705 1722
             $v['new_order_amount'] = $new_order->order_amount;
1706
-            // 3.当日粉丝总成交额
1723
+            // 3.粉丝总成交额
1707 1724
             $v['order_amount'] = $order->order_amount;
1708 1725
             // 总单数
1709 1726
             $v['order_count'] = $order->order_count;
@@ -1715,45 +1732,11 @@ class StatisticsController extends Controller
1715 1732
 
1716 1733
         }
1717 1734
 
1718
-        //总计
1719
-        $total_data = [
1720
-            'cost' => 0,
1721
-            'fan_count' => 0,
1722
-            'order_count' => 0,
1723
-            'order_amount' => 0,
1724
-            'roi' => 0,
1725
-            'conversion_times' => 0,
1726
-        ];
1727
-
1728
-        //投入
1729
-        $adcost = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times'))->where(function($query) use($stime, $etime, $city){    
1730
-            if($stime) $query->where('ad_time', '>=', $stime);
1731
-            if($etime) $query->where('ad_time', '<=', $etime);
1732
-            if($city) $query->where('city', 'like', '%'.$city.'%');
1733
-        })->first();
1734
-        $total_data['cost'] = $adcost->total_cost;
1735
-        $total_data['conversion_times'] = $adcost->conversion_times;
1736
-        //总新粉
1737
-        $phones = DB::table('customers')->where('fanTime','>=', '2019-09-01')->where(function($query) use($stime, $etime, $city){    
1738
-            if($stime) $query->where('fanTime', '>=', $stime);
1739
-            if($etime) $query->where('fanTime', '<=', $etime);
1740
-            if($city) $query->where('receiverCity', 'like', '%'.$city.'%');
1741
-        })->lists('phone');
1742
-        $total_data['fan_count'] = !empty($phones) ? count($phones) : 0;
1743
-        //总收入
1744
-        $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->first();
1745
-        $total_data['order_count'] = $order->order_count;
1746
-        $total_data['order_amount'] = $order->order_amount;
1747
-        $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1748
-
1749
-        return view('statistics/districtRoi', ['result' =>$result,
1735
+        return view('statistics/districtTotalRoi', ['result' =>$result,
1750 1736
             'page'              =>$page,
1751 1737
             'count'             =>$count,
1752
-            'pages'             =>$pages,                          
1753
-            'stime'             =>$stime,
1754
-            'etime'             =>$etime,          
1755
-            'city'             =>$city,          
1756
-            'total_data'             =>$total_data,          
1738
+            'pages'             =>$pages,                                    
1739
+            'city'             =>$city,                    
1757 1740
             ]);
1758 1741
     }
1759 1742
 }

+ 3 - 0
resources/views/statistics/districtRoi.blade.php

@@ -26,6 +26,9 @@
26 26
                     <li>总投放成本:&yen;{{$total_data['cost']}}&nbsp;&nbsp;&nbsp;&nbsp;
27 27
                     总加粉数:{{$total_data['conversion_times']}}&nbsp;&nbsp;&nbsp;&nbsp;
28 28
                     总新粉数量:{{$total_data['fan_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
29
+                    新粉成单数:{{$total_data['new_order_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
30
+                    新粉收入:&yen;{{$total_data['new_order_amount']}}&nbsp;&nbsp;&nbsp;&nbsp;
31
+                    新粉ROI:{{$total_data['new_roi']}}&nbsp;&nbsp;&nbsp;&nbsp;
29 32
                     总成单数:{{$total_data['order_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
30 33
                     总收入:&yen;{{$total_data['order_amount']}}&nbsp;&nbsp;&nbsp;&nbsp;
31 34
                     总计ROI:{{$total_data['roi']}}</li>