sunhao 5 years ago
parent
commit
acc5025aba

+ 15 - 11
app/Http/Controllers/Admin/StatisticsController.php

@@ -22,6 +22,7 @@ use App\SalerTargets;
22 22
 use App\TemplatesLog;
23 23
 use App\OrderGoodsSkus;
24 24
 use App\Goods;
25
+use App\GoodsSkus;
25 26
 use App\RedisModel as Redis;
26 27
 use Illuminate\Http\Request;
27 28
 use Illuminate\Support\Facades\DB;
@@ -4744,14 +4745,16 @@ class StatisticsController extends Controller
4744 4745
      */
4745 4746
     public function volumeRank(Request $request){
4746 4747
         $stime = date('Y-m-d', strtotime('-30 day'));
4747
-        $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();
4748
+        $result = OrderGoodsSkus::select(DB::raw('goods_id, sku_id, sum(send_num) as volume, count(1) as counts'))->where('create_time', '>=', $stime)->where('send_num','>',0)->where('is_del', 0)->groupBy('sku_id')->orderBy('volume', 'desc')->get();
4748 4749
         $result = json_decode(json_encode($result), true);
4749 4750
         foreach($result as $k=>&$v){
4750 4751
             $goods = Goods::where('id', $v['goods_id'])->first();
4752
+            $skus = GoodsSkus::select('is_weigh', 'propsName', 'price')->where('id', $v['sku_id'])->first();
4751 4753
             $v['name'] = $goods->name;
4752
-            $v['cate'] = $goods->goodsCategoryName;
4753
-            $v['productCode'] = $goods->productCode;
4754
-            $v['picUrl'] = $goods->picUrl;           
4754
+            $v['propsName'] = $skus->propsName;      
4755
+            $v['propsName'] .= !empty($skus) && $skus->is_weigh == 1 ? '【称重商品】' : '';  
4756
+            $v['price'] = $skus->price;
4757
+            $v['amount'] = round($v['price'] * $volume, 2);
4755 4758
         }
4756 4759
         return view('statistics/volumeRank', ['result' =>$result,                                                                                                  
4757 4760
             ]);
@@ -4759,19 +4762,20 @@ class StatisticsController extends Controller
4759 4762
 
4760 4763
     public function volumeRank_export(Request $request){
4761 4764
         $stime = date('Y-m-d', strtotime('-30 day'));
4762
-        $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();
4765
+        $result = OrderGoodsSkus::select(DB::raw('goods_id, sku_id, sum(send_num) as volume, count(1) as counts'))->where('create_time', '>=', $stime)->where('send_num','>',0)->where('is_del', 0)->groupBy('sku_id')->orderBy('volume', 'desc')->get();
4763 4766
         $result = json_decode(json_encode($result), true);
4764 4767
         foreach($result as $k=>&$v){
4765 4768
             $goods = Goods::where('id', $v['goods_id'])->first();
4769
+            $skus = GoodsSkus::select('is_weigh', 'propsName', 'price')->where('id', $v['sku_id'])->first();
4766 4770
             $v['name'] = $goods->name;
4767
-            $v['cate'] = $goods->goodsCategoryName;
4768
-            $v['productCode'] = $goods->productCode;
4769
-            $v['picUrl'] = $goods->picUrl; 
4770
-            $v['rank_id'] = $k+1;          
4771
+            $v['propsName'] = $skus->propsName;      
4772
+            $v['propsName'] .= !empty($skus) && $skus->is_weigh == 1 ? '【称重商品】' : '';  
4773
+            $v['price'] = $skus->price;
4774
+            $v['amount'] = round($v['price'] * $volume, 2);
4771 4775
         }
4772 4776
 
4773
-        $indexKey = ['rank_id','name','cate','picUrl','productCode','volume'];
4774
-        $title = ['排名', '商品标题', '所属分类', '商品图片', '商品货号', '最近30日商品销量'];
4777
+        $indexKey = ['rank_id','name','propsName','price','counts','volume','amount'];
4778
+        $title = ['排名', '商品标题', '商品规格', '价格', '最近30日成单量', '最近30日销量', '近30日销售额'];
4775 4779
         $filename = 'shangpingpaihang_'.date('Y-m-d_H').'.xlsx';
4776 4780
         return Order::export_excel($result, $filename, $indexKey, $title);
4777 4781
     }

+ 12 - 11
resources/views/statistics/volumeRank.blade.php

@@ -14,25 +14,26 @@
14 14
                 <thead>
15 15
                 <tr class="text-c">
16 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>                                                                                                                          
17
+                    <th width="10%">商品标题</th>                                 
18
+                    <th width="10%">商品规格</th> 
19
+                    <th width="8%">价格</th> 
20
+                    <th width="8%">成单量</th>
21
+                    <th width="8%">最近30日销量</th>
22
+                    <th width="8%">最近30日销售额</th>
23
+
23 24
                 </tr>
24 25
                 </thead>
25 26
                 <tbody>
26 27
                 @if($result)
27 28
                     @foreach($result as $k=>$a)
28 29
                         <tr class="text-c" style=" text-align:center;">                           
29
-                            <td>{{$k+1}}</td>                            
30
-                            <!--td>{{$a['goods_id']}}</td-->                            
30
+                            <td>{{$k+1}}</td>                                                       
31 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>                            
32
+                            <td>{{$a['propsName']}}</td>                                                       
33
+                            <td>{{$a['price']}}</td>                                                       
34
+                            <td>{{$a['counts']}}</td>                                                       
35 35
                             <td>{{$a['volume']}}</td>                            
36
+                            <td>{{$a['amount']}}</td>                            
36 37
                             
37 38
                         </tr>
38 39
                     @endforeach