Commit 163d3b7e765d78ba18643d3b59231c6875521184

Authored by pengye
1 parent 25f7e986

优惠券扫码购买页3

... ... @@ -12,63 +12,19 @@ Page({
dataStr: Date.now() * 1 / 1000,
discountPrice: '', //优惠价格
actualPrice: '', //实付价格
inputValue: '', //输入的金额
canSolt: {}, //当前时间是哪个餐段、节假日
},
sid: '', //扫码进入带的参数商家id
couponModal: '',
monidata: [{
desc: "0", //优惠条件
price: "6", //优惠金额
showCpupon: '1', //是否可选
checked: true, //是否勾选
activity_id: "566",
aid: "948",
aname: "新测试一下",
cdate: "1739429461", //领取日期
arule: {
commission: "1",
is_accumulation: "1",
is_appointment: "1",
is_commission: "1",
is_compartment: "1",
is_eatin: "1",
is_same_day: "1", //领取当日是否可用
is_share_have: "1",
is_share_lose: "1",
is_takeout: "1",
},
etime: "1739635199",
exp_date: '{"week_show":"无","week_data":[{"id":null,"title":"周日","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"周一","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"周二","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"周三","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"周四","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"周五","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"周六","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false},{"id":null,"title":"法定假日","select":false,"roleName":null,"phone":null,"account":null,"selectMor":false,"selectNoon":false,"selectNig":false}]}',
explain: "",
grant_last: "93",
grant_num: "100",
id: "948",
is_examine: "1",
is_open: "1",
is_type: "3",
lite_qrcode: "https://xt04.colorcun.com/activity/LiteQRcode/activity_948.jpeg",
map_address: "陕西省西安市沣惠南路36号",
openid: "oB-xJ5NGdgXHM0Pdsq2kAf7z-n9k",
phone: "15715807436",
seller_image: "http://libpc.colorcun.com/20241118173230_b2dbe5ec7ca79a64bf7eea6f0cab3dca",
seller_tel: "010-6257270,15236523652336",
sellerid: "4352",
sellername: "长安大排档总店",
status: "1",
stime: "1739289600",
uid: "7035",
uid_list: null,
urllink: "https://wxaurl.cn/m7EcFm28Kfr",
}],
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.couponModal = this.selectComponent("#couponModal");
// this.couponModal.showModal()
this.setData({
...options
})
if (options.sid) {
this.getSellerDetail(options.sid)
this.sid = options.sid
this.getSellerDetailFun(options.sid)
}
},
// 打开优惠券弹框
... ... @@ -80,7 +36,7 @@ Page({
this.couponModal.closeModal()
},
// 获取店铺名称
getSellerDetail(sid) {
getSellerDetailFun(sid) {
App.Customer.GetSellerDetail({
sid
}).then(res => {
... ... @@ -88,20 +44,21 @@ Page({
this.setData({
seller: {
seller_image: data.seller_image,
sellername: data.sellername
sellername: data.sellername,
sid: data.id
}
})
this.getCoupon()
// 判断当前时间餐段、节假日
this.getSellerDailyFun(data.daily)
})
},
// 获取所有优惠券列表
getCoupon() {
App.Activity.ActivityListByOpenid().then(res => {
App.Activity.ActivityListByOpenid({
sellerid: this.sid
}).then(res => {
if (res.ret == 200 && res.data && res.data.length > 0) {
let list = res.data.filter(item => {
return this.data.dataStr < (item.etime * 1) && item.is_open == '1'
})
let list = res.data
list.forEach(detail => {
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
... ... @@ -137,15 +94,50 @@ Page({
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
const list = this.data.couponArr
const values = e.detail.value
let arr = []
let currentCoupon = '0'; //没选券 为0 可叠加券1 不可叠加券2
for (let i = 0, lenI = list.length; i < lenI; ++i) {
list[i].checked = false
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
if (list[i].activity_id === values[j]) {
arr.push({
...list[i]
})
list[i].checked = true
if (list[i].accumulationShow == '1') {
currentCoupon = '1'
} else {
currentCoupon = '2'
}
break
}
}
}
console.log('没选券 为0 可叠加券1 不可叠加券2', currentCoupon);
//没选券 所有可选的打开
if (currentCoupon == '0') {
list.forEach(item => {
if (item.canCheck == "1") {
item.showCpupon = '1';
}
})
}
//选的不可叠加券 其他所有的可叠加券都不可选
if (currentCoupon == '2') {
list.forEach(item => {
if (item.accumulationShow == "1") {
item.showCpupon = '0';
}
})
}
//选的可叠加券 其他所有的不可叠加券都不可选
if (currentCoupon == '1') {
list.forEach(item => {
if (item.accumulationShow == "0") {
item.showCpupon = '0';
}
})
}
this.setData({
couponArr: list
})
... ... @@ -180,6 +172,7 @@ Page({
console.log('优惠金额----', price);
let val = this.data.inputValue * 1;
let actualPrice = val - price.toFixed(2)
price = price.toFixed(2)
this.setData({
discountPrice: price,
actualPrice: actualPrice > 0 ? actualPrice : 0.1,
... ... @@ -189,172 +182,261 @@ Page({
// 处理显示券可用、不可用的列表
async colationData() {
let list = this.data.couponArr;
// list = list
list = await this.filterCoupons(list);
list = await this.findBestCoupons(list);
console.log('eeeeeeeeeeee', list);
let obj = await this.findBestCoupons(list);
list = obj.arr
console.log('处理过后的券数据', list);
list.sort((a, b) => b.canCheck - a.canCheck);
list.sort((a, b) => b.showCpupon - a.showCpupon);
// list.filter(i=>{return i.aexpiration!='0' && i.aexpiration>0})
this.setData({
couponArr: list
couponArr: list,
finalList: obj.finalList
})
},
// 付款
confirmPayment() {
let actualPrice = this.data.actualPrice
if (actualPrice <= 0) {
return
}
App.PayOnline.CombineTransactionsByNewActivity({
sellerid: this.data.seller.sid,
price: actualPrice,
}).then(res => {
console.log('付款信息', res.data);
if (res.ret != '200') {
wx.showToast({
title: res.msg,
duration: 1000,
icon: 'none',
})
}
if (res.ret == '200') {
wx.requestPayment({
timeStamp: res.data.timeStamp + '',
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success(ress) {
if (ress.errMsg == 'requestPayment:ok') {
this.writeOff()
console.log('支付成功', ress);
wx.showToast({
title: '支付成功',
duration: 1000,
icon: 'none',
})
}
console.log('支付失败', ress);
wx.showToast({
title: '支付失败,请重新下单',
duration: 1000,
})
},
fail(ress) {
console.log('支付失败', ress);
wx.showToast({
title: '支付失败,请重新下单',
duration: 1000,
icon: 'none',
})
},
})
}
})
},
// 核销所勾选的券
writeOff() {
console.log('勾选的券', this.data.finalList);
if (this.data.finalList.length > 0) {
let str = this.data.finalList.map(item => item.activity_id).join(',');
console.log('核销所勾选的券传参', str);
App.Activity.SetActivityStatus({
id: str,
}).then(res => {
if (res.ret == '200') {
console.log('核销成功', str);
}
})
}
},
// 判断券开启、有效期结束时间、领取后有效天数、领取当天可用、不可用日期
filterCoupons(list) {
console.log(1111111, list);
// const currentTime = Math.floor(Date.now() / 1000); // 获取当前时间的 Unix 时间戳(秒)
// const today = new Date(); // 获取今天的日期
// today.setHours(0, 0, 0, 0); // 将时间设为今天的开始时间
// const todayTimestamp = Math.floor(today.getTime() / 1000); // 获取今天的开始时间戳
// return list.filter(coupon => {
// const couponCDate = parseInt(coupon.cdate); // 领取日期
// const validDays = parseInt(coupon.aexpiration); // 有效天数
// const isSameDay = parseInt(coupon.arule.is_same_day); // 领取当日是否可用
// // 计算有效期结束时间
// const couponExpirationDate = couponCDate + validDays * 24 * 60 * 60; // 有效期结束时间戳
// // 筛选条件
// const isWithinValidity = todayTimestamp >= couponCDate && todayTimestamp <= couponExpirationDate;
// return (
// (todayTimestamp > couponCDate && isWithinValidity) || // 今天不是领取当日,但在有效天数内
// (todayTimestamp === couponCDate && isSameDay === 1 && validDays >= 1) // 今天是领取当日且可用
// );
// });
// const currentTime = Math.floor(Date.now() / 1000); // 获取当前时间的 Unix 时间戳(秒)
// const today = new Date(); // 获取今天的日期
// today.setHours(0, 0, 0, 0); // 将时间设为今天的开始时间
// const todayTimestamp = Math.floor(today.getTime() / 1000); // 获取今天的开始时间戳
// list.forEach(coupon => {
// const couponCDate = parseInt(coupon.cdate); // 领取日期
// const validDays = parseInt(coupon.aexpiration); // 有效天数
// const isSameDay = parseInt(coupon.arule.is_same_day); // 领取当日是否可用
// // const couponExpirationDate = couponCDate + validDays * 24 * 60 * 60; // 有效期结束时间戳
// let date = new Date(couponCDate * 1000);
// date.setDate(date.getDate() + validDays);
// date.setHours(23, 59, 59, 0);
// let couponExpirationDate = Math.floor(date.getTime() / 1000);
// // 今天的开始时间戳 <= 领取日期
// const isWithinValidity = (todayTimestamp <= couponCDate) && (todayTimestamp <= couponExpirationDate);
// console.log('领取日期---',couponCDate);
// console.log('有效天数---',validDays);
// console.log('领取当日是否可用---',isSameDay);
// console.log('有效期结束时间戳---',couponExpirationDate);
// console.log('isWithinValidity---',isWithinValidity);
// console.log('获取今天的开始时间戳---',todayTimestamp);
// console.log('wwwwwwwwwww---',(todayTimestamp >= couponCDate));
// console.log('ggggggggggg---',(todayTimestamp <= couponExpirationDate));
// // 今天不是领取当日,但在有效天数内 || 今天是领取当日且可用
// if ((todayTimestamp > couponCDate && isWithinValidity) || (todayTimestamp === couponCDate && isSameDay === 1 && validDays >= 1)) {
// coupon.aa = '1';
// console.log('可用',coupon.aname);
// } else {
// coupon.aa = '0';
// console.log('不可用',coupon.aname);
// }
// });
const currentTime = Math.floor(Date.now() / 1000); // 获取当前时间的 Unix 时间戳(秒)
// 获取今天的开始时间和结束时间
const today = new Date();
today.setHours(0, 0, 0, 0); // 设置为今天的开始时间
const todayStartTimestamp = Math.floor(today.getTime() / 1000); // 今天的开始时间戳
today.setHours(23, 59, 59); // 设置为今天的结束时间
const todayEndTimestamp = Math.floor(today.getTime() / 1000); // 今天的结束时间戳
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
list.forEach(coupon => {
const couponCDate = parseInt(coupon.cdate); // 领取日期
const validDays = parseInt(coupon.aexpiration); // 有效天数
const isSameDay = parseInt(coupon.arule.is_same_day); // 领取当日是否可用
// 计算有效期结束时间
const couponExpirationDate = couponCDate + validDays * 24 * 60 * 60; // 有效期结束时间戳
// 判断条件
const isWithinValidity = todayStartTimestamp > couponCDate && todayEndTimestamp < couponExpirationDate;
if (
(todayStartTimestamp > couponCDate && isWithinValidity) || // 今天不是领取当日,但在有效天数内
(todayStartTimestamp === couponCDate && isSameDay === 1 && validDays >= 1) // 今天是领取当日且可用
) {
coupon.aa = '1'; // 符合条件,设置为可选
const startUseDate = new Date(currentDate);
let endUseDate = new Date(currentDate);
const couponDate = new Date(coupon.cdate * 1000);
if (coupon.arule.is_same_day) {
startUseDate.setDate(couponDate.getDate() - 1);
} else {
startUseDate.setDate(couponDate.getDate());
}
// 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间
if (coupon.aexpiration == '0' || coupon.aexpiration == '') {
let date = new Date(coupon.etime * 1000);
endUseDate = date
} else {
coupon.aa = '0'; // 不符合条件,设置为不可选
endUseDate.setDate(couponDate.getDate() + parseInt(coupon.aexpiration));
}
// 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 在有效天数内 && 券是开启状态
const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) &&
(this.data.dataStr < (coupon.etime * 1) && coupon.is_open == '1')
let obj = this.data.canSolt
let selectedValue = true;
let str = true
if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) {
let today = new Date(); // 获取今天是星期几(0-6,0表示周日)
let dayOfWeek = today.getDay();
let arr = coupon.exp_date.week_data
let todayArr = arr[dayOfWeek];
let legalHolidayValue = arr[arr.length - 1];
if (obj.can === "晚餐") {
selectedValue = todayArr.selectNig;
} else if (obj.can === "午餐") {
selectedValue = todayArr.selectNoon;
} else if (obj.can === "早餐") {
selectedValue = todayArr.selectMor;
}
selectedValue = !selectedValue
console.log(coupon.aname, coupon.exp_date.week_show, `今天是 ${todayArr.title},选择值为: ${selectedValue}`);
// 根据 isshow 判断法定假日是否可用
if (obj.isshow === "1") {
if (obj.can === "晚餐") {
str = legalHolidayValue.selectNig;
} else if (obj.can === "午餐") {
str = legalHolidayValue.selectNoon;
} else if (obj.can === "早餐") {
str = legalHolidayValue.selectMor;
}
str = !str
}
console.log(coupon.aname, '法定节假期', `,选择值为: ${str}`);
}
let availableDate = true;
if (str || selectedValue) {
availableDate = true
}
if (!str || !selectedValue) {
availableDate = false
}
if ((str && !selectedValue) || (!str && selectedValue)) {
availableDate = false
}
coupon.isOk = isUseDate && (availableDate || coupon.exp_date.week_show == '无') ? '1' : '0'; //是否在可用时间内 1可使用 2不可使用
endUseDate.setHours(23, 59, 59, 999); // 设置时间为23:59:59.999
const timestamp = Math.floor(endUseDate.getTime() / 1000);
let c = coupon.etime * 1
coupon.expirationDate = Math.min(timestamp, c);
});
console.log('1111', list);
return list
},
// (消费要求为无门槛 或者 小于输入金额的) && 勾选最优的
// 最优惠的消费券组合(消费要求为无门槛 或者 满足优惠券使用金额 && 勾选最优的、最早到期的)
findBestCoupons(arr) {
console.log(333333333);
console.log('勾选最优的之前', arr);
let inputValue = this.data.inputValue;
const amount = parseFloat(inputValue); // 将输入金额转换为数字
const validCoupons = arr.filter(coupon => (coupon.aa == '1' && parseFloat(coupon.desc) <= amount)); // 筛选符合条件的优惠券
console.log('validCouponsvalidCoupons', validCoupons);
let bestDiscount = 0;
let bestCoupons = [];
// 按到期时间排序,确保优先选择最早到期的券
validCoupons.sort((a, b) => parseInt(a.etime) - parseInt(b.etime));
// 使用递归函数来查找所有组合
function findBestCombination(currentCoupons, currentDiscount, remainingCoupons) {
const totalDiscount = currentDiscount;
const finalPrice = amount - totalDiscount;
// 检查当前组合是否是最佳组合且实付价格不小于0
if (finalPrice >= 0 && totalDiscount > bestDiscount) {
bestDiscount = totalDiscount;
bestCoupons = currentCoupons.slice(); // 复制当前组合
const amount = parseFloat(inputValue);
const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount));
arr.forEach(item => {
const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
});
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
let list1 = []; // 可叠加的优惠券组合
let list2 = []; // 最优惠的不可叠加的优惠券
let finalList = []; //最终用的优惠券组合
// 计算可叠加的组合
let remainingValue = inputValue; // 剩余金额
let totalDiscount = 0; // 总优惠金额
// 尝试组合可叠加的优惠券
validCoupons.forEach(coupon => {
if (coupon.accumulationShow === '1') {
const discountAmount = parseInt(coupon.price);
if (remainingValue > 0) {
list1.push(coupon);
totalDiscount += discountAmount; // 累加优惠金额
remainingValue -= discountAmount; // 减少应付金额
}
}
// 遍历剩余的优惠券
for (let i = 0; i < remainingCoupons.length; i++) {
const nextCoupon = remainingCoupons[i];
currentCoupons.push(nextCoupon); // 选择当前优惠券
findBestCombination(currentCoupons, currentDiscount + parseFloat(nextCoupon.price), remainingCoupons.slice(i + 1)); // 递归查找
currentCoupons.pop(); // 回溯
});
// 检查可叠加组合是否有效
if (remainingValue < 0) {
list1 = []; // 如果剩余金额小于0,清空可叠加列表
}
// 重置剩余金额,用于不可叠加的优惠券
remainingValue = inputValue;
// 遍历有效优惠券,寻找不可叠加的优惠券
validCoupons.forEach(coupon => {
if (coupon.accumulationShow === '0') {
const discountAmount = parseInt(coupon.price);
// 计算实际支付金额
const finalAmount = inputValue - discountAmount;
// 确保实际支付金额不小于0,并且是最优惠的
if (finalAmount >= 0) {
if (!list2.length || discountAmount > parseInt(bestCoupon.price)) {
list2.push({
...coupon
}); // 更新最优惠的不可叠加券
}
}
}
});
console.log('可叠加的优惠券组合', list1);
console.log('不可叠加的优惠券', list2);
// 计算两个列表的最大优惠值
let maxStackableValue = list1.reduce((total, coupon) => total + coupon.price, 0);
let maxNonStackableValue = list2.reduce((total, coupon) => total + coupon.price, 0);
// 比较两个最大值并输出结果
if (maxStackableValue > maxNonStackableValue) {
console.log(`可叠加优惠券组合的最大优惠值更高: ${maxStackableValue}`);
finalList = list1
} else if (maxStackableValue < maxNonStackableValue) {
console.log(`不可叠加券的最大优惠值更高: ${maxNonStackableValue}`);
finalList = list2
} else {
console.log(`两者的优惠值相同: ${maxStackableValue}`);
let copiedList1 = JSON.parse(JSON.stringify(list1));
let copiedList2 = JSON.parse(JSON.stringify(list2));
let minList1 = copiedList1.length > 0 ? Math.min(...copiedList1.map(item => item.expirationDate)) : Infinity;
let minList2 = copiedList2.length > 0 ? Math.min(...copiedList2.map(item => item.expirationDate)) : Infinity;
// 判断最小的 expirationDate 是在 list1 还是 list2
if (minList1 <= minList2) {
console.log('最小的在 list1 中', list1);
finalList = list1
} else {
console.log('最小的在 list2 中', list2);
finalList = list2
}
}
findBestCombination([], 0, validCoupons);
let totalDiscountPrice = 0;
console.log('选中的券组合', finalList);
let discountPrice = 0;
// 更新选中的优惠券
bestCoupons.forEach(coupon => {
finalList.forEach(coupon => {
let target = arr.find(obj => obj.activity_id === coupon.activity_id);
if (target) {
target.showCpupon = 1;
target.checked = true;
discountPrice += coupon.price * 1; // 使用 parseFloat 确保类型正确
}
console.log('选中的券', {
...coupon
});
coupon.showCpupon = '1';
coupon.checked = true;
totalDiscountPrice += parseFloat(coupon.price); // 使用 parseFloat 确保类型正确
});
console.log('总优惠金额:', totalDiscountPrice);
let actualPrice = (amount - totalDiscountPrice).toFixed(2);
discountPrice = discountPrice.toFixed(2)
console.log('总优惠金额:', discountPrice);
let actualPrice = (amount - discountPrice).toFixed(2);
console.log('实际支付金额:', actualPrice);
this.setData({
discountPrice: totalDiscountPrice,
discountPrice,
actualPrice: actualPrice > 0 ? actualPrice : '0.1', // 确保实际支付金额不小于0.01
});
return arr; // 返回更新后的数组
return {
arr,
finalList, // 返回可叠加和不可叠加的优惠券组合
};
},
// 处理优惠券不可用日期数据
hasConsecutiveSelect(arr, type) {
... ... @@ -400,6 +482,175 @@ Page({
firstTitle
};
},
// 判断当前时间餐段、节假日
getSellerDailyFun(lunchDis) {
let lunchDinnerList = [];
if (lunchDis.morning) {
lunchDinnerList.push({
can: "早餐",
solt: 1,
class: "morning",
})
}
if (lunchDis.noon) {
lunchDinnerList.push({
can: "午餐",
solt: 2,
class: "dinner",
})
}
if (lunchDis.night) {
lunchDinnerList.push({
can: "晚餐",
solt: 3,
class: "lunch",
})
}
const currentTime = new Date().toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit'
});
let obj = this.checkTimeInInterval(currentTime, lunchDis, lunchDinnerList);
//节假日数组
var holidays = [
'2025-1-1', // 元旦
'2025-1-28', // 春节
'2025-1-29', // 春节
'2025-1-30', // 春节
'2025-1-31', // 春节
'2025-2-1', // 春节
'2025-2-2', // 春节
'2025-2-3', // 春节
'2025-2-4', // 春节
'2025-4-4', //清明
'2025-4-5', //清明
'2025-4-6', //清明
'2025-5-1', // 劳动节
'2025-5-2', // 劳动节
'2025-5-3', // 劳动节
'2025-5-4', // 劳动节
'2025-5-5', // 劳动节
'2025-5-31', // 端午节
'2025-6-1', // 端午节
'2025-6-2', // 端午节
'2025-10-1', // 国庆节、中秋节
'2025-10-2', // 国庆节、中秋节
'2025-10-3', // 国庆节、中秋节
'2025-10-4', // 国庆节、中秋节
'2025-10-5', // 国庆节、中秋节
'2025-10-6', // 国庆节、中秋节
'2025-10-7', // 国庆节、中秋节
'2025-10-8', // 国庆节、中秋节
];
//周末上班日期数组
var nWeekend = [
'2025-1-26', //春节调整
'2025-2-8', //春节调整
'2025-4-27', //五一调整
'2025-9-28', //国庆调整
'2025-10-11', //国庆调整
];
var curdate = new Date();
curdate.setTime(curdate.getTime() + 4 * 24 * 60 * 60 * 1000);
var year = curdate.getFullYear();
var month = curdate.getMonth() + 1;
var date = curdate.getDate();
var formattedDate = year + "-" + month + "-" + date;
obj.isshow = '0'
//该日期同时满足2个条件即为节假日:1.在节假日数组内或在周末. 2.不在周末上班日期数组
if ((holidays.indexOf(formattedDate) >= 0 || (curdate.getDay() == 0 || curdate.getDay() == 6)) && nWeekend.indexOf(formattedDate) < 0) {
obj.isshow = '1'
} else {
obj.isshow = '0'
}
console.log('不可用日期信息:餐段、节假日', obj);
if (obj && obj.can && obj.solt) {
this.setData({
canSolt: {
...obj
}
})
}
this.getCoupon()
},
// 传参currentTime 当前时间 例16:51 lunchDis 餐段 {morning: "07:00-10:00",night: "16:00-21:00",noon: "11:00-14:30"}
// 判断当前时间餐段
checkTimeInInterval(currentTime, lunchDis, lunchDinnerList) {
const [currentHour, currentMinute] = currentTime.split(':');
const [morningHour2, morningMinute2] = lunchDis.morning ? lunchDis.morning.split("-")[1].split(':') : [0, 0];
const [noonHour1, noonMinute1] = lunchDis.noon ? lunchDis.noon.split("-")[1].split(':') : [0, 0];
const [noonHour2, noonMinute2] = lunchDis.noon ? lunchDis.noon.split("-")[1].split(':') : [0, 0];
const [nightHour1, nightMinute1] = lunchDis.night ? lunchDis.night.split("-")[1].split(':') : [0, 0];
const currentTimestamp = new Date().setHours(currentHour, currentMinute, 0, 0); //当前时间
const time1 = (morningHour2 && morningMinute2) ? new Date().setHours(morningHour2, morningMinute2, 0, 0) : ''; //早餐截止时间
const time2 = (noonHour1 && noonMinute1) ? new Date().setHours(noonHour1, noonMinute1, 0, 0) : ''; //午餐开始时间
const time3 = (noonHour2 && noonMinute2) ? new Date().setHours(noonHour2, noonMinute2, 0, 0) : ''; //午餐截止时间
const time4 = (nightHour1 && nightMinute1) ? new Date().setHours(nightHour1, nightMinute1, 0, 0) : ''; //晚餐开始时间
// 1个餐段
if (lunchDinnerList.length == 1) {
return {
solt: lunchDinnerList[0].solt,
can: lunchDinnerList[0].can
};
}
// 2个餐段(早,午)(早,晚)(午,晚)
if (lunchDinnerList.length == 2) {
let obj1 = lunchDinnerList[0];
let obj2 = lunchDinnerList[1];
let timeA1 = obj1.solt == 1 ? time1 : time2;
let timeA2 = obj2.solt == 2 ? time2 : time4;
if (currentTimestamp < timeA1) { // 在早餐/午餐截止时间之前
return obj1.solt == 1 ? {
solt: 1,
can: '早餐'
} : {
solt: 2,
can: '午餐'
};
} else if (currentTimestamp > timeA1 && currentTimestamp < timeA2) { //在早餐/午餐截止时间之后 && 午餐/晚餐开始时间之前
return obj2.solt == 2 ? {
solt: 2,
can: '午餐'
} : {
solt: 3,
can: '晚餐'
};
} else if (currentTimestamp > timeA2) { //在午餐/晚餐截止时间之后
return obj1.solt == 1 ? {
solt: 1,
can: '早餐'
} : {
solt: 2,
can: '午餐'
};
}
}
// 3个餐段(早,午,晚)
if (lunchDinnerList.length == 3) {
if (currentTimestamp < time1) { //当前时间 在早餐截止时间之前
return {
solt: 1,
can: '早餐'
};
} else if (currentTimestamp > time1 && currentTimestamp < time2) { //在早餐截止时间之后 && 午餐开始时间之前
return {
solt: 2,
can: '午餐'
};
} else if (currentTimestamp > time3 && currentTimestamp < time4) { //在午餐截止时间之后 && 晚餐开始时间之前
return {
solt: 3,
can: '晚餐'
};
} else {
return {
solt: 3,
can: '晚餐'
};
}
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
... ...
... ... @@ -19,9 +19,9 @@
</view>
<view class="couponsWrap">
<view class="couponLeft">抵扣后</view>
<view class="couponRight" wx:if="{{actualPrice}}">¥{{actualPrice}}</view>
<view class="couponRight" wx:if="{{actualPrice && inputValue}}">¥{{actualPrice}}</view>
</view>
<view class="payBtn font32r">付款</view>
<view class="payBtn font32r" bindtap="confirmPayment">付款</view>
</view>
<my-modal id="couponModal" fadeStyle="slideUp" height="{{couponArr.length > '3' ? '80%' : '60%'}}">
<view slot="modalName" class="titleModal">
... ... @@ -42,22 +42,14 @@
<view class="itemRight">
<view class="anameText">
<text class="font40r">{{item.aname}}</text>
<view class="discountText1 font20r" wx:if="{{item.is_type == '3'}}">{{item.accumulationShow == '1' ? '可' : '不可'}}叠加</view>
<view class="discountText1 font20r">{{item.accumulationShow == '1' ? '可' : '不可'}}叠加</view>
</view>
<view wx:if="{{item.endDateStr}}" class="font20r bottomTitle">有效日期:<view class="bottom font20r">{{item.endDateStr}}</view>
</view>
<view wx:if="{{item.noonText || item.noonText}}" class="font20r bottomTitle">不可使用:<view wx:if="{{item.noonText}}" class="bottom font20r">{{item.noonText}}</view>
<view wx:if="{{item.noonText || item.noonText}}" class="font20r bottomTitle"><text>不可使用:</text><view wx:if="{{item.noonText}}" class="bottom font20r">{{item.noonText}}</view>
</view>
<view wx:if="{{item.nigText}}" class="bottom font20r nodate">{{item.nigText}}</view>
<view wx:if="{{item.exp_date.week_show=='无'}}" class="bottom font20r">无使用时间限制</view>
<view class="bottom font20r">领取日期:{{item.cdateText}}</view>
<view class="bottom font20r">{{item.arule.is_same_day == '1' ? '领取当日可用' : '领取当日不可用'}}</view>
<view class="bottom font20r">领取后{{item.aexpiration}}天有效</view>
</view>
<checkbox disabled="{{item.showCpupon == '0'}}" value="{{item.activity_id}}" checked="{{item.checked}}" />
</view>
... ...
... ... @@ -178,6 +178,10 @@
font-weight: 600;
}
.bottomTitle text {
flex-shrink: 0;
}
.bottom {
font-weight: normal;
}
... ... @@ -204,7 +208,6 @@
.itemRight view {
display: flex;
align-items: center;
line-height: 36rpx;
}
... ... @@ -213,17 +216,17 @@
}
checkbox {
height: 50rpx;
width: 50rpx;
height: 40rpx;
width: 40rpx;
margin-right: 20rpx;
}
radio::before,
checkbox::before {
height: 50rpx;
height: 40rpx;
top: 32% !important;
right: 0 !important;
width: 50rpx;
width: 40rpx;
content: '' !important;
}
... ...
... ... @@ -179,7 +179,8 @@ Page({
// 是否已领取
getCoupon() {
App.Activity.ActivityListByOpenid({
aid: this.data.opt.id
aid: this.data.opt.id,
sellerid:this.data.opt.sid
}).then(res => {
if (res.ret === 200) {
this.setData({
... ...
... ... @@ -1004,7 +1004,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -959,7 +959,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -959,7 +959,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -958,7 +958,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -915,7 +915,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -959,7 +959,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -958,7 +958,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -992,7 +992,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -345,7 +345,8 @@ Page({
let couponArr = this.data.couponArr;
let totalPrice = this.data.totalPrice;
App.Activity.ActivityListByOpenid({
aid: item.id
aid: item.id,
sellerid:this.data.sid,
}).then(res => {
if (res.ret == 200) {
if (res.data.length == 0) {
... ...
... ... @@ -762,4 +762,18 @@ export default {
openid:'openid',
cachetime: 0,
},
//小程序最新使用优惠付款
'App.PayOnline.CombineTransactionsByNewActivity':{
alias:'App.PayOnline.CombineTransactionsByNewActivity',
openid:'openid',
cachetime: 0,
},
//核销
'App.Activity.SetActivityStatus':{
alias:'App.Activity.SetActivityStatus',
openid:'openid',
cachetime: 0,
},
}
\ No newline at end of file
... ...