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

分析中 已回复 待规划 {{opt.name}}
分析中 已回复 待规划
订单提交计算数据有误

管理 管理 编辑 删除

问题说明:订单提交计算时返回数据转换有误

修改文件: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;
    }



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

全 最后编辑于2026-01-23 15:26:55

快捷回复
回复
回复
回复({{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}}
16
{{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客服