|
...
|
...
|
@@ -16,15 +16,18 @@ Page({ |
|
|
|
actualPrice: '', //实付价格
|
|
|
|
inputValue: '', //输入的金额
|
|
|
|
canSolt: {}, //当前时间是哪个餐段、节假日
|
|
|
|
totalPrice: '', //送券的总金额
|
|
|
|
},
|
|
|
|
sid: '', //扫码进入带的参数商家id
|
|
|
|
couponModal: '',
|
|
|
|
giveCouponModal: '',
|
|
|
|
myToast:'',
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad(options) {
|
|
|
|
this.couponModal = this.selectComponent("#couponModal");
|
|
|
|
this.giveCouponModal = this.selectComponent("#giveCouponModal");
|
|
|
|
if (options.sid) {
|
|
|
|
this.sid = options.sid
|
|
|
|
this.getSellerDetailFun(options.sid)
|
|
...
|
...
|
@@ -38,6 +41,15 @@ Page({ |
|
|
|
closeCouponModal() {
|
|
|
|
this.couponModal.closeModal()
|
|
|
|
},
|
|
|
|
// 打开优惠券弹框
|
|
|
|
showgiveCouponModal() {
|
|
|
|
this.giveCouponModal.showModal()
|
|
|
|
},
|
|
|
|
// 关闭优惠券弹框
|
|
|
|
closegiveCouponModal() {
|
|
|
|
this.giveCouponModal.closeModal()
|
|
|
|
wx.exitMiniProgram({})
|
|
|
|
},
|
|
|
|
// 获取店铺名称
|
|
|
|
getSellerDetailFun(sid) {
|
|
|
|
App.Customer.GetSellerDetail({
|
|
...
|
...
|
@@ -55,6 +67,114 @@ Page({ |
|
|
|
this.getSellerDailyFun(data.daily)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 赠送券
|
|
|
|
giftCouponsFun(priceSum) {
|
|
|
|
App.Activity.GetActivityConfig({
|
|
|
|
sellerid: this.data.seller.sid,
|
|
|
|
}).then(res => {
|
|
|
|
if (res.ret == 200) {
|
|
|
|
let data = res.data;
|
|
|
|
priceSum = parseFloat(priceSum)
|
|
|
|
// 满减
|
|
|
|
if (data.full_reduction && data.full_reduction == '1') {
|
|
|
|
let fullData = data.full_reduction_data ? util.determine(data.full_reduction_data) : ''
|
|
|
|
let coupons = fullData.coupons ? util.determine(fullData.coupons) : '';
|
|
|
|
const now = Math.floor(Date.now() / 1000);
|
|
|
|
// 在送券活动开始的有效期之内
|
|
|
|
if (now >= parseInt(fullData.stime) && now <= parseInt(fullData.etime)) {
|
|
|
|
// rule 1每满门槛均发放(满50送一张券,金额是100送2张)
|
|
|
|
// rule 0仅发放一次(每次满足金额一个券只发一张)
|
|
|
|
if (fullData.rule == '1') {
|
|
|
|
const price = parseFloat(fullData.price)
|
|
|
|
const amount = parseInt(priceSum / price)
|
|
|
|
if (coupons.length > 0) this.getCouponFun(coupons, '1', amount)
|
|
|
|
} else {
|
|
|
|
if (coupons.length > 0) this.getCouponFun(coupons, '1', 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 阶梯
|
|
|
|
if (data.stairs && data.stairs == '1') {
|
|
|
|
let stairsData = data.stairs_data ? util.determine(data.stairs_data) : ''
|
|
|
|
let ladder_data = stairsData.ladder_data ? util.determine(stairsData.ladder_data) : '';
|
|
|
|
const now = Math.floor(Date.now() / 1000);
|
|
|
|
// 在送券活动开始的有效期之内
|
|
|
|
if (now >= parseInt(stairsData.stime) && now <= parseInt(stairsData.etime)) {
|
|
|
|
let obj = this.findObjectByNum(ladder_data, priceSum)
|
|
|
|
if (obj && obj.coupons) {
|
|
|
|
let coupons = obj.coupons ? util.determine(obj.coupons) : '';
|
|
|
|
this.getCouponFun(coupons, '2', '1')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getCouponFun(coupons, type, amount) {
|
|
|
|
console.log('送的券coupons---', coupons, type, amount);
|
|
|
|
let str = coupons.map(item => item.id).join(',');
|
|
|
|
App.Activity.GetActivityById({
|
|
|
|
id: str,
|
|
|
|
}).then(res => {
|
|
|
|
if (res.ret == 200) {
|
|
|
|
let list = res.data;
|
|
|
|
let couponArr = [];
|
|
|
|
list.forEach(item => {
|
|
|
|
// 如果送券的数量大于剩余券的数量,设置送券的数量=剩余券的数量
|
|
|
|
if (type == '1' && amount > item.grant_last && item.grant_last > 0) {
|
|
|
|
item.amountA = item.grant_last
|
|
|
|
} else {
|
|
|
|
item.amountA = amount
|
|
|
|
}
|
|
|
|
// 只留下开启状态 && 在券的有效期内 && 可领取数量大于0的
|
|
|
|
if (item.is_open == '1' && this.data.dataStr < item.etime * 1 && ((type == '1' && item.grant_last >= item.amountA) || (type == '2' && item.grant_last > 0))) {
|
|
|
|
console.log('可领取的券', item.aname, {
|
|
|
|
...item
|
|
|
|
});
|
|
|
|
couponArr.push({
|
|
|
|
...item
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (couponArr.length > 0) {
|
|
|
|
let result = [];
|
|
|
|
let ids = '';
|
|
|
|
let totalPrice = 0;
|
|
|
|
if (amount) {
|
|
|
|
couponArr.forEach(item => {
|
|
|
|
for (let i = 0; i < item.amountA; i++) {
|
|
|
|
result.push(item.id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ids = result.join(",")
|
|
|
|
} else {
|
|
|
|
ids = coupons.map(item => item.id).join(',')
|
|
|
|
}
|
|
|
|
totalPrice = couponArr.reduce((sum, item) => sum + item.price * item.amountA, 0);
|
|
|
|
this.setData({
|
|
|
|
totalPrice,
|
|
|
|
})
|
|
|
|
this.showgiveCouponModal()
|
|
|
|
this.setcouponFun(ids)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
setcouponFun(str) {
|
|
|
|
console.log('领取券方法ids---', str);
|
|
|
|
App.Activity.SetActivityAsReserve({
|
|
|
|
aid: str,
|
|
|
|
}).then((json) => {
|
|
|
|
if (json.ret != 200) {
|
|
|
|
wx.showToast({
|
|
|
|
title: res.msg,
|
|
|
|
duration: 2000,
|
|
|
|
mask: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取所有优惠券列表
|
|
|
|
getCoupon() {
|
|
|
|
App.Activity.ActivityListByOpenid({
|
|
...
|
...
|
@@ -276,6 +396,7 @@ Page({ |
|
|
|
paySign: res.data.paySign,
|
|
|
|
success(ress) {
|
|
|
|
if (ress.errMsg == 'requestPayment:ok') {
|
|
|
|
that.giftCouponsFun(actualPrice) //送券
|
|
|
|
that.setData({
|
|
|
|
inputValue: '',
|
|
|
|
finalList: [],
|
|
...
|
...
|
@@ -285,7 +406,7 @@ Page({ |
|
|
|
})
|
|
|
|
that.getCoupon()
|
|
|
|
console.log('支付成功', ress);
|
|
|
|
return that.myToast.showToast('支付成功', 2000)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log('支付失败', ress);
|
|
|
|
return that.myToast.showToast('支付失败,请重新下单', 2000)
|
|
...
|
...
|
@@ -338,7 +459,7 @@ Page({ |
|
|
|
} else {
|
|
|
|
startUseDate.setTime(couponDate.getTime()); // 直接设置为 couponDate 的时间
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间
|
|
|
|
if (coupon.aexpiration == '0' || coupon.aexpiration == '') {
|
|
|
|
let date = new Date(coupon.etime * 1000);
|
|
...
|
...
|
@@ -416,7 +537,7 @@ Page({ |
|
|
|
// }else{
|
|
|
|
// yxDesc+=parseFloat(cur.desc)
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// pre+=parseFloat(cur.price)
|
|
|
|
// yxArr.push(cur)
|
|
|
|
// }
|
|
...
|
...
|
@@ -454,10 +575,10 @@ Page({ |
|
|
|
currentCombination.pop(); // 回溯
|
|
|
|
couponCount[obj.aid]--; // 回溯时减少使用次数
|
|
|
|
}
|
|
|
|
// 提前退出:如果当前和加上当前数字已经小于输入值,后续的数字也会更小
|
|
|
|
if (currentSum*1 + obj.price*1 < amount) break;
|
|
|
|
// 提前退出:如果当前和加上当前数字已经小于输入值,后续的数字也会更小
|
|
|
|
if (currentSum*1 + obj.price*1 < amount) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const couponCount = {};
|
|
...
|
...
|
@@ -482,7 +603,7 @@ Page({ |
|
|
|
console.log('不可叠加的优惠券', list2);
|
|
|
|
// 计算两个列表的最大优惠值
|
|
|
|
let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
|
|
|
|
|
|
|
|
|
|
|
|
// 比较两个最大值并输出结果
|
|
|
|
if (maxStackableValue > maxNonStackableValue) {
|
|
|
|
finalList = list1
|
|
...
|
...
|
@@ -707,7 +828,7 @@ Page({ |
|
|
|
solt: 2,
|
|
|
|
can: '午餐'
|
|
|
|
};
|
|
|
|
} else if (currentTimestamp > timeA2) { //在午餐/晚餐截止时间之后
|
|
|
|
} else if (currentTimestamp > timeA2) { //在午餐/晚餐截止时间之后
|
|
|
|
return obj2.solt == 2 ? {
|
|
|
|
solt: 2,
|
|
|
|
can: '午餐'
|
|
...
|
...
|
@@ -734,7 +855,7 @@ Page({ |
|
|
|
solt: 2,
|
|
|
|
can: '午餐'
|
|
|
|
}
|
|
|
|
} else if (currentTimestamp > time3 && currentTimestamp < time4) { //在午餐截止时间之后 && 晚餐开始时间之前
|
|
|
|
} else if (currentTimestamp > time3 && currentTimestamp < time4) { //在午餐截止时间之后 && 晚餐开始时间之前
|
|
|
|
return {
|
|
|
|
solt: 2,
|
|
|
|
can: '午餐'
|
|
...
|
...
|
@@ -747,6 +868,25 @@ Page({ |
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 获取当前应该赠送的阶梯券
|
|
|
|
findObjectByNum(arr, num) {
|
|
|
|
let result = {};
|
|
|
|
let maxPrice = -Infinity;
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
const price = parseInt(arr[i].price, 10);
|
|
|
|
if (price <= num && price > maxPrice) {
|
|
|
|
maxPrice = price;
|
|
|
|
result = arr[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
// 跳转到我的券列表
|
|
|
|
certificate() {
|
|
|
|
wx.reLaunch({
|
|
|
|
url: '/pages/me/coupon_news'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
...
|
...
|
|