forked from gxwebsoft/mp-10550
```
feat(env): 更新开发环境 API 地址将开发环境的 API_BASE_URL 从本地地址更新为线上测试地址,确保开发时能正确连接后端服务。 feat(shop):优化订单确认页优惠券逻辑与支付信息记录- 增加商品总价计算过程的日志输出,便于排查数值精度问题 - 添加多处优惠券选择和推荐时的详细日志,提升调试能力 - 改进支付前数据记录,包含完整订单和优惠券信息 - 优化手动选择优惠券失败时的错误日志输出 - 调整 View 结构以修复分享按钮在某些情况下的渲染问题 - 微调商品详情页样式,增加左侧间距 refactor(shop): 包装分享按钮以提升结构稳定性在商品详情页中,将分享按钮包裹在 View 标签内,以增强组件结构稳定性和兼容性。 ```
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -273,12 +273,14 @@ const GoodsDetail = () => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<View>
|
||||||
<button
|
<button
|
||||||
className={'flex flex-col justify-center items-center text-gray-500 px-1 gap-1 text-nowrap whitespace-nowrap'}
|
className={'flex flex-col justify-center items-center text-gray-500 px-1 gap-1 text-nowrap whitespace-nowrap'}
|
||||||
open-type="share"><Share
|
open-type="share"><Share
|
||||||
size={20}/>
|
size={20}/>
|
||||||
<span className={'text-xs'}>分享</span>
|
<span className={'text-xs'}>分享</span>
|
||||||
</button>
|
</button>
|
||||||
|
</View>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -73,7 +73,21 @@ const OrderConfirm = () => {
|
|||||||
// 计算商品总价
|
// 计算商品总价
|
||||||
const getGoodsTotal = () => {
|
const getGoodsTotal = () => {
|
||||||
if (!goods) return 0
|
if (!goods) return 0
|
||||||
return parseFloat(goods.price || '0') * quantity
|
const price = parseFloat(goods.price || '0')
|
||||||
|
const total = price * quantity
|
||||||
|
|
||||||
|
// 🔍 详细日志,用于排查数值精度问题
|
||||||
|
console.log('💵 商品总价计算:', {
|
||||||
|
goodsPrice: goods.price,
|
||||||
|
goodsPriceType: typeof goods.price,
|
||||||
|
parsedPrice: price,
|
||||||
|
quantity: quantity,
|
||||||
|
total: total,
|
||||||
|
totalFixed2: total.toFixed(2),
|
||||||
|
totalString: total.toString()
|
||||||
|
})
|
||||||
|
|
||||||
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算优惠券折扣
|
// 计算优惠券折扣
|
||||||
@@ -174,9 +188,45 @@ const OrderConfirm = () => {
|
|||||||
const handleCouponSelect = (coupon: CouponCardProps) => {
|
const handleCouponSelect = (coupon: CouponCardProps) => {
|
||||||
const total = getGoodsTotal()
|
const total = getGoodsTotal()
|
||||||
|
|
||||||
|
// 🔍 详细日志记录,用于排查问题
|
||||||
|
console.log('🎫 手动选择优惠券详细信息:', {
|
||||||
|
coupon: {
|
||||||
|
id: coupon.id,
|
||||||
|
title: coupon.title,
|
||||||
|
type: coupon.type,
|
||||||
|
amount: coupon.amount,
|
||||||
|
minAmount: coupon.minAmount,
|
||||||
|
status: coupon.status
|
||||||
|
},
|
||||||
|
orderInfo: {
|
||||||
|
goodsPrice: goods?.price,
|
||||||
|
quantity: quantity,
|
||||||
|
total: total,
|
||||||
|
totalFixed: total.toFixed(2)
|
||||||
|
},
|
||||||
|
validation: {
|
||||||
|
isUsable: isCouponUsable(coupon, total),
|
||||||
|
discount: calculateCouponDiscount(coupon, total),
|
||||||
|
reason: getCouponUnusableReason(coupon, total)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 检查是否可用
|
// 检查是否可用
|
||||||
if (!isCouponUsable(coupon, total)) {
|
if (!isCouponUsable(coupon, total)) {
|
||||||
const reason = getCouponUnusableReason(coupon, total)
|
const reason = getCouponUnusableReason(coupon, total)
|
||||||
|
|
||||||
|
// 🚨 记录手动选择失败的详细信息
|
||||||
|
console.error('🚨 手动选择优惠券失败:', {
|
||||||
|
reason,
|
||||||
|
coupon,
|
||||||
|
total,
|
||||||
|
minAmount: coupon.minAmount,
|
||||||
|
comparison: {
|
||||||
|
totalVsMinAmount: `${total} < ${coupon.minAmount}`,
|
||||||
|
result: total < (coupon.minAmount || 0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: reason || '优惠券不可用',
|
title: reason || '优惠券不可用',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@@ -225,6 +275,29 @@ const OrderConfirm = () => {
|
|||||||
const bestCoupon = usableCoupons[0] // 已经按优惠金额排序,第一个就是最优的
|
const bestCoupon = usableCoupons[0] // 已经按优惠金额排序,第一个就是最优的
|
||||||
const discount = calculateCouponDiscount(bestCoupon, total)
|
const discount = calculateCouponDiscount(bestCoupon, total)
|
||||||
|
|
||||||
|
// 🔍 详细日志记录自动推荐的信息
|
||||||
|
console.log('🤖 自动推荐优惠券详细信息:', {
|
||||||
|
coupon: {
|
||||||
|
id: bestCoupon.id,
|
||||||
|
title: bestCoupon.title,
|
||||||
|
type: bestCoupon.type,
|
||||||
|
amount: bestCoupon.amount,
|
||||||
|
minAmount: bestCoupon.minAmount,
|
||||||
|
status: bestCoupon.status
|
||||||
|
},
|
||||||
|
orderInfo: {
|
||||||
|
goodsPrice: goods?.price,
|
||||||
|
quantity: quantity,
|
||||||
|
total: total,
|
||||||
|
totalFixed: total.toFixed(2)
|
||||||
|
},
|
||||||
|
validation: {
|
||||||
|
isUsable: isCouponUsable(bestCoupon, total),
|
||||||
|
discount: discount,
|
||||||
|
reason: getCouponUnusableReason(bestCoupon, total)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (discount > 0) {
|
if (discount > 0) {
|
||||||
setSelectedCoupon(bestCoupon)
|
setSelectedCoupon(bestCoupon)
|
||||||
|
|
||||||
@@ -349,23 +422,37 @@ const OrderConfirm = () => {
|
|||||||
comments: goods.name,
|
comments: goods.name,
|
||||||
deliveryType: 0,
|
deliveryType: 0,
|
||||||
buyerRemarks: orderRemark,
|
buyerRemarks: orderRemark,
|
||||||
// 确保couponId是数字类型
|
// 🔧 确保 couponId 是正确的数字类型,且不传递 undefined
|
||||||
couponId: selectedCoupon ? Number(selectedCoupon.id) : undefined
|
couponId: selectedCoupon ? parseInt(String(selectedCoupon.id), 10) : undefined
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 根据支付方式选择支付类型
|
// 根据支付方式选择支付类型
|
||||||
const paymentType = payment.type === 0 ? PaymentType.BALANCE : PaymentType.WECHAT;
|
const paymentType = payment.type === 0 ? PaymentType.BALANCE : PaymentType.WECHAT;
|
||||||
|
|
||||||
console.log('开始支付:', {
|
// 🔍 支付前的详细信息记录
|
||||||
|
console.log('💰 开始支付 - 详细信息:', {
|
||||||
orderData,
|
orderData,
|
||||||
paymentType,
|
paymentType,
|
||||||
selectedCoupon: selectedCoupon ? {
|
selectedCoupon: selectedCoupon ? {
|
||||||
id: selectedCoupon.id,
|
id: selectedCoupon.id,
|
||||||
title: selectedCoupon.title,
|
title: selectedCoupon.title,
|
||||||
|
type: selectedCoupon.type,
|
||||||
|
amount: selectedCoupon.amount,
|
||||||
|
minAmount: selectedCoupon.minAmount,
|
||||||
discount: getCouponDiscount()
|
discount: getCouponDiscount()
|
||||||
} : null,
|
} : null,
|
||||||
|
priceCalculation: {
|
||||||
|
goodsPrice: goods?.price,
|
||||||
|
quantity: quantity,
|
||||||
|
goodsTotal: getGoodsTotal(),
|
||||||
|
couponDiscount: getCouponDiscount(),
|
||||||
finalPrice: getFinalPrice()
|
finalPrice: getFinalPrice()
|
||||||
|
},
|
||||||
|
couponValidation: selectedCoupon ? {
|
||||||
|
isUsable: isCouponUsable(selectedCoupon, getGoodsTotal()),
|
||||||
|
reason: getCouponUnusableReason(selectedCoupon, getGoodsTotal())
|
||||||
|
} : null
|
||||||
});
|
});
|
||||||
|
|
||||||
// 执行支付 - 移除这里的成功提示,让PaymentHandler统一处理
|
// 执行支付 - 移除这里的成功提示,让PaymentHandler统一处理
|
||||||
@@ -527,7 +614,7 @@ const OrderConfirm = () => {
|
|||||||
height: '80px',
|
height: '80px',
|
||||||
}} lazyLoad={false}/>
|
}} lazyLoad={false}/>
|
||||||
</View>
|
</View>
|
||||||
<View className={'flex flex-col w-full'} style={{width: '100%'}}>
|
<View className={'flex flex-col w-full ml-2'} style={{width: '100%'}}>
|
||||||
<Text className={'font-medium w-full'}>{goods.name}</Text>
|
<Text className={'font-medium w-full'}>{goods.name}</Text>
|
||||||
<Text className={'number text-gray-400 text-sm py-2'}>80g/袋</Text>
|
<Text className={'number text-gray-400 text-sm py-2'}>80g/袋</Text>
|
||||||
<View className={'flex justify-between items-center'}>
|
<View className={'flex justify-between items-center'}>
|
||||||
|
|||||||
Reference in New Issue
Block a user