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; }