From 14f274f174d1138d501ea85d40edb677567b9115 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 4 Sep 2020 16:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/ShoppingCart.php | 5 +++++ app/Service/v3/Implementations/ShopCartService.php | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Model/v3/ShoppingCart.php b/app/Model/v3/ShoppingCart.php index a7dac14..1ae9403 100644 --- a/app/Model/v3/ShoppingCart.php +++ b/app/Model/v3/ShoppingCart.php @@ -9,4 +9,9 @@ use App\Model\Model; class ShoppingCart extends Model { protected $table = 'lanzu_shopping_cart'; + + public function goods() + { + return $this->hasOne(Goods::class, 'id', 'goods_id'); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index 759e496..3f73f81 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -12,7 +12,9 @@ class ShopCartService implements ShopCartServiceInterface public function do() { $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',15)->pluck('store_id')->toArray(); - $res = Store::query()->with('shoppingCart')->whereIn('id',$storeIds) + $res = Store::query()->with(['ShoppingCart' => function($query) { + $query->with('goods'); + }])->whereIn('id',$storeIds) ->get(); return $res; } @@ -25,7 +27,9 @@ class ShopCartService implements ShopCartServiceInterface public function undo() { $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',198)->pluck('store_id')->toArray(); - $res = Store::query()->with('shoppingCart')->whereIn('id',$storeIds) + $res = Store::query()->with(['ShoppingCart' => function($query) { + $query->with('goods'); + }])->whereIn('id',$storeIds) ->get(); return $res; }