Преглед изворни кода

actionGoodsList 接口更新 -- 支持商品帅选

shizhongqi пре 11 месеци
родитељ
комит
1c16528dfd

+ 24 - 3
app-hd/controllers/CategoryController.php

@@ -120,6 +120,7 @@ class CategoryController extends BaseController
         $get = Yii::$app->request->get();
         $catId = $get['catId'] ?? 0;
         $where = [];
+        $goodsCond = [];
         $where['mainId'] = $this->mainId;
         if (!empty($catId)) {
             $where['cId'] = $catId;
@@ -128,15 +129,35 @@ class CategoryController extends BaseController
         if (is_numeric($flower)) {
             $where['flower'] = $flower;
         }
+        // flowerNum 是针对 xhGoods 表的条件查询
         $flowerNum = $get['flowerNum'] ?? 0;
-        if (!empty($flowerNum)) {
-            $where['flowerNum'] = $flowerNum;
+        if ($flowerNum > 0) {
+            $goodsCond['flowerNum'] = $flowerNum;
         }
+        if (isset($get['lookPrice'])) { // 1:有价格 2:无价格 -- 根据前端的传值
+            $lookPrice = intval($get['lookPrice']);
+            if ($lookPrice == 1) {
+                $goodsCond['priceType'] = 1;
+            }
+            if ($lookPrice == 2) {
+                $goodsCond['priceType'] = 0;
+            }
+        }
+        if (isset($get['lookStock'])) { // 1:有库存 2:无库存 -- 根据前端的传值
+            $lookStock = intval($get['lookStock']);
+            if ($lookStock == 1) {
+                $goodsCond['stock>'] = 0;
+            }
+            if ($lookStock == 2) {
+                $goodsCond['stock'] = 0;
+            }
+        }
+
         $searchText = $get['searchText'] ?? '';
         if (!empty($searchText)) {
             $where['name'] = ['like', $searchText];
         }
-        $data = GoodsCategoryService::getGoodsList($where);
+        $data = GoodsCategoryService::getGoodsList($where, $goodsCond);
         util::success($data);
     }
 

+ 1 - 1
biz-hd/goods/classes/GoodsClass.php

@@ -344,7 +344,7 @@ class GoodsClass extends BaseClass
 
     /**
      * 组装商品基本信息
-     * @param $list goods商品数组
+     * @param $list  "goods商品数组"
      * @param bool $getItem 是否获取"成品的花材"
      * @param array $sortIds 按商品分类的inTurn 进行排序的商品id数组
      * @return mixed

+ 13 - 4
biz-hd/goods/services/GoodsCategoryService.php

@@ -8,11 +8,15 @@ use bizHd\goods\classes\GoodsClass;
 
 class GoodsCategoryService extends BaseService
 {
-    const OFTEN_CLASS_ID = '-2'; //常用分类
     public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
 
-    //查询一个分类下的商品,有分页 ssh 2019.12.2
-    public static function getGoodsList($where)
+    /**
+     * 查询一个分类下的商品,有分页
+     * @param array $where 分类的查询条件
+     * @param array $goodsCondition 商品的查询条件
+     * @return mixed
+     */
+    public static function getGoodsList($where, $goodsCondition = [])
     {
         $where['delStatus'] = 0; // 排除已删除
         $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
@@ -20,8 +24,13 @@ class GoodsCategoryService extends BaseService
         if (empty($list)) {
             return $data;
         }
+
         $ids = array_column($list, 'gId');
-        $goodsList = GoodsClass::getAllByCondition(['id' => ['in', $ids]], null, '*');
+        $goodsWhere = ['id' => ['in', $ids]];
+        if (count($goodsCondition) > 0) {
+            $goodsWhere = array_merge($goodsWhere, $goodsCondition);
+        }
+        $goodsList = GoodsClass::getAllByCondition($goodsWhere, null, '*');
         $data['list'] = GoodsClass::groupGoodsBaseInfo($goodsList, false, $ids);
         return $data;
     }