Browse Source

地域roi

sunhao 5 years ago
parent
commit
5cce75bb25

+ 74 - 0
app/Http/Controllers/Admin/StatisticsController.php

@@ -11,6 +11,7 @@ use App\Http\Controllers\Controller;
11 11
 use App\Logs;
12 12
 use App\CustTotal;
13 13
 use App\CustDetail;
14
+use App\AdCost;
14 15
 use Illuminate\Http\Request;
15 16
 use Illuminate\Support\Facades\DB;
16 17
 
@@ -1457,4 +1458,77 @@ class StatisticsController extends Controller
1457 1458
         header('Location:https://datav.aliyuncs.com/share/423b408234ea48d49a2a4ee7f33fa4e4');
1458 1459
         exit;
1459 1460
     }
1461
+
1462
+    /**
1463
+     * 地区roi
1464
+     */
1465
+    public function districtRoi(Request $request){
1466
+        $page = (int)$request->input('page');
1467
+        $pageSize = 20;
1468
+        if($page<=0){
1469
+            $page = 1;
1470
+        }
1471
+
1472
+        $offset = ($page-1) * $pageSize;
1473
+        $stime = $request->input('stime');
1474
+        $etime = $request->input('etime');
1475
+        $city = $request->input('city');
1476
+
1477
+        if($city !== null){
1478
+            $city = str_replace('市', '', $city);
1479
+        }       
1480
+
1481
+        $ret = AdCost::select('id')->where(function($query) use($stime, $etime, $city){    
1482
+            if($stime) $query->where('ad_time', '>=', $stime);
1483
+            if($etime) $query->where('ad_time', '<=', $etime);
1484
+            if($city) $query->where('city', '=', $city);
1485
+        })->groupBy('ad_time')->groupBy('city')->get();
1486
+        $ret = json_decode(json_encode($ret), true);
1487
+
1488
+        $count = count($ret);
1489
+        if ($count > 1) {
1490
+            // 总页数
1491
+            $pages = ceil($count/$pageSize);
1492
+        }else{
1493
+            // 总页数
1494
+            $pages = 1;
1495
+        }
1496
+
1497
+        $result = AdCost::select(DB::raw('sum(cost) as total_cost, city, ad_time'))->where(function($query) use($stime, $etime, $city){    
1498
+            if($stime) $query->where('ad_time', '>=', $stime);
1499
+            if($etime) $query->where('ad_time', '<=', $etime);
1500
+            if($city) $query->where('city', 'like', $city.'%');
1501
+        })->groupBy('ad_time')->groupBy('city')->orderBy('ad_time', 'desc')->offset($offset)->limit($pageSize)->get();
1502
+
1503
+        $result = json_decode(json_encode($result), true);
1504
+        foreach($result as $k=>&$v){
1505
+            //新粉收入
1506
+            //当日加粉
1507
+            $city_name = str_replace('市', '', $v['city']);
1508
+            $phones = DB::table('customers')->where('fanTime', $v['ad_time'])->where('receiverCity', $city_name)->lists('phone');
1509
+            #当日加粉订单总计:
1510
+            $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();
1511
+            #当日新粉成单:            
1512
+            $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();
1513
+            // 1.当日新粉成单数
1514
+            $v['new_order_count'] = $new_order->order_count;
1515
+            // 2.当日新粉成交额 
1516
+            $v['new_order_amount'] = $new_order->order_amount;
1517
+            // 3.当日粉丝总成交额
1518
+            $v['order_amount'] = $order->order_amount;
1519
+            //新粉roi
1520
+            $v['new_roi'] = $v['total_cost']>0 ? round($v['new_order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
1521
+            //累计roi
1522
+            $v['total_roi'] = $v['total_cost']>0 ? round($v['order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
1523
+        }
1524
+
1525
+        return view('statistics/districtRoi', ['result' =>$result,
1526
+            'page'              =>$page,
1527
+            'count'             =>$count,
1528
+            'pages'             =>$pages,                          
1529
+            'stime'             =>$stime,
1530
+            'etime'             =>$etime,          
1531
+            'city'             =>$city,          
1532
+            ]);
1533
+    }
1460 1534
 }

+ 2 - 0
app/Http/routes.php

@@ -121,6 +121,8 @@ Route::group(['prefix' => 'admin'], function(){
121 121
         Route::get('/statistics/orderSaleRank', 'Admin\StatisticsController@orderSaleRank');
122 122
         //实时订单地域分布
123 123
         Route::get('/statistics/orderDistrict', 'Admin\StatisticsController@orderDistrict');
124
+        //地域roi
125
+        Route::get('/statistics/districtRoi', 'Admin\StatisticsController@districtRoi');
124 126
 
125 127
     });
126 128
     

+ 4 - 0
resources/views/admin/index.blade.php

@@ -110,6 +110,10 @@
110 110
                     <ul>                       
111 111
                         <li @if(!isset($res['statistics/orderDistrict'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/orderDistrict')}}" data-title="实时订单地域分布" href="javascript:void(0)">实时订单地域分布</a></li>                        
112 112
                     </ul>
113
+                    <ul>                       
114
+                        <li @if(!isset($res['statistics/districtRoi'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/districtRoi')}}" data-title="地域ROI统计" href="javascript:void(0)">地域ROI统计</a></li>                        
115
+                    </ul>
116
+                   
113 117
                 </dd>
114 118
             </dl>
115 119
                      

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

@@ -0,0 +1,123 @@
1
+@extends('admin/master')
2
+@section('content')
3
+    <body>
4
+    <div class="page-container">
5
+        <div>
6
+            <div>   
7
+                <input class="input-text" style="width:5%;text-align:center" type="text" value="所属城市"/>
8
+                <input id="city" type="text"  class="input-text" style="width:6%;text-align:center" name="city" value="{{$city?$city:''}}">                         
9
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="开始时间"/>
10
+                <input id="stime" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:12%;text-align:center;margin-left: -5px" name="stime" value="{{$stime?$stime:''}}">
11
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
12
+                <input id="etime"type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:12%;text-align:center;margin-left: -5px" name="etime" value="{{$etime?$etime:''}}">
13
+               
14
+                
15
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>
16
+                <!--a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 导出数据</a-->
17
+                
18
+            </div>
19
+        </div>
20
+        
21
+        <div class="mt-20">
22
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
23
+                <thead>
24
+                <tr class="text-c">
25
+                    <th width="5%">日期</th>
26
+                    <th width="5%">城市</th>
27
+                    <th width="5%">投放成本</th>
28
+                    <th width="5%">新粉收入</th>
29
+                    <th width="5%">新粉ROI</th>
30
+                    <th width="5%">累计收入</th>
31
+                    <th width="5%">累计ROI</th>                                                
32
+                </tr>
33
+                </thead>
34
+                <tbody>
35
+                @if($result)
36
+                    @foreach($result as $a)
37
+                        <tr class="text-c" style=" text-align:center;">                           
38
+                            <td>{{$a['ad_time']}}</td>                                                                                         
39
+                            <td>{{$a['city']}}</td>                                                                                         
40
+                            <td>{{$a['total_cost']}}</td>                                                                                         
41
+                            <td>{{$a['new_order_amount']}}</td>                                                                                         
42
+                            <td>{{$a['new_roi']}}</td>                                                                                         
43
+                            <td>{{$a['order_amount']}}</td>                                                                                         
44
+                            <td>{{$a['total_roi']}}</td>                                                                                         
45
+                        </tr>
46
+                    @endforeach
47
+                @endif
48
+                </tbody>
49
+            </table>
50
+        </div>
51
+        <div id="page" class="page_div"></div>
52
+    </div>
53
+    
54
+    <!--_footer 作为公共模版分离出去-->
55
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
56
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
57
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
58
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
59
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
60
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
61
+    <!--/_footer 作为公共模版分离出去-->
62
+    <!--/_footer 作为公共模版分离出去-->
63
+     <script type="text/javascript">
64
+        /*广告-添加*/
65
+        function statistics_add(title){
66
+            location.href="/admin/statistics/totalcreate";
67
+        }
68
+        /*广告-编辑*/
69
+        function statistics_edit(title,id){
70
+            location.href="/admin/statistics/totaledit/"+id;
71
+        }
72
+        /*广告-设为首页显示*/
73
+        function up(obj,id){
74
+            layer.confirm('确认要设为首页显示吗?',function(index){
75
+                location.href='/admin/statistics/up/'+id;
76
+            });
77
+        }
78
+        /*广告-移除*/
79
+        function statistics_del(obj,id){
80
+            layer.confirm('确认要删除吗?',function(index){
81
+                location.href='/admin/statistics/totaldelete/'+id;
82
+            });
83
+        }
84
+        /*广告-设为首页隐藏*/
85
+        function down(obj,id){
86
+            layer.confirm('确认要设为首页隐藏吗?',function(index){
87
+                location.href='/admin/statistics/down/'+id;
88
+            });
89
+        }
90
+        function user_search(){
91
+            var stime = $('#stime').val();
92
+            var etime = $('#etime').val();
93
+            var city = $('#city').val();
94
+            //var page = {{$page}};
95
+            location.href = 'districtRoi?stime='+stime+'&etime='+etime+'&city='+city;
96
+        }
97
+        //导出
98
+        function statistics_export(){
99
+            var stime = $('#stime').val();
100
+            var etime = $('#etime').val();
101
+            var city = $('#city').val();
102
+            location.href = '/admin/statistics/districtRoi_export?stime='+stime+'&etime='+etime+'&city='+city;
103
+        }
104
+       
105
+        /*分页*/
106
+            
107
+        $("#page").paging({
108
+            pageNo:{{$page}},
109
+            totalPage: {{$pages}},
110
+            totalSize: {{$count}},
111
+            callback: function(num) {
112
+                var stime = $('#stime').val();
113
+                var etime = $('#etime').val();
114
+                var city = $('#city').val();
115
+                location.href='districtRoi?page='+num+'&stime='+stime+'&etime='+etime+'&city='+city;
116
+            }
117
+        })
118
+        
119
+    </script>
120
+   
121
+    </body>
122
+
123
+@endsection