Commit 3e48468d59f000bf15b6ec1e4e2f516ec4dc6e82
1 parent
010f85ad
付款页setDate、getDate不支持,替换成getTime、setTime方法
Showing
1 changed file
with
37 additions
and
36 deletions
| @@ -63,7 +63,7 @@ Page({ | @@ -63,7 +63,7 @@ Page({ | ||
| 63 | if (res.ret == 200 && res.data && res.data.length > 0) { | 63 | if (res.ret == 200 && res.data && res.data.length > 0) { |
| 64 | let list = res.data | 64 | let list = res.data |
| 65 | // console.log('listlistlist',JSON.stringify(list)); | 65 | // console.log('listlistlist',JSON.stringify(list)); |
| 66 | - // list= monidata | 66 | + // list= list.concat(monidata) |
| 67 | list.forEach(detail => { | 67 | list.forEach(detail => { |
| 68 | detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : ''; | 68 | detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : ''; |
| 69 | detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : ''; | 69 | detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : ''; |
| @@ -85,7 +85,7 @@ Page({ | @@ -85,7 +85,7 @@ Page({ | ||
| 85 | let edateText = ''; //有效期截止时间(领取日期+领取后几天有效的日期) | 85 | let edateText = ''; //有效期截止时间(领取日期+领取后几天有效的日期) |
| 86 | let date = new Date(detail.cdate * 1000); | 86 | let date = new Date(detail.cdate * 1000); |
| 87 | if (detail.arule.is_same_day != '1') { | 87 | if (detail.arule.is_same_day != '1') { |
| 88 | - date.setDate(date.getDate() + 1); | 88 | + date.setTime(date.getTime() + 24 * 60 * 60 * 1000); // 加一天的毫秒数 |
| 89 | } | 89 | } |
| 90 | date.setHours(0, 0, 0, 0); | 90 | date.setHours(0, 0, 0, 0); |
| 91 | let newTimestamp = Math.floor(date.getTime() / 1000); | 91 | let newTimestamp = Math.floor(date.getTime() / 1000); |
| @@ -96,7 +96,7 @@ Page({ | @@ -96,7 +96,7 @@ Page({ | ||
| 96 | detail.deadlineDate = detail.etime | 96 | detail.deadlineDate = detail.etime |
| 97 | } else { | 97 | } else { |
| 98 | let time = new Date(detail.cdate * 1000); | 98 | let time = new Date(detail.cdate * 1000); |
| 99 | - time.setDate(time.getDate() + parseInt(detail.aexpiration)); | 99 | + time.setTime(time.getTime() + parseInt(detail.aexpiration) * 24 * 60 * 60 * 1000); // 加上有效期天数的毫秒数 |
| 100 | time.setHours(23, 59, 0, 0); | 100 | time.setHours(23, 59, 0, 0); |
| 101 | let deadlineDate = Math.floor(time.getTime() / 1000); | 101 | let deadlineDate = Math.floor(time.getTime() / 1000); |
| 102 | detail.deadlineDate = deadlineDate | 102 | detail.deadlineDate = deadlineDate |
| @@ -171,7 +171,7 @@ Page({ | @@ -171,7 +171,7 @@ Page({ | ||
| 171 | list.forEach(item => { | 171 | list.forEach(item => { |
| 172 | if (item.accumulationShow == "0" || (remaining - item.price < 0 && !item.checked)) { | 172 | if (item.accumulationShow == "0" || (remaining - item.price < 0 && !item.checked)) { |
| 173 | item.showCpupon = '0'; | 173 | item.showCpupon = '0'; |
| 174 | - } else if (item.accumulationShow == "1") { | 174 | + } else if (item.accumulationShow == "1" && item.canCheck == '1') { |
| 175 | item.showCpupon = '1'; | 175 | item.showCpupon = '1'; |
| 176 | } | 176 | } |
| 177 | }) | 177 | }) |
| @@ -316,24 +316,25 @@ Page({ | @@ -316,24 +316,25 @@ Page({ | ||
| 316 | ...obj | 316 | ...obj |
| 317 | }); | 317 | }); |
| 318 | list.forEach(coupon => { | 318 | list.forEach(coupon => { |
| 319 | - const startUseDate = new Date(currentDate); | ||
| 320 | - let endUseDate = new Date(currentDate); | ||
| 321 | const couponDate = new Date(coupon.cdate * 1000); | 319 | const couponDate = new Date(coupon.cdate * 1000); |
| 320 | + const startUseDate = new Date(couponDate); | ||
| 321 | + const endUseDate = new Date(couponDate); | ||
| 322 | if (coupon.arule.is_same_day) { | 322 | if (coupon.arule.is_same_day) { |
| 323 | - startUseDate.setDate(couponDate.getDate() - 1); | 323 | + startUseDate.setTime(couponDate.getTime() - 24 * 60 * 60 * 1000); // 前一天 |
| 324 | } else { | 324 | } else { |
| 325 | - startUseDate.setDate(couponDate.getDate()); | 325 | + startUseDate.setTime(couponDate.getTime()); // 直接设置为 couponDate 的时间 |
| 326 | } | 326 | } |
| 327 | + | ||
| 327 | // 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间 | 328 | // 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间 |
| 328 | if (coupon.aexpiration == '0' || coupon.aexpiration == '') { | 329 | if (coupon.aexpiration == '0' || coupon.aexpiration == '') { |
| 329 | let date = new Date(coupon.etime * 1000); | 330 | let date = new Date(coupon.etime * 1000); |
| 330 | - endUseDate = date | 331 | + endUseDate.setTime(date.getTime()); |
| 331 | } else { | 332 | } else { |
| 332 | - endUseDate.setDate(couponDate.getDate() + parseInt(coupon.aexpiration)); | 333 | + endUseDate.setTime(couponDate.getTime() + parseInt(coupon.aexpiration) * 24 * 60 * 60 * 1000); // 加上有效期天数 |
| 333 | } | 334 | } |
| 334 | endUseDate.setHours(23, 59, 59, 999); | 335 | endUseDate.setHours(23, 59, 59, 999); |
| 335 | // 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 券是开启状态 | 336 | // 今天不是领取当日,但在有效天数内 && 今天是领取当日且可用 && 券是开启状态 |
| 336 | - const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1' | 337 | + const isUseDate = (currentDate > startUseDate && currentDate < endUseDate) && coupon.is_open == '1'; |
| 337 | let selectedValue = true; | 338 | let selectedValue = true; |
| 338 | let str = true | 339 | let str = true |
| 339 | if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) { | 340 | if (coupon.exp_date && coupon.exp_date.week_data && coupon.exp_date.week_data.length > 0) { |
| @@ -377,14 +378,14 @@ Page({ | @@ -377,14 +378,14 @@ Page({ | ||
| 377 | coupon.isOk = isUseDate && (availableDate || coupon.exp_date.week_show == '无') ? '1' : '0'; //是否在可用时间内 1可使用 2不可使用 | 378 | coupon.isOk = isUseDate && (availableDate || coupon.exp_date.week_show == '无') ? '1' : '0'; //是否在可用时间内 1可使用 2不可使用 |
| 378 | coupon.expirationDate = coupon.deadlineDate; | 379 | coupon.expirationDate = coupon.deadlineDate; |
| 379 | }); | 380 | }); |
| 380 | - return list | 381 | + return list; |
| 381 | }, | 382 | }, |
| 382 | // 最优惠的消费券组合(消费要求为无门槛 或者 满足优惠券使用金额 && 勾选最优的、最早到期的) | 383 | // 最优惠的消费券组合(消费要求为无门槛 或者 满足优惠券使用金额 && 勾选最优的、最早到期的) |
| 383 | findBestCoupons(arr) { | 384 | findBestCoupons(arr) { |
| 384 | console.log('勾选最优的之前', arr); | 385 | console.log('勾选最优的之前', arr); |
| 385 | let inputValue = this.data.inputValue; | 386 | let inputValue = this.data.inputValue; |
| 386 | const amount = parseFloat(inputValue); | 387 | const amount = parseFloat(inputValue); |
| 387 | - const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount)); | 388 | + const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount) && amount>=parseFloat(coupon.price)); |
| 388 | // 排序后,优先选择最大优惠的券 | 389 | // 排序后,优先选择最大优惠的券 |
| 389 | validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price)); | 390 | validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price)); |
| 390 | arr.forEach(item => { | 391 | arr.forEach(item => { |
| @@ -396,28 +397,28 @@ Page({ | @@ -396,28 +397,28 @@ Page({ | ||
| 396 | let list2 = []; // 最优惠的不可叠加的优惠券 | 397 | let list2 = []; // 最优惠的不可叠加的优惠券 |
| 397 | let finalList = []; //最终用的优惠券组合 | 398 | let finalList = []; //最终用的优惠券组合 |
| 398 | // 计算可叠加的组合 | 399 | // 计算可叠加的组合 |
| 399 | - let remainingValue = amount; // 剩余金额 | ||
| 400 | - let totalDiscount = 0; // 总优惠金额 | ||
| 401 | - // 尝试组合可叠加的优惠券 | ||
| 402 | - validCoupons.forEach(coupon => { | ||
| 403 | - // 可叠加券 | ||
| 404 | - if (coupon.accumulationShow == '1') { | ||
| 405 | - const discountAmount = parseFloat(coupon.price); | ||
| 406 | - // 只有在添加优惠券后剩余金额仍大于或等于0时才添加 | ||
| 407 | - if (remainingValue - discountAmount >= 0) { | ||
| 408 | - list1.push(coupon); | ||
| 409 | - totalDiscount += discountAmount; // 累加优惠金额 | ||
| 410 | - remainingValue -= discountAmount; // 减少应付金额 | 400 | + let maxDiscount = 0; |
| 401 | + | ||
| 402 | + function backtrack(startIndex, currentCombination, currentDiscount, remainingValue) { | ||
| 403 | + // 如果当前组合的优惠大于最大优惠且剩余金额不小于0,更新最大优惠和最佳组合 | ||
| 404 | + if (currentDiscount > maxDiscount && remainingValue >= 0) { | ||
| 405 | + maxDiscount = currentDiscount; | ||
| 406 | + list1 = [...currentCombination]; | ||
| 407 | + } | ||
| 408 | + for (let i = startIndex; i < validCoupons.length; i++) { | ||
| 409 | + const coupon = validCoupons[i]; | ||
| 410 | + if (coupon.accumulationShow == '1') { // 仅考虑可叠加的优惠券 | ||
| 411 | + const discountAmount = parseFloat(coupon.price); | ||
| 412 | + if (remainingValue - discountAmount >= 0) { // 确保剩余金额足够 | ||
| 413 | + currentCombination.push(coupon); | ||
| 414 | + backtrack(i + 1, currentCombination, currentDiscount + discountAmount, remainingValue - discountAmount); // 递归时从 i + 1 开始 | ||
| 415 | + currentCombination.pop(); // 回溯 | ||
| 416 | + } | ||
| 411 | } | 417 | } |
| 412 | } | 418 | } |
| 413 | - }); | ||
| 414 | - console.log('可叠加的优惠券组合1:', list1); | ||
| 415 | - // 检查可叠加组合是否有效 | ||
| 416 | - if (remainingValue < 0) { | ||
| 417 | - list1 = []; // 如果剩余金额小于0,清空可叠加列表 | ||
| 418 | } | 419 | } |
| 419 | - // 重置剩余金额,用于不可叠加的优惠券 | ||
| 420 | - remainingValue = amount; | 420 | + backtrack(0, [], 0, amount); // 开始回溯 |
| 421 | + console.log('最佳可叠加优惠券组合:', list1); | ||
| 421 | // 遍历有效优惠券,寻找不可叠加的优惠券 | 422 | // 遍历有效优惠券,寻找不可叠加的优惠券 |
| 422 | validCoupons.forEach(coupon => { | 423 | validCoupons.forEach(coupon => { |
| 423 | if (coupon.accumulationShow === '0') { | 424 | if (coupon.accumulationShow === '0') { |
| @@ -439,7 +440,7 @@ Page({ | @@ -439,7 +440,7 @@ Page({ | ||
| 439 | // 计算两个列表的最大优惠值 | 440 | // 计算两个列表的最大优惠值 |
| 440 | let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0); | 441 | let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0); |
| 441 | let maxNonStackableValue = list2.reduce((total, coupon) => total + parseFloat(coupon.price), 0); | 442 | let maxNonStackableValue = list2.reduce((total, coupon) => total + parseFloat(coupon.price), 0); |
| 442 | - | 443 | + |
| 443 | // 比较两个最大值并输出结果 | 444 | // 比较两个最大值并输出结果 |
| 444 | if (maxStackableValue > maxNonStackableValue) { | 445 | if (maxStackableValue > maxNonStackableValue) { |
| 445 | console.log(`可叠加优惠券组合的最大优惠值更高: ${maxStackableValue}`); | 446 | console.log(`可叠加优惠券组合的最大优惠值更高: ${maxStackableValue}`); |
| @@ -605,11 +606,11 @@ Page({ | @@ -605,11 +606,11 @@ Page({ | ||
| 605 | var curdate = new Date(); | 606 | var curdate = new Date(); |
| 606 | var year = curdate.getFullYear(); | 607 | var year = curdate.getFullYear(); |
| 607 | var month = curdate.getMonth() + 1; | 608 | var month = curdate.getMonth() + 1; |
| 608 | - var date = curdate.getDate(); | 609 | + var date = Math.floor((curdate.getTime() % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60 * 24)) + 1; // 计算当前日期 |
| 609 | var formattedDate = year + "-" + month + "-" + date; | 610 | var formattedDate = year + "-" + month + "-" + date; |
| 610 | obj.isshow = '0' | 611 | obj.isshow = '0' |
| 611 | - //该日期同时满足2个条件即为节假日:1.在节假日数组内或在周末. 2.不在周末上班日期数组 | ||
| 612 | - if ((holidays.indexOf(formattedDate) >= 0 || (curdate.getDay() == 0 || curdate.getDay() == 6)) && nWeekend.indexOf(formattedDate) < 0) { | 612 | + //在节假日数组内 |
| 613 | + if ((holidays.indexOf(formattedDate) >= 0) && nWeekend.indexOf(formattedDate) < 0) { | ||
| 613 | obj.isshow = '1' | 614 | obj.isshow = '1' |
| 614 | } else { | 615 | } else { |
| 615 | obj.isshow = '0' | 616 | obj.isshow = '0' |
-
Please register or login to post a comment