问题说明:订单提交计算时返回数据转换有误
修改文件:app/services/order/StoreOrderComputedServices.php
修改方法:computedOrder()
修改最后返回数据
public function computedOrder(int $uid, array $userInfo, array $cartGroup, int $addressId, string $payType, bool $useIntegral = false, int $couponId = 0, int $shippingType = 1, int $store_id = 0, int $is_store_delivery_type = 0)
{
$offlinePayStatus = (int)sys_config('offline_pay_status') ?? 2;
$systemPayType = PayServices::PAY_TYPE;
if ($offlinePayStatus == 2) unset($systemPayType['offline']);
if ($payType && !array_key_exists($payType, $systemPayType)) {
throw new ValidateException('选择支付方式有误');
}
if (!$userInfo) {
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$userInfo = $userServices->getUserCacheInfo($uid);
if (!$userInfo) {
throw new ValidateException('用户不存在!');
}
}
$cartInfo = $cartGroup['cartInfo'];
$priceGroup = $cartGroup['priceGroup'];
$deduction = $cartGroup['deduction'];
$other = $cartGroup['other'];
$promotions = $other['promotions'] ?? [];
$payPrice = (float)$priceGroup['totalPrice'];
$payIntegral = (int)$priceGroup['totalIntegral'] ?? 0;
$couponPrice = (float)$priceGroup['couponPrice'];
$firstOrderPrice = (float)$priceGroup['firstOrderPrice'];
$changePrice = (float)$priceGroup['changePrice'] ?? 0.00;
$servicePrice = (float)$priceGroup['servicePrice'] ?? 0.00;
$addr = $cartGroup['addr'] ?? [];
$postage = $priceGroup;
if (!$addr || $addr['id'] != $addressId) {
/** @var UserAddressServices $addressServices */
$addressServices = app()->make(UserAddressServices::class);
$addr = $addressServices->getAdderssCache($addressId);
//改变地址重新计算邮费
$postage = [];
}
$combinationId = $this->paramData['combinationId'] ?? 0;
$seckillId = $this->paramData['seckill_id'] ?? 0;
$bargainId = $this->paramData['bargainId'] ?? 0;
$newcomerId = $this->paramData['newcomerId'] ?? 0;
$isActivity = $combinationId || $seckillId || $bargainId || $newcomerId;
$type = (int)$deduction['type'] ?? 0;
$results = batch([
'promotions' => function () use ($cartInfo, $type) {
$promotionsPrice = 0;
if ($type == 8) return $promotionsPrice;
foreach ($cartInfo as $key => $cart) {
if (isset($cart['sum_promotions_price']) && isset($cart['price_type']) && $cart['price_type'] == 'promotions') {
$promotionsPrice = bcadd((string)$promotionsPrice, (string)$cart['sum_promotions_price'], 2);
}
}
return $promotionsPrice;
},
'postage' => function () use ($uid, $shippingType, $payType, $cartInfo, $addr, $payPrice, $postage, $other, $type, $store_id, $is_store_delivery_type) {
if ($type == 8 || $type == 10) $shippingType = 2;
return $this->computedPayPostage($uid, $shippingType, $payType, $cartInfo, $addr, $payPrice, $postage, $other, $store_id, $is_store_delivery_type);
}
]);
$promotionsDetail = [];
if ($promotions) {
foreach ($promotions as $key => $value) {
if (isset($value['details']['sum_promotions_price']) && $value['details']['sum_promotions_price']) {
$promotionsDetail[] = ['id' => $value['id'], 'name' => $value['name'], 'title' => $value['title'], 'desc' => $value['desc'], 'promotions_price' => $value['details']['sum_promotions_price'], 'promotions_type' => $value['promotions_type']];
}
}
if ($promotionsDetail) {
$typeArr = array_column($promotionsDetail, 'promotions_type');
array_multisort($typeArr, SORT_ASC, $promotionsDetail);
}
}
// [$p, $couponPrice] = $results['coupon'];
[$p, $payPostage, $storePostageDiscount, $storeFreePostage, $isStoreFreePostage, $poorFreeShipping, $poorDeliveryPrice, $sameCityStoreFreePostage] = $results['postage'];
if ($type == 8) {
$firstOrderPrice = 0;
$payPrice = 0;
}
if ($firstOrderPrice < $payPrice) {//首单优惠金额
$payPrice = bcsub((string)$payPrice, (string)$firstOrderPrice, 2);
} else {
$payPrice = 0;
}
if (sys_config('integral_ratio_status') && !$isActivity) {
//使用积分
[$payPrice, $deductionPrice, $usedIntegral, $SurplusIntegral] = $this->useIntegral($useIntegral, $userInfo, $payPrice, $other);
}
//邮费
$payPrice = (float)bcadd((string)$payPrice, (string)$payPostage, 2);
//服务费
$payPrice = (float)bcadd((string)$payPrice, (string)$servicePrice, 2);
$payPrice = max($payPrice, 0);
$validProductIds = [];
$gainIntegral = 0;
foreach ($cartInfo as &$item) {
$item['invalid'] = false;
if ($shippingType === 2 && isset($item['productInfo']['delivery_type']) && in_array(2, $item['productInfo']['delivery_type'])) {
$item['invalid'] = true;
}
if (isset($cart['cart_type']) && $cart['cart_type'] > 0) {//赠品 卡项关联跳过
continue;
}
//订单商品营销设置:赠送积分
$cartInfoGainIntegral = isset($item['productInfo']['give_integral']) ? bcmul((string)$item['cart_num'], (string)$item['productInfo']['give_integral'], 0) : 0;
$gainIntegral = bcadd((string)$gainIntegral, (string)$cartInfoGainIntegral, 0);
$validProductIds[] = $item['productInfo']['id'] ?? 0;
}
//赠送积分:优惠活动赠送+订单商品营销设置赠送+下单赠送
$order_integral = $this->getGiveIntegral($uid, (string)$payPrice);
$give_integral = (int)$other['give_integral'] + (int)$gainIntegral + (int)$order_integral;
//赠送优惠券:优惠活动赠送+订单商品营销设置赠送
$give_coupon = [];
$giveCouponIds = $other['give_coupon'] ?? [];
/** @var StoreProductCouponServices $storeProductCouponServices */
$storeProductCouponServices = app()->make(StoreProductCouponServices::class);
$giveCouponIds = array_unique(array_merge($giveCouponIds, $storeProductCouponServices->getCouponIdsByProduct($validProductIds)));
if ($giveCouponIds) {
/** @var StoreCouponIssueServices $couponIssueService */
$couponIssueService = app()->make(StoreCouponIssueServices::class);
$give_coupon = $couponIssueService->getColumn([['id', 'IN', $giveCouponIds]], 'id,coupon_title');
}
$result = [
'total_price' => (float)$priceGroup['totalPrice'],
'pay_price' => (float)$payPrice,
'pay_integral' => max($payIntegral, 0),
'total_postage' => (float)bcadd((string)$payPostage, (string)($storePostageDiscount ?? 0), 2),
'pay_postage' => (float)$payPostage,
'first_order_price' => (float)($firstOrderPrice ?? 0),
'coupon_price' => $couponPrice ?? 0,
'promotions_price' => $results['promotions'] ?? 0,
'promotions_detail' => $promotionsDetail,
'deduction_price' => (float)($deductionPrice ?? 0),
'usedIntegral' => $usedIntegral ?? 0,
'SurplusIntegral' => $SurplusIntegral ?? 0,
'storePostageDiscount' => (float)($storePostageDiscount ?? 0),
'isStoreFreePostage' => $isStoreFreePostage ?? false,
'storeFreePostage' => (float)($storeFreePostage ?? 0),
'sameCityStoreFreePostage' => (float)($sameCityStoreFreePostage ?? 0),
'poorFreeShipping' => (float)($poorFreeShipping ?? 0),//差多少包邮
'poorDeliveryPrice' => (float)(in_array($type, [1, 2, 3, 4]) ? 0 : ($poorDeliveryPrice ?? 0)),//差多少起送
'change_price' => $changePrice,
'service_price' => $servicePrice,
'cartInfo' => $cartInfo,
'give_integral' => $give_integral,
'give_coupon' => $give_coupon
];
$this->paramData = [];
return $result;
}
