Browse Source

7日地域roi

sunhao 5 years ago
parent
commit
0950c2ebf8

+ 17 - 0
app/DistrictRoi7.php

@@ -0,0 +1,17 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: Administrator
5
+ * Date: 2017/12/5
6
+ * Time: 15:07
7
+ */
8
+
9
+namespace App;
10
+use Illuminate\Database\Eloquent\Model;
11
+
12
+class DistrictRoi7 extends Model
13
+{
14
+    public $timestamps = false;
15
+    protected $table = "district_roi_7";
16
+   
17
+}

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

@@ -13,6 +13,7 @@ use App\CustTotal;
13 13
 use App\CustDetail;
14 14
 use App\AdCost;
15 15
 use App\Order;
16
+use App\DistrictRoi7;
16 17
 use Illuminate\Http\Request;
17 18
 use Illuminate\Support\Facades\DB;
18 19
 
@@ -1838,6 +1839,11 @@ class StatisticsController extends Controller
1838 1839
      * 地区汇总roi
1839 1840
      */
1840 1841
     public function districtTotalRoi(Request $request){
1842
+        $page = (int)$request->input('page');
1843
+        $pageSize = 20;
1844
+        if($page<=0){
1845
+            $page = 1;
1846
+        }
1841 1847
 
1842 1848
         $offset = ($page-1) * $pageSize;
1843 1849
         $city = $request->input('city');
@@ -1850,8 +1856,14 @@ class StatisticsController extends Controller
1850 1856
             if($city) $query->where('city', 'like', '%'.$city.'%');
1851 1857
         })->groupBy('city')->get();
1852 1858
         $ret = json_decode(json_encode($ret), true);
1853
-
1854 1859
         $count = count($ret);
1860
+        if ($count > 1) {
1861
+            // 总页数
1862
+            $pages = ceil($count/$pageSize);
1863
+        }else{
1864
+            // 总页数
1865
+            $pages = 1;
1866
+        }
1855 1867
 
1856 1868
         $result = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times, city'))->where(function($query) use($city){    
1857 1869
             if($city) $query->where('city', 'like', '%'.$city.'%');
@@ -1893,7 +1905,98 @@ class StatisticsController extends Controller
1893 1905
             ]);
1894 1906
 
1895 1907
     }
1896
-}
1897 1908
 
1909
+    /**
1910
+     * 地域roi7日
1911
+     */
1912
+    public function districtRoi7day(Request $request){
1913
+        $page = (int)$request->input('page');
1914
+        $pageSize = 20;
1915
+        if($page<=0){
1916
+            $page = 1;
1917
+        }
1918
+
1919
+        $offset = ($page-1) * $pageSize;
1920
+        $stime = $request->input('stime');
1921
+        $etime = $request->input('etime');
1922
+        $city = $request->input('city');
1923
+
1924
+        if($city !== null){
1925
+            $city = str_replace('市', '', $city);
1926
+        }
1927
+
1928
+        $count = DistrictRoi7::where(function($query) use($stime, $etime, $city){    
1929
+            if($stime) $query->where('ad_time', '>=', $stime);
1930
+            if($etime) $query->where('ad_time', '<=', $etime);
1931
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1932
+        })->count();
1933
+
1934
+        if ($count > 1) {
1935
+            // 总页数
1936
+            $pages = ceil($count/$pageSize);
1937
+        }else{
1938
+            // 总页数
1939
+            $pages = 1;
1940
+        }
1941
+
1942
+        $result = DistrictRoi7::where(function($query) use($stime, $etime, $city){    
1943
+            if($stime) $query->where('ad_time', '>=', $stime);
1944
+            if($etime) $query->where('ad_time', '<=', $etime);
1945
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1946
+        })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
1947
+
1948
+        $result = json_decode(json_encode($result), true);
1949
+        foreach($result as $k=>&$v){
1950
+             //新粉roi
1951
+            $v['new_roi'] = $v['cost']>0 ? round($v['new_fan_order_amount'] / $v['cost'], 4) * 100 .'%' : '';
1952
+            //累计roi
1953
+            $v['total_roi'] = $v['cost']>0 ? round($v['order_amount'] / $v['cost'], 4) * 100 .'%' : '';
1954
+        }
1955
+
1956
+        return view('statistics/districtRoi7day', ['result' =>$result,
1957
+            'page'              =>$page,
1958
+            'count'             =>$count,
1959
+            'pages'             =>$pages,                                    
1960
+            'city'             =>$city,                    
1961
+            'stime'             =>$stime,                    
1962
+            'etime'             =>$etime,                    
1963
+            ]);
1964
+
1965
+    }
1966
+
1967
+    /**
1968
+     * 地域roi7日
1969
+     */
1970
+    public function districtRoi7day_export(Request $request){
1971
+
1972
+        $stime = $request->input('stime');
1973
+        $etime = $request->input('etime');
1974
+        $city = $request->input('city');
1975
+
1976
+        if($city !== null){
1977
+            $city = str_replace('市', '', $city);
1978
+        }
1979
+
1980
+        $result = DistrictRoi7::where(function($query) use($stime, $etime, $city){    
1981
+            if($stime) $query->where('ad_time', '>=', $stime);
1982
+            if($etime) $query->where('ad_time', '<=', $etime);
1983
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1984
+        })->orderBy('id', 'desc')->get();
1985
+
1986
+        $result = json_decode(json_encode($result), true);
1987
+        foreach($result as $k=>&$v){
1988
+             //新粉roi
1989
+            $v['new_roi'] = $v['cost']>0 ? round($v['new_fan_order_amount'] / $v['cost'], 4) * 100 .'%' : '';
1990
+            //累计roi
1991
+            $v['total_roi'] = $v['cost']>0 ? round($v['order_amount'] / $v['cost'], 4) * 100 .'%' : '';
1992
+        }
1993
+
1994
+        $indexKey = ['ad_time','city','cost','gzh_count','fan_count','new_fan_order_count','new_fan_order_amount','new_roi','order_count','order_amount','total_roi'];
1995
+        $title = ['日期', '城市', '投放成本', '加粉数', '新粉数量', '新粉成单数', '新粉收入', '新粉ROI', '7日累计成单数', '7日累计收入', '7日累计ROI'];
1996
+        $filename = 'districtRoi7day_'.date('Y-m-d_H').'.xlsx';
1997
+        return Order::export_excel($result, $filename, $indexKey, $title);
1998
+    }
1999
+}
2000
+  
1898 2001
 
1899 2002
 

+ 3 - 0
app/Http/routes.php

@@ -125,6 +125,9 @@ Route::group(['prefix' => 'admin'], function(){
125 125
         Route::get('/statistics/districtRoi', 'Admin\StatisticsController@districtRoi');
126 126
         //地域roi导出
127 127
         Route::get('/statistics/districtRoi_export', 'Admin\StatisticsController@districtRoi_export');
128
+        //地域roi7日
129
+        Route::get('/statistics/districtRoi7day', 'Admin\StatisticsController@districtRoi7day');
130
+        Route::get('/statistics/districtRoi7day_export', 'Admin\StatisticsController@districtRoi7day_export');
128 131
         //团队财务报表
129 132
         Route::get('/statistics/teamFinanceList', 'Admin\StatisticsController@teamFinanceList');
130 133
         Route::get('/statistics/teamFinanceList_export', 'Admin\StatisticsController@teamFinanceList_export');

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

@@ -114,6 +114,9 @@
114 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 115
                     </ul>
116 116
                     <ul>                       
117
+                        <li @if(!isset($res['statistics/districtRoi'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/districtRoi7day')}}" data-title="地域ROI7日统计" href="javascript:void(0)">地域ROI7日统计</a></li>                        
118
+                    </ul>
119
+                    <ul>                       
117 120
                         <li @if(!isset($res['statistics/teamFinanceList'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/teamFinanceList')}}" data-title="团队订单财务明细" href="javascript:void(0)">团队订单财务明细</a></li>                        
118 121
                     </ul>
119 122
                     <ul>                       

+ 106 - 0
resources/views/statistics/districtRoi7day.blade.php

@@ -0,0 +1,106 @@
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"></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%">新粉数量</th>
30
+                    <th width="5%">新粉成单数</th>
31
+                    <th width="5%">新粉收入</th>
32
+                    <th width="5%">新粉ROI</th>
33
+                    <th width="5%">7日累计成单数</th>
34
+                    <th width="5%">7日累计收入</th>
35
+                    <th width="5%">7日累计ROI</th>                                                
36
+                </tr>
37
+                </thead>
38
+                <tbody>
39
+                @if($result)
40
+                    @foreach($result as $a)
41
+                        <tr class="text-c" style=" text-align:center;">                           
42
+                            <td>{{$a['ad_time']}}</td>                                                                                         
43
+                            <td>{{$a['city']}}</td>                                                                                         
44
+                            <td>{{$a['cost']}}</td>                                                                                           
45
+                            <td>{{$a['gzh_count']}}</td>                                                                                           
46
+                            <td>{{$a['fan_count']}}</td>                                                                                           
47
+                            <td>{{$a['new_fan_order_count']}}</td>                                                                                         
48
+                            <td>{{$a['new_fan_order_amount']}}</td>                                                                                         
49
+                            <td>{{$a['new_roi']}}</td>                                                                                         
50
+                            <td>{{$a['order_count']}}</td>                                                                                         
51
+                            <td>{{$a['order_amount']}}</td>                                                                                         
52
+                            <td>{{$a['total_roi']}}</td>                                                                                         
53
+                        </tr>
54
+                    @endforeach
55
+                @endif
56
+                </tbody>
57
+            </table>
58
+        </div>
59
+        <div id="page" class="page_div"></div>
60
+    </div>
61
+    
62
+    <!--_footer 作为公共模版分离出去-->
63
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
64
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
65
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
66
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
67
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
68
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
69
+    <!--/_footer 作为公共模版分离出去-->
70
+    <!--/_footer 作为公共模版分离出去-->
71
+     <script type="text/javascript">
72
+        
73
+        function user_search(){
74
+            var stime = $('#stime').val();
75
+            var etime = $('#etime').val();
76
+            var city = $('#city').val();
77
+            //var page = {{$page}};
78
+            location.href = 'districtRoi7day?stime='+stime+'&etime='+etime+'&city='+city;
79
+        }
80
+        //导出
81
+        function statistics_export(){
82
+            var stime = $('#stime').val();
83
+            var etime = $('#etime').val();
84
+            var city = $('#city').val();
85
+            location.href = '/admin/statistics/districtRoi7day_export?stime='+stime+'&etime='+etime+'&city='+city;
86
+        }
87
+       
88
+        /*分页*/
89
+            
90
+        $("#page").paging({
91
+            pageNo:{{$page}},
92
+            totalPage: {{$pages}},
93
+            totalSize: {{$count}},
94
+            callback: function(num) {
95
+                var stime = $('#stime').val();
96
+                var etime = $('#etime').val();
97
+                var city = $('#city').val();
98
+                location.href='districtRoi7day?page='+num+'&stime='+stime+'&etime='+etime+'&city='+city;
99
+            }
100
+        })
101
+        
102
+    </script>
103
+   
104
+    </body>
105
+
106
+@endsection