fix(shop-cart): 修复购物车后端查询及前后端字段名对齐问题

- 修复后端ShopCartMapper SQL,关联查询商品和SKU信息,返回完整商品详情字段
- 新增ShopCart实体非持久化字段,映射商品名称、图片、价格、库存等
- 调整后端Controller列表方法,自动过滤当前登录用户购物车数据
- 前端ShopCart接口新增salePrice、dealerPrice字段,CartContext映射新增字段
- 修正购物车数量和选中状态字段名,前端与后端统一使用cartNum和selected
- 统一更新购物车数量、选中状态的接口调用参数,避免因字段不匹配导致更新失败
- 购物车及结算页价格显示逻辑优先使用后端扁平dealerPrice字段,兼容VIP价格显示
- 各购物车相关页面调整添加购物车参数,确保字段名一致和正确传递
This commit is contained in:
2026-07-14 01:14:15 +08:00
parent 711db25093
commit 93a46bdae7
8 changed files with 67 additions and 25 deletions

View File

@@ -182,7 +182,7 @@ const CartPage: React.FC = () => {
)}
<View className="flex justify-between items-center">
<Text className="text-sm font-bold text-red-500">
¥{isVipMember() && (item.product as any)?.dealerPrice ? (item.product as any).dealerPrice : (item.skuPrice || item.sku?.price || item.product?.salePrice || item.product?.price || '0')}
¥{isVipMember() && (item.dealerPrice || (item.product as any)?.dealerPrice) ? (item.dealerPrice || (item.product as any).dealerPrice) : (item.skuPrice || item.sku?.price || item.salePrice || item.product?.salePrice || item.product?.price || '0')}
</Text>
<View className="flex items-center gap-3">
<View className="w-6 h-6 rounded bg-gray-100 flex items-center justify-center" onClick={() => updateQuantity(item.goodsId, item.skuId, item.quantity - 1)}>

View File

@@ -135,7 +135,7 @@ const CategoryPage: React.FC = () => {
if (!requireLogin({ action: 'addToCart' })) return
addToCart({
goodsId: product.goodsId!,
num: product.step || 1,
cartNum: product.step || 1,
}).then(() => {
Taro.showToast({ title: '已加入购物车', icon: 'success' })
}).catch(err => {

View File

@@ -149,9 +149,9 @@ const CheckoutPage: React.FC = () => {
if (!items || items.length === 0) return 0
const vip = isVipMember()
return items.reduce((sum, item) => {
// VIP 会员优先使用 dealerPrice
const dealerPrice = vip ? (item.product as any)?.dealerPrice : null
const unitPrice = dealerPrice || item.skuPrice || item.sku?.price || item.product?.salePrice || item.product?.price || 0
// VIP 会员优先使用 dealerPrice(后端关联字段 > product 嵌套对象)
const dealerPrice = vip ? (item.dealerPrice || (item.product as any)?.dealerPrice) : null
const unitPrice = dealerPrice || item.skuPrice || item.sku?.price || item.salePrice || item.product?.salePrice || item.product?.price || 0
return sum + Number(unitPrice) * (item.quantity || item.num || 1)
}, 0)
}, [buyNowItems, selectedItems])
@@ -368,7 +368,7 @@ const CheckoutPage: React.FC = () => {
<View className='flex justify-between items-center mt-1'>
<Text className='text-xs text-gray-500'>x{item.quantity || item.num || 1}</Text>
<Text className='text-sm font-medium text-gray-800'>
¥{isVipMember() && (item.product as any)?.dealerPrice ? (item.product as any).dealerPrice : (item.skuPrice || item.sku?.salePrice || item.sku?.price || item.product?.salePrice || item.product?.price || '0')}
¥{isVipMember() && (item.dealerPrice || (item.product as any)?.dealerPrice) ? (item.dealerPrice || (item.product as any).dealerPrice) : (item.skuPrice || item.sku?.salePrice || item.sku?.price || item.salePrice || item.product?.salePrice || item.product?.price || '0')}
</Text>
</View>
</View>

View File

@@ -147,7 +147,7 @@ const ShopPage: React.FC = () => {
if (!requireLogin({ action: 'addToCart' })) return
addToCart({
goodsId: product.goodsId!,
num: product.step || 1,
cartNum: product.step || 1,
}).then(() => {
Taro.showToast({ title: '已加入购物车', icon: 'success' })
}).catch(err => {