Browse Source

完善功能

gorden 9 months ago
parent
commit
c3ef9953fd

+ 14 - 4
app/admin/service/goods/GoodsService.php

@@ -208,6 +208,18 @@ class GoodsService
         $pageSize = $request->get('pageSize');
         $goodsName = $request->get('goods_name', '');
 
+        $categorySuperId = $request->get('category_super_id', '');
+        $categoryIds = $request->get('category_id', []);
+        if (!empty($categorySuperId)) {
+            $category = SysCategory::where('category_id', $categorySuperId)->first();
+            if (empty($category->category_super_path)) {
+                $category->category_super_path = '#' . $categorySuperId . '#';
+            } else {
+                $category->category_super_path = $category->category_super_path . '#' . $categorySuperId . '#';
+            }
+            $categoryIds = SysCategory::where('category_super_path', 'like', '%' . $category->category_super_path)->pluck('category_id');
+        }
+
         $rows = Goods::with([
             'category' => function ($query) {
                 $query->select('category_id', 'category_name');
@@ -224,8 +236,7 @@ class GoodsService
                     $q->where('goods_name', 'like', '%' . $goodsName . '%')
                         ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
                 });
-            })->where('goods_classify', 'GOODS')
-            ->where('goods_category', '生态园')
+            })->whereIn('join_goods_category_id', $categoryIds)
             ->orderBy('goods_addtimes', 'DESC')
             ->forPage($page, $pageSize)
             ->get()
@@ -235,8 +246,7 @@ class GoodsService
                 $q->where('goods_name', 'like', '%' . $goodsName . '%')
                     ->OrWhere('goods_title', 'like', '%' . $goodsName . '%');
             });
-        })->where('goods_classify', 'SERVICE')
-            ->where('goods_category', 'FARM')
+        })->whereIn('join_goods_category_id', $categoryIds)
             ->count();
 
         foreach ($rows as &$row) {

+ 2 - 2
app/admin/service/sys_manage/CategoryService.php

@@ -89,7 +89,7 @@ class CategoryService
             if ($params['category_super_id'] != 0) {
                 // 回填path
                 $categoryPath = self::getCategoryPath($params['category_super_id']);
-                SysCategory::where('category_id', $categoryId)->update(['category_super_path' => $categoryPath . '#' . $categoryId . '#']);
+                SysCategory::where('category_id', $categoryId)->update(['category_super_path' => $categoryPath . '#' . $params['category_super_id'] . '#']);
             }
             // 提交事务
             DB::commit();
@@ -135,7 +135,7 @@ class CategoryService
             ];
             if ($category->category_super_id != $params['category_super_id'] && $params['category_super_id'] != 0) {
                 $data['category_super_id'] = $params['category_super_id'];
-                $data['category_super_path'] = self::getCategoryPath($params['category_super_id']) . '#' . $id . '#';
+                $data['category_super_path'] = self::getCategoryPath($params['category_super_id']) . '#' . $params['category_super_id'] . '#';
             }
             if (!SysCategory::where('category_id', $id)->update($data)) {
                 throw new \Exception('分类修改失败');