Browse Source

地域总计

sunhao 5 years ago
parent
commit
0c20bb92fc

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

@@ -1494,13 +1494,14 @@ class StatisticsController extends Controller
1494 1494
             $pages = 1;
1495 1495
         }
1496 1496
 
1497
-        $result = AdCost::select(DB::raw('sum(cost) as total_cost, city, ad_time'))->where(function($query) use($stime, $etime, $city){    
1497
+        $result = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times, city, ad_time'))->where(function($query) use($stime, $etime, $city){    
1498 1498
             if($stime) $query->where('ad_time', '>=', $stime);
1499 1499
             if($etime) $query->where('ad_time', '<=', $etime);
1500 1500
             if($city) $query->where('city', 'like', '%'.$city.'%');
1501 1501
         })->groupBy('ad_time')->groupBy('city')->orderBy('ad_time', 'desc')->offset($offset)->limit($pageSize)->get();
1502 1502
 
1503 1503
         $result = json_decode(json_encode($result), true);
1504
+
1504 1505
         foreach($result as $k=>&$v){
1505 1506
             //新粉收入
1506 1507
             //当日加粉
@@ -1523,8 +1524,40 @@ class StatisticsController extends Controller
1523 1524
             //累计roi
1524 1525
             $v['total_roi'] = $v['total_cost']>0 ? round($v['order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
1525 1526
             $v['new_fan_count'] = count($phones);
1527
+
1526 1528
         }
1527 1529
 
1530
+        //总计
1531
+        $total_data = [
1532
+            'cost' => 0,
1533
+            'fan_count' => 0,
1534
+            'order_count' => 0,
1535
+            'order_amount' => 0,
1536
+            'roi' => 0,
1537
+            'conversion_times' => 0,
1538
+        ];
1539
+
1540
+        //投入
1541
+        $adcost = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times'))->where(function($query) use($stime, $etime, $city){    
1542
+            if($stime) $query->where('ad_time', '>=', $stime);
1543
+            if($etime) $query->where('ad_time', '<=', $etime);
1544
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1545
+        })->first();
1546
+        $total_data['cost'] = $adcost->total_cost;
1547
+        $total_data['conversion_times'] = $adcost->conversion_times;
1548
+        //总新粉
1549
+        $phones = DB::table('customers')->where('fanTime','>=', '2019-09-01')->where(function($query) use($stime, $etime, $city){    
1550
+            if($stime) $query->where('fanTime', '>=', $stime);
1551
+            if($etime) $query->where('fanTime', '<=', $etime);
1552
+            if($city) $query->where('receiverCity', 'like', '%'.$city.'%');
1553
+        })->lists('phone');
1554
+        $total_data['fan_count'] = !empty($phones) ? count($phones) : 0;
1555
+        //总收入
1556
+        $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();
1557
+        $total_data['order_count'] = $order->order_count;
1558
+        $total_data['order_amount'] = $order->order_amount;
1559
+        $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1560
+
1528 1561
         return view('statistics/districtRoi', ['result' =>$result,
1529 1562
             'page'              =>$page,
1530 1563
             'count'             =>$count,
@@ -1532,6 +1565,7 @@ class StatisticsController extends Controller
1532 1565
             'stime'             =>$stime,
1533 1566
             'etime'             =>$etime,          
1534 1567
             'city'             =>$city,          
1568
+            'total_data'             =>$total_data,          
1535 1569
             ]);
1536 1570
     }
1537 1571
 }

+ 18 - 1
resources/views/statistics/districtRoi.blade.php

@@ -17,7 +17,22 @@
17 17
                 
18 18
             </div>
19 19
         </div>
20
-        
20
+        <br>
21
+        <table class="table  table-border table-bordered table-bg table-hover table-sort">
22
+                <tr>
23
+                    <th width="5%">汇总信息</th>
24
+                    <th>
25
+                <ul>
26
+                    <li>总投放成本:&yen;{{$total_data['cost']}}&nbsp;&nbsp;&nbsp;&nbsp;
27
+                    总加粉数:{{$total_data['conversion_times']}}&nbsp;&nbsp;&nbsp;&nbsp;
28
+                    总新粉数量:{{$total_data['fan_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
29
+                    总成单数:{{$total_data['order_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
30
+                    总收入:&yen;{{$total_data['order_amount']}}&nbsp;&nbsp;&nbsp;&nbsp;
31
+                    总计ROI:{{$total_data['roi']}}</li>
32
+                </ul>
33
+                    </th>
34
+                </tr>
35
+        </table>
21 36
         <div class="mt-20">
22 37
             <table class="table table-border table-bordered table-bg table-hover table-sort">
23 38
                 <thead>
@@ -25,6 +40,7 @@
25 40
                     <th width="5%">日期</th>
26 41
                     <th width="5%">城市</th>
27 42
                     <th width="5%">投放成本</th>
43
+                    <th width="5%">加粉数</th>
28 44
                     <th width="5%">新粉数量</th>
29 45
                     <th width="5%">新粉成单数</th>
30 46
                     <th width="5%">新粉收入</th>
@@ -41,6 +57,7 @@
41 57
                             <td>{{$a['ad_time']}}</td>                                                                                         
42 58
                             <td>{{$a['city']}}</td>                                                                                         
43 59
                             <td>{{$a['total_cost']}}</td>                                                                                           
60
+                            <td>{{$a['conversion_times']}}</td>                                                                                           
44 61
                             <td>{{$a['new_fan_count']}}</td>                                                                                           
45 62
                             <td>{{$a['new_order_count']}}</td>                                                                                         
46 63
                             <td>{{$a['new_order_amount']}}</td>