Commit bb62d8feb823d4cda027b8be860afd96f45e142f

Authored by pengye
1 parent 60c70216

付款页支付满额赠送券

... ... @@ -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'
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
... ...
... ... @@ -64,4 +64,16 @@
</checkbox-group>
</scroll-view>
</view>
</my-modal>
<my-modal id="giveCouponModal" fadeStyle="slideUp" height="240px">
<view slot="modalName" class="titleModal ">
<image bindtap="closegiveCouponModal" class="closeImg" src="https://qn.colorcun.com/closeOutline.png" mode=""/>
<view class="nameInfo">{{seller.sellername}}</view>
<view class="couponTotal">赠送给您<text>{{totalPrice}}元</text>代金券</view>
</view>
<view slot="modalContent">
<view class="couponInfo font24r">您到店扫码支付即可自动使用</view>
<view bindtap="closegiveCouponModal" class="couponBtn font36r">我知道了</view>
<view class="couponText font24r" bindtap="certificate">点击查看详情</view>
</view>
</my-modal>
\ No newline at end of file
... ...
... ... @@ -261,4 +261,82 @@ checkbox::before {
.couponNo .bottomTitle,
.couponNo .bottom {
color: #999;
}
#giveCouponModal .titleModal {
margin-top: 65%;
position: relative;
flex-direction: column;
border-bottom: none;
}
#giveCouponModal .mymodal {
background: rgba(0, 0, 0, 0.8);
width: 100% !important;
top: 0 !important;
height: auto !important;
z-index: 300;
}
.nameInfo {
font-family: PingFang SC;
font-weight: 600;
font-size: 52rpx;
line-height: 56rpx;
color: #fff;
margin-bottom: 150rpx;
padding-top: 60rpx;
}
.couponTotal {
color: #dfdfdf;
font-family: PingFang SC;
font-weight: 400;
font-size: 40rpx;
line-height: 48rpx;
margin-bottom: 40rpx;
display: flex;
align-items: center;
justify-content: center;
}
.couponTotal text {
color: #ffc806;
font-weight: 600;
font-size: 100rpx;
margin: 0 14rpx;
}
.couponBtn {
width: 80%;
margin: 0 auto;
border-radius: 42rpx;
background: linear-gradient(90.98deg, #f41919 0.25%, #ff7426 120.07%);
font-weight: 400;
color: #fff;
text-align: center;
border: 4rpx solid #fff;
padding: 12rpx 0;
margin: 16rpx auto 20rpx auto;
}
.couponText {
color: #fff;
text-decoration: underline;
text-align: center;
}
.couponInfo {
text-decoration: none;
margin-bottom: 30rpx;
color: #DFDFDF;
text-align: center;
}
.closeImg {
width: 60rpx;
height: 60rpx;
position: absolute;
right: 0;
top: 0;
}
\ No newline at end of file
... ...
... ... @@ -784,4 +784,12 @@ export default {
openid:'openid',
cachetime: 0,
},
//获取商家券赠送规则配置
'App.Activity.GetActivityConfig':{
alias:'App.Activity.GetActivityConfig',
openid:'openid',
cachetime: 0,
},
}
\ No newline at end of file
... ...