Browse Source

fix:优化商品分类接口

super-yimizi 1 month ago
parent
commit
acd1dd2daf

+ 9 - 4
application/api/controller/Category.php

@@ -4,7 +4,7 @@ namespace app\api\controller;
 
 use app\common\model\Category as CategoryModel;
 use fast\Tree;
-
+use app\common\Enum\StatusEnum;
 /**
  * 商品分类
  */
@@ -20,14 +20,19 @@ class Category extends Base
 
             $list = CategoryModel::relation([
                 'goods' => function ($query) {
-                    $query->field('id,title,image,price,sales,views,description,marketprice,createtime')->limit(10);
+                    $query->field('id,title,sub_title,image,price,sales,views,description,lineation_price,createtime')->limit(10);
                 }
-            ])->where('pid', 0)->where('isnav', 1)->order('weigh desc,id asc')->select();
+            ])->where('pid', 0)
+            ->where('status',StatusEnum::ENABLED)
+            ->order('weigh desc,id asc')->select();
 
         } else //二级分类 //三级分类
         {
             $tree = Tree::instance();
-            $categoryList = CategoryModel::field('id,pid,name,image')->order('weigh desc,id asc')->where('isnav', 1)->select();
+            $categoryList = CategoryModel::field('id,pid,name,image')
+            ->order('weigh desc,id asc')
+            ->where('status',StatusEnum::ENABLED)
+            ->select();
             $tree->init(collection($categoryList)->toArray(), 'pid');
             $list = $tree->getTreeArray(0);
 

+ 3 - 3
application/common/Service/Goods/CategoryService.php

@@ -3,7 +3,7 @@
 namespace app\common\Service\Goods;
 
 use app\common\model\Category;
-
+use app\common\Enum\StatusEnum;
 class CategoryService
 {
     /**
@@ -17,7 +17,7 @@ class CategoryService
         // $cacheName = 'shop-childrens-' . $ids . '-' . $withself;
         // $result = Cache::get($cacheName);
         // if ($result === false) {
-            $categoryList = Category::where('status', 'normal')
+            $categoryList = Category::where('status', StatusEnum::ENABLED)
                 ->order('weigh desc,id desc')
                 ->select();
 
@@ -40,7 +40,7 @@ class CategoryService
      */
     public static function getCategoryByIds($arrCategoryIds = []){
         $categoryList = Category::where('id', 'IN', $arrCategoryIds)
-        ->where('status', 'normal')
+        ->where('status', StatusEnum::ENABLED)
         ->order('weigh desc,id desc')
         ->field('id,name,image,weigh,pid')
         ->select();

+ 3 - 16
application/common/model/Category.php

@@ -22,7 +22,7 @@ class Category extends Model
     protected $updateTime = 'updatetime';
     // 追加属性
     protected $append = [
-        'flag_text',
+    
     ];
 
     protected static $config = [];
@@ -45,10 +45,6 @@ class Category extends Model
         });
     }
 
-    public function setFlagAttr($value, $data)
-    {
-        return is_array($value) ? implode(',', $value) : $value;
-    }
 
     public function getImageAttr($value, $data)
     {
@@ -56,18 +52,9 @@ class Category extends Model
         return cdnurl($value, true);
     }
 
-    public function getFlagList()
-    {
-        return ['hot' => __('Hot'), 'index' => __('Index'), 'recommend' => __('Recommend')];
-    }
+  
+
 
-    public function getFlagTextAttr($value, $data)
-    {
-        $value = $value ?: ($data['flag'] ?? '');
-        $valueArr = explode(',', $value);
-        $list = $this->getFlagList();
-        return implode(',', array_intersect_key($list, array_flip($valueArr)));
-    } 
 
     public static function getIndexCategoryList()
     {