Browse Source

专题管理

gorden 9 months ago
parent
commit
8717df0cf0
1 changed files with 7 additions and 7 deletions
  1. 7 7
      app/admin/service/goods/GoodsService.php

+ 7 - 7
app/admin/service/goods/GoodsService.php

@@ -100,6 +100,11 @@ class GoodsService
         $pageSize = $request->get('pageSize');
         $goodsName = $request->get('goods_name', '');
         $categoryId = $request->get('join_goods_category_id', null);
+        if ($categoryId == null) {
+            $categoryId = [65, 43];
+        } elseif (is_string($categoryId)) {
+            $categoryId = [$categoryId];
+        }
 
         $rows = Goods::with([
             'category' => function ($query) {
@@ -117,10 +122,7 @@ class GoodsService
                     $q->where('goods_name', 'like', '%' . $goodsName . '%')
                         ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
                 });
-            })->when($categoryId != null, function ($query) use ($categoryId) {
-                $query->where('join_goods_category_id', $categoryId);
-            })
-            ->whereIn('join_goods_category_id', [65, 43])
+            })->whereIn('join_goods_category_id', $categoryId)
             ->orderBy('goods_addtimes', 'DESC')
             ->forPage($page, $pageSize)
             ->get()
@@ -130,9 +132,7 @@ class GoodsService
                 $q->where('goods_name', 'like', '%' . $goodsName . '%')
                     ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
             });
-        })->when($categoryId != null, function ($query) use ($categoryId) {
-            $query->where('join_goods_category_id', $categoryId);
-        })->whereIn('join_goods_category_id', [65, 43])->count();
+        })->whereIn('join_goods_category_id', $categoryId)->count();
 
         foreach ($rows as &$row) {
             $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];