修复点餐页面购物车初始化时未拿到商品信息导致判断是否可用限时折扣有误问题

This commit is contained in:
2025-12-23 10:42:04 +08:00
parent 3b9fcc4f7f
commit 624056758d
3 changed files with 92 additions and 78 deletions

View File

@@ -1,5 +1,5 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false; // const debug = process.env.NODE_ENV == 'development' ? true : false;
const debug = true; // false线上 true本地 const debug = false; // false线上 true本地
// #ifdef H5 // #ifdef H5
const proxyApi = "/api"; const proxyApi = "/api";
// #endif // #endif

View File

@@ -308,8 +308,7 @@
) { ) {
youhuiReset(); youhuiReset();
} }
if (Message.operate_type == 'bulk_edit') { if (Message.operate_type == 'bulk_edit') {}
}
return Message; return Message;
} }
@@ -319,24 +318,27 @@
let cartsSocket = null; let cartsSocket = null;
cartStore.goodsInit(); cartStore.goodsInit();
const socketInitPar = { const socketInitPar = reactive({
type: "shopping", type: "shopping",
operate_type: "init", operate_type: "init",
table_code: uni.cache.get("tableCode"), table_code: uni.cache.get("tableCode"),
shop_id: uni.cache.get("shopId"), shop_id: uni.cache.get("shopId"),
}; time_dis_info: null
});
function socketInit() { function socketInit() {
cartsSocket = useWebSocket(); cartsSocket = useWebSocket();
cartStore.socketSendMsg=(data)=>{ cartStore.socketSendMsg = (data) => {
cartsSocket.sendMessage({ cartsSocket.sendMessage({
...data, ...data,
table_code: uni.cache.get("tableCode"), table_code: uni.cache.get("tableCode"),
shop_id: uni.cache.get("shopId"), shop_id: uni.cache.get("shopId"),
}) })
} }
cartsSocket.connect(socketInitPar, onMessage); cartsSocket.connect(socketInitPar, onMessage);
} }
const noPayStatus = { const noPayStatus = {
@@ -1097,8 +1099,8 @@
Object.assign(listinfo, res); Object.assign(listinfo, res);
getOrderInfoAfterCalcInit(res); getOrderInfoAfterCalcInit(res);
} }
const limitTimeDiscountRes=ref(null) const limitTimeDiscountRes = ref(null)
async function init(opt) { async function init(opt) {
await storeuser.actionsproductqueryProduct(); await storeuser.actionsproductqueryProduct();
@@ -1120,16 +1122,16 @@
if (res && typeof res == "object") { if (res && typeof res == "object") {
setOrder(res); setOrder(res);
} }
}else{ } else {
const limitRes = await limitTimeDiscountapi.getConfig({ const limitRes = await limitTimeDiscountapi.getConfig({
shopId: uni.cache.get('shopId') shopId: uni.cache.get('shopId')
}); });
if (limitRes && typeof limitRes == 'object') { if (limitRes && typeof limitRes == 'object') {
limitTimeDiscountRes.value = limitRes; limitTimeDiscountRes.value = limitRes;
} else { } else {
limitTimeDiscountRes.value = null; limitTimeDiscountRes.value = null;
} }
} }
//获取店铺信息 //获取店铺信息
@@ -1265,7 +1267,14 @@
}); });
watch(() => cartStore.limitTimeDiscount, (newval, oldval) => { watch(() => cartStore.limitTimeDiscount, (newval, oldval) => {
})
watch(()=>cartStore.limitTimeDiscount,(newval)=>{
socketInitPar.time_dis_info=newval
},{
deep:true,
immediate:true
}) })
/** /**
@@ -1289,7 +1298,8 @@
) ? ) ?
1 : 1 :
0; 0;
if (canUseLimitTimeDiscount != cart.isTimeDiscount) { const is_time_discount = cart.isTimeDiscount || cart.is_time_discount
if (canUseLimitTimeDiscount != is_time_discount) {
newData.history.push({ newData.history.push({
id: cart.id, id: cart.id,
is_time_discount: canUseLimitTimeDiscount, is_time_discount: canUseLimitTimeDiscount,
@@ -1307,7 +1317,9 @@
) ? ) ?
1 : 1 :
0; 0;
if (canUseLimitTimeDiscount != cart.isTimeDiscount) {
const is_time_discount = cart.isTimeDiscount || cart.is_time_discount
if (canUseLimitTimeDiscount != is_time_discount) {
newData.cart.push({ newData.cart.push({
id: cart.id, id: cart.id,
is_time_discount: canUseLimitTimeDiscount, is_time_discount: canUseLimitTimeDiscount,
@@ -1318,8 +1330,8 @@
if (newData.history.length <= 0 && newData.cart.length <= 0) { if (newData.history.length <= 0 && newData.cart.length <= 0) {
return; return;
} }
console.log('bulk_edit',{ console.log('bulk_edit', {
...socketInitPar, ...socketInitPar,
operate_type: "bulk_edit", operate_type: "bulk_edit",
data: newData, data: newData,

View File

@@ -1455,7 +1455,8 @@
type: 'shopping', type: 'shopping',
operate_type: 'init', operate_type: 'init',
table_code: uni.cache.get('tableCode'), table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId') shop_id: uni.cache.get('shopId'),
time_dis_info: null
} }
}; };
const useSocket = useWebSocket(); const useSocket = useWebSocket();
@@ -1554,20 +1555,29 @@
// 购物车初始化时进行判断商品是否可以使用限时折扣,然后更新 // 购物车初始化时进行判断商品是否可以使用限时折扣,然后更新
let socketTimer = null let socketTimer = null
// 返回商品对应sku数据
function cartInit(arr) { function cartInit(arr) {
const result = [] const result = []
cartStore.carts = arr.map(v => { cartStore.carts = arr.map(v => {
const is_time_discount = limitUtils.canUseLimitTimeDiscount(v, cartStore.limitTimeDiscount, shopInfo, const goods=matchedProducts.value.find(g=>g.id==v.product_id)
const goodsSkuList=goods.skuList||[]
const findSku=goodsSkuList.find(sku=>sku.id==v.sku_id)
const memberPrice=findSku?findSku.memberPrice:0
const is_time_discount = limitUtils.canUseLimitTimeDiscount({...v,memberPrice}, cartStore.limitTimeDiscount, shopInfo,
shopUserInfo.value, 'product_id'); shopUserInfo.value, 'product_id');
return { return {
...v, ...v,
is_time_discount: is_time_discount ? 1 : 0 is_time_discount: is_time_discount ? 1 : 0,
memberPrice
} }
}) })
for (let cart of arr) { for (let cart of arr) {
const findItem = cartStore.carts.find(v => v.id == cart.id) const findItem = cartStore.carts.find(v => v.id == cart.id)
console.log('findItem',findItem)
console.log('matchedProducts',matchedProducts.value)
if (findItem && findItem.is_time_discount != cart.is_time_discount) { if (findItem && findItem.is_time_discount != cart.is_time_discount) {
result.push({ result.push({
id: cart.id, id: cart.id,
@@ -1670,14 +1680,14 @@
time_dis_info: cartStore.limitTimeDiscount time_dis_info: cartStore.limitTimeDiscount
}; };
console.log('cartStore.limitTimeDiscount', cartStore.limitTimeDiscount) console.log('cartStore.limitTimeDiscount', cartStore.limitTimeDiscount)
useSocket.sendMessage({ // useSocket.sendMessage({
type: 'shopping', // type: 'shopping',
operate_type: 'time_discount_save', // operate_type: 'time_discount_save',
table_code: Message.data.new_table_code, // table_code: Message.data.new_table_code,
shop_id: uni.cache.get('shopId'), // shop_id: uni.cache.get('shopId'),
operate_type: 'time_discount_save', // operate_type: 'time_discount_save',
data: cartStore.limitTimeDiscount // data: cartStore.limitTimeDiscount
}); // });
useSocket.sendMessage(data); useSocket.sendMessage(data);
} }
@@ -1854,11 +1864,14 @@
let res = await APIhistoryOrder({ let res = await APIhistoryOrder({
tableCode: uni.cache.get('tableCode') tableCode: uni.cache.get('tableCode')
}); });
orderinfo.value = { if (res && typeof res === 'object') {
id: res.id, orderinfo.value = {
detailMap: res.detailMap, id: res.id,
placeNum: res.placeNum detailMap: res.detailMap,
}; placeNum: res.placeNum
};
}
} }
}; };
@@ -2272,7 +2285,7 @@
}); });
} }
const limitTimeDiscountRes = ref(null);
onLoad(async (e) => { onLoad(async (e) => {
if (e.type) { if (e.type) {
orderType.value = e.type; orderType.value = e.type;
@@ -2289,12 +2302,13 @@
Object.assign(shopInfo, shopInfoRes.shopInfo); Object.assign(shopInfo, shopInfoRes.shopInfo);
uni.cache.set('shopInfo', shopInfoRes.shopInfo) uni.cache.set('shopInfo', shopInfoRes.shopInfo)
} }
if (userInfo && typeof userInfo === 'object') { if (userInfo && typeof userInfo === 'object') {
shopUserInfo.value = userInfo shopUserInfo.value = userInfo
uni.cache.set('shopUserInfo', userInfo) uni.cache.set('shopUserInfo', userInfo)
} }
await productqueryProduct();
const extraInitPar = {} const extraInitPar = {}
if (e.one_more_order && e.order_id) { if (e.one_more_order && e.order_id) {
@@ -2302,24 +2316,40 @@
extraInitPar.order_id = e.order_id extraInitPar.order_id = e.order_id
extraInitPar.user_id = uni.cache.get('userInfo').id || '' extraInitPar.user_id = uni.cache.get('userInfo').id || ''
} }
const time_dis_info= await getLimitDiscount()
const time_dis_info = await getLimitDiscount()
options.initMessage.time_dis_info = time_dis_info
useSocket.connect({ useSocket.connect({
...options.initMessage, ...options.initMessage,
...extraInitPar, ...extraInitPar,
time_dis_info
}, onMessage); }, onMessage);
cartStore.setOldOrder({ cartStore.setOldOrder({
detailMap: {}, detailMap: {},
originAmount: 0 originAmount: 0
}); });
await proxy.$onLaunched;
//新客立减
getNewUserDiscount();
// 满减活动
getDiscountActivity();
let res = await APIhistoryOrder({
tableCode: uni.cache.get('tableCode')
});
oldOrder.value = res;
if (res && res.id && shopInfo.registerType == 'after') {
toHistory();
return;
}
setTimeout(() => {
// 启动网络监听
useSocket.initNetworkListener();
getElementTop();
}, 500);
}); });
const limitTimeDiscountRes = ref(null);
const nowTime = ref(getEndTimeInSeconds(dayjs().format('HH:mm'))); const nowTime = ref(getEndTimeInSeconds(dayjs().format('HH:mm')));
let timer = setInterval(() => { let timer = setInterval(() => {
nowTime.value = getEndTimeInSeconds(dayjs().format('HH:mm')); nowTime.value = getEndTimeInSeconds(dayjs().format('HH:mm'));
@@ -2356,7 +2386,8 @@
if (!cartStore.limitTimeDiscount || !cartStore.limitTimeDiscount.id) { if (!cartStore.limitTimeDiscount || !cartStore.limitTimeDiscount.id) {
return 0; return 0;
} }
return limitUtils.canUseLimitTimeDiscount(item, cartStore.limitTimeDiscount, shopInfo, shopUserInfo.value, 'id')?1:0; return limitUtils.canUseLimitTimeDiscount(item, cartStore.limitTimeDiscount, shopInfo, shopUserInfo.value, 'id') ?
1 : 0;
} }
function returnLimitPrice(item) { function returnLimitPrice(item) {
@@ -2474,10 +2505,10 @@
return 0 return 0
}) })
const oldOrder = ref(null); const oldOrder = ref(null);
// 限时折扣 // 限时折扣
async function getLimitDiscount(){ async function getLimitDiscount() {
const limitRes = await limitTimeDiscountapi.getConfig({ const limitRes = await limitTimeDiscountapi.getConfig({
shopId: uni.cache.get('shopId') shopId: uni.cache.get('shopId')
}); });
@@ -2486,7 +2517,6 @@
} else { } else {
cartStore.limitTimeDiscount = null; cartStore.limitTimeDiscount = null;
} }
return cartStore.limitTimeDiscount
websocketsendMessage({ websocketsendMessage({
type: 'shopping', type: 'shopping',
operate_type: 'time_discount_save', operate_type: 'time_discount_save',
@@ -2496,38 +2526,10 @@
data: cartStore.limitTimeDiscount data: cartStore.limitTimeDiscount
}); });
console.log('onMounted:限时折扣', cartStore.limitTimeDiscount); console.log('onMounted:限时折扣', cartStore.limitTimeDiscount);
return cartStore.limitTimeDiscount
} }
onMounted(async () => { onMounted(async () => {
// #ifdef MP-WEIXIN
await proxy.$onLaunched;
// #endif
// 获取当前页面栈
const pages = getCurrentPages();
// 获取当前页面实例
const currentPage = pages[pages.length - 1];
// 获取页面参数
const options = currentPage.options;
console.log('onMounted', options);
//新客立减
getNewUserDiscount();
// 满减活动
getDiscountActivity();
let res = await APIhistoryOrder({
tableCode: uni.cache.get('tableCode')
});
oldOrder.value = res;
await productqueryProduct();
if (res && res.id && shopInfo.registerType == 'after') {
toHistory();
return;
}
setTimeout(() => {
// 启动网络监听
useSocket.initNetworkListener();
getElementTop();
}, 500);
}); });
//跳转历史订单 //跳转历史订单