From be9601ff91b00fcd891b430e44c3cfa368102926 Mon Sep 17 00:00:00 2001 From: Kroytz Date: Wed, 15 Jul 2026 23:49:28 +0800 Subject: [PATCH] fix delivery fee --- .../app/storeshop/vo/DeliveryFeeRespVO.java | 3 ++ .../storeshop/AppStoreShopServiceImpl.java | 1 + yshop-drink-uniapp-vue3/api/address.js | 5 -- .../components/pages/address/address.vue | 53 ++++++------------- .../pages/components/pages/pay/pay.vue | 12 ++++- yshop-drink-uniapp-vue3/pages/index/index.vue | 2 +- yshop-drink-uniapp-vue3/pages/menu/menu.vue | 8 +-- 7 files changed, 33 insertions(+), 51 deletions(-) diff --git a/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/controller/app/storeshop/vo/DeliveryFeeRespVO.java b/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/controller/app/storeshop/vo/DeliveryFeeRespVO.java index 4e2eb06..9389adf 100644 --- a/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/controller/app/storeshop/vo/DeliveryFeeRespVO.java +++ b/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/controller/app/storeshop/vo/DeliveryFeeRespVO.java @@ -16,6 +16,9 @@ public class DeliveryFeeRespVO { @Schema(description = "收货地址到门店的距离(千米)") private Double distanceKm; + @Schema(description = "门店配送范围(千米)") + private Integer maxDistanceKm; + @Schema(description = "配送费(元),超出配送范围时为 0") private BigDecimal deliveryPrice; diff --git a/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/service/storeshop/AppStoreShopServiceImpl.java b/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/service/storeshop/AppStoreShopServiceImpl.java index 69002f9..c66c2e7 100644 --- a/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/service/storeshop/AppStoreShopServiceImpl.java +++ b/yshop-drink-boot3/yshop-module-mall/yshop-module-store-biz/src/main/java/co/yixiang/yshop/module/store/service/storeshop/AppStoreShopServiceImpl.java @@ -46,6 +46,7 @@ public class AppStoreShopServiceImpl extends ServiceImpl { return; } - console.log('scene.value:',scene.value) - - if (scene.value == 'menu' || scene.value == 'pay') { - let data = await shopGetDistanceFromLocation({ - lat: address.latitude, - lng: address.longitude, - lat2: main.store.lat, - lng2: main.store.lng - }); - if (!data) { - return; - } - - if (parseFloat(data) > store.value.distance) { - uni.showToast({ - title: '不在配送范围!', - icon: 'error' - }) - return; - } - main.SET_ADDRESS(address) - main.SET_ORDER_TYPE('takeout') - main.store.far = data - main.store.far_text = data + 'km' - main.SET_STORE(main.store) - main.SET_LOCATION({ - latitude: address.lat, - longitude: address.lng - }); - + console.log('scene.value:',scene.value) + + if (scene.value == 'menu' || scene.value == 'pay') { + main.SET_ADDRESS(address) + main.SET_ORDER_TYPE('takeout') + main.SET_LOCATION({ + latitude: address.latitude, + longitude: address.longitude + }); + if (scene.value == 'menu') { uni.switchTab({ url: '/pages/menu/menu' diff --git a/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue b/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue index de77452..e4815b2 100644 --- a/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue +++ b/yshop-drink-uniapp-vue3/pages/components/pages/pay/pay.vue @@ -84,6 +84,8 @@ const { orderType,address, store,location,isLogin,member,mycoupon } = storeToRef const active = ref(false) const deliveryFee = ref(0) const outOfRange = ref(false) +const deliveryDistance = ref(0) +const maxDistance = ref(0) const title = ref('确认订单') const jsStr = ref('') const cart = ref([]) @@ -165,12 +167,16 @@ watch([address, store, orderType], async () => { if (orderType.value !== 'takeout' || !store.value.id) { deliveryFee.value = 0 outOfRange.value = false + deliveryDistance.value = 0 + maxDistance.value = 0 return } // 未选地址时显示默认配送费 if (!address.value || !address.value.longitude) { deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0 outOfRange.value = false + deliveryDistance.value = 0 + maxDistance.value = parseFloat(store.value.distance) || 0 return } try { @@ -181,9 +187,13 @@ watch([address, store, orderType], async () => { }) outOfRange.value = !!res.outOfRange deliveryFee.value = parseFloat(res.deliveryPrice) || 0 + deliveryDistance.value = parseFloat(res.distanceKm) || 0 + maxDistance.value = parseFloat(res.maxDistanceKm) || 0 } catch (e) { deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0 outOfRange.value = false + deliveryDistance.value = 0 + maxDistance.value = parseFloat(store.value.distance) || 0 } }, { immediate: true }) @@ -366,7 +376,7 @@ const submit = () => { const pay = async() => { // 外卖时校验收货地址是否在配送范围 if (orderType.value == 'takeout' && outOfRange.value) { - uToast.value.show({message:'当前收货地址不在配送范围内',type: 'error'}); + uToast.value.show({message:`当前地址距门店${deliveryDistance.value}km,配送范围${maxDistance.value}km`,type: 'error'}); return; } let that = this; diff --git a/yshop-drink-uniapp-vue3/pages/index/index.vue b/yshop-drink-uniapp-vue3/pages/index/index.vue index 1286839..6733e9c 100644 --- a/yshop-drink-uniapp-vue3/pages/index/index.vue +++ b/yshop-drink-uniapp-vue3/pages/index/index.vue @@ -25,7 +25,7 @@ 您好,{{ isLogin ? member.nickname : '游客' }} - java-springboot-意向点餐外卖系统 + 意向点餐外卖系统 diff --git a/yshop-drink-uniapp-vue3/pages/menu/menu.vue b/yshop-drink-uniapp-vue3/pages/menu/menu.vue index 5118ce0..39113df 100644 --- a/yshop-drink-uniapp-vue3/pages/menu/menu.vue +++ b/yshop-drink-uniapp-vue3/pages/menu/menu.vue @@ -263,7 +263,7 @@ import { } from '@/api/market' const main = useMainStore() const { orderType,address, store,location,isLogin } = storeToRefs(main) -const title = ref('食刻点单') +const title = ref('米糖烘焙') const text = ref('滚动通知') const keyword = ref('') @@ -699,12 +699,6 @@ const toPay = () => { uToast.value.show({message:'本店不支持外卖',type: 'error'}); return; } - // 判断当前是否在配送范围内(基于用户定位距离粗略判断,最终以下单时收货地址校验为准) - if (orderType.value == 'takeout' && store.value.dis && store.value.distance < (store.value.dis / 1000)) { - uToast.value.show({message:'选中的地址不在配送范围',type: 'error'}); - return; - } - uni.showLoading({ title: '加载中' })