Commit bb62d8feb823d4cda027b8be860afd96f45e142f

Authored by pengye
1 parent 60c70216

付款页支付满额赠送券

@@ -16,15 +16,18 @@ Page({ @@ -16,15 +16,18 @@ Page({
16 actualPrice: '', //实付价格 16 actualPrice: '', //实付价格
17 inputValue: '', //输入的金额 17 inputValue: '', //输入的金额
18 canSolt: {}, //当前时间是哪个餐段、节假日 18 canSolt: {}, //当前时间是哪个餐段、节假日
  19 + totalPrice: '', //送券的总金额
19 }, 20 },
20 sid: '', //扫码进入带的参数商家id 21 sid: '', //扫码进入带的参数商家id
21 couponModal: '', 22 couponModal: '',
  23 + giveCouponModal: '',
22 myToast:'', 24 myToast:'',
23 /** 25 /**
24 * 生命周期函数--监听页面加载 26 * 生命周期函数--监听页面加载
25 */ 27 */
26 onLoad(options) { 28 onLoad(options) {
27 this.couponModal = this.selectComponent("#couponModal"); 29 this.couponModal = this.selectComponent("#couponModal");
  30 + this.giveCouponModal = this.selectComponent("#giveCouponModal");
28 if (options.sid) { 31 if (options.sid) {
29 this.sid = options.sid 32 this.sid = options.sid
30 this.getSellerDetailFun(options.sid) 33 this.getSellerDetailFun(options.sid)
@@ -38,6 +41,15 @@ Page({ @@ -38,6 +41,15 @@ Page({
38 closeCouponModal() { 41 closeCouponModal() {
39 this.couponModal.closeModal() 42 this.couponModal.closeModal()
40 }, 43 },
  44 + // 打开优惠券弹框
  45 + showgiveCouponModal() {
  46 + this.giveCouponModal.showModal()
  47 + },
  48 + // 关闭优惠券弹框
  49 + closegiveCouponModal() {
  50 + this.giveCouponModal.closeModal()
  51 + wx.exitMiniProgram({})
  52 + },
41 // 获取店铺名称 53 // 获取店铺名称
42 getSellerDetailFun(sid) { 54 getSellerDetailFun(sid) {
43 App.Customer.GetSellerDetail({ 55 App.Customer.GetSellerDetail({
@@ -55,6 +67,114 @@ Page({ @@ -55,6 +67,114 @@ Page({
55 this.getSellerDailyFun(data.daily) 67 this.getSellerDailyFun(data.daily)
56 }) 68 })
57 }, 69 },
  70 + // 赠送券
  71 + giftCouponsFun(priceSum) {
  72 + App.Activity.GetActivityConfig({
  73 + sellerid: this.data.seller.sid,
  74 + }).then(res => {
  75 + if (res.ret == 200) {
  76 + let data = res.data;
  77 + priceSum = parseFloat(priceSum)
  78 + // 满减
  79 + if (data.full_reduction && data.full_reduction == '1') {
  80 + let fullData = data.full_reduction_data ? util.determine(data.full_reduction_data) : ''
  81 + let coupons = fullData.coupons ? util.determine(fullData.coupons) : '';
  82 + const now = Math.floor(Date.now() / 1000);
  83 + // 在送券活动开始的有效期之内
  84 + if (now >= parseInt(fullData.stime) && now <= parseInt(fullData.etime)) {
  85 + // rule 1每满门槛均发放(满50送一张券,金额是100送2张)
  86 + // rule 0仅发放一次(每次满足金额一个券只发一张)
  87 + if (fullData.rule == '1') {
  88 + const price = parseFloat(fullData.price)
  89 + const amount = parseInt(priceSum / price)
  90 + if (coupons.length > 0) this.getCouponFun(coupons, '1', amount)
  91 + } else {
  92 + if (coupons.length > 0) this.getCouponFun(coupons, '1', 1)
  93 + }
  94 + }
  95 + }
  96 + // 阶梯
  97 + if (data.stairs && data.stairs == '1') {
  98 + let stairsData = data.stairs_data ? util.determine(data.stairs_data) : ''
  99 + let ladder_data = stairsData.ladder_data ? util.determine(stairsData.ladder_data) : '';
  100 + const now = Math.floor(Date.now() / 1000);
  101 + // 在送券活动开始的有效期之内
  102 + if (now >= parseInt(stairsData.stime) && now <= parseInt(stairsData.etime)) {
  103 + let obj = this.findObjectByNum(ladder_data, priceSum)
  104 + if (obj && obj.coupons) {
  105 + let coupons = obj.coupons ? util.determine(obj.coupons) : '';
  106 + this.getCouponFun(coupons, '2', '1')
  107 + }
  108 + }
  109 + }
  110 +
  111 + }
  112 + })
  113 + },
  114 + getCouponFun(coupons, type, amount) {
  115 + console.log('送的券coupons---', coupons, type, amount);
  116 + let str = coupons.map(item => item.id).join(',');
  117 + App.Activity.GetActivityById({
  118 + id: str,
  119 + }).then(res => {
  120 + if (res.ret == 200) {
  121 + let list = res.data;
  122 + let couponArr = [];
  123 + list.forEach(item => {
  124 + // 如果送券的数量大于剩余券的数量,设置送券的数量=剩余券的数量
  125 + if (type == '1' && amount > item.grant_last && item.grant_last > 0) {
  126 + item.amountA = item.grant_last
  127 + } else {
  128 + item.amountA = amount
  129 + }
  130 + // 只留下开启状态 && 在券的有效期内 && 可领取数量大于0的
  131 + if (item.is_open == '1' && this.data.dataStr < item.etime * 1 && ((type == '1' && item.grant_last >= item.amountA) || (type == '2' && item.grant_last > 0))) {
  132 + console.log('可领取的券', item.aname, {
  133 + ...item
  134 + });
  135 + couponArr.push({
  136 + ...item
  137 + })
  138 + }
  139 + })
  140 + if (couponArr.length > 0) {
  141 + let result = [];
  142 + let ids = '';
  143 + let totalPrice = 0;
  144 + if (amount) {
  145 + couponArr.forEach(item => {
  146 + for (let i = 0; i < item.amountA; i++) {
  147 + result.push(item.id);
  148 + }
  149 + });
  150 + ids = result.join(",")
  151 + } else {
  152 + ids = coupons.map(item => item.id).join(',')
  153 + }
  154 + totalPrice = couponArr.reduce((sum, item) => sum + item.price * item.amountA, 0);
  155 + this.setData({
  156 + totalPrice,
  157 + })
  158 + this.showgiveCouponModal()
  159 + this.setcouponFun(ids)
  160 + }
  161 + }
  162 + })
  163 + },
  164 + setcouponFun(str) {
  165 + console.log('领取券方法ids---', str);
  166 + App.Activity.SetActivityAsReserve({
  167 + aid: str,
  168 + }).then((json) => {
  169 + if (json.ret != 200) {
  170 + wx.showToast({
  171 + title: res.msg,
  172 + duration: 2000,
  173 + mask: true
  174 + })
  175 + }
  176 + })
  177 + },
58 // 获取所有优惠券列表 178 // 获取所有优惠券列表
59 getCoupon() { 179 getCoupon() {
60 App.Activity.ActivityListByOpenid({ 180 App.Activity.ActivityListByOpenid({
@@ -276,6 +396,7 @@ Page({ @@ -276,6 +396,7 @@ Page({
276 paySign: res.data.paySign, 396 paySign: res.data.paySign,
277 success(ress) { 397 success(ress) {
278 if (ress.errMsg == 'requestPayment:ok') { 398 if (ress.errMsg == 'requestPayment:ok') {
  399 + that.giftCouponsFun(actualPrice) //送券
279 that.setData({ 400 that.setData({
280 inputValue: '', 401 inputValue: '',
281 finalList: [], 402 finalList: [],
@@ -285,7 +406,7 @@ Page({ @@ -285,7 +406,7 @@ Page({
285 }) 406 })
286 that.getCoupon() 407 that.getCoupon()
287 console.log('支付成功', ress); 408 console.log('支付成功', ress);
288 - return that.myToast.showToast('支付成功', 2000) 409 + return
289 } 410 }
290 console.log('支付失败', ress); 411 console.log('支付失败', ress);
291 return that.myToast.showToast('支付失败,请重新下单', 2000) 412 return that.myToast.showToast('支付失败,请重新下单', 2000)
@@ -338,7 +459,7 @@ Page({ @@ -338,7 +459,7 @@ Page({
338 } else { 459 } else {
339 startUseDate.setTime(couponDate.getTime()); // 直接设置为 couponDate 的时间 460 startUseDate.setTime(couponDate.getTime()); // 直接设置为 couponDate 的时间
340 } 461 }
341 - 462 +
342 // 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间 463 // 券领取天数为0或者为空 默认券可使用最晚时间是券有效期截止时间
343 if (coupon.aexpiration == '0' || coupon.aexpiration == '') { 464 if (coupon.aexpiration == '0' || coupon.aexpiration == '') {
344 let date = new Date(coupon.etime * 1000); 465 let date = new Date(coupon.etime * 1000);
@@ -416,7 +537,7 @@ Page({ @@ -416,7 +537,7 @@ Page({
416 // }else{ 537 // }else{
417 // yxDesc+=parseFloat(cur.desc) 538 // yxDesc+=parseFloat(cur.desc)
418 // } 539 // }
419 - 540 +
420 // pre+=parseFloat(cur.price) 541 // pre+=parseFloat(cur.price)
421 // yxArr.push(cur) 542 // yxArr.push(cur)
422 // } 543 // }
@@ -454,10 +575,10 @@ Page({ @@ -454,10 +575,10 @@ Page({
454 currentCombination.pop(); // 回溯 575 currentCombination.pop(); // 回溯
455 couponCount[obj.aid]--; // 回溯时减少使用次数 576 couponCount[obj.aid]--; // 回溯时减少使用次数
456 } 577 }
457 - // 提前退出:如果当前和加上当前数字已经小于输入值,后续的数字也会更小  
458 - if (currentSum*1 + obj.price*1 < amount) break; 578 + // 提前退出:如果当前和加上当前数字已经小于输入值,后续的数字也会更小
  579 + if (currentSum*1 + obj.price*1 < amount) break;
459 } 580 }
460 - 581 +
461 } 582 }
462 } 583 }
463 const couponCount = {}; 584 const couponCount = {};
@@ -482,7 +603,7 @@ Page({ @@ -482,7 +603,7 @@ Page({
482 console.log('不可叠加的优惠券', list2); 603 console.log('不可叠加的优惠券', list2);
483 // 计算两个列表的最大优惠值 604 // 计算两个列表的最大优惠值
484 let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0); 605 let maxStackableValue = list1.reduce((total, coupon) => total + parseFloat(coupon.price), 0);
485 - 606 +
486 // 比较两个最大值并输出结果 607 // 比较两个最大值并输出结果
487 if (maxStackableValue > maxNonStackableValue) { 608 if (maxStackableValue > maxNonStackableValue) {
488 finalList = list1 609 finalList = list1
@@ -707,7 +828,7 @@ Page({ @@ -707,7 +828,7 @@ Page({
707 solt: 2, 828 solt: 2,
708 can: '午餐' 829 can: '午餐'
709 }; 830 };
710 - } else if (currentTimestamp > timeA2) { //在午餐/晚餐截止时间之后 831 + } else if (currentTimestamp > timeA2) { //在午餐/晚餐截止时间之后
711 return obj2.solt == 2 ? { 832 return obj2.solt == 2 ? {
712 solt: 2, 833 solt: 2,
713 can: '午餐' 834 can: '午餐'
@@ -734,7 +855,7 @@ Page({ @@ -734,7 +855,7 @@ Page({
734 solt: 2, 855 solt: 2,
735 can: '午餐' 856 can: '午餐'
736 } 857 }
737 - } else if (currentTimestamp > time3 && currentTimestamp < time4) { //在午餐截止时间之后 && 晚餐开始时间之前 858 + } else if (currentTimestamp > time3 && currentTimestamp < time4) { //在午餐截止时间之后 && 晚餐开始时间之前
738 return { 859 return {
739 solt: 2, 860 solt: 2,
740 can: '午餐' 861 can: '午餐'
@@ -747,6 +868,25 @@ Page({ @@ -747,6 +868,25 @@ Page({
747 } 868 }
748 } 869 }
749 }, 870 },
  871 + // 获取当前应该赠送的阶梯券
  872 + findObjectByNum(arr, num) {
  873 + let result = {};
  874 + let maxPrice = -Infinity;
  875 + for (let i = 0; i < arr.length; i++) {
  876 + const price = parseInt(arr[i].price, 10);
  877 + if (price <= num && price > maxPrice) {
  878 + maxPrice = price;
  879 + result = arr[i];
  880 + }
  881 + }
  882 + return result;
  883 + },
  884 + // 跳转到我的券列表
  885 + certificate() {
  886 + wx.reLaunch({
  887 + url: '/pages/me/coupon_news'
  888 + })
  889 + },
750 /** 890 /**
751 * 生命周期函数--监听页面初次渲染完成 891 * 生命周期函数--监听页面初次渲染完成
752 */ 892 */
@@ -64,4 +64,16 @@ @@ -64,4 +64,16 @@
64 </checkbox-group> 64 </checkbox-group>
65 </scroll-view> 65 </scroll-view>
66 </view> 66 </view>
  67 +</my-modal>
  68 +<my-modal id="giveCouponModal" fadeStyle="slideUp" height="240px">
  69 + <view slot="modalName" class="titleModal ">
  70 + <image bindtap="closegiveCouponModal" class="closeImg" src="https://qn.colorcun.com/closeOutline.png" mode=""/>
  71 + <view class="nameInfo">{{seller.sellername}}</view>
  72 + <view class="couponTotal">赠送给您<text>{{totalPrice}}元</text>代金券</view>
  73 + </view>
  74 + <view slot="modalContent">
  75 + <view class="couponInfo font24r">您到店扫码支付即可自动使用</view>
  76 + <view bindtap="closegiveCouponModal" class="couponBtn font36r">我知道了</view>
  77 + <view class="couponText font24r" bindtap="certificate">点击查看详情</view>
  78 + </view>
67 </my-modal> 79 </my-modal>
@@ -261,4 +261,82 @@ checkbox::before { @@ -261,4 +261,82 @@ checkbox::before {
261 .couponNo .bottomTitle, 261 .couponNo .bottomTitle,
262 .couponNo .bottom { 262 .couponNo .bottom {
263 color: #999; 263 color: #999;
  264 +}
  265 +
  266 +#giveCouponModal .titleModal {
  267 + margin-top: 65%;
  268 + position: relative;
  269 + flex-direction: column;
  270 + border-bottom: none;
  271 +}
  272 +
  273 +#giveCouponModal .mymodal {
  274 + background: rgba(0, 0, 0, 0.8);
  275 + width: 100% !important;
  276 + top: 0 !important;
  277 + height: auto !important;
  278 + z-index: 300;
  279 +}
  280 +
  281 +.nameInfo {
  282 + font-family: PingFang SC;
  283 + font-weight: 600;
  284 + font-size: 52rpx;
  285 + line-height: 56rpx;
  286 + color: #fff;
  287 + margin-bottom: 150rpx;
  288 + padding-top: 60rpx;
  289 +}
  290 +
  291 +.couponTotal {
  292 + color: #dfdfdf;
  293 + font-family: PingFang SC;
  294 + font-weight: 400;
  295 + font-size: 40rpx;
  296 + line-height: 48rpx;
  297 + margin-bottom: 40rpx;
  298 + display: flex;
  299 + align-items: center;
  300 + justify-content: center;
  301 +}
  302 +
  303 +.couponTotal text {
  304 + color: #ffc806;
  305 + font-weight: 600;
  306 + font-size: 100rpx;
  307 + margin: 0 14rpx;
  308 +}
  309 +
  310 +.couponBtn {
  311 + width: 80%;
  312 + margin: 0 auto;
  313 + border-radius: 42rpx;
  314 + background: linear-gradient(90.98deg, #f41919 0.25%, #ff7426 120.07%);
  315 + font-weight: 400;
  316 + color: #fff;
  317 + text-align: center;
  318 + border: 4rpx solid #fff;
  319 + padding: 12rpx 0;
  320 + margin: 16rpx auto 20rpx auto;
  321 +}
  322 +
  323 +.couponText {
  324 + color: #fff;
  325 + text-decoration: underline;
  326 + text-align: center;
  327 +}
  328 +
  329 +.couponInfo {
  330 + text-decoration: none;
  331 + margin-bottom: 30rpx;
  332 + color: #DFDFDF;
  333 + text-align: center;
  334 +}
  335 +
  336 +.closeImg {
  337 + width: 60rpx;
  338 + height: 60rpx;
  339 + position: absolute;
  340 + right: 0;
  341 + top: 0;
264 } 342 }
@@ -784,4 +784,12 @@ export default { @@ -784,4 +784,12 @@ export default {
784 openid:'openid', 784 openid:'openid',
785 cachetime: 0, 785 cachetime: 0,
786 }, 786 },
  787 +
  788 + //获取商家券赠送规则配置
  789 + 'App.Activity.GetActivityConfig':{
  790 + alias:'App.Activity.GetActivityConfig',
  791 + openid:'openid',
  792 + cachetime: 0,
  793 + },
  794 +
787 } 795 }