```
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 = {
|
||||
// 开发环境
|
||||
development: {
|
||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
||||
APP_NAME: '开发环境',
|
||||
DEBUG: 'true',
|
||||
},
|
||||
|
||||
@@ -273,12 +273,14 @@ const GoodsDetail = () => {
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
className={'flex flex-col justify-center items-center text-gray-500 px-1 gap-1 text-nowrap whitespace-nowrap'}
|
||||
open-type="share"><Share
|
||||
size={20}/>
|
||||
<span className={'text-xs'}>分享</span>
|
||||
</button>
|
||||
<View>
|
||||
<button
|
||||
className={'flex flex-col justify-center items-center text-gray-500 px-1 gap-1 text-nowrap whitespace-nowrap'}
|
||||
open-type="share"><Share
|
||||
size={20}/>
|
||||
<span className={'text-xs'}>分享</span>
|
||||
</button>
|
||||
</View>
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
|
||||
@@ -73,7 +73,21 @@ const OrderConfirm = () => {
|
||||
// 计算商品总价
|
||||
const getGoodsTotal = () => {
|
||||
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
|
||||
}
|
||||
|
||||
// 计算优惠券折扣
|
||||
@@ -116,12 +130,12 @@ const OrderConfirm = () => {
|
||||
title: '当前优惠券不满足使用条件,已自动取消',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
|
||||
// 🎯 自动推荐新的最优优惠券
|
||||
if (usableCoupons.length > 0) {
|
||||
const bestCoupon = usableCoupons[0]
|
||||
const discount = calculateCouponDiscount(bestCoupon, newTotal)
|
||||
|
||||
|
||||
if (discount > 0) {
|
||||
setSelectedCoupon(bestCoupon)
|
||||
Taro.showToast({
|
||||
@@ -135,7 +149,7 @@ const OrderConfirm = () => {
|
||||
// 🔔 如果没有选中优惠券但有可用的,推荐最优的
|
||||
const bestCoupon = usableCoupons[0]
|
||||
const discount = calculateCouponDiscount(bestCoupon, newTotal)
|
||||
|
||||
|
||||
if (discount > 0) {
|
||||
setSelectedCoupon(bestCoupon)
|
||||
Taro.showToast({
|
||||
@@ -149,7 +163,7 @@ const OrderConfirm = () => {
|
||||
const bestCoupon = usableCoupons[0]
|
||||
const currentDiscount = calculateCouponDiscount(selectedCoupon, newTotal)
|
||||
const bestDiscount = calculateCouponDiscount(bestCoupon, newTotal)
|
||||
|
||||
|
||||
// 如果有更好的优惠券(优惠超过0.01元)
|
||||
if (bestDiscount > currentDiscount + 0.01 && bestCoupon.id !== selectedCoupon.id) {
|
||||
Taro.showModal({
|
||||
@@ -174,9 +188,45 @@ const OrderConfirm = () => {
|
||||
const handleCouponSelect = (coupon: CouponCardProps) => {
|
||||
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)) {
|
||||
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({
|
||||
title: reason || '优惠券不可用',
|
||||
icon: 'none'
|
||||
@@ -224,10 +274,33 @@ const OrderConfirm = () => {
|
||||
if (usableCoupons.length > 0 && !selectedCoupon) {
|
||||
const bestCoupon = usableCoupons[0] // 已经按优惠金额排序,第一个就是最优的
|
||||
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) {
|
||||
setSelectedCoupon(bestCoupon)
|
||||
|
||||
|
||||
// 显示智能推荐提示
|
||||
Taro.showToast({
|
||||
title: `已为您推荐最优优惠券,可省¥${discount.toFixed(2)}`,
|
||||
@@ -236,7 +309,7 @@ const OrderConfirm = () => {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 🔔 优惠券提示:如果有可用优惠券,显示提示
|
||||
if (usableCoupons.length > 0) {
|
||||
console.log(`发现${usableCoupons.length}张可用优惠券,已为您推荐最优惠券`)
|
||||
@@ -313,11 +386,11 @@ const OrderConfirm = () => {
|
||||
// 🔔 支付前最后一次检查:提醒用户是否有可用优惠券
|
||||
const total = getGoodsTotal()
|
||||
const usableCoupons = filterUsableCoupons(availableCoupons, total)
|
||||
|
||||
|
||||
if (usableCoupons.length > 0) {
|
||||
const bestCoupon = usableCoupons[0]
|
||||
const discount = calculateCouponDiscount(bestCoupon, total)
|
||||
|
||||
|
||||
if (discount > 0) {
|
||||
// 用模态框提醒用户
|
||||
const confirmResult = await new Promise<boolean>((resolve) => {
|
||||
@@ -328,7 +401,7 @@ const OrderConfirm = () => {
|
||||
fail: () => resolve(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
if (confirmResult) {
|
||||
setSelectedCoupon(bestCoupon)
|
||||
// 使用优惠券后重新计算价格,然后继续支付
|
||||
@@ -349,23 +422,37 @@ const OrderConfirm = () => {
|
||||
comments: goods.name,
|
||||
deliveryType: 0,
|
||||
buyerRemarks: orderRemark,
|
||||
// 确保couponId是数字类型
|
||||
couponId: selectedCoupon ? Number(selectedCoupon.id) : undefined
|
||||
// 🔧 确保 couponId 是正确的数字类型,且不传递 undefined
|
||||
couponId: selectedCoupon ? parseInt(String(selectedCoupon.id), 10) : undefined
|
||||
}
|
||||
);
|
||||
|
||||
// 根据支付方式选择支付类型
|
||||
const paymentType = payment.type === 0 ? PaymentType.BALANCE : PaymentType.WECHAT;
|
||||
|
||||
console.log('开始支付:', {
|
||||
// 🔍 支付前的详细信息记录
|
||||
console.log('💰 开始支付 - 详细信息:', {
|
||||
orderData,
|
||||
paymentType,
|
||||
selectedCoupon: selectedCoupon ? {
|
||||
id: selectedCoupon.id,
|
||||
title: selectedCoupon.title,
|
||||
type: selectedCoupon.type,
|
||||
amount: selectedCoupon.amount,
|
||||
minAmount: selectedCoupon.minAmount,
|
||||
discount: getCouponDiscount()
|
||||
} : null,
|
||||
finalPrice: getFinalPrice()
|
||||
priceCalculation: {
|
||||
goodsPrice: goods?.price,
|
||||
quantity: quantity,
|
||||
goodsTotal: getGoodsTotal(),
|
||||
couponDiscount: getCouponDiscount(),
|
||||
finalPrice: getFinalPrice()
|
||||
},
|
||||
couponValidation: selectedCoupon ? {
|
||||
isUsable: isCouponUsable(selectedCoupon, getGoodsTotal()),
|
||||
reason: getCouponUnusableReason(selectedCoupon, getGoodsTotal())
|
||||
} : null
|
||||
});
|
||||
|
||||
// 执行支付 - 移除这里的成功提示,让PaymentHandler统一处理
|
||||
@@ -527,7 +614,7 @@ const OrderConfirm = () => {
|
||||
height: '80px',
|
||||
}} lazyLoad={false}/>
|
||||
</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={'number text-gray-400 text-sm py-2'}>80g/袋</Text>
|
||||
<View className={'flex justify-between items-center'}>
|
||||
|
||||
Reference in New Issue
Block a user