diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 9c74126..14f22b3 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -183,7 +183,7 @@ class OrderOnlineController extends BaseController json_decode($params['store_list']), $params['total_money'], $params['delivery_time_note'], - ($params['service_money'] ?: 0), + ($params['service_money'] ?? 0), $couponIds, $params['plat'] ?: '' ); diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index a2824dd..babe919 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -121,6 +121,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface Db::beginTransaction(); try { + // 获取分布式全局ID + $generator = ApplicationContext::getContainer()->get(IdGeneratorInterface::class); + $globalOrderId = $generator->generate(); + $mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable(); $childTable = ApplicationContext::getContainer()->get(Order::class)->getTable(); @@ -240,15 +244,16 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 计算红包折扣金额 foreach ($canRealUseCoupons as $key => &$coupon) { - if (!in_array($coupon['id'], $receiveCouponIds)) { - unset($coupon); + + if (!in_array($coupon->id, $receiveCouponIds)) { + unset($canRealUseCoupons[$key]); continue; } - if ($coupon['coupon']['discount_type'] == Coupon::DISCOUNT_TYPE_CASH) { - $couponMoney = bcadd($couponMoney, $coupon['coupon']['discounts'], 2); - } elseif ($coupon['coupon']['discount_type'] == Coupon::DISCOUNT_TYPE_RATE) { - $discountRate = bcdiv($coupon['coupon']['discounts'],10); + if ($coupon->coupon->discount_type == Coupon::DISCOUNT_TYPE_CASH) { + $couponMoney = bcadd($couponMoney, $coupon->coupon->discounts, 2); + } elseif ($coupon->coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) { + $discountRate = bcdiv($coupon->coupon->discounts,10); $discountRate = bcsub(1,$discountRate); $discountMoney = bcmul($orderAmount, $discountRate); $couponMoney = bcadd($couponMoney, $discountMoney, 2); @@ -257,10 +262,6 @@ class OrderOnlineService implements OrderOnlineServiceInterface } - // 获取分布式全局ID - $generator = ApplicationContext::getContainer()->get(IdGeneratorInterface::class); - $globalOrderId = $generator->generate(); - $orderAmount = bcadd((string)$orderAmount, '0', 2); $totalAmount = bcadd((string)$totalAmount, (string)$orderAmount); $totalAmount = bcadd((string)$totalAmount, (string)$deliveryAmount); @@ -333,11 +334,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface } } - // 优惠券红包使用记录 - $this->couponService->orderUseCoupons($globalOrderId, $canRealUseCoupons); - Db::commit(); + if (!empty($receiveCouponIds)) { + $this->couponService->orderUseCoupons($globalOrderId, $canRealUseCoupons); + } + // 清除购物车 $this->shopCartUpdateService->doClear($userId, $marketId); diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index 0851fe2..eef1807 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -88,7 +88,7 @@ class UserAddressService implements UserAddressServiceInterface if(empty($address['address']->lng) || empty($address['address']->lat) || empty($market->lng) || empty($market->lat)){ throw new ErrorCodeException(ErrorCode::LOCATION_USER_ADDRESS); } - var_dump($address->lng,$market); + $distance = $this->locationService->getDistanceByTencent($address['address']->lng,$address['address']->lat,$market->lng,$market->lat); $distributionPrice = $this->distributionPriceService->do($distance); $res['address'] = $address;