修复限时折扣问题

This commit is contained in:
2025-12-16 13:26:02 +08:00
parent aa41ecbc52
commit 90e75d0f7e
3 changed files with 149 additions and 51 deletions

View File

@@ -557,7 +557,7 @@
<script setup>
import xbSwiperPreview from '@/components/xb-swiper-preview/index.vue';
//价格计算辅助函数
import {
limitUtils
} from 'ysk-utils';
@@ -604,9 +604,9 @@
import Loading from '@/components/Loading.vue';
import dayjs from 'dayjs';
import isBetween from 'dayjs/plugin/isBetween';
import {
APIshopUserInfo
APIshopUserInfo,APIusershopInfodetail
} from "@/common/api/member.js";
dayjs.extend(isBetween);
import {
@@ -619,9 +619,12 @@
import {
getDistance
} from '@/utils/address.js';
import {isObjectEqual,isArrayEqual} from './components/utils.js'
import {
isObjectEqual,
isArrayEqual
} from './components/utils.js'
//点单智能推荐
function onBuyClick(item) {
let index = -1;
@@ -1078,9 +1081,9 @@
}
};
// 根据购物车的数据匹配选中的商品查找是否有匹配的数组
const matchingProduct = async (data) => {
return matchedProducts.value.find((product, index) => {
@@ -1515,9 +1518,45 @@
is_print: 1
});
}
let socketInitFinished=false
// 购物车初始化时进行判断商品是否可以使用限时折扣,然后更新
let socketTimer = null
function cartInit(arr) {
const result = []
cartStore.carts = arr.map(v => {
const is_time_discount = limitUtils.canUseLimitTimeDiscount(v, cartStore.limitTimeDiscount, shopInfo,
shopUserInfo.value, 'product_id');
return {
...v,
is_time_discount: is_time_discount ? 1 : 0
}
})
for (let cart of arr) {
const findItem = cartStore.carts.find(v => v.id == cart.id)
if (findItem&&findItem.is_time_discount != cart.is_time_discount) {
result.push({
id: cart.id,
is_time_discount: findItem.is_time_discount
})
}
}
if (result.length > 0) {
useSocket.sendMessage({
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
type: "shopping",
operate_type: "bulk_edit",
data: {
cart: result
}
});
}
}
let socketInitFinished = false
// 收到的消息变化
async function onMessage(Message) {
if (Message) {
@@ -1535,17 +1574,17 @@
// 初始化
if (Message.operate_type == 'init') {
cartStore.carts = Message.data;
cartStore.limitTimeDiscount = Message.time_dis_info;
cartInit(Message.data)
uni.hideLoading();
isLoading.value = false;
// 初始化商品数量
// setGoodsInitSel(Message.data)
if(!socketInitFinished){
if (!socketInitFinished) {
useSocket.chnageInitMessage(options.initMessage)
socketInitFinished=true
socketInitFinished = true
}
}
// 转桌成功
@@ -1841,7 +1880,7 @@
const matchedProductsCount = matchedProducts.value.reduce((sum, item) => {
const num = typeof item.cartNumber === 'string' ? parseFloat(item.cartNumber) : item
.cartNumber;
.cartNumber;
return sum + num;
}, 0);
@@ -2055,14 +2094,14 @@
websocketsendMessage(data);
}
const juli=computed(()=>{
const juli = computed(() => {
const juli = getDistance(userStore.location.latitude, userStore.location.longitude, shopInfo.lat,
shopInfo.lng);
return juli.toFixed(2)
})
//计算距离判断是否可以点餐
async function computedDistance(shopInfo) {
return new Promise((resolve, reject) => {
@@ -2119,8 +2158,7 @@
console.log('shopInfoRes===', shopInfoRes);
await computedDistance(shopInfoRes.shopInfo);
if (shopInfoRes.shopInfo.id !== tableShopInfo.value.id) {
if (shopInfoRes.shopInfo.id !== shopInfo.id) {
uni.showModal({
title: '注意',
content: '扫码店铺与当前店铺不一致,请重新加载页面',
@@ -2158,13 +2196,22 @@
orderType.value = e.type;
}
//获取用户信息
const userInfo= await APIshopUserInfo({
shopId:uni.cache.get('shopId')
const userInfo = await APIshopUserInfo({
shopId: uni.cache.get('shopId')
})
if(userInfo&& typeof userInfo ==='object'){
shopUserInfo.value=userInfo
uni.cache.set('shopUserInfo',userInfo)
//获取店铺信息
const shopInfoRes = await APIusershopInfodetail({
shopId: uni.cache.get('shopId')
});
if(shopInfoRes&&shopInfoRes.shopInfo){
Object.assign(shopInfo, shopInfoRes.shopInfo);
uni.cache.set('shopInfo',shopInfoRes.shopInfo)
}
if (userInfo && typeof userInfo === 'object') {
shopUserInfo.value = userInfo
uni.cache.set('shopUserInfo', userInfo)
}
const extraInitPar = {}
@@ -2177,7 +2224,7 @@
...options.initMessage,
...extraInitPar
}, onMessage);
console.log('onLoad:e', e);
cartStore.setOldOrder({
@@ -2313,7 +2360,7 @@
fullAmount = item;
}
}
return fullAmount;
});