Browse Source

下单清购物车

master
weigang 5 years ago
parent
commit
16d953632b
  1. 4
      app/Service/v3/Implementations/OrderOnlineService.php
  2. 13
      app/Service/v3/Implementations/ShopCartUpdateService.php
  3. 2
      app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php

4
app/Service/v3/Implementations/OrderOnlineService.php

@ -179,6 +179,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
$dataOrderGoods = []; # 订单商品
$storeTypeIds = []; # 订单中的商户类型,用于校验红包
$activityGoodsIds = []; # 活动商品IDs
$shopcartIds = [];
foreach ($storeList as $key => &$storeItem) {
@ -199,6 +200,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
// 用户购物车数据
$cartIds = explode(',', $storeItem->cart_ids);
$shopcartIds = array_merge($shopcartIds, $cartIds);
$carts = ShoppingCart::query()->whereIn('id', $cartIds)->where(['market_id' => $marketId, 'user_id' => $userId])->get();
foreach ($carts as $k => &$cart) {
// 查个商品,做商品有效的判断检查
@ -393,7 +395,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
}
// 清除购物车
$this->shopCartUpdateService->doClear($userId, $marketId);
$this->shopCartUpdateService->doClear($userId, $marketId, $shopcartIds);
// 记录badge
$this->badgeService->doByOrder($userId, array_values(array_column($dataChildren, 'store_id')), $orderMain->global_order_id, OrderState::UNPAID);

13
app/Service/v3/Implementations/ShopCartUpdateService.php

@ -105,13 +105,18 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface
* 清空购物车
* @param $userId
* @param $marketId
* @param array $shopcartIds
* @return int|mixed
*/
public function doClear($userId, $marketId)
public function doClear($userId, $marketId, $shopcartIds = [])
{
return ShoppingCart::query()->where([
$builder = ShoppingCart::query()->where([
['user_id','=',$userId],
['market_id','=',$marketId],
])
->delete();
]);
if (!empty($shopcartIds)) {
$builder = $builder->whereIn('id', $shopcartIds);
}
return $builder->delete();
}
}

2
app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php

@ -10,5 +10,5 @@ interface ShopCartUpdateServiceInterface
public function undo($shopcartIds);
public function doClear($userId, $marketId);
public function doClear($userId, $marketId, $shopcartIds = []);
}
Loading…
Cancel
Save