|
|
|
@ -117,6 +117,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
public function do($marketId, $userId, $userAddrId, $storeList, $totalMoney, $deliveryTimeNote='尽快送达', $serviceMoney=0, $receiveCouponIds=null, $plat=''){ |
|
|
|
|
|
|
|
$redis = ApplicationContext::getContainer()->get(Redis::class); |
|
|
|
$isCacheInventory = false; |
|
|
|
$carts = []; |
|
|
|
Db::beginTransaction(); |
|
|
|
try { |
|
|
|
@ -189,7 +190,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
} |
|
|
|
$check = $this->goodsService->check($goods, $cart->num); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.']'); |
|
|
|
} |
|
|
|
} elseif ($cart->activity_type == 2) { |
|
|
|
$goods = GoodsActivity::query()->lockForUpdate()->with('store')->find($cart->goods_id); |
|
|
|
@ -198,7 +199,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
} |
|
|
|
$check = $this->goodsActivityService->check($goods, $cart->num, $userId); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.']'); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@ -211,6 +212,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
} else { |
|
|
|
$redis->incrBy($inventoryKey, intval($cart->num)); |
|
|
|
} |
|
|
|
$isCacheInventory = true; |
|
|
|
|
|
|
|
// 算金额
|
|
|
|
$goodsAmount = bcmul((string)$goods->price, (string)$cart->num); # 当前商品的金额
|
|
|
|
@ -359,6 +361,8 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
return $this->paymentService->do($globalOrderId, $totalAmount, $userId, config('wechat.notify_url.online')); |
|
|
|
} catch (Exception $e) { |
|
|
|
Db::rollBack(); |
|
|
|
|
|
|
|
if ($isCacheInventory) { |
|
|
|
// 释redis库存
|
|
|
|
foreach ($carts as $k => &$cart) { |
|
|
|
// 拼接activity_type和goods_id
|
|
|
|
@ -370,8 +374,14 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
$redis->decrBy($inventoryKey, intval($cart->num)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => $e->getMessage()]); |
|
|
|
throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL); |
|
|
|
|
|
|
|
$message = ''; |
|
|
|
if ($e instanceof ErrorCodeException) { |
|
|
|
$message = $e->getMessage(); |
|
|
|
} |
|
|
|
throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL, $message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|