Quellcode durchsuchen

add - 分类新增 platform_appid

liugc vor 10 Monaten
Ursprung
Commit
2bc654a34c
2 geänderte Dateien mit 29 neuen und 4 gelöschten Zeilen
  1. 12 3
      app/api/lists/GoodsCategoryLists.php
  2. 17 1
      app/api/logic/GoodsLogic.php

+ 12 - 3
app/api/lists/GoodsCategoryLists.php

@@ -1,6 +1,7 @@
 <?php
 namespace app\api\lists;
 
+use app\api\logic\GoodsLogic;
 use app\common\model\goods_category\GoodsCategory;
 use app\common\lists\ListsSearchInterface;
 
@@ -26,7 +27,15 @@ class GoodsCategoryLists extends BaseApiDataLists implements ListsSearchInterfac
 
         ];
     }
-
+    public function queryWhere()
+    {
+        $where = [];
+        if (isset($this->params['platform_appid']) && !empty($this->params['platform_appid'])) {
+            $ids = GoodsLogic::getPlatformCategoryIds($this->params['platform_appid']);
+            $where[] = ['id','in' ,$ids];
+        }
+        return $where;
+    }
 
     /**
      * @notes 获取列表
@@ -39,7 +48,7 @@ class GoodsCategoryLists extends BaseApiDataLists implements ListsSearchInterfac
      */
     public function lists(): array
     {
-        $lists = GoodsCategory::where($this->searchWhere)->where('status',1)
+        $lists = GoodsCategory::where($this->searchWhere)->where($this->queryWhere())->where('status',1)
             ->field(['id', 'pid' ,'picture', 'name'])
             ->order(['weigh' => 'desc'])
             ->select()
@@ -57,7 +66,7 @@ class GoodsCategoryLists extends BaseApiDataLists implements ListsSearchInterfac
      */
     public function count(): int
     {
-        return GoodsCategory::where($this->searchWhere)->count();
+        return GoodsCategory::where($this->searchWhere)->where($this->queryWhere())->count();
     }
 
 }

+ 17 - 1
app/api/logic/GoodsLogic.php

@@ -221,7 +221,23 @@ class GoodsLogic extends BaseLogic
         return ExternalPlatformGoods::where('external_platform_id',$platform_value)->where('goods_id',$goods_id)->value('service_fee');
     }
 
-
+    public static function getPlatformCategoryIds($platform_appid){
+        try{
+            $platform_value = ExternalPlatform::where('appid',$platform_appid)->value('id');
+            $goods_categorys= Goods::where('platform_value',$platform_value)
+                ->field('goods_category_ids')
+                ->group('goods_category_ids')
+                ->select()->toArray();
+            $res = [];
+            foreach ($goods_categorys as $goods_category) {
+                $res = array_unique(array_merge($res, $goods_category['goods_category_ids']));
+            }
+            return $res;
+        }catch(\Exception $e){
+            self::setError($e->getMessage());
+            return [0];
+        }
+    }
 
 
 }