Browse Source

购物车 优化

master
Lemon 5 years ago
parent
commit
14f274f174
  1. 5
      app/Model/v3/ShoppingCart.php
  2. 8
      app/Service/v3/Implementations/ShopCartService.php

5
app/Model/v3/ShoppingCart.php

@ -9,4 +9,9 @@ use App\Model\Model;
class ShoppingCart extends Model class ShoppingCart extends Model
{ {
protected $table = 'lanzu_shopping_cart'; protected $table = 'lanzu_shopping_cart';
public function goods()
{
return $this->hasOne(Goods::class, 'id', 'goods_id');
}
} }

8
app/Service/v3/Implementations/ShopCartService.php

@ -12,7 +12,9 @@ class ShopCartService implements ShopCartServiceInterface
public function do() public function do()
{ {
$storeIds = Db::table('lanzu_shopping_cart')->where('user_id',15)->pluck('store_id')->toArray(); $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(); ->get();
return $res; return $res;
} }
@ -25,7 +27,9 @@ class ShopCartService implements ShopCartServiceInterface
public function undo() public function undo()
{ {
$storeIds = Db::table('lanzu_shopping_cart')->where('user_id',198)->pluck('store_id')->toArray(); $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(); ->get();
return $res; return $res;
} }

Loading…
Cancel
Save