shish il y a 11 mois
Parent
commit
9080e1f4f2

+ 1 - 32
app-hd/controllers/CategoryController.php

@@ -131,40 +131,9 @@ class CategoryController extends BaseController
     public function actionGoodsList()
     {
         $get = Yii::$app->request->get();
-        $catId = $get['catId'] ?? 0;
-        $requestType = $get['requestType'] ?? '';
-        if (empty($requestType)) {
-            util::fail('未知请求');
-        }
-        $where = [];
-        $where['mainId'] = $this->mainId;
-        $where['delStatus'] = 0;
-        $searchText = $get['searchText'] ?? '';
-        $where['name'] = $searchText;
-        if (!empty($catId)) {
-            $where['cId'] = $catId;
-        }
-        if ($requestType == 'kd') {
-            //花束开单列表
-            $where['stock>'] = 0;
-        } elseif ($requestType == 'goodsList') {
-            //花束列表
-            if (isset($get['priceStatus'])) {
-                $where['priceStatus'] = $get['priceStatus'];
-            }
-            if (isset($get['stockStatus'])) {
-                $where['stockStatus'] = $get['stockStatus'];
-            }
-            $flowerNum = $get['flowerNum'] ?? 0;
-            if ($flowerNum > 0) {
-                $where['flowerNum'] = $flowerNum;
-            }
-        } else {
-            util::fail('未知请求类型');
-        }
         $shop = $this->shop;
         $custom = $this->custom;
-        $data = GoodsCategoryClass::getGoodsList($where, $shop, $custom);
+        $data = GoodsCategoryClass::getGoodsList($get, $shop, $custom);
         util::success($data);
     }
 

+ 1 - 13
app-mall/controllers/CategoryController.php

@@ -51,22 +51,10 @@ class CategoryController extends BaseController
         if (empty($user)) {
             util::success(['list' => []]);
         }
-
-        $where = [];
         $get = Yii::$app->request->get();
-        $categoryId = isset($get['categoryId']) ? intval($get['categoryId']) : 0;
-        if ($categoryId != 0) {
-            $where['cId'] = $categoryId;
-        }
-        $where['mainId'] = $this->mainId;
-        $where['delStatus'] = 0;//只获取非删除状态
-        $where['status'] = 1;//上下架状态为1(正常)
-        $searchText = $get['searchText'] ?? '';
-        $where['name'] = $searchText;
         $shop = $this->shop;
         $custom = $this->custom;
-        $params = [];
-        $data = GoodsCategoryClass::getGoodsList($where, $shop, $custom, $params);
+        $data = GoodsCategoryClass::getGoodsList($get, $shop, $custom);
         util::success($data);
     }
 

+ 63 - 32
biz-hd/goods/classes/GoodsCategoryClass.php

@@ -4,6 +4,7 @@ namespace bizHd\goods\classes;
 
 use bizHd\goods\models\GoodsCategory;
 use common\components\business;
+use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
@@ -13,55 +14,85 @@ class GoodsCategoryClass extends BaseClass
     public static $baseFile = '\bizHd\goods\models\GoodsCategory';
 
     //$params 必须预留字段,为后面做准备
-    public static function getGoodsList($where, $shop, $custom, $params = [])
+    public static function getGoodsList($askInfo, $shop, $custom, $params = [])
     {
-        // 获取分页参数
-        $get = Yii::$app->request->get();
-        $page = $get['page'] ?? 1;
-        $pageSize = $get['pageSize'] ?? 20;
+        $requestType = $askInfo['requestType'] ?? '';
+        $page = $askInfo['page'] ?? 1;
+        $pageSize = $askInfo['pageSize'] ?? 20;
+        if (empty($requestType)) {
+            util::fail('没有请求类型');
+        }
 
-        //目前只有商品名称、商品的分类和商品的排序,在xhGoodsCategory里冗余,并且商品的排序只在xhGoodsCategory有
+        /** GoodsCategory 版块查询 **/
         $mainId = $shop->mainId;
-        // 查询某分类下有库存的商品
         $query = GoodsCategory::find();
         $query->where(['xhGoodsCategory.mainId' => $mainId]);
-        if (!empty($where['cId'])) {
-            $query->andWhere(['xhGoodsCategory.cId' => $where['cId']]);
+        if (!empty($askInfo['cId']) || !empty($askInfo['categoryId'])) {
+            $cId = $askInfo['cId'] ?? 0;
+            if (empty($cId)) {
+                $cId = $askInfo['categoryId'] ?? 0;
+            }
+            $query->andWhere(['xhGoodsCategory.cId' => $cId]);
         }
-        if (!empty($where['name'])) {
-            $query->andWhere(['like', 'xhGoodsCategory.name', $where['name']]);
+        if (!empty($askInfo['searchText'])) {
+            $query->andWhere(['like', 'xhGoodsCategory.name', $askInfo['searchText']]);
         }
 
-        $flowerNum = $params['flowerNum'] ?? -1;
-        $priceStatus = $where['priceStatus'] ?? -1;
-        $stockStatus = $where['stockStatus'] ?? -1;
-        $requestType = $get['requestType'] ?? '';
+        $query->joinWith(['goods' => function ($query) use ($askInfo,$requestType) {
 
-        $query->joinWith(['goods' => function ($query) use ($flowerNum, $priceStatus, $stockStatus, $requestType) {
             if ($requestType == 'kd') {
+                //花束开单
+                $query->andWhere(['xhGoods.delStatus' => 0]);
                 $query->andWhere(['>', 'xhGoods.stock', 0]);
-            }
-            if ($stockStatus == 1) {
-                $query->andWhere(['>', 'xhGoods.stock', 0]);
-            }
-            if ($stockStatus == 2) {
-                $query->andWhere(['xhGoods.stock' => 0]);
-            }
-            if ($priceStatus == 1) {
-                $query->andWhere(['xhGoods.priceType' => 1]);
-            }
-            if ($priceStatus == 2) {
+            } elseif ($requestType == 'goodsList') {
+                //花束管理列表
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+
+                $priceStatus = $askInfo['priceStatus'] ?? -1;
+                if ($priceStatus > -1) {
+                    //1 有价格,2 无价格
+                    if ($priceStatus == 1) {
+                        $query->andWhere(['xhGoods.priceType' => 1]);
+                    }
+                    if ($priceStatus == 2) {
+                        $query->andWhere(['xhGoods.priceType' => 0]);
+                    }
+                }
+
+                $stockStatus = $askInfo['stockStatus'] ?? -1;
+                if ($stockStatus > -1) {
+                    //1 有库存,2 无库存
+                    if ($stockStatus == 1) {
+                        $query->andWhere(['>', 'xhGoods.stock', 0]);
+                    }
+                    if ($stockStatus == 2) {
+                        $query->andWhere(['xhGoods.stock' => 0]);
+                    }
+                }
+
+                $flowerNum = $askInfo['flowerNum'] ?? 0;
+                if ($flowerNum > 0) {
+                    $query->andWhere(['xhGoods.flowerNum' => $flowerNum]);
+                }
+            } elseif ($requestType == 'mall') {
+                //花束商城
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+                $query->andWhere(['xhGoods.status' => 1]);
+                $query->andWhere(['xhGoods.priceType' => 0]);
+            } elseif ($requestType == 'album') {
+                //图集
+                $query->andWhere(['xhGoods.delStatus' => 0]);
+                $query->andWhere(['xhGoods.status' => 1]);
                 $query->andWhere(['xhGoods.priceType' => 0]);
             }
-            if ($flowerNum > 0) {
-                $query->andWhere(['xhGoods.flowerNum' => $flowerNum]);
-            }
+
         }]);
-        $query->orderBy(['inTurn' => SORT_DESC]);
 
+
+
+        $query->orderBy(['inTurn' => SORT_DESC]);
         // 获取总数
         $total = $query->count();
-
         // 分页查询
         $goodsCategoryInfoList = $query->offset(($page - 1) * $pageSize)
             ->limit($pageSize)