kphcdr 1 năm trước cách đây
mục cha
commit
cca8be73b2

+ 1 - 1
app/Modules/Mini/Controllers/PageController.php

@@ -32,7 +32,7 @@ class PageController extends BaseController
     {
         return $this->ok([
             "banner" => $this->service->banner(),
-            "categoryTree" => $this->service->categoryTree(),
+            "categoryTree" => $this->service->categoryTree("home"),
             "hot_goods" => $this->service->hotGoods(10),
             "recommend_goods" => $this->service->recommendedGoods(10),
         ]);

+ 7 - 2
app/Modules/Mini/Services/PageService.php

@@ -32,9 +32,14 @@ class PageService extends BaseService
         })->values();
     }
 
-    public function categoryTree()
+    public function categoryTree($source = "")
     {
-        $categoryS = Category::with("childS")->where("parent_id", 0)->where("index_weight", ">", 0)->orderByDesc("category_weight")->get(["id", "name", "thumb", "parent_id", "level", "weight"]);
+        if ($source == "home") {
+            $categoryS = Category::with("childS")->where("parent_id", 0)->where("index_weight", ">", 0)->orderByDesc("category_weight")->get(["id", "name", "thumb", "parent_id", "level", "weight"]);
+        } else {
+            $categoryS = Category::with("childS")->where("parent_id", 0)->where("index_weight", ">", 0)->orderByDesc("index_weight")->get(["id", "name", "thumb", "parent_id", "level", "weight"]);
+        }
+
         return $categoryS->map(function (Category $category) {
             return [
                 "id" => $category->id,