|
...
|
...
|
@@ -73,14 +73,19 @@ Page({ |
|
|
|
this.setData({
|
|
|
|
purePhoneNumber: data.phone,
|
|
|
|
})
|
|
|
|
this.getUserInfo()
|
|
|
|
this.getUserInfo(data.phone)
|
|
|
|
this.getUserRechargeInfo(data.phone)
|
|
|
|
this.getCoupon()
|
|
|
|
} else {
|
|
|
|
this.getUserInfo()
|
|
|
|
this.setData({
|
|
|
|
purePhoneNumber: '',
|
|
|
|
})
|
|
|
|
this.getCoupon()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 查询手机号失败时,先拉取 openid 维度的券兜底
|
|
|
|
this.getCoupon()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
...
|
...
|
@@ -192,11 +197,13 @@ Page({ |
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取用户在商家&所有消费金
|
|
|
|
getUserInfo() {
|
|
|
|
App.Activity.GetConsumeBySeller({
|
|
|
|
getUserInfo(phone) {
|
|
|
|
let params = {
|
|
|
|
openid: getApp().openid,
|
|
|
|
sellerid: this.sid,
|
|
|
|
}).then((json) => {
|
|
|
|
}
|
|
|
|
if(phone) params.phone = phone;
|
|
|
|
App.Activity.GetConsumeBySeller({...params}).then((json) => {
|
|
|
|
if (json.ret == 200) {
|
|
|
|
let data = json.data;
|
|
|
|
if (data && data.length > 0) {
|
|
...
|
...
|
@@ -477,8 +484,10 @@ Page({ |
|
|
|
if (!id) {
|
|
|
|
let price = this.data.actualPrice * 1 * this.data.multiple
|
|
|
|
if (!price) return false
|
|
|
|
let str = this.data.finalList.map(item => item.activity_id).join(',');
|
|
|
|
console.log('核销所勾选的券传参', str);
|
|
|
|
// isinitial为1的券用activity_id传参,isinitial为0的券用phone_activity_id传参
|
|
|
|
let activityIdStr = this.data.finalList.filter(item => item.isinitial == '1').map(item => item.activity_id).join(',');
|
|
|
|
let phoneActivityIdStr = this.data.finalList.filter(item => item.isinitial == '0').map(item => item.phone_activity_id).join(',');
|
|
|
|
console.log('充值所勾选的券传参', activityIdStr, phoneActivityIdStr);
|
|
|
|
let params = {
|
|
|
|
type: '2',
|
|
|
|
types: '4', // 1邀请函 2提前点餐 3商家端app分享 4支付页充值 5我的页面余额充值
|
|
...
|
...
|
@@ -493,8 +502,11 @@ Page({ |
|
|
|
if (this.data.consumeDiscount * 1 > 0 && this.data.consumeSwitch) {
|
|
|
|
params.consume = this.data.consumeDiscount;
|
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
params.activity_id = str;
|
|
|
|
if (activityIdStr) {
|
|
|
|
params.activity_id = activityIdStr;
|
|
|
|
}
|
|
|
|
if (phoneActivityIdStr) {
|
|
|
|
params.phone_activity_id = phoneActivityIdStr;
|
|
|
|
}
|
|
|
|
if (this.data.givePrice) {
|
|
|
|
params.givePrice = this.data.givePrice; //当餐免费送的余额
|
|
...
|
...
|
@@ -533,7 +545,7 @@ Page({ |
|
|
|
this.setData({
|
|
|
|
purePhoneNumber: res.data.phone_info.purePhoneNumber,
|
|
|
|
})
|
|
|
|
this.getUserInfo()
|
|
|
|
this.getUserInfo(res.data.phone_info.purePhoneNumber)
|
|
|
|
this.bindUserPhoneFun(res.data.phone_info.purePhoneNumber)
|
|
|
|
this.getUserRechargeInfo(res.data.phone_info.purePhoneNumber)
|
|
|
|
} else {
|
|
...
|
...
|
@@ -675,108 +687,143 @@ Page({ |
|
|
|
},
|
|
|
|
// 获取所有优惠券列表
|
|
|
|
getCoupon() {
|
|
|
|
let phone = this.data.purePhoneNumber
|
|
|
|
// 1、先通过 openid 获取已领取的券,标记 isinitial:1
|
|
|
|
App.Activity.ActivityListByOpenid({
|
|
|
|
sellerid: this.sid
|
|
|
|
}).then(res => {
|
|
|
|
let openidCouponList = []
|
|
|
|
if (res.ret == 200 && res.data && res.data.length > 0) {
|
|
|
|
let list = res.data
|
|
|
|
list.forEach(detail => {
|
|
|
|
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
detail.arule = detail.arule ? util.determine(detail.arule) : '';
|
|
|
|
detail.expiration_date = detail.expiration_date ? util.determine(detail.expiration_date) : '';
|
|
|
|
detail.aexpiration = detail.aexpiration ? util.determine(detail.aexpiration) : '';
|
|
|
|
if (detail.arule) {
|
|
|
|
detail.accumulationShow = detail.arule.is_accumulation
|
|
|
|
}
|
|
|
|
if (detail.exp_date && detail.exp_date.week_data) {
|
|
|
|
let mor = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
|
|
|
|
let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
|
|
|
|
let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '3').rArr.join('、')
|
|
|
|
if (mor) mor = '早餐:' + mor
|
|
|
|
if (noon) noon = '午餐:' + noon
|
|
|
|
if (nig) nig = '晚餐:' + nig
|
|
|
|
detail.morText = mor;
|
|
|
|
detail.noonText = noon;
|
|
|
|
detail.nigText = nig;
|
|
|
|
}
|
|
|
|
detail.checked = false;
|
|
|
|
detail.showCpupon = '0';
|
|
|
|
// 获取使用券的有效期
|
|
|
|
detail.cdate = detail.cdate * 1;
|
|
|
|
detail.useStime = '';
|
|
|
|
detail.useEtime = '';
|
|
|
|
let condition = detail.aexpiration
|
|
|
|
if (condition.valid_forever === '0' && condition.stime && condition.etime) {
|
|
|
|
detail.useStime = condition.stime;
|
|
|
|
detail.useEtime = condition.etime;
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '1') {
|
|
|
|
detail.foreverText = '永久有效';
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '0' && condition.today) {
|
|
|
|
let obj = this.setTimeRange(detail.cdate, 0, parseInt(condition.today) - 1);
|
|
|
|
detail.useStime = obj.useStime;
|
|
|
|
detail.useEtime = obj.useEtime;
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '0' && condition.tomorrow) {
|
|
|
|
let obj = this.setTimeRange(detail.cdate, 1, condition.tomorrow * 1);
|
|
|
|
detail.useStime = obj.useStime;
|
|
|
|
detail.useEtime = obj.useEtime;
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '0' && condition.sday && condition.eday) {
|
|
|
|
let obj = this.setTimeRange(detail.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
|
|
|
|
detail.useStime = obj.useStime;
|
|
|
|
detail.useEtime = obj.useEtime;
|
|
|
|
}
|
|
|
|
if((detail.useStime>0 && detail.useEtime>0) || condition.valid_forever === '1') {
|
|
|
|
detail.endDateStr = condition.valid_forever == '1' ? '永久有效' : (util.unixtoTime(detail.useStime, 'YYYY-MM-DD') + '至' + util.unixtoTime(detail.useEtime, 'YYYY-MM-DD'));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list = list.filter(item => {
|
|
|
|
return (this.data.dataStr < (item.useEtime * 1) || item.aexpiration.valid_forever == '1');
|
|
|
|
})
|
|
|
|
list.sort((a, b) => {
|
|
|
|
if (a.aexpiration.valid_forever == '1' && b.aexpiration.valid_forever != '1') return 1;
|
|
|
|
if (a.aexpiration.valid_forever != '1' && b.aexpiration.valid_forever == '1') return -1;
|
|
|
|
return (a.useEtime * 1) - (b.useEtime * 1)
|
|
|
|
})
|
|
|
|
let couponArr = list
|
|
|
|
// 相同aid的券合并成一张,用加减号选择张数
|
|
|
|
let couponGroup = {}
|
|
|
|
let couponList = []
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
let key = item.aid ? item.aid : item.activity_id
|
|
|
|
if (couponGroup[key]) {
|
|
|
|
couponGroup[key].num = (couponGroup[key].num * 1) + 1
|
|
|
|
couponGroup[key].activityIds.push(item.activity_id)
|
|
|
|
} else {
|
|
|
|
item.num = 1
|
|
|
|
item.checkedNum = 0
|
|
|
|
item.activityIds = [item.activity_id]
|
|
|
|
couponGroup[key] = item
|
|
|
|
couponList.push(item)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
couponArr = couponList
|
|
|
|
// 单次使用数量限制,0表示不限制,默认0;合并完成后统一计算
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
let useLimit = item.single_use_limit ? (item.single_use_limit * 1) : 0
|
|
|
|
item.maxNum = (useLimit > 0 && useLimit < item.num) ? useLimit : item.num
|
|
|
|
})
|
|
|
|
console.log('couponArr----',couponArr);
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
couponArr
|
|
|
|
openidCouponList = res.data
|
|
|
|
openidCouponList.forEach(item => {
|
|
|
|
item.isinitial = '1'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 未授权手机号时,直接用 openid 获取的券
|
|
|
|
if (!phone) {
|
|
|
|
this.filterCouponList(openidCouponList)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// 2、再通过授权手机号获取的券,标记 isinitial:0
|
|
|
|
App.Activity.GetActivityListByPhone({
|
|
|
|
sellerid: this.sid,
|
|
|
|
phone
|
|
|
|
}).then(res2 => {
|
|
|
|
let phoneCouponList = []
|
|
|
|
if (res2 && res2.ret == 200 && res2.data && res2.data.length > 0) {
|
|
|
|
phoneCouponList = res2.data
|
|
|
|
phoneCouponList.forEach(item => {
|
|
|
|
item.isinitial = '0'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 3、两个数组 concat 合并成所有券后,统一筛选可用的券
|
|
|
|
this.filterCouponList(openidCouponList.concat(phoneCouponList))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 所有券合并后,统一筛选可用的券
|
|
|
|
filterCouponList(list) {
|
|
|
|
if (list.length == 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
list.forEach(detail => {
|
|
|
|
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
detail.arule = detail.arule ? util.determine(detail.arule) : '';
|
|
|
|
detail.expiration_date = detail.expiration_date ? util.determine(detail.expiration_date) : '';
|
|
|
|
detail.aexpiration = detail.aexpiration ? util.determine(detail.aexpiration) : '';
|
|
|
|
if (detail.arule) {
|
|
|
|
detail.accumulationShow = detail.arule.is_accumulation
|
|
|
|
}
|
|
|
|
if (detail.exp_date && detail.exp_date.week_data) {
|
|
|
|
let mor = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
|
|
|
|
let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
|
|
|
|
let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '3').rArr.join('、')
|
|
|
|
if (mor) mor = '早餐:' + mor
|
|
|
|
if (noon) noon = '午餐:' + noon
|
|
|
|
if (nig) nig = '晚餐:' + nig
|
|
|
|
detail.morText = mor;
|
|
|
|
detail.noonText = noon;
|
|
|
|
detail.nigText = nig;
|
|
|
|
}
|
|
|
|
detail.checked = false;
|
|
|
|
detail.showCpupon = '0';
|
|
|
|
// 获取使用券的有效期
|
|
|
|
detail.cdate = detail.cdate * 1;
|
|
|
|
detail.useStime = '';
|
|
|
|
detail.useEtime = '';
|
|
|
|
let condition = detail.aexpiration
|
|
|
|
if (condition.valid_forever === '0' && condition.stime && condition.etime) {
|
|
|
|
detail.useStime = condition.stime;
|
|
|
|
detail.useEtime = condition.etime;
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '1') {
|
|
|
|
detail.foreverText = '永久有效';
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '0' && condition.today) {
|
|
|
|
let obj = this.setTimeRange(detail.cdate, 0, parseInt(condition.today) - 1);
|
|
|
|
detail.useStime = obj.useStime;
|
|
|
|
detail.useEtime = obj.useEtime;
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '0' && condition.tomorrow) {
|
|
|
|
let obj = this.setTimeRange(detail.cdate, 1, condition.tomorrow * 1);
|
|
|
|
detail.useStime = obj.useStime;
|
|
|
|
detail.useEtime = obj.useEtime;
|
|
|
|
}
|
|
|
|
if (condition.valid_forever === '0' && condition.sday && condition.eday) {
|
|
|
|
let obj = this.setTimeRange(detail.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
|
|
|
|
detail.useStime = obj.useStime;
|
|
|
|
detail.useEtime = obj.useEtime;
|
|
|
|
}
|
|
|
|
if((detail.useStime>0 && detail.useEtime>0) || condition.valid_forever === '1') {
|
|
|
|
detail.endDateStr = condition.valid_forever == '1' ? '永久有效' : (util.unixtoTime(detail.useStime, 'YYYY-MM-DD') + '至' + util.unixtoTime(detail.useEtime, 'YYYY-MM-DD'));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list = list.filter(item => {
|
|
|
|
return (this.data.dataStr < (item.useEtime * 1) || item.aexpiration.valid_forever == '1');
|
|
|
|
})
|
|
|
|
list.sort((a, b) => {
|
|
|
|
if (a.aexpiration.valid_forever == '1' && b.aexpiration.valid_forever != '1') return 1;
|
|
|
|
if (a.aexpiration.valid_forever != '1' && b.aexpiration.valid_forever == '1') return -1;
|
|
|
|
return (a.useEtime * 1) - (b.useEtime * 1)
|
|
|
|
})
|
|
|
|
let couponArr = list
|
|
|
|
// 同来源(openid/phone)且相同aid的券合并成一张,用加减号选择张数;不同来源分开
|
|
|
|
let couponGroup = {}
|
|
|
|
let couponList = []
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
// openid券与phone券分开合并:同来源且同aid的券合并成一张,用加减号选择张数
|
|
|
|
let key = (item.isinitial == '0' ? 'p_' : 'o_') + (item.aid ? item.aid : (item.activity_id || item.phone_activity_id))
|
|
|
|
let id = item.activity_id || item.phone_activity_id
|
|
|
|
if (couponGroup[key]) {
|
|
|
|
couponGroup[key].num = (couponGroup[key].num * 1) + 1
|
|
|
|
couponGroup[key].activityIds.push(id)
|
|
|
|
} else {
|
|
|
|
item._key = key
|
|
|
|
item.num = 1
|
|
|
|
item.checkedNum = 0
|
|
|
|
item.activityIds = [id]
|
|
|
|
couponGroup[key] = item
|
|
|
|
couponList.push(item)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
couponArr = couponList
|
|
|
|
// 单次使用数量限制,0表示不限制,默认0;合并完成后统一计算
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
let useLimit = item.single_use_limit ? (item.single_use_limit * 1) : 0
|
|
|
|
item.maxNum = (useLimit > 0 && useLimit < item.num) ? useLimit : item.num
|
|
|
|
})
|
|
|
|
console.log('couponArr----',couponArr);
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
couponArr
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 加减号选择券的张数
|
|
|
|
changeCouponNum(e) {
|
|
|
|
let type = e.currentTarget.dataset.type;
|
|
|
|
let aid = e.currentTarget.dataset.aid;
|
|
|
|
let key = e.currentTarget.dataset.key;
|
|
|
|
const list = this.data.couponArr
|
|
|
|
let item = list.find(i => i.aid == aid)
|
|
|
|
let item = list.find(i => i._key == key)
|
|
|
|
if (!item) return
|
|
|
|
if (type == 'plus') {
|
|
|
|
if (item.canAdd != '1') return
|
|
...
|
...
|
@@ -790,10 +837,10 @@ Page({ |
|
|
|
},
|
|
|
|
// 加减号中间输入框:只允许正整数或0,且不能超过当前可用张数
|
|
|
|
numInputChange(e) {
|
|
|
|
let aid = e.currentTarget.dataset.aid;
|
|
|
|
let key = e.currentTarget.dataset.key;
|
|
|
|
let val = (e.detail.value || '').replace(/[^\d]/g, ''); // 只保留数字
|
|
|
|
const list = this.data.couponArr
|
|
|
|
let item = list.find(i => i.aid == aid)
|
|
|
|
let item = list.find(i => i._key == key)
|
|
|
|
if (!item) return
|
|
|
|
let maxSelect = this.getMaxSelectNum(item)
|
|
|
|
let num = val === '' ? 0 : parseInt(val, 10)
|
|
...
|
...
|
@@ -809,7 +856,7 @@ Page({ |
|
|
|
let descStr = 0
|
|
|
|
let val = 0
|
|
|
|
list.forEach(i => {
|
|
|
|
if (i.checkedNum > 0 && i.aid != item.aid) {
|
|
|
|
if (i.checkedNum > 0 && i._key != item._key) {
|
|
|
|
let d = parseFloat(i.desc) || 0
|
|
|
|
if (d > 0) descStr += d * i.checkedNum
|
|
|
|
val += parseFloat(i.price) * i.checkedNum
|
|
...
|
...
|
@@ -893,7 +940,8 @@ Page({ |
|
|
|
for (let k = 0; k < item.checkedNum; k++) {
|
|
|
|
finalList.push({
|
|
|
|
...item,
|
|
|
|
activity_id: item.activityIds[k]
|
|
|
|
activity_id: item.isinitial == '0' ? '' : item.activityIds[k],
|
|
|
|
phone_activity_id: item.isinitial == '0' ? item.activityIds[k] : (item.phone_activity_id || ''),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -1070,8 +1118,10 @@ Page({ |
|
|
|
wx.showLoading({
|
|
|
|
title: '支付中',
|
|
|
|
})
|
|
|
|
let str = this.data.finalList.map(item => item.activity_id).join(',');
|
|
|
|
console.log('核销所勾选的券传参', str);
|
|
|
|
// isinitial为1的券用activity_id传参,isinitial为0的券用phone_activity_id传参
|
|
|
|
let activityIdStr = this.data.finalList.filter(item => item.isinitial == '1').map(item => item.activity_id).join(',');
|
|
|
|
let phoneActivityIdStr = this.data.finalList.filter(item => item.isinitial == '0').map(item => item.phone_activity_id).join(',');
|
|
|
|
console.log('核销所勾选的券传参', activityIdStr, phoneActivityIdStr);
|
|
|
|
let params = {
|
|
|
|
sellerid: this.data.seller.sid,
|
|
|
|
price: soothPrice,
|
|
...
|
...
|
@@ -1080,8 +1130,11 @@ Page({ |
|
|
|
params.consume = this.data.consumeDiscount;
|
|
|
|
params.phone = this.data.purePhoneNumber;
|
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
params.activity_id = str;
|
|
|
|
if (activityIdStr) {
|
|
|
|
params.activity_id = activityIdStr;
|
|
|
|
}
|
|
|
|
if (phoneActivityIdStr) {
|
|
|
|
params.phone_activity_id = phoneActivityIdStr;
|
|
|
|
}
|
|
|
|
// 用余额支付 || 支付金额为0
|
|
|
|
if (this.data.soothPrice == '0.00') {
|
|
...
|
...
|
@@ -1091,8 +1144,11 @@ Page({ |
|
|
|
price: this.data.inputValue,
|
|
|
|
phone: this.data.purePhoneNumber,
|
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
obj.activity_id = str;
|
|
|
|
if (activityIdStr) {
|
|
|
|
obj.activity_id = activityIdStr;
|
|
|
|
}
|
|
|
|
if (phoneActivityIdStr) {
|
|
|
|
obj.phone_activity_id = phoneActivityIdStr;
|
|
|
|
}
|
|
|
|
let consumeDiscount = this.data.consumeDiscount * 1
|
|
|
|
if (this.data.balancePay * 1 > 0) {
|
|
...
|
...
|
@@ -1124,6 +1180,7 @@ Page({ |
|
|
|
if (this.data.balancePay) {
|
|
|
|
params.recharge_balance = this.data.balancePay;
|
|
|
|
}
|
|
|
|
console.log('params-----',params);
|
|
|
|
App.PayOnline.CombineTransactionsByNewActivity(params).then(res => {
|
|
|
|
console.log('付款信息', res.data);
|
|
|
|
if (res.ret != '200') {
|
|
...
|
...
|
@@ -1204,7 +1261,7 @@ Page({ |
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
payFail() {
|
|
|
|
payFail(isShow) {
|
|
|
|
this.setData({
|
|
|
|
inputValue: '',
|
|
|
|
finalList: [],
|
|
...
|
...
|
@@ -1216,8 +1273,11 @@ Page({ |
|
|
|
payType:'2',
|
|
|
|
soothPrice: '',
|
|
|
|
})
|
|
|
|
this.getCoupon()
|
|
|
|
this.getUserInfo()
|
|
|
|
// onShow触发时不提前拉券,等getCheckUserHavePhone拿到手机号后再拉,避免漏掉手机号维度的券
|
|
|
|
if (!isShow) {
|
|
|
|
this.getCoupon()
|
|
|
|
this.getUserInfo(this.data.purePhoneNumber)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
giftConsumeFun(priceSum, orderid) {
|
|
|
|
let isReturn = this.data.isReturn;
|
|
...
|
...
|
@@ -1251,7 +1311,7 @@ Page({ |
|
|
|
sellerid: this.data.seller.sid
|
|
|
|
}).then(res => {
|
|
|
|
if(type == '1'){
|
|
|
|
this.getUserInfo()
|
|
|
|
this.getUserInfo(this.data.purePhoneNumber)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
...
|
...
|
@@ -1361,11 +1421,13 @@ Page({ |
|
|
|
let consumeDiscount = this.data.consumeDiscount;
|
|
|
|
let inputValue = this.data.inputValue;
|
|
|
|
const amount = parseFloat(inputValue - consumeDiscount);
|
|
|
|
// 券唯一标识:手机号维度券没有 activity_id,用 phone_activity_id 区分,避免不同券互相误匹配
|
|
|
|
const couponKey = coupon => (coupon.isinitial == '0' ? 'p_' + coupon.phone_activity_id : 'o_' + coupon.activity_id);
|
|
|
|
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 => {
|
|
|
|
const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
|
|
|
|
const isValid = validCoupons.some(validCoupon => couponKey(validCoupon) == couponKey(item));
|
|
|
|
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
|
|
|
|
});
|
|
|
|
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
|
|
...
|
...
|
@@ -1399,12 +1461,12 @@ Page({ |
|
|
|
let maxCopies = Math.floor((amount - thresholdDescSum) / couponDesc)
|
|
|
|
if (maxCopies > coupon.maxNum) maxCopies = coupon.maxNum
|
|
|
|
if (maxCopies > 0) {
|
|
|
|
selectCount[coupon.aid] = maxCopies
|
|
|
|
selectCount[coupon._key] = maxCopies
|
|
|
|
thresholdDescSum += couponDesc * maxCopies
|
|
|
|
maxThresholdValue += couponPrice * maxCopies
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list1 = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
list1 = stackingCoupons.filter(i => (selectCount[i._key] || 0) > 0)
|
|
|
|
console.log('可叠加优惠券组合', list1);
|
|
|
|
// 3. 无门槛可叠加券:满减门槛之和小于输入金额时可以叠加,等于时和满减组合取优惠更大的
|
|
|
|
// 先算无门槛券单独使用的优惠总额
|
|
...
|
...
|
@@ -1417,7 +1479,7 @@ Page({ |
|
|
|
let num = Math.floor((amount - noDescValue) / couponPrice)
|
|
|
|
if (num > coupon.maxNum) num = coupon.maxNum
|
|
|
|
if (num > 0) {
|
|
|
|
noDescCount[coupon.aid] = num
|
|
|
|
noDescCount[coupon._key] = num
|
|
|
|
noDescValue += couponPrice * num
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -1432,21 +1494,21 @@ Page({ |
|
|
|
let num = Math.floor((amount - maxStackableValue) / couponPrice)
|
|
|
|
if (num > coupon.maxNum) num = coupon.maxNum
|
|
|
|
if (num > 0) {
|
|
|
|
selectCount[coupon.aid] = num
|
|
|
|
selectCount[coupon._key] = num
|
|
|
|
maxStackableValue += couponPrice * num
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
list1 = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
list1 = stackingCoupons.filter(i => (selectCount[i._key] || 0) > 0)
|
|
|
|
} else if (noDescValue > maxThresholdValue) {
|
|
|
|
// 门槛等于输入金额,不能叠加,取无门槛券或满减券中优惠更大的
|
|
|
|
list1 = stackingCoupons.filter(i => (noDescCount[i.aid] || 0) > 0)
|
|
|
|
list1 = stackingCoupons.filter(i => (noDescCount[i._key] || 0) > 0)
|
|
|
|
selectCount = noDescCount
|
|
|
|
maxStackableValue = noDescValue
|
|
|
|
} else if (noDescValue == maxThresholdValue && noDescValue > 0) {
|
|
|
|
// 优惠相同取最早到期
|
|
|
|
let listThreshold = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
let listNoDesc = stackingCoupons.filter(i => (noDescCount[i.aid] || 0) > 0)
|
|
|
|
let listThreshold = stackingCoupons.filter(i => (selectCount[i._key] || 0) > 0)
|
|
|
|
let listNoDesc = stackingCoupons.filter(i => (noDescCount[i._key] || 0) > 0)
|
|
|
|
let min1 = listThreshold.length > 0 ? Math.min(...listThreshold.map(item => item.useEtime)) : Infinity
|
|
|
|
let min2 = listNoDesc.length > 0 ? Math.min(...listNoDesc.map(item => item.useEtime)) : Infinity
|
|
|
|
if (min2 < min1) {
|
|
...
|
...
|
@@ -1500,11 +1562,11 @@ Page({ |
|
|
|
let discountPrice = 0;
|
|
|
|
// 更新选中的优惠券
|
|
|
|
finalList.forEach(coupon => {
|
|
|
|
let target = arr.findIndex(obj => obj.activity_id === coupon.activity_id);
|
|
|
|
let target = arr.findIndex(obj => couponKey(obj) === couponKey(coupon));
|
|
|
|
if (target>-1) {
|
|
|
|
arr[target].showCpupon = 1;
|
|
|
|
arr[target].checkedNum = stackCount[coupon.aid] || 1;
|
|
|
|
discountPrice += parseFloat(coupon.price) * (stackCount[coupon.aid] || 1); // 使用 parseFloat 确保类型正确
|
|
|
|
arr[target].checkedNum = stackCount[coupon._key] || 1;
|
|
|
|
discountPrice += parseFloat(coupon.price) * (stackCount[coupon._key] || 1); // 使用 parseFloat 确保类型正确
|
|
|
|
}
|
|
|
|
console.log('选中的券', {
|
|
|
|
...coupon
|
|
...
|
...
|
@@ -1517,7 +1579,8 @@ Page({ |
|
|
|
for (let k = 0; k < item.checkedNum; k++) {
|
|
|
|
finalList.push({
|
|
|
|
...item,
|
|
|
|
activity_id: item.activityIds[k]
|
|
|
|
activity_id: item.isinitial == '0' ? '' : item.activityIds[k],
|
|
|
|
phone_activity_id: item.isinitial == '0' ? item.activityIds[k] : (item.phone_activity_id || ''),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
...
|
...
|
@@ -1842,7 +1905,7 @@ Page({ |
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
this.payFail()
|
|
|
|
this.payFail(true)
|
|
|
|
this.getCheckUserHavePhone()
|
|
|
|
this.getFreeMealConfigFun()
|
|
|
|
},
|
...
|
...
|
|