Browse Source

分销商商品列表

shensong 5 years ago
parent
commit
547261fc4f

+ 17 - 0
app/GoodsSkus.php

@@ -34,5 +34,22 @@ class GoodsSkus extends Model
34 34
         $quantity = $sku_quantity - $w_num;
35 35
         return ['quantity' => $quantity, 'w_num' => $w_num];
36 36
     }
37
+
38
+    public static function actualQuantityNotNull(){
39
+        //取出所有商品规格信息
40
+        $skuList = GoodsSkus::all();
41
+        $actualSkuList = array();
42
+
43
+        //遍历商品规格信息,分别计算库用库存并判断
44
+        foreach($skuList as $sku){
45
+            $quantityArr = self::actualQuantityByRedis($sku['id']);
46
+            if($quantityArr['quantity'] > 0){
47
+                //将可用库存大于0的赋值给新数组
48
+                $actualSkuList[] = $sku['id'];
49
+            }
50
+        }
51
+
52
+        return $actualSkuList;
53
+    }
37 54
    
38 55
 }

+ 37 - 19
app/Http/Controllers/Admin/GoodsController.php

@@ -657,19 +657,13 @@ class GoodsController extends Controller
657 657
         //获取分类
658 658
         $cates = DB::table('categorys')->lists('name', 'id');
659 659
         //获取请求参数
660
-        $name = $request->input('name');
661
-        $cate_name = trim($request->input('cate_name'));
662
-        $status = $request->input('status');
663
-
664
-        if(is_null($status)){
665
-            $status = 0;
666
-        }
667
-
668
-        $page = (int)$request->input('page');
660
+        $name = trim($request->input('name',''));
661
+        $cate_name = trim($request->input('cate_name',''));
662
+        $status = $request->input('status','-1');
663
+        $realQuantity = $request->input('quantity','-1');
664
+        $outPrice = $request->input('outPrice','-1');
665
+        $page = (int)$request->input('page','1');
669 666
         $pageSize = 20;
670
-        if($page<=0){
671
-            $page = 1;
672
-        }
673 667
 
674 668
         //若有请求参数,初步查询处理
675 669
         $goodsIds = array();
@@ -679,7 +673,7 @@ class GoodsController extends Controller
679 673
                 if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
680 674
             })->lists('id');
681 675
 
682
-            //无搜索结果,直接返回空
676
+            //TODO 无搜索结果,直接返回空,添加检索框以后不要忘了修改这里
683 677
             if(count($goodsIds) == 0){
684 678
                 return view('goods/indexcopy', ['result' =>[],
685 679
                     'page'              =>$page,
@@ -689,18 +683,28 @@ class GoodsController extends Controller
689 683
                     'cate_name'         =>$cate_name,
690 684
                     'cates'             =>$cates,
691 685
                     'status'            =>$status,
686
+                    'quantity'          =>$realQuantity,
687
+                    'outPrice'          =>$outPrice,
692 688
                 ]);
693 689
             }
694 690
         }
695 691
 
692
+        //筛选所有可用库存大于0的规格id
693
+        $actualSkuList = array();
694
+        if($realQuantity != '-1'){
695
+            $actualSkuList = GoodsSkus::actualQuantityNotNull();
696
+        }
697
+
696 698
         //获取数据总条数
697
-        $count = GoodsSkus::where(function($query) use ($goodsIds,$status){
699
+        $count = GoodsSkus::where(function($query) use ($goodsIds,$status,$realQuantity,$outPrice,$actualSkuList){
698 700
             if(count($goodsIds) > 1){
699 701
                 $query->whereIn('goodsCode',$goodsIds);
700 702
             }else if(count($goodsIds) == 1){
701 703
                 $query->where('goodsCode',$goodsIds);
702 704
             }
703 705
             if($status != '-1') $query->where('is_del',$status);
706
+            if($realQuantity != '-1') $query->whereIn('id',$actualSkuList);
707
+            if($outPrice != '-1') $query->where('outPrice','>','0');
704 708
         })->count();
705 709
 
706 710
         //分页数据处理
@@ -714,13 +718,15 @@ class GoodsController extends Controller
714 718
 
715 719
         //获取数据项
716 720
         $offset = ($page-1) * $pageSize;
717
-        $result = GoodsSkus::where(function($query) use ($goodsIds,$status){
721
+        $result = GoodsSkus::where(function($query) use ($goodsIds,$status,$realQuantity,$outPrice,$actualSkuList){
718 722
             if(count($goodsIds) > 1){
719 723
                 $query->whereIn('goodsCode',$goodsIds);
720 724
             } else if(count($goodsIds) == 1){
721 725
                 $query->where('goodsCode',$goodsIds);
722 726
             }
723 727
             if($status != '-1') $query->where('is_del',$status);
728
+            if($realQuantity != '-1') $query->whereIn('id',$actualSkuList);
729
+            if($outPrice != '-1') $query->where('outPrice','>','0');
724 730
         })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
725 731
         $result = json_decode(json_encode($result),true);
726 732
 
@@ -746,6 +752,8 @@ class GoodsController extends Controller
746 752
             'cate_name'         =>$cate_name,
747 753
             'cates'             =>$cates,
748 754
             'status'            =>$status,
755
+            'quantity'          =>$realQuantity,
756
+            'outPrice'          =>$outPrice,
749 757
         ]);
750 758
     }
751 759
 
@@ -756,9 +764,11 @@ class GoodsController extends Controller
756 764
      */
757 765
     public function indexCopyExport(Request $request){
758 766
         //获取请求参数
759
-        $name = $request->input('name');
760
-        $cate_name = trim($request->input('cate_name'));
761
-        $status = $request->input('status');
767
+        $name = trim($request->input('name',''));
768
+        $cate_name = trim($request->input('cate_name',''));
769
+        $status = $request->input('status','-1');
770
+        $realQuantity = $request->input('quantity','-1');
771
+        $outPrice = $request->input('outPrice','-1');
762 772
 
763 773
         //若有请求参数,初步获取查询结果
764 774
         $goodsIds = array();
@@ -773,14 +783,22 @@ class GoodsController extends Controller
773 783
             }
774 784
         }
775 785
 
786
+        //筛选所有可用库存大于0的规格id
787
+        $actualSkuList = array();
788
+        if($realQuantity != '-1'){
789
+            $actualSkuList = GoodsSkus::actualQuantityNotNull();
790
+        }
791
+
776 792
         //进一步获取数据查询结果
777
-        $result = GoodsSkus::where(function($query) use ($goodsIds,$status){
793
+        $result = GoodsSkus::where(function($query) use ($goodsIds,$status,$realQuantity,$outPrice,$actualSkuList){
778 794
             if(count($goodsIds) > 1){
779 795
                 $query->whereIn('goodsCode',$goodsIds);
780 796
             }else if(count($goodsIds) == 1){
781 797
                 $query->where('goodsCode',$goodsIds);
782 798
             }
783 799
             if($status != '-1') $query->where('is_del',$status);
800
+            if($realQuantity != '-1') $query->whereIn('id',$actualSkuList);
801
+            if($outPrice != '-1') $query->where('outPrice','>','0');
784 802
         })->orderBy('id', 'desc')->get();
785 803
         $result = json_decode(json_encode($result),true);
786 804
 

+ 19 - 3
resources/views/goods/indexcopy.blade.php

@@ -24,6 +24,16 @@
24 24
                 <option value="0" @if($status=='0') selected @endif>已上架</option>
25 25
                 <option value="1" @if($status=='1') selected @endif>已下架</option>
26 26
             </select>
27
+            <input class="input-text" style="width:7%;text-align:center" type="text" value="商品可用库存"/>
28
+            <select class="select-box" style="width:7%;text-align:center" name="quantity" id='quantity'>
29
+                <option value="-1" @if($quantity=='-1') selected @endif>选择库存</option>
30
+                <option value="1" @if($quantity=='1') selected @endif>商品可用库存大于0</option>
31
+            </select>
32
+            <input class="input-text" style="width:6%;text-align:center" type="text" value="分销商价格"/>
33
+            <select class="select-box" style="width:7%;text-align:center" name="outPrice" id='outPrice'>
34
+                <option value="-1" @if($outPrice=='-1') selected @endif>选择价格</option>
35
+                <option value="1" @if($outPrice=='1') selected @endif>分销商价格大于0</option>
36
+            </select>
27 37
             <a class="btn btn-primary radius" onclick="user_search()" href="javascript:;">搜索</a>
28 38
             <a class="btn btn-primary radius" onclick="goods_export()" href="javascript:;">导出商品</a>
29 39
         </div>
@@ -90,14 +100,18 @@
90 100
             var name = $('#name').val();
91 101
             var cate_name = $('#cate_name').val();
92 102
             var status = $('#status').val();
93
-            location.href = 'index_copy?page=' + num + '&name=' + name + '&cate_name=' + cate_name + '&status=' + status;
103
+            var quantity = $('#quantity').val();
104
+            var outPrice = $('#outPrice').val();
105
+            location.href = 'index_copy?page=' + num + '&name=' + name + '&cate_name=' + cate_name + '&status=' + status + '&quantity=' + quantity + '&outPrice=' + outPrice;
94 106
         }
95 107
 
96 108
         function goods_export() {
97 109
             var name = $('#name').val();
98 110
             var cate_name = $('#cate_name').val();
99 111
             var status = $('#status').val();
100
-            location.href = 'index_copy_export?name=' + name + '&cate_name=' + cate_name + '&status=' + status;
112
+            var quantity = $('#quantity').val();
113
+            var outPrice = $('#outPrice').val();
114
+            location.href = 'index_copy_export?name=' + name + '&cate_name=' + cate_name + '&status=' + status + '&quantity=' + quantity + '&outPrice=' + outPrice;
101 115
         }
102 116
 
103 117
         $("#page").paging({
@@ -108,7 +122,9 @@
108 122
                 var name = $('#name').val();
109 123
                 var cate_name = $('#cate_name').val();
110 124
                 var status = $('#status').val();
111
-                location.href = 'index_copy?page=' + num + '&name=' + name + '&cate_name=' + cate_name + '&status=' + status;
125
+                var quantity = $('#quantity').val();
126
+                var outPrice = $('#outPrice').val();
127
+                location.href = 'index_copy?page=' + num + '&name=' + name + '&cate_name=' + cate_name + '&status=' + status + '&quantity=' + quantity + '&outPrice=' + outPrice;
112 128
             }
113 129
         })
114 130