From 26c662eeb60805cfab4027651a82da9b813a9a02 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 3 Sep 2020 21:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89=E5=88=86?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/Category.php | 31 +++++++++++++++++++ .../v3/Implementations/CategoryService.php | 8 ++--- 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 app/Model/v3/Category.php diff --git a/app/Model/v3/Category.php b/app/Model/v3/Category.php new file mode 100644 index 0000000..24311b0 --- /dev/null +++ b/app/Model/v3/Category.php @@ -0,0 +1,31 @@ +where(['status' => 1])->orderBy('sort', 'desc'); + }); + } + + public function getGoodsTypesAttribute() + { + return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray(); + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/CategoryService.php b/app/Service/v3/Implementations/CategoryService.php index 4ecae9c..efbd046 100644 --- a/app/Service/v3/Implementations/CategoryService.php +++ b/app/Service/v3/Implementations/CategoryService.php @@ -3,6 +3,7 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\SsdbKeys; +use App\Model\v3\Category; use App\Model\v3\Goods; use App\Model\v3\GoodsType; use App\Model\v3\StoreType; @@ -30,12 +31,7 @@ class CategoryService implements CategoryServiceInterface public function all() { - return StoreType::query() - ->with('goodsTypes') - ->orderBy('sort', 'DESC') - ->orderBy('id', 'DESC') - ->get() - ->toArray(); + return Category::query()->where(['parent_id' => 0])->get()->toArray(); } public function allForStore($storeId)