Browse Source

商品售卖排行

sunhao 5 years ago
parent
commit
fff3fbd91e

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

@@ -20,6 +20,8 @@ use App\DistrictRoi45;
20 20
 use App\DistrictRoi60;
21 21
 use App\SalerTargets;
22 22
 use App\TemplatesLog;
23
+use App\OrderGoodsSkus;
24
+use App\Goods;
23 25
 use App\RedisModel as Redis;
24 26
 use Illuminate\Http\Request;
25 27
 use Illuminate\Support\Facades\DB;
@@ -4674,10 +4676,46 @@ class StatisticsController extends Controller
4674 4676
         $filename = 'huizongshuj_'.date('Y-m-d_H').'.xlsx';
4675 4677
         return Order::export_excel($result, $filename, $indexKey, $title); 
4676 4678
     }
4679
+
4680
+    /**
4681
+     * 近30天销量排行
4682
+     */
4683
+    public function volumeRank(Request $request){
4684
+        $stime = date('Y-m-d', strtotime('-30 day'));
4685
+        $result = OrderGoodsSkus::select(DB::raw('goods_id, sum(send_num) as volume'))->where('create_time', '>=', $stime)->where('send_num','>',0)->where('is_del', 0)->groupBy('goods_id')->orderBy('volume', 'desc')->get();
4686
+        $result = json_decode(json_encode($result), true);
4687
+        foreach($result as $k=>&$v){
4688
+            $goods = Goods::where('id', $v['goods_id'])->first();
4689
+            $v['name'] = $goods->name;
4690
+            $v['cate'] = $goods->goodsCategoryName;
4691
+            $v['productCode'] = $goods->productCode;
4692
+            $v['picUrl'] = $goods->picUrl;           
4693
+        }
4694
+        return view('statistics/volumeRank', ['result' =>$result,                                                                                                  
4695
+            ]);
4696
+    }
4697
+
4698
+    public function volumeRank_export(Request $request){
4699
+        $stime = date('Y-m-d', strtotime('-30 day'));
4700
+        $result = OrderGoodsSkus::select(DB::raw('goods_id, sum(send_num) as volume'))->where('create_time', '>=', $stime)->where('send_num','>',0)->where('is_del', 0)->groupBy('goods_id')->orderBy('volume', 'desc')->get();
4701
+        $result = json_decode(json_encode($result), true);
4702
+        foreach($result as $k=>&$v){
4703
+            $goods = Goods::where('id', $v['goods_id'])->first();
4704
+            $v['name'] = $goods->name;
4705
+            $v['cate'] = $goods->goodsCategoryName;
4706
+            $v['productCode'] = $goods->productCode;
4707
+            $v['picUrl'] = $goods->picUrl; 
4708
+            $v['rank_id'] = $k+1;          
4709
+        }
4710
+
4711
+        $indexKey = ['rank_id','name','cate','picUrl','productCode','volume'];
4712
+        $title = ['排名', '商品标题', '所属分类', '商品图片', '商品货号', '最近30日商品销量'];
4713
+        $filename = 'shangpingpaihang_'.date('Y-m-d_H').'.xlsx';
4714
+        return Order::export_excel($result, $filename, $indexKey, $title);
4715
+    }
4677 4716
                                                                                 
4678 4717
 }
4679
-                                                                        
4680
-                                          
4718
+                                                                          
4681 4719
   
4682 4720
 
4683 4721
 

+ 3 - 0
app/Http/routes.php

@@ -233,6 +233,9 @@ Route::group(['prefix' => 'admin'], function(){
233 233
         //按月统计销售加粉下单情况
234 234
         Route::get('template/templateLogMonthReport',   'Admin\TemplateController@templateLogMonthReport');
235 235
         Route::get('template/templateLogMonthReport_export',   'Admin\TemplateController@templateLogMonthReport_export');
236
+        
237
+        Route::get('statistics/volumeRank',   'Admin\StatisticsController@volumeRank');
238
+        Route::get('statistics/volumeRank_export',   'Admin\StatisticsController@volumeRank_export');
236 239
 
237 240
     });
238 241
     

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

@@ -138,7 +138,10 @@
138 138
                         <li @if(!isset($res['template/templateLogReport'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/template/templateLogMonthReport')}}" data-title="销售模板导粉月报" href="javascript:void(0)">销售模板导粉月报</a></li> 
139 139
 
140 140
                         <li @if(!isset($res['statistics/salerOrderFugou'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/salerOrderFugou')}}" data-title="销售粉丝复购报表" href="javascript:void(0)">销售粉丝复购报表</a></li> 
141
-                        <li @if(!isset($res['statistics/dayGrandTotal'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/dayGrandTotal')}}" data-title="每日数据累计汇总报表" href="javascript:void(0)">每日数据累计汇总报表</a></li>                        
141
+                        <li @if(!isset($res['statistics/dayGrandTotal'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/dayGrandTotal')}}" data-title="每日数据累计汇总报表" href="javascript:void(0)">每日数据累计汇总报表</a></li> 
142
+
143
+                        <li @if(!isset($res['statistics/volumeRank'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/volumeRank')}}" data-title="近30日商品售卖排行榜" href="javascript:void(0)">近30日商品售卖排行榜</a></li> 
144
+
142 145
                     </ul>
143 146
                    
144 147
                 </dd>

+ 74 - 0
resources/views/statistics/volumeRank.blade.php

@@ -0,0 +1,74 @@
1
+@extends('admin/master')
2
+@section('content')
3
+    <body>
4
+    <div class="page-container">
5
+        <div>
6
+            <div>                 
7
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 导出数据</a>
8
+                
9
+            </div>
10
+        </div>
11
+        
12
+        <div class="mt-20">
13
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
14
+                <thead>
15
+                <tr class="text-c">
16
+                    <th width="5%">排名</th>
17
+                    <!--th width="8%">商品id</th-->
18
+                    <th width="10%">商品标题</th>
19
+                    <th width="8%">所属分类</th>                                 
20
+                    <th width="10%">商品图片</th>                                 
21
+                    <th width="8%">商品货号</th>                                 
22
+                    <th width="8%">最近30日商品销量</th>                                                                                                                          
23
+                </tr>
24
+                </thead>
25
+                <tbody>
26
+                @if($result)
27
+                    @foreach($result as $k=>$a)
28
+                        <tr class="text-c" style=" text-align:center;">                           
29
+                            <td>{{$k+1}}</td>                            
30
+                            <!--td>{{$a['goods_id']}}</td-->                            
31
+                            <td>{{$a['name']}}</td>                            
32
+                            <td>{{$a['cate']}}</td>                            
33
+                            <td><img style="width: 100px" src="{{$a['picUrl']}}"/></td>                            
34
+                            <td>{{$a['productCode']}}</td>                            
35
+                            <td>{{$a['volume']}}</td>                            
36
+                            
37
+                        </tr>
38
+                    @endforeach
39
+                @endif
40
+                </tbody>
41
+            </table>
42
+        </div>
43
+        <!--div id="page" class="page_div"></div-->
44
+    </div>
45
+    
46
+    <!--_footer 作为公共模版分离出去-->
47
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
48
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
49
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
50
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
51
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
52
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
53
+    <!--/_footer 作为公共模版分离出去-->
54
+    <!--/_footer 作为公共模版分离出去-->
55
+     <script type="text/javascript">
56
+      
57
+        function user_search(){
58
+            var stime = $('#stime').val();
59
+            var etime = $('#etime').val();
60
+            var team_id = $('#team_id').val();
61
+            location.href = 'volumeRank?stime='+stime+'&etime='+etime+'&team_id='+team_id;
62
+        }
63
+        //导出
64
+        function statistics_export(){
65
+            location.href = '/admin/statistics/volumeRank_export';
66
+        }
67
+       
68
+      
69
+        
70
+    </script>
71
+   
72
+    </body>
73
+
74
+@endsection