Browse Source

梯形图加时间

sunhao 5 years ago
parent
commit
b2ea7f952b

+ 39 - 8
app/Http/Controllers/Admin/StatisticsController.php

@@ -1204,20 +1204,51 @@ class StatisticsController extends Controller
1204 1204
      * 成单率梯形图
1205 1205
      */
1206 1206
     public function orderRateList(Request $request){
1207
+        $stime = $request->input('stime');
1208
+        $etime = $request->input('etime');
1209
+        $_day = 30;
1210
+        if($stime == '' && $etime == ''){
1211
+            $stime = date("Y-m-d", strtotime('-32 day'));
1212
+            $etime = date("Y-m-d", strtotime('-2 day'));
1213
+        }else{
1214
+            if($stime){
1215
+                $_day = floor( (time() - strtotime($stime)) / 86400) - 1; //距昨天天数
1216
+            }
1217
+        }
1207 1218
         #统计天数
1208 1219
         $month = date('d')<=2 ? date('Y-m', strtotime('-1 month')) : date('Y-m'); //当前月
1209
-        $day_count = DB::table('cust_day_remain')->where('month_time', $month)->count();
1210
-        #计算分区级别 固定分20区
1211
-        $_day = round($day_count / 30);
1212
-        if($_day == 0) $_day = 1;
1213
-        $result = DB::table('cust_day_remain')->orderBy('idate', 'asc')->orderBy('month_time', 'asc')->get();
1220
+        $day_count = DB::table('cust_day_remain')->where('month_time', $month)->where(function($query) use($stime, $etime){
1221
+            if($stime) $query->where('idate','>=', $stime);
1222
+            if($etime) $query->where('idate','<=', $etime);
1223
+        })->count();
1224
+
1225
+        $result = DB::table('cust_day_remain')->where(function($query) use($stime, $etime){
1226
+            if($stime) $query->where('idate','>=', $stime);
1227
+            if($etime) $query->where('idate','<=', $etime);
1228
+        })->orderBy('idate', 'asc')->orderBy('month_time', 'asc')->get();
1229
+
1230
+        if($stime)
1214 1231
         #获取列
1215 1232
         $columns = array();
1216
-        $i_max = floor($day_count/$_day) > 30 ? 30 : floor($day_count/$_day);
1233
+        $i_max = 31;
1217 1234
         for($i=0; $i<$i_max; $i++){
1218
-            $columns[] = $i*$_day;
1235
+            $columns[] = $i;
1219 1236
         }
1220 1237
 
1238
+        if($_day >= 45){
1239
+            $columns[] = 45;
1240
+        }
1241
+        if($_day >= 60){
1242
+            $columns[] = 60;
1243
+        }
1244
+        if($_day >= 75){
1245
+            $columns[] = 75;
1246
+        }
1247
+        if($_day >= 90){
1248
+            $columns[] = 90;
1249
+        }
1250
+
1251
+
1221 1252
         #数据整合
1222 1253
         $data = array();
1223 1254
         foreach($result as $k=>$v){
@@ -1239,7 +1270,7 @@ class StatisticsController extends Controller
1239 1270
         }
1240 1271
         //echo '<pre>';
1241 1272
         //print_r($new_data);print_r($columns);exit;
1242
-        return view('statistics/orderRateList', ['result' =>$new_data, 'columns'=>$columns]);
1273
+        return view('statistics/orderRateList', ['result' =>$new_data, 'columns'=>$columns, 'stime'=>$stime, 'etime'=>$etime]);
1243 1274
 
1244 1275
     }
1245 1276
 }

+ 14 - 4
resources/views/statistics/orderRateList.blade.php

@@ -4,7 +4,11 @@
4 4
     <div class="page-container">
5 5
         <div>
6 6
             <div>    
7
-                
7
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="开始时间"/>
8
+                <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:''}}">
9
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
10
+                <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:''}}">
11
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>
8 12
                 <!--a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 导出数据</a-->
9 13
                 
10 14
             </div>
@@ -14,10 +18,10 @@
14 18
             <table class="table table-border table-bordered table-bg table-hover table-sort">
15 19
                 <thead>
16 20
                 <tr class="text-c">
17
-                    <th width="8%">时间</th>
18
-                    <th width="8%">新增用户</th>
21
+                    <th width="4%">时间</th>
22
+                    <th width="3%">新增用户</th>
19 23
                     @foreach($columns as $v)
20
-                    <th width="8%">@if($v==0) 当天 @else {{$v}}天后@endif</th>
24
+                    <th width="3%">@if($v==0) 当天 @else {{$v}}天后@endif</th>
21 25
                     @endforeach                          
22 26
                 </tr>
23 27
                 </thead>
@@ -76,6 +80,12 @@
76 80
                 location.href='/admin/statistics/down/'+id;
77 81
             });
78 82
         }
83
+
84
+        function user_search(){
85
+            var stime = $('#stime').val();
86
+            var etime = $('#etime').val();
87
+            location.href = 'orderRateList?stime='+stime+'&etime='+etime;
88
+        }
79 89
         
80 90
         
81 91
     </script>