Commit 3e48468d59f000bf15b6ec1e4e2f516ec4dc6e82

Authored by “pengye”
1 parent 010f85ad

付款页setDate、getDate不支持,替换成getTime、setTime方法

... ... @@ -63,7 +63,7 @@ Page({
if (res.ret == 200 && res.data && res.data.length > 0) {
let list = res.data
// console.log('listlistlist',JSON.stringify(list));
// list= monidata
// list= list.concat(monidata)
list.forEach(detail => {
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
... ... @@ -85,7 +85,7 @@ Page({
let edateText = ''; //有效期截止时间(领取日期+领取后几天有效的日期)
let date = new Date(detail.cdate * 1000);
if (detail.arule.is_same_day != '1') {
date.setDate(date.getDate() + 1);
date.setTime(date.getTime() + 24 * 60 * 60 * 1000); // 加一天的毫秒数
}
date.setHours(0, 0, 0, 0);
let newTimestamp = Math.floor(date.getTime() / 1000);
... ... @@ -96,7 +96,7 @@ Page({
detail.deadlineDate = detail.etime
} else {
let time = new Date(detail.cdate * 1000);
time.setDate(time.getDate() + parseInt(detail.aexpiration));
time.setTime(time.getTime() + parseInt(detail.aexpiration) * 24 * 60 * 60 * 1000); // 加上有效期天数的毫秒数
time.setHours(23, 59, 0, 0);
let deadlineDate = Math.floor(time.getTime() / 1000);
detail.deadlineDate = deadlineDate
... ... @@ -171,7 +171,7 @@ Page({
list.forEach(item => {
if (item.accumulationShow == "0" || (remaining - item.price < 0 && !item.checked)) {
item.showCpupon = '0';
} else if (item.accumulationShow == "1") {
} else if (item.accumulationShow == "1" && item.canCheck == '1') {
item.showCpupon = '1';
}
})
... ... @@ -316,24 +316,25 @@ Page({
...obj
});
list.forEach(coupon => {
const startUseDate = new Date(currentDate);
let endUseDate = new Date(currentDate);
const couponDate = new Date(coupon.cdate * 1000);
const startUseDate = new Date(couponDate);
const endUseDate = new Date(couponDate);
if (coupon.arule.is_same_day) {
startUseDate.setDate(couponDate.getDate() - 1);
startUseDate.setTime(couponDate.getTime() - 24 * 60 * 60 * 1000); // 前一天
} else {
startUseDate.setDate(couponDate.getDate());
startUseDate.setTime(couponDate.getTime()); // 直接设置为 couponDate 的时间
}
// 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间
if (coupon.aexpiration == '0' || coupon.aexpiration == '') {
let date = new Date(coupon.etime * 1000);
endUseDate = date
endUseDate.setTime(date.getTime());
} else {
endUseDate.setDate(couponDate.getDate() + parseInt(coupon.aexpiration));
endUseDate.setTime(couponDate.getTime() + parseInt(coupon.aexpiration) * 24 * 60 * 60 * 1000); // 加上有效期天数
}
endUseDate.setHours(23, 59, 59, 999);
// 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 券是开启状态
const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1'
const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1';
let selectedValue = true;
let str = true
if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) {
... ... @@ -377,14 +378,14 @@ Page({
coupon.isOk = isUseDate && (availableDate || coupon.exp_date.week_show == '无') ? '1' : '0'; //是否在可用时间内 1可使用 2不可使用
coupon.expirationDate = coupon.deadlineDate;
});
return list
return list;
},
// 最优惠的消费券组合(消费要求为无门槛 或者 满足优惠券使用金额 && 勾选最优的、最早到期的)
findBestCoupons(arr) {
console.log('勾选最优的之前', arr);
let inputValue = this.data.inputValue;
const amount = parseFloat(inputValue);
const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount));
const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount) && amount>=parseFloat(coupon.price));
// 排序后,优先选择最大优惠的券
validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
arr.forEach(item => {
... ... @@ -396,28 +397,28 @@ Page({
let list2 = []; // 最优惠的不可叠加的优惠券
let finalList = []; //最终用的优惠券组合
// 计算可叠加的组合
let remainingValue = amount; // 剩余金额
let totalDiscount = 0; // 总优惠金额
// 尝试组合可叠加的优惠券
validCoupons.forEach(coupon => {
// 可叠加券
if (coupon.accumulationShow == '1') {
const discountAmount = parseFloat(coupon.price);
// 只有在添加优惠券后剩余金额仍大于或等于0时才添加
if (remainingValue - discountAmount >= 0) {
list1.push(coupon);
totalDiscount += discountAmount; // 累加优惠金额
remainingValue -= discountAmount; // 减少应付金额
let maxDiscount = 0;
function backtrack(startIndex, currentCombination, currentDiscount, remainingValue) {
// 如果当前组合的优惠大于最大优惠且剩余金额不小于0,更新最大优惠和最佳组合
if (currentDiscount > maxDiscount && remainingValue >= 0) {
maxDiscount = currentDiscount;
list1 = [...currentCombination];
}
for (let i = startIndex; i < validCoupons.length; i++) {
const coupon = validCoupons[i];
if (coupon.accumulationShow == '1') { // 仅考虑可叠加的优惠券
const discountAmount = parseFloat(coupon.price);
if (remainingValue - discountAmount >= 0) { // 确保剩余金额足够
currentCombination.push(coupon);
backtrack(i + 1, currentCombination, currentDiscount + discountAmount, remainingValue - discountAmount); // 递归时从 i + 1 开始
currentCombination.pop(); // 回溯
}
}
}
});
console.log('可叠加的优惠券组合1:', list1);
// 检查可叠加组合是否有效
if (remainingValue < 0) {
list1 = []; // 如果剩余金额小于0,清空可叠加列表
}
// 重置剩余金额,用于不可叠加的优惠券
remainingValue = amount;
backtrack(0, [], 0, amount); // 开始回溯
console.log('最佳可叠加优惠券组合:', list1);
// 遍历有效优惠券,寻找不可叠加的优惠券
validCoupons.forEach(coupon => {
if (coupon.accumulationShow === '0') {
... ... @@ -439,7 +440,7 @@ Page({
// 计算两个列表的最大优惠值
let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
let maxNonStackableValue = list2.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
// 比较两个最大值并输出结果
if (maxStackableValue > maxNonStackableValue) {
console.log(`可叠加优惠券组合的最大优惠值更高: ${maxStackableValue}`);
... ... @@ -605,11 +606,11 @@ Page({
var curdate = new Date();
var year = curdate.getFullYear();
var month = curdate.getMonth() + 1;
var date = curdate.getDate();
var date = Math.floor((curdate.getTime() % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60 * 24)) + 1; // 计算当前日期
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) {
//在节假日数组内
if ((holidays.indexOf(formattedDate) >= 0) && nWeekend.indexOf(formattedDate) < 0) {
obj.isshow = '1'
} else {
obj.isshow = '0'
... ...