Просмотр исходного кода

花掌柜首页配置-关联分类要过滤掉禁用、删除的分类

ouyang 2 дней назад
Родитель
Сommit
a868169076

+ 6 - 2
app-hd/controllers/CategoryController.php

@@ -32,11 +32,15 @@ class CategoryController extends BaseController
         util::success(['list' => $list]);
     }
 
-    //分类列表
+    /**
+     * 分类列表
+     * onlyEnabled=1:仅启用且未删除(门店首页配置关联分类等场景)
+     */
     public function actionList()
     {
         $get = Yii::$app->request->get();
-        $list = CategoryService::getCategoryList($this->mainId);
+        $onlyEnabled = isset($get['onlyEnabled']) && (int)$get['onlyEnabled'] === 1;
+        $list = CategoryService::getCategoryList($this->mainId, $onlyEnabled);
         util::success($list);
     }
 

+ 10 - 2
biz-hd/goods/services/CategoryService.php

@@ -12,10 +12,18 @@ class CategoryService extends BaseService
 {
     public static $baseFile = '\bizHd\goods\classes\CategoryClass';
 
-    //取所有的分类 ssh 2019.12.7
-    public static function getCategoryList($mainId)
+    /**
+     * 取分类列表(管理端/配置选类用)
+     * @param int $mainId 商家 mainId
+     * @param bool $onlyEnabled true 时只返回启用且未删除分类(首页配置关联分类等)
+     */
+    public static function getCategoryList($mainId, $onlyEnabled = false)
     {
         $where = ['mainId' => $mainId, 'delStatus' => 0];
+        // 首页轮播/金刚区等选分类:排除禁用(status!=1)
+        if ($onlyEnabled) {
+            $where['status'] = 1;
+        }
         $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
         if (empty($cat)) {
             return $cat;