fix delivery fee
This commit is contained in:
1 parent
88563423fa
commit
be9601ff91
7 files changed
+33
-51
No files matched your search
+3
@@ -16,6 +16,9 @@ public class DeliveryFeeRespVO {
|
|||||||
@Schema(description = "收货地址到门店的距离(千米)")
|
@Schema(description = "收货地址到门店的距离(千米)")
|
||||||
private Double distanceKm;
|
private Double distanceKm;
|
||||||
|
|
||||||
|
@Schema(description = "门店配送范围(千米)")
|
||||||
|
private Integer maxDistanceKm;
|
||||||
|
|
||||||
@Schema(description = "配送费(元),超出配送范围时为 0")
|
@Schema(description = "配送费(元),超出配送范围时为 0")
|
||||||
private BigDecimal deliveryPrice;
|
private BigDecimal deliveryPrice;
|
||||||
|
|
||||||
|
|||||||
+1
@@ -46,6 +46,7 @@ public class AppStoreShopServiceImpl extends ServiceImpl<StoreShopMapper, StoreS
|
|||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
vo.setMaxDistanceKm(shop.getDistance());
|
||||||
double distanceKm = DeliveryCalculator.calcDistanceKm(
|
double distanceKm = DeliveryCalculator.calcDistanceKm(
|
||||||
shop.getLng(), shop.getLat(), String.valueOf(lng), String.valueOf(lat));
|
shop.getLng(), shop.getLat(), String.valueOf(lng), String.valueOf(lat));
|
||||||
BigDecimal price = DeliveryCalculator.calcDeliveryPrice(shop, distanceKm);
|
BigDecimal price = DeliveryCalculator.calcDeliveryPrice(shop, distanceKm);
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ export function addressDelete(data) {
|
|||||||
return api.post(`/address/del/${data.id}`, undefined, { login: true })
|
return api.post(`/address/del/${data.id}`, undefined, { login: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置默认地址
|
|
||||||
export function shopGetDistanceFromLocation(data) {
|
|
||||||
return api.post(`/address/getDistanceFromLocation`, data, { login: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加或修改地址
|
// 添加或修改地址
|
||||||
export function getAddressAddAndEdit(data) {
|
export function getAddressAddAndEdit(data) {
|
||||||
return api.post(`/address/addAndEdit`, data, { login: true })
|
return api.post(`/address/addAndEdit`, data, { login: true })
|
||||||
|
|||||||
@@ -41,14 +41,13 @@ import {
|
|||||||
import { useMainStore } from '@/store/store'
|
import { useMainStore } from '@/store/store'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { onLoad,onShow } from '@dcloudio/uni-app'
|
import { onLoad,onShow } from '@dcloudio/uni-app'
|
||||||
import { formatDateTime,prePage } from '@/utils/util'
|
import { formatDateTime,prePage } from '@/utils/util'
|
||||||
import {
|
import {
|
||||||
addressAll,
|
addressAll,
|
||||||
addressDelete,
|
addressDelete
|
||||||
shopGetDistanceFromLocation
|
} from '@/api/address'
|
||||||
} from '@/api/address'
|
|
||||||
const main = useMainStore()
|
const main = useMainStore()
|
||||||
const { isLogin,addresses,store } = storeToRefs(main)
|
const { isLogin,addresses } = storeToRefs(main)
|
||||||
const title = ref('我的地址')
|
const title = ref('我的地址')
|
||||||
|
|
||||||
const scene = ref('menu')
|
const scene = ref('menu')
|
||||||
@@ -118,36 +117,16 @@ const chooseAddress = async(address) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('scene.value:',scene.value)
|
console.log('scene.value:',scene.value)
|
||||||
|
|
||||||
if (scene.value == 'menu' || scene.value == 'pay') {
|
if (scene.value == 'menu' || scene.value == 'pay') {
|
||||||
let data = await shopGetDistanceFromLocation({
|
main.SET_ADDRESS(address)
|
||||||
lat: address.latitude,
|
main.SET_ORDER_TYPE('takeout')
|
||||||
lng: address.longitude,
|
main.SET_LOCATION({
|
||||||
lat2: main.store.lat,
|
latitude: address.latitude,
|
||||||
lng2: main.store.lng
|
longitude: address.longitude
|
||||||
});
|
});
|
||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
if (scene.value == 'menu') {
|
if (scene.value == 'menu') {
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
url: '/pages/menu/menu'
|
url: '/pages/menu/menu'
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ const { orderType,address, store,location,isLogin,member,mycoupon } = storeToRef
|
|||||||
const active = ref(false)
|
const active = ref(false)
|
||||||
const deliveryFee = ref(0)
|
const deliveryFee = ref(0)
|
||||||
const outOfRange = ref(false)
|
const outOfRange = ref(false)
|
||||||
|
const deliveryDistance = ref(0)
|
||||||
|
const maxDistance = ref(0)
|
||||||
const title = ref('确认订单')
|
const title = ref('确认订单')
|
||||||
const jsStr = ref('')
|
const jsStr = ref('')
|
||||||
const cart = ref([])
|
const cart = ref([])
|
||||||
@@ -165,12 +167,16 @@ watch([address, store, orderType], async () => {
|
|||||||
if (orderType.value !== 'takeout' || !store.value.id) {
|
if (orderType.value !== 'takeout' || !store.value.id) {
|
||||||
deliveryFee.value = 0
|
deliveryFee.value = 0
|
||||||
outOfRange.value = false
|
outOfRange.value = false
|
||||||
|
deliveryDistance.value = 0
|
||||||
|
maxDistance.value = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 未选地址时显示默认配送费
|
// 未选地址时显示默认配送费
|
||||||
if (!address.value || !address.value.longitude) {
|
if (!address.value || !address.value.longitude) {
|
||||||
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
|
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
|
||||||
outOfRange.value = false
|
outOfRange.value = false
|
||||||
|
deliveryDistance.value = 0
|
||||||
|
maxDistance.value = parseFloat(store.value.distance) || 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -181,9 +187,13 @@ watch([address, store, orderType], async () => {
|
|||||||
})
|
})
|
||||||
outOfRange.value = !!res.outOfRange
|
outOfRange.value = !!res.outOfRange
|
||||||
deliveryFee.value = parseFloat(res.deliveryPrice) || 0
|
deliveryFee.value = parseFloat(res.deliveryPrice) || 0
|
||||||
|
deliveryDistance.value = parseFloat(res.distanceKm) || 0
|
||||||
|
maxDistance.value = parseFloat(res.maxDistanceKm) || 0
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
|
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
|
||||||
outOfRange.value = false
|
outOfRange.value = false
|
||||||
|
deliveryDistance.value = 0
|
||||||
|
maxDistance.value = parseFloat(store.value.distance) || 0
|
||||||
}
|
}
|
||||||
}, { immediate: true })
|
}, { immediate: true })
|
||||||
|
|
||||||
@@ -366,7 +376,7 @@ const submit = () => {
|
|||||||
const pay = async() => {
|
const pay = async() => {
|
||||||
// 外卖时校验收货地址是否在配送范围
|
// 外卖时校验收货地址是否在配送范围
|
||||||
if (orderType.value == 'takeout' && outOfRange.value) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let that = this;
|
let that = this;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<uv-swiper class="index-banner__swiper" height="300" imgMode="aspectFill" keyName="image" :list="listAds" indicatorMode="dot" indicatorStyle="bottom"></uv-swiper>
|
<uv-swiper class="index-banner__swiper" height="300" imgMode="aspectFill" keyName="image" :list="listAds" indicatorMode="dot" indicatorStyle="bottom"></uv-swiper>
|
||||||
<view class="index-banner__intro">
|
<view class="index-banner__intro">
|
||||||
<view class="index-banner__greet">您好,{{ isLogin ? member.nickname : '游客' }}</view>
|
<view class="index-banner__greet">您好,{{ isLogin ? member.nickname : '游客' }}</view>
|
||||||
<view class="index-banner__note">java-springboot-意向点餐外卖系统</view>
|
<view class="index-banner__note">意向点餐外卖系统</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="index-content">
|
<view class="index-content">
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ import {
|
|||||||
} from '@/api/market'
|
} from '@/api/market'
|
||||||
const main = useMainStore()
|
const main = useMainStore()
|
||||||
const { orderType,address, store,location,isLogin } = storeToRefs(main)
|
const { orderType,address, store,location,isLogin } = storeToRefs(main)
|
||||||
const title = ref('食刻点单')
|
const title = ref('米糖烘焙')
|
||||||
const text = ref('滚动通知')
|
const text = ref('滚动通知')
|
||||||
const keyword = ref('')
|
const keyword = ref('')
|
||||||
|
|
||||||
@@ -699,12 +699,6 @@ const toPay = () => {
|
|||||||
uToast.value.show({message:'本店不支持外卖',type: 'error'});
|
uToast.value.show({message:'本店不支持外卖',type: 'error'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 判断当前是否在配送范围内(基于用户定位距离粗略判断,最终以下单时收货地址校验为准)
|
|
||||||
if (orderType.value == 'takeout' && store.value.dis && store.value.distance < (store.value.dis / 1000)) {
|
|
||||||
uToast.value.show({message:'选中的地址不在配送范围',type: 'error'});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '加载中'
|
title: '加载中'
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user