全部
常见问题
产品动态
精选推荐
功能建议

分析中 已回复 待规划 {{opt.name}}
分析中 已回复 待规划
【修复】uniapp前端切换收货地址后立即下单导致订单邮费明细不一致

管理 管理 编辑 删除

行数以当前本地源码为准,不同版本可能有少量偏移。


1. 前端增加订单确认/算价请求状态

文件:crmeb_pro_uniapp/pages/goods/order_confirm/index.vue

方法:data()

行数:784-787

代码:


confirmLoading: false,
computedLoading: false,
confirmRequestId: 0,
computedRequestId: 0,

2. 前端计算价格只接受最后一次请求结果

文件:crmeb_pro_uniapp/pages/goods/order_confirm/index.vue

方法:computedPrice()

行数:1106-1143

代码:


computedPrice: function () {
    let requestId = ++this.computedRequestId;
    this.computedLoading = true;
    let shippingType = this.shippingType;
    postOrderComputed(this.orderKey, {
        addressId: this.addressId,
        useIntegral: this.useIntegral ? 1 : 0,
        useMoney: this.balanceCheck ? 1 : 0,
        couponId: this.couponId,
        shipping_type: parseInt(shippingType) + 1,
        payType: this.payType
    })
        .then((res) => {
            if (requestId !== this.computedRequestId) return;
            let result = res.data.result;
            if (result) {
                this.totalPrice = result.pay_price;
                this.totalIntegral = result.pay_integral;
                this.integral_price = result.deduction_price;
                this.usedMoney = result.usedMoney;
                this.coupon_price = result.coupon_price;
                this.promotions_detail = result.promotions_detail;
                this.integral = this.useIntegral ? result.SurplusIntegral : this.userInfo.integral;
                this.now_money = this.balanceCheck ? result.surplusMoney : this.userInfo.now_money;
                this.$set(this.priceGroup, 'storePostage', shippingType == 1 ? 0 : result.pay_postage);
                this.$set(this.priceGroup, 'storePostageDiscount', result.storePostageDiscount);
            }
        })
        .catch((err) => {
            return this.$util.Tips({
                title: err
            });
        })
        .finally(() => {
            if (requestId === this.computedRequestId) {
                this.computedLoading = false;
            }
        });
},

3. 前端切换地址时去掉旧 orderKey 的重复算价

文件:crmeb_pro_uniapp/pages/goods/order_confirm/index.vue

方法:OnChangeAddress(id, item)

行数:1214-1223

代码:


if (this.shippingType == 0) {
    this.addressId = id;
    this.getaddressInfo();
} else {
    this.system_store = item;
    this.storeId = id;
    this.range = item.range;
}
if (!this.send_gift_type) {
    this.getConfirm();
}

4. 前端确认单只接受最后一次请求并阻止计算中提交

文件:crmeb_pro_uniapp/pages/goods/order_confirm/index.vue

方法:getConfirm(numType)、formVerify()

行数:1241-1388、1566-1572

代码:


getConfirm: function (numType) {
    if (this.send_gift_type == 2) return;
    let that = this;
    let requestId = ++this.confirmRequestId;
    this.confirmLoading = true;
    let shippingType = parseInt(this.shippingType) + 1;
    let addressId = 0,
        storeid;
    if (shippingType == 1) {
        addressId = that.addressId;
        storeid = 0;
    } else {
        addressId = '';
        storeid = that.storeId;
    }
    let senGiftType = that.send_gift_type != 0 ? 1 : 0;
    orderConfirm(that.cartId, that.news, addressId, shippingType, storeid, that.couponId, that.luckRecordId, senGiftType)
        .then((res) => {
            if (requestId !== that.confirmRequestId) return;
            // 中间原有赋值逻辑保持不变
            that.$set(that, 'orderKey', res.data.orderKey);
            that.$set(that, 'priceGroup', res.data.priceGroup);
            that.computedPrice();
        })
        .catch((err) => {
            return this.$util.Tips({ title: err });
        })
        .finally(() => {
            if (requestId === that.confirmRequestId) {
                that.confirmLoading = false;
            }
        });
},

formVerify() {
    let that = this;
    if (that.confirmLoading || that.computedLoading) {
        return that.$util.Tips({
            title: '订单金额计算中,请稍后提交'
        });
    }
    // 后续原有校验逻辑保持不变
}

5. 后端计算订单金额时使用本次地址重新计算后的商品运费明细

文件:crmeb_pro/app/services/order/StoreOrderComputedServices.php

方法:computedOrder(...)

行数:157-179

代码:


// [$p, $couponPrice] = $results['coupon'];
[$p, $payPostage, $storePostageDiscount, $storeFreePostage, $isStoreFreePostage, $computedCartInfo] = $results['postage'];
if ($couponPrice < $payPrice) {//优惠券金额
    $payPrice = bcsub((string)$payPrice, (string)$couponPrice, 2);
} else {
    $payPrice = 0;
}
if ($type == 8) {
    $firstOrderPrice = 0;
    $payPrice = 0;
}
if ($firstOrderPrice < $payPrice) {//首单优惠金额
    $payPrice = bcsub((string)$payPrice, (string)$firstOrderPrice, 2);
} else {
    $payPrice = 0;
}
if ($uid && sys_config('integral_ratio_status') && in_array($type, [0, 6])) {
    //使用积分
    [$payPrice, $deductionPrice, $usedIntegral, $SurplusIntegral] = $this->useIntegral($useIntegral, $userInfo, $payPrice, $other);
}
// 使用本次地址重新计算后的商品运费明细,避免旧订单缓存中的 postage_price 被继续写入订单明细。
$cartInfo = $computedCartInfo ?: $cartInfo;

6. 后端计算邮费时返回最新 cartInfo,并在免邮/无邮费时清空商品邮费

文件:crmeb_pro/app/services/order/StoreOrderComputedServices.php

方法:computedPayPostage(...)

行数:526-577

代码:


public function computedPayPostage(int $uid, int $shipping_type, string $payType, array $cartInfo, array $addr, string $payPrice, array $postage = [], array $other = [], int $isSendGift = 0)
{
    $storePostageDiscount = 0;
    $storeFreePostage = $postage['storeFreePostage'] ?? 0;
    $isStoreFreePostage = false;
    if ($isSendGift == 1) {
        $shipping_type = 0;
        $addr = [];
    }
    if (!$storeFreePostage) {
        $storeFreePostage = floatval(sys_config('store_free_postage')) ?: 0;//满额包邮金额
    }
    if (!$addr && !isset($addr['id']) || !$cartInfo) {
        $payPostage = 0;
    } else {
        //$shipping_type = 1 快递发货 $shipping_type = 2 门店自提
        if ($shipping_type == 2) {
            if (!sys_config('store_func_status', 1) || !sys_config('store_self_mention', 1)) $shipping_type = 1;
        }
        //门店自提 || (线下支付 && 线下支付包邮) 没有邮费支付  ||  节日任务赠送
        $holidayGiftPushServices = app()->make(HolidayGiftPushServices::class);
        $holidayGift = $holidayGiftPushServices->receiveHolidayGift($uid, 1);

        if ($shipping_type === 2 || ($payType == 'offline' && ((isset($other['offlinePostage']) && $other['offlinePostage']) || sys_config('offline_postage')) == 1) || $holidayGift) {
            $payPostage = 0;
        } else {
            if (!$postage || !isset($postage['storePostage']) || !isset($postage['storePostageDiscount'])) {
                $postage = $this->getOrderPriceGroup($uid, $cartInfo, $addr, $storeFreePostage);
            }
            $cartInfo = $postage['cartInfo'] ?? $cartInfo;
            $payPostage = $postage['storePostage'];
            $storePostageDiscount = $postage['storePostageDiscount'];
            /** @var UserServices $userService */
            $userService = app()->make(UserServices::class);
            //享受svip 运费折扣
            if ($userService->checkUserIsSvip($uid)) {
                $payPostage = bcsub((string)$payPostage, (string)$storePostageDiscount, 2);
            } else {
                $storePostageDiscount = 0;
            }
            $isStoreFreePostage = $postage['isStoreFreePostage'] ?? false;

            $payPrice = (float)bcadd((string)$payPrice, (string)$payPostage, 2);
        }
    }
    if ((float)$payPostage <= 0) {
        foreach ($cartInfo as &$item) {
            $item['postage_price'] = 0;
        }
        unset($item);
    }
    return [$payPrice, $payPostage, $storePostageDiscount, $storeFreePostage, $isStoreFreePostage, $cartInfo];
}

7. 后端创建订单时使用重算后的商品明细落库

文件:crmeb_pro/app/services/order/StoreOrderCreateServices.php

方法:createOrder(...)

行数:159-164

代码:

/** @var StoreOrderComputedServices $computedServices */
$computedServices = app()->make(StoreOrderComputedServices::class);
$priceData = $computedServices->computedOrder($uid, $userInfo, $cartGroup, $addressId, $payType, $useIntegral, $couponId, $shippingType, $isSendGift);
// 下单时以本次提交地址重新计算后的商品明细为准,避免旧 orderKey 缓存中的邮费明细落库。
$cartInfo = $priceData['cartInfo'] ?? $cartGroup['cartInfo'];


附件

backend-order-address-postage-fix.zip

附件

frontend-order-address-postage-fix.zip

{{voteData.voteSum}} 人已参与
支持
反对
请登录后查看

liusll 最后编辑于2026-06-15 18:06:18

快捷回复
回复
回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推荐': '推荐'}}
{{item.is_suggest == 1? '取消推荐': '推荐'}} 【已收集】
{{item.floor}}# 沙发 板凳 地板 {{item.floor}}# 【已收集】
{{item.user_info.title || '暂无简介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打赏
已打赏¥{{item.reward_price}}
{{item.like_count}}
分享
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打赏
已打赏¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
收起 展开更多
查看更多
打赏
已打赏¥{{reward_price}}
37
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定
打赏金额
当前余额:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
请输入 0.1-{{reward_max_price}} 范围内的数值
打赏成功
¥{{price}}
完成 确认打赏

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服
CRMEB咨询热线 400-8888-794

扫码领取产品资料

功能清单
思维导图
安装教程
CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服