kphcdr hace 1 año
padre
commit
baf0c4db96

+ 5 - 40
app/Modules/Mini/Controllers/PageController.php

@@ -20,29 +20,11 @@ class PageController extends BaseController
 
 
     public function filterConfig()
     public function filterConfig()
     {
     {
+        $params = $this->valid([
+            "type" => "required",
+        ]);
         return $this->ok([
         return $this->ok([
-            [
-                "id" => 1,
-                "name" => "类目示例",
-                "type" => "category",
-                "child" => [
-                    [
-                        "id" => 1,
-                        "name" => "名称",
-                    ],
-                ],
-            ],
-            [
-                "id" => 1,
-                "name" => "属性示例",
-                "type" => "attr",
-                "child" => [
-                    [
-                        "id" => 1,
-                        "name" => "名称",
-                    ],
-                ],
-            ],
+            "list" => $this->service->filterConfig($params),
         ]);
         ]);
     }
     }
 
 
@@ -81,24 +63,7 @@ class PageController extends BaseController
             "keyword" => "",
             "keyword" => "",
             "attrs" => "",
             "attrs" => "",
         ]);
         ]);
+
         return $this->ok($this->service->search($params));
         return $this->ok($this->service->search($params));
-        return $this->ok([
-            "total" => 1,
-            "page_total" => 1,
-            "list" => [
-                [
-                    "id" => 1,
-                    "name" => "商品名称",
-                    "thumb" => Image::imageUrl(),
-                ],
-            ],
-            "category" => [
-                [
-                    "id" => 1,
-                    "thumb" => Image::imageUrl(),
-                    "name" => "分类名称",
-                ],
-            ],
-        ]);
     }
     }
 }
 }

+ 21 - 0
app/Modules/Mini/Services/PageService.php

@@ -6,6 +6,8 @@ use App\Base\BaseService;
 use App\Models\Goods\Category;
 use App\Models\Goods\Category;
 use App\Models\Goods\Goods;
 use App\Models\Goods\Goods;
 use App\Models\Goods\GoodsCategoryMap;
 use App\Models\Goods\GoodsCategoryMap;
+use App\Models\Goods\Spec;
+use App\Models\Goods\SpecAttr;
 use App\Models\Setting;
 use App\Models\Setting;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Arr;
@@ -94,6 +96,25 @@ class PageService extends BaseService
         return array_merge($cids, $cidss, [$id]);
         return array_merge($cids, $cidss, [$id]);
     }
     }
 
 
+    public function filterConfig($params)
+    {
+        $spec = Spec::whereIsCustom(0)->get();
+
+        return $spec->map(function (Spec $model) {
+            return [
+                "id" => $model->id,
+                "name" => $model->name,
+                "type" => "attr",
+                "child" => $model->attrs->map(function (SpecAttr $attr) {
+                    return [
+                        "id" => $attr->id,
+                        "name" => $attr->name,
+                    ];
+                }),
+            ];
+        });
+    }
+
     public function categoryGoods($params)
     public function categoryGoods($params)
     {
     {
         $id = $params['id'];
         $id = $params['id'];