fix(订单): 详情展示原运费与运费优惠

- 下单时保存 postage_discount,供订单详情还原优惠前快递运费
- 价格信息运费改为快递运费,展示原价并单独展示会员运费优惠
- 自提/上门订单运费优惠清零
This commit is contained in:
吴昊天 2026-10-22 14:19:10 +08:00
parent 581fe81df7
commit 6b1f41dddb
3 changed files with 28 additions and 6 deletions

View File

@ -1403,11 +1403,14 @@ class CenterOrderController
// 自提模式强制运费为 0;上门服务模式运费替换为商品上门费用(同上 computed 方法的处理逻辑)
$finalPayPostage = $computedResult['pay_postage'] ?? 0;
// 会员运费优惠:pay_postage 为优惠后运费,详情页需还原原运费并单独展示优惠
$finalPostageDiscount = (string)($computedResult['storePostageDiscount'] ?? '0.00');
if ($formDeliveryType === 'pickup') {
if ($finalPayPostage > 0) {
$finalPayPrice = bcsub((string)$finalPayPrice, (string)$finalPayPostage, 2);
}
$finalPayPostage = 0;
$finalPostageDiscount = '0.00';
} elseif ($formDeliveryType === 'door') {
// 上门服务:运费 = 商品上门费用(实时从数据库读取,避免缓存快照过期导致金额不一致)
$doorPostage = 0.00;
@ -1429,6 +1432,7 @@ class CenterOrderController
}
$finalPayPrice = bcadd((string)$finalPayPrice, (string)$doorPostage, 2);
$finalPayPostage = $doorPostage;
$finalPostageDiscount = '0.00';
}
// 5. 先写产品类型扩展表,拿到扩展表记录 id 作为中台表的 source_id
@ -1633,7 +1637,8 @@ class CenterOrderController
'delivery' => [
'delivery_type' => $deliveryType,
],
// 金额字段已提升为实体列,extra_info 中不再双写
// 金额字段已提升为实体列;运费优惠需保留供详情页还原原运费
'postage_discount' => $finalPostageDiscount,
'sku_info' => $this->buildSkuInfoForExtra($cartInfo[0] ?? []),
// 商品明细快照,供订单详情/退款页面使用
'items' => $this->buildOrderItemsForExtra($cartInfo),

View File

@ -680,15 +680,29 @@ class OrderCenterServices extends BaseService implements OrderCenterSyncInterfac
'type' => 'subtotal',
];
// 运费(>0 才显示)
// 快递运费:展示优惠前金额(pay_postage 为会员运费优惠后的实付运费)
$postage = (float)($detail['pay_postage'] ?? 0);
if ($postage > 0) {
$extraInfo = $detail['extra_info'] ?? [];
if (!is_array($extraInfo)) {
$extraInfo = [];
}
$postageDiscount = (float)($extraInfo['postage_discount'] ?? 0);
$originalPostage = (float)bcadd((string)$postage, (string)$postageDiscount, 2);
if ($originalPostage > 0) {
$items[] = [
'label' => '运费',
'value' => '+' . number_format($postage, 2, '.', ''),
'label' => '快递运费',
'value' => '+' . number_format($originalPostage, 2, '.', ''),
'type' => 'shipping',
];
}
// 会员运费优惠单独展示,与订单确认页口径一致
if ($postageDiscount > 0) {
$items[] = [
'label' => '会员运费优惠',
'value' => '-' . number_format($postageDiscount, 2, '.', ''),
'type' => 'shipping_discount',
];
}
// 优惠券抵扣
if (!empty($detail['coupon_price']) && (float)$detail['coupon_price'] > 0) {
$items[] = [

View File

@ -177,7 +177,8 @@ class OrderCreateServices extends BaseService
'delivery' => [
'delivery_type' => $shippingType === 2 ? 'pickup' : ($shippingType === 3 ? 'door' : 'express'),
],
// 金额字段已提升为实体列,extra_info 中不再双写
// 金额字段已提升为实体列;运费优惠需保留原始运费与优惠额供订单详情展示
'postage_discount' => (string)($priceData['postage_discount'] ?? '0.00'),
// 商品规格快照,供订单列表/详情页展示
'sku_info' => $this->buildSkuInfo($cartGroup['cartInfo'][0] ?? []),
// v8.1.1 商品级售后:写入 items 快照(含 cart_id),供售后引擎加载商品列表
@ -336,6 +337,8 @@ class OrderCreateServices extends BaseService
'pay_price' => $priceData['pay_price'] ?? 0,
'coupon_price' => $priceData['coupon_price'] ?? 0,
'pay_postage' => $priceData['pay_postage'] ?? 0,
// 会员运费优惠:pay_postage 是优惠后运费,需单独落库供详情页展示原运费与优惠
'postage_discount' => $priceData['storePostageDiscount'] ?? 0,
'deduction_price' => $priceData['deduction_price'] ?? 0,
'usedIntegral' => $priceData['usedIntegral'] ?? 0,
];