|
@@ -73,14 +73,19 @@ Page({ |
|
@@ -73,14 +73,19 @@ Page({ |
|
73
|
this.setData({
|
73
|
this.setData({
|
|
74
|
purePhoneNumber: data.phone,
|
74
|
purePhoneNumber: data.phone,
|
|
75
|
})
|
75
|
})
|
|
76
|
- this.getUserInfo()
|
76
|
+ this.getUserInfo(data.phone)
|
|
77
|
this.getUserRechargeInfo(data.phone)
|
77
|
this.getUserRechargeInfo(data.phone)
|
|
|
|
78
|
+ this.getCoupon()
|
|
78
|
} else {
|
79
|
} else {
|
|
79
|
this.getUserInfo()
|
80
|
this.getUserInfo()
|
|
80
|
this.setData({
|
81
|
this.setData({
|
|
81
|
purePhoneNumber: '',
|
82
|
purePhoneNumber: '',
|
|
82
|
})
|
83
|
})
|
|
|
|
84
|
+ this.getCoupon()
|
|
83
|
}
|
85
|
}
|
|
|
|
86
|
+ } else {
|
|
|
|
87
|
+ // 查询手机号失败时,先拉取 openid 维度的券兜底
|
|
|
|
88
|
+ this.getCoupon()
|
|
84
|
}
|
89
|
}
|
|
85
|
})
|
90
|
})
|
|
86
|
},
|
91
|
},
|
|
@@ -192,11 +197,13 @@ Page({ |
|
@@ -192,11 +197,13 @@ Page({ |
|
192
|
})
|
197
|
})
|
|
193
|
},
|
198
|
},
|
|
194
|
// 获取用户在商家&所有消费金
|
199
|
// 获取用户在商家&所有消费金
|
|
195
|
- getUserInfo() {
|
|
|
|
196
|
- App.Activity.GetConsumeBySeller({
|
200
|
+ getUserInfo(phone) {
|
|
|
|
201
|
+ let params = {
|
|
197
|
openid: getApp().openid,
|
202
|
openid: getApp().openid,
|
|
198
|
sellerid: this.sid,
|
203
|
sellerid: this.sid,
|
|
199
|
- }).then((json) => {
|
204
|
+ }
|
|
|
|
205
|
+ if(phone) params.phone = phone;
|
|
|
|
206
|
+ App.Activity.GetConsumeBySeller({...params}).then((json) => {
|
|
200
|
if (json.ret == 200) {
|
207
|
if (json.ret == 200) {
|
|
201
|
let data = json.data;
|
208
|
let data = json.data;
|
|
202
|
if (data && data.length > 0) {
|
209
|
if (data && data.length > 0) {
|
|
@@ -477,8 +484,10 @@ Page({ |
|
@@ -477,8 +484,10 @@ Page({ |
|
477
|
if (!id) {
|
484
|
if (!id) {
|
|
478
|
let price = this.data.actualPrice * 1 * this.data.multiple
|
485
|
let price = this.data.actualPrice * 1 * this.data.multiple
|
|
479
|
if (!price) return false
|
486
|
if (!price) return false
|
|
480
|
- let str = this.data.finalList.map(item => item.activity_id).join(',');
|
|
|
|
481
|
- console.log('核销所勾选的券传参', str);
|
487
|
+ // isinitial为1的券用activity_id传参,isinitial为0的券用phone_activity_id传参
|
|
|
|
488
|
+ let activityIdStr = this.data.finalList.filter(item => item.isinitial == '1').map(item => item.activity_id).join(',');
|
|
|
|
489
|
+ let phoneActivityIdStr = this.data.finalList.filter(item => item.isinitial == '0').map(item => item.phone_activity_id).join(',');
|
|
|
|
490
|
+ console.log('充值所勾选的券传参', activityIdStr, phoneActivityIdStr);
|
|
482
|
let params = {
|
491
|
let params = {
|
|
483
|
type: '2',
|
492
|
type: '2',
|
|
484
|
types: '4', // 1邀请函 2提前点餐 3商家端app分享 4支付页充值 5我的页面余额充值
|
493
|
types: '4', // 1邀请函 2提前点餐 3商家端app分享 4支付页充值 5我的页面余额充值
|
|
@@ -493,8 +502,11 @@ Page({ |
|
@@ -493,8 +502,11 @@ Page({ |
|
493
|
if (this.data.consumeDiscount * 1 > 0 && this.data.consumeSwitch) {
|
502
|
if (this.data.consumeDiscount * 1 > 0 && this.data.consumeSwitch) {
|
|
494
|
params.consume = this.data.consumeDiscount;
|
503
|
params.consume = this.data.consumeDiscount;
|
|
495
|
}
|
504
|
}
|
|
496
|
- if (str) {
|
|
|
|
497
|
- params.activity_id = str;
|
505
|
+ if (activityIdStr) {
|
|
|
|
506
|
+ params.activity_id = activityIdStr;
|
|
|
|
507
|
+ }
|
|
|
|
508
|
+ if (phoneActivityIdStr) {
|
|
|
|
509
|
+ params.phone_activity_id = phoneActivityIdStr;
|
|
498
|
}
|
510
|
}
|
|
499
|
if (this.data.givePrice) {
|
511
|
if (this.data.givePrice) {
|
|
500
|
params.givePrice = this.data.givePrice; //当餐免费送的余额
|
512
|
params.givePrice = this.data.givePrice; //当餐免费送的余额
|
|
@@ -533,7 +545,7 @@ Page({ |
|
@@ -533,7 +545,7 @@ Page({ |
|
533
|
this.setData({
|
545
|
this.setData({
|
|
534
|
purePhoneNumber: res.data.phone_info.purePhoneNumber,
|
546
|
purePhoneNumber: res.data.phone_info.purePhoneNumber,
|
|
535
|
})
|
547
|
})
|
|
536
|
- this.getUserInfo()
|
548
|
+ this.getUserInfo(res.data.phone_info.purePhoneNumber)
|
|
537
|
this.bindUserPhoneFun(res.data.phone_info.purePhoneNumber)
|
549
|
this.bindUserPhoneFun(res.data.phone_info.purePhoneNumber)
|
|
538
|
this.getUserRechargeInfo(res.data.phone_info.purePhoneNumber)
|
550
|
this.getUserRechargeInfo(res.data.phone_info.purePhoneNumber)
|
|
539
|
} else {
|
551
|
} else {
|
|
@@ -675,108 +687,143 @@ Page({ |
|
@@ -675,108 +687,143 @@ Page({ |
|
675
|
},
|
687
|
},
|
|
676
|
// 获取所有优惠券列表
|
688
|
// 获取所有优惠券列表
|
|
677
|
getCoupon() {
|
689
|
getCoupon() {
|
|
|
|
690
|
+ let phone = this.data.purePhoneNumber
|
|
|
|
691
|
+ // 1、先通过 openid 获取已领取的券,标记 isinitial:1
|
|
678
|
App.Activity.ActivityListByOpenid({
|
692
|
App.Activity.ActivityListByOpenid({
|
|
679
|
sellerid: this.sid
|
693
|
sellerid: this.sid
|
|
680
|
}).then(res => {
|
694
|
}).then(res => {
|
|
|
|
695
|
+ let openidCouponList = []
|
|
681
|
if (res.ret == 200 && res.data && res.data.length > 0) {
|
696
|
if (res.ret == 200 && res.data && res.data.length > 0) {
|
|
682
|
- let list = res.data
|
|
|
|
683
|
- list.forEach(detail => {
|
|
|
|
684
|
- detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
685
|
- detail.arule = detail.arule ? util.determine(detail.arule) : '';
|
|
|
|
686
|
- detail.expiration_date = detail.expiration_date ? util.determine(detail.expiration_date) : '';
|
|
|
|
687
|
- detail.aexpiration = detail.aexpiration ? util.determine(detail.aexpiration) : '';
|
|
|
|
688
|
- if (detail.arule) {
|
|
|
|
689
|
- detail.accumulationShow = detail.arule.is_accumulation
|
|
|
|
690
|
- }
|
|
|
|
691
|
- if (detail.exp_date && detail.exp_date.week_data) {
|
|
|
|
692
|
- let mor = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
|
|
|
|
693
|
- let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
|
|
|
|
694
|
- let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '3').rArr.join('、')
|
|
|
|
695
|
- if (mor) mor = '早餐:' + mor
|
|
|
|
696
|
- if (noon) noon = '午餐:' + noon
|
|
|
|
697
|
- if (nig) nig = '晚餐:' + nig
|
|
|
|
698
|
- detail.morText = mor;
|
|
|
|
699
|
- detail.noonText = noon;
|
|
|
|
700
|
- detail.nigText = nig;
|
|
|
|
701
|
- }
|
|
|
|
702
|
- detail.checked = false;
|
|
|
|
703
|
- detail.showCpupon = '0';
|
|
|
|
704
|
- // 获取使用券的有效期
|
|
|
|
705
|
- detail.cdate = detail.cdate * 1;
|
|
|
|
706
|
- detail.useStime = '';
|
|
|
|
707
|
- detail.useEtime = '';
|
|
|
|
708
|
- let condition = detail.aexpiration
|
|
|
|
709
|
- if (condition.valid_forever === '0' && condition.stime && condition.etime) {
|
|
|
|
710
|
- detail.useStime = condition.stime;
|
|
|
|
711
|
- detail.useEtime = condition.etime;
|
|
|
|
712
|
- }
|
|
|
|
713
|
- if (condition.valid_forever === '1') {
|
|
|
|
714
|
- detail.foreverText = '永久有效';
|
|
|
|
715
|
- }
|
|
|
|
716
|
- if (condition.valid_forever === '0' && condition.today) {
|
|
|
|
717
|
- let obj = this.setTimeRange(detail.cdate, 0, parseInt(condition.today) - 1);
|
|
|
|
718
|
- detail.useStime = obj.useStime;
|
|
|
|
719
|
- detail.useEtime = obj.useEtime;
|
|
|
|
720
|
- }
|
|
|
|
721
|
- if (condition.valid_forever === '0' && condition.tomorrow) {
|
|
|
|
722
|
- let obj = this.setTimeRange(detail.cdate, 1, condition.tomorrow * 1);
|
|
|
|
723
|
- detail.useStime = obj.useStime;
|
|
|
|
724
|
- detail.useEtime = obj.useEtime;
|
|
|
|
725
|
- }
|
|
|
|
726
|
- if (condition.valid_forever === '0' && condition.sday && condition.eday) {
|
|
|
|
727
|
- let obj = this.setTimeRange(detail.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
|
|
|
|
728
|
- detail.useStime = obj.useStime;
|
|
|
|
729
|
- detail.useEtime = obj.useEtime;
|
|
|
|
730
|
- }
|
|
|
|
731
|
- if((detail.useStime>0 && detail.useEtime>0) || condition.valid_forever === '1') {
|
|
|
|
732
|
- detail.endDateStr = condition.valid_forever == '1' ? '永久有效' : (util.unixtoTime(detail.useStime, 'YYYY-MM-DD') + '至' + util.unixtoTime(detail.useEtime, 'YYYY-MM-DD'));
|
|
|
|
733
|
- }
|
|
|
|
734
|
- })
|
|
|
|
735
|
- list = list.filter(item => {
|
|
|
|
736
|
- return (this.data.dataStr < (item.useEtime * 1) || item.aexpiration.valid_forever == '1');
|
|
|
|
737
|
- })
|
|
|
|
738
|
- list.sort((a, b) => {
|
|
|
|
739
|
- if (a.aexpiration.valid_forever == '1' && b.aexpiration.valid_forever != '1') return 1;
|
|
|
|
740
|
- if (a.aexpiration.valid_forever != '1' && b.aexpiration.valid_forever == '1') return -1;
|
|
|
|
741
|
- return (a.useEtime * 1) - (b.useEtime * 1)
|
|
|
|
742
|
- })
|
|
|
|
743
|
- let couponArr = list
|
|
|
|
744
|
- // 相同aid的券合并成一张,用加减号选择张数
|
|
|
|
745
|
- let couponGroup = {}
|
|
|
|
746
|
- let couponList = []
|
|
|
|
747
|
- couponArr.forEach(item => {
|
|
|
|
748
|
- let key = item.aid ? item.aid : item.activity_id
|
|
|
|
749
|
- if (couponGroup[key]) {
|
|
|
|
750
|
- couponGroup[key].num = (couponGroup[key].num * 1) + 1
|
|
|
|
751
|
- couponGroup[key].activityIds.push(item.activity_id)
|
|
|
|
752
|
- } else {
|
|
|
|
753
|
- item.num = 1
|
|
|
|
754
|
- item.checkedNum = 0
|
|
|
|
755
|
- item.activityIds = [item.activity_id]
|
|
|
|
756
|
- couponGroup[key] = item
|
|
|
|
757
|
- couponList.push(item)
|
|
|
|
758
|
- }
|
|
|
|
759
|
- })
|
|
|
|
760
|
- couponArr = couponList
|
|
|
|
761
|
- // 单次使用数量限制,0表示不限制,默认0;合并完成后统一计算
|
|
|
|
762
|
- couponArr.forEach(item => {
|
|
|
|
763
|
- let useLimit = item.single_use_limit ? (item.single_use_limit * 1) : 0
|
|
|
|
764
|
- item.maxNum = (useLimit > 0 && useLimit < item.num) ? useLimit : item.num
|
|
|
|
765
|
- })
|
|
|
|
766
|
- console.log('couponArr----',couponArr);
|
|
|
|
767
|
-
|
|
|
|
768
|
- this.setData({
|
|
|
|
769
|
- couponArr
|
697
|
+ openidCouponList = res.data
|
|
|
|
698
|
+ openidCouponList.forEach(item => {
|
|
|
|
699
|
+ item.isinitial = '1'
|
|
770
|
})
|
700
|
})
|
|
771
|
}
|
701
|
}
|
|
|
|
702
|
+ // 未授权手机号时,直接用 openid 获取的券
|
|
|
|
703
|
+ if (!phone) {
|
|
|
|
704
|
+ this.filterCouponList(openidCouponList)
|
|
|
|
705
|
+ return
|
|
|
|
706
|
+ }
|
|
|
|
707
|
+ // 2、再通过授权手机号获取的券,标记 isinitial:0
|
|
|
|
708
|
+ App.Activity.GetActivityListByPhone({
|
|
|
|
709
|
+ sellerid: this.sid,
|
|
|
|
710
|
+ phone
|
|
|
|
711
|
+ }).then(res2 => {
|
|
|
|
712
|
+ let phoneCouponList = []
|
|
|
|
713
|
+ if (res2 && res2.ret == 200 && res2.data && res2.data.length > 0) {
|
|
|
|
714
|
+ phoneCouponList = res2.data
|
|
|
|
715
|
+ phoneCouponList.forEach(item => {
|
|
|
|
716
|
+ item.isinitial = '0'
|
|
|
|
717
|
+ })
|
|
|
|
718
|
+ }
|
|
|
|
719
|
+ // 3、两个数组 concat 合并成所有券后,统一筛选可用的券
|
|
|
|
720
|
+ this.filterCouponList(openidCouponList.concat(phoneCouponList))
|
|
|
|
721
|
+ })
|
|
|
|
722
|
+ })
|
|
|
|
723
|
+ },
|
|
|
|
724
|
+ // 所有券合并后,统一筛选可用的券
|
|
|
|
725
|
+ filterCouponList(list) {
|
|
|
|
726
|
+ if (list.length == 0) {
|
|
|
|
727
|
+ return
|
|
|
|
728
|
+ }
|
|
|
|
729
|
+ list.forEach(detail => {
|
|
|
|
730
|
+ detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
|
|
|
|
731
|
+ detail.arule = detail.arule ? util.determine(detail.arule) : '';
|
|
|
|
732
|
+ detail.expiration_date = detail.expiration_date ? util.determine(detail.expiration_date) : '';
|
|
|
|
733
|
+ detail.aexpiration = detail.aexpiration ? util.determine(detail.aexpiration) : '';
|
|
|
|
734
|
+ if (detail.arule) {
|
|
|
|
735
|
+ detail.accumulationShow = detail.arule.is_accumulation
|
|
|
|
736
|
+ }
|
|
|
|
737
|
+ if (detail.exp_date && detail.exp_date.week_data) {
|
|
|
|
738
|
+ let mor = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
|
|
|
|
739
|
+ let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
|
|
|
|
740
|
+ let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '3').rArr.join('、')
|
|
|
|
741
|
+ if (mor) mor = '早餐:' + mor
|
|
|
|
742
|
+ if (noon) noon = '午餐:' + noon
|
|
|
|
743
|
+ if (nig) nig = '晚餐:' + nig
|
|
|
|
744
|
+ detail.morText = mor;
|
|
|
|
745
|
+ detail.noonText = noon;
|
|
|
|
746
|
+ detail.nigText = nig;
|
|
|
|
747
|
+ }
|
|
|
|
748
|
+ detail.checked = false;
|
|
|
|
749
|
+ detail.showCpupon = '0';
|
|
|
|
750
|
+ // 获取使用券的有效期
|
|
|
|
751
|
+ detail.cdate = detail.cdate * 1;
|
|
|
|
752
|
+ detail.useStime = '';
|
|
|
|
753
|
+ detail.useEtime = '';
|
|
|
|
754
|
+ let condition = detail.aexpiration
|
|
|
|
755
|
+ if (condition.valid_forever === '0' && condition.stime && condition.etime) {
|
|
|
|
756
|
+ detail.useStime = condition.stime;
|
|
|
|
757
|
+ detail.useEtime = condition.etime;
|
|
|
|
758
|
+ }
|
|
|
|
759
|
+ if (condition.valid_forever === '1') {
|
|
|
|
760
|
+ detail.foreverText = '永久有效';
|
|
|
|
761
|
+ }
|
|
|
|
762
|
+ if (condition.valid_forever === '0' && condition.today) {
|
|
|
|
763
|
+ let obj = this.setTimeRange(detail.cdate, 0, parseInt(condition.today) - 1);
|
|
|
|
764
|
+ detail.useStime = obj.useStime;
|
|
|
|
765
|
+ detail.useEtime = obj.useEtime;
|
|
|
|
766
|
+ }
|
|
|
|
767
|
+ if (condition.valid_forever === '0' && condition.tomorrow) {
|
|
|
|
768
|
+ let obj = this.setTimeRange(detail.cdate, 1, condition.tomorrow * 1);
|
|
|
|
769
|
+ detail.useStime = obj.useStime;
|
|
|
|
770
|
+ detail.useEtime = obj.useEtime;
|
|
|
|
771
|
+ }
|
|
|
|
772
|
+ if (condition.valid_forever === '0' && condition.sday && condition.eday) {
|
|
|
|
773
|
+ let obj = this.setTimeRange(detail.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
|
|
|
|
774
|
+ detail.useStime = obj.useStime;
|
|
|
|
775
|
+ detail.useEtime = obj.useEtime;
|
|
|
|
776
|
+ }
|
|
|
|
777
|
+ if((detail.useStime>0 && detail.useEtime>0) || condition.valid_forever === '1') {
|
|
|
|
778
|
+ detail.endDateStr = condition.valid_forever == '1' ? '永久有效' : (util.unixtoTime(detail.useStime, 'YYYY-MM-DD') + '至' + util.unixtoTime(detail.useEtime, 'YYYY-MM-DD'));
|
|
|
|
779
|
+ }
|
|
|
|
780
|
+ })
|
|
|
|
781
|
+ list = list.filter(item => {
|
|
|
|
782
|
+ return (this.data.dataStr < (item.useEtime * 1) || item.aexpiration.valid_forever == '1');
|
|
|
|
783
|
+ })
|
|
|
|
784
|
+ list.sort((a, b) => {
|
|
|
|
785
|
+ if (a.aexpiration.valid_forever == '1' && b.aexpiration.valid_forever != '1') return 1;
|
|
|
|
786
|
+ if (a.aexpiration.valid_forever != '1' && b.aexpiration.valid_forever == '1') return -1;
|
|
|
|
787
|
+ return (a.useEtime * 1) - (b.useEtime * 1)
|
|
|
|
788
|
+ })
|
|
|
|
789
|
+ let couponArr = list
|
|
|
|
790
|
+ // 同来源(openid/phone)且相同aid的券合并成一张,用加减号选择张数;不同来源分开
|
|
|
|
791
|
+ let couponGroup = {}
|
|
|
|
792
|
+ let couponList = []
|
|
|
|
793
|
+ couponArr.forEach(item => {
|
|
|
|
794
|
+ // openid券与phone券分开合并:同来源且同aid的券合并成一张,用加减号选择张数
|
|
|
|
795
|
+ let key = (item.isinitial == '0' ? 'p_' : 'o_') + (item.aid ? item.aid : (item.activity_id || item.phone_activity_id))
|
|
|
|
796
|
+ let id = item.activity_id || item.phone_activity_id
|
|
|
|
797
|
+ if (couponGroup[key]) {
|
|
|
|
798
|
+ couponGroup[key].num = (couponGroup[key].num * 1) + 1
|
|
|
|
799
|
+ couponGroup[key].activityIds.push(id)
|
|
|
|
800
|
+ } else {
|
|
|
|
801
|
+ item._key = key
|
|
|
|
802
|
+ item.num = 1
|
|
|
|
803
|
+ item.checkedNum = 0
|
|
|
|
804
|
+ item.activityIds = [id]
|
|
|
|
805
|
+ couponGroup[key] = item
|
|
|
|
806
|
+ couponList.push(item)
|
|
|
|
807
|
+ }
|
|
|
|
808
|
+ })
|
|
|
|
809
|
+ couponArr = couponList
|
|
|
|
810
|
+ // 单次使用数量限制,0表示不限制,默认0;合并完成后统一计算
|
|
|
|
811
|
+ couponArr.forEach(item => {
|
|
|
|
812
|
+ let useLimit = item.single_use_limit ? (item.single_use_limit * 1) : 0
|
|
|
|
813
|
+ item.maxNum = (useLimit > 0 && useLimit < item.num) ? useLimit : item.num
|
|
|
|
814
|
+ })
|
|
|
|
815
|
+ console.log('couponArr----',couponArr);
|
|
|
|
816
|
+
|
|
|
|
817
|
+ this.setData({
|
|
|
|
818
|
+ couponArr
|
|
772
|
})
|
819
|
})
|
|
773
|
},
|
820
|
},
|
|
774
|
// 加减号选择券的张数
|
821
|
// 加减号选择券的张数
|
|
775
|
changeCouponNum(e) {
|
822
|
changeCouponNum(e) {
|
|
776
|
let type = e.currentTarget.dataset.type;
|
823
|
let type = e.currentTarget.dataset.type;
|
|
777
|
- let aid = e.currentTarget.dataset.aid;
|
824
|
+ let key = e.currentTarget.dataset.key;
|
|
778
|
const list = this.data.couponArr
|
825
|
const list = this.data.couponArr
|
|
779
|
- let item = list.find(i => i.aid == aid)
|
826
|
+ let item = list.find(i => i._key == key)
|
|
780
|
if (!item) return
|
827
|
if (!item) return
|
|
781
|
if (type == 'plus') {
|
828
|
if (type == 'plus') {
|
|
782
|
if (item.canAdd != '1') return
|
829
|
if (item.canAdd != '1') return
|
|
@@ -790,10 +837,10 @@ Page({ |
|
@@ -790,10 +837,10 @@ Page({ |
|
790
|
},
|
837
|
},
|
|
791
|
// 加减号中间输入框:只允许正整数或0,且不能超过当前可用张数
|
838
|
// 加减号中间输入框:只允许正整数或0,且不能超过当前可用张数
|
|
792
|
numInputChange(e) {
|
839
|
numInputChange(e) {
|
|
793
|
- let aid = e.currentTarget.dataset.aid;
|
840
|
+ let key = e.currentTarget.dataset.key;
|
|
794
|
let val = (e.detail.value || '').replace(/[^\d]/g, ''); // 只保留数字
|
841
|
let val = (e.detail.value || '').replace(/[^\d]/g, ''); // 只保留数字
|
|
795
|
const list = this.data.couponArr
|
842
|
const list = this.data.couponArr
|
|
796
|
- let item = list.find(i => i.aid == aid)
|
843
|
+ let item = list.find(i => i._key == key)
|
|
797
|
if (!item) return
|
844
|
if (!item) return
|
|
798
|
let maxSelect = this.getMaxSelectNum(item)
|
845
|
let maxSelect = this.getMaxSelectNum(item)
|
|
799
|
let num = val === '' ? 0 : parseInt(val, 10)
|
846
|
let num = val === '' ? 0 : parseInt(val, 10)
|
|
@@ -809,7 +856,7 @@ Page({ |
|
@@ -809,7 +856,7 @@ Page({ |
|
809
|
let descStr = 0
|
856
|
let descStr = 0
|
|
810
|
let val = 0
|
857
|
let val = 0
|
|
811
|
list.forEach(i => {
|
858
|
list.forEach(i => {
|
|
812
|
- if (i.checkedNum > 0 && i.aid != item.aid) {
|
859
|
+ if (i.checkedNum > 0 && i._key != item._key) {
|
|
813
|
let d = parseFloat(i.desc) || 0
|
860
|
let d = parseFloat(i.desc) || 0
|
|
814
|
if (d > 0) descStr += d * i.checkedNum
|
861
|
if (d > 0) descStr += d * i.checkedNum
|
|
815
|
val += parseFloat(i.price) * i.checkedNum
|
862
|
val += parseFloat(i.price) * i.checkedNum
|
|
@@ -893,7 +940,8 @@ Page({ |
|
@@ -893,7 +940,8 @@ Page({ |
|
893
|
for (let k = 0; k < item.checkedNum; k++) {
|
940
|
for (let k = 0; k < item.checkedNum; k++) {
|
|
894
|
finalList.push({
|
941
|
finalList.push({
|
|
895
|
...item,
|
942
|
...item,
|
|
896
|
- activity_id: item.activityIds[k]
|
943
|
+ activity_id: item.isinitial == '0' ? '' : item.activityIds[k],
|
|
|
|
944
|
+ phone_activity_id: item.isinitial == '0' ? item.activityIds[k] : (item.phone_activity_id || ''),
|
|
897
|
})
|
945
|
})
|
|
898
|
}
|
946
|
}
|
|
899
|
}
|
947
|
}
|
|
@@ -1070,8 +1118,10 @@ Page({ |
|
@@ -1070,8 +1118,10 @@ Page({ |
|
1070
|
wx.showLoading({
|
1118
|
wx.showLoading({
|
|
1071
|
title: '支付中',
|
1119
|
title: '支付中',
|
|
1072
|
})
|
1120
|
})
|
|
1073
|
- let str = this.data.finalList.map(item => item.activity_id).join(',');
|
|
|
|
1074
|
- console.log('核销所勾选的券传参', str);
|
1121
|
+ // isinitial为1的券用activity_id传参,isinitial为0的券用phone_activity_id传参
|
|
|
|
1122
|
+ let activityIdStr = this.data.finalList.filter(item => item.isinitial == '1').map(item => item.activity_id).join(',');
|
|
|
|
1123
|
+ let phoneActivityIdStr = this.data.finalList.filter(item => item.isinitial == '0').map(item => item.phone_activity_id).join(',');
|
|
|
|
1124
|
+ console.log('核销所勾选的券传参', activityIdStr, phoneActivityIdStr);
|
|
1075
|
let params = {
|
1125
|
let params = {
|
|
1076
|
sellerid: this.data.seller.sid,
|
1126
|
sellerid: this.data.seller.sid,
|
|
1077
|
price: soothPrice,
|
1127
|
price: soothPrice,
|
|
@@ -1080,8 +1130,11 @@ Page({ |
|
@@ -1080,8 +1130,11 @@ Page({ |
|
1080
|
params.consume = this.data.consumeDiscount;
|
1130
|
params.consume = this.data.consumeDiscount;
|
|
1081
|
params.phone = this.data.purePhoneNumber;
|
1131
|
params.phone = this.data.purePhoneNumber;
|
|
1082
|
}
|
1132
|
}
|
|
1083
|
- if (str) {
|
|
|
|
1084
|
- params.activity_id = str;
|
1133
|
+ if (activityIdStr) {
|
|
|
|
1134
|
+ params.activity_id = activityIdStr;
|
|
|
|
1135
|
+ }
|
|
|
|
1136
|
+ if (phoneActivityIdStr) {
|
|
|
|
1137
|
+ params.phone_activity_id = phoneActivityIdStr;
|
|
1085
|
}
|
1138
|
}
|
|
1086
|
// 用余额支付 || 支付金额为0
|
1139
|
// 用余额支付 || 支付金额为0
|
|
1087
|
if (this.data.soothPrice == '0.00') {
|
1140
|
if (this.data.soothPrice == '0.00') {
|
|
@@ -1091,8 +1144,11 @@ Page({ |
|
@@ -1091,8 +1144,11 @@ Page({ |
|
1091
|
price: this.data.inputValue,
|
1144
|
price: this.data.inputValue,
|
|
1092
|
phone: this.data.purePhoneNumber,
|
1145
|
phone: this.data.purePhoneNumber,
|
|
1093
|
}
|
1146
|
}
|
|
1094
|
- if (str) {
|
|
|
|
1095
|
- obj.activity_id = str;
|
1147
|
+ if (activityIdStr) {
|
|
|
|
1148
|
+ obj.activity_id = activityIdStr;
|
|
|
|
1149
|
+ }
|
|
|
|
1150
|
+ if (phoneActivityIdStr) {
|
|
|
|
1151
|
+ obj.phone_activity_id = phoneActivityIdStr;
|
|
1096
|
}
|
1152
|
}
|
|
1097
|
let consumeDiscount = this.data.consumeDiscount * 1
|
1153
|
let consumeDiscount = this.data.consumeDiscount * 1
|
|
1098
|
if (this.data.balancePay * 1 > 0) {
|
1154
|
if (this.data.balancePay * 1 > 0) {
|
|
@@ -1124,6 +1180,7 @@ Page({ |
|
@@ -1124,6 +1180,7 @@ Page({ |
|
1124
|
if (this.data.balancePay) {
|
1180
|
if (this.data.balancePay) {
|
|
1125
|
params.recharge_balance = this.data.balancePay;
|
1181
|
params.recharge_balance = this.data.balancePay;
|
|
1126
|
}
|
1182
|
}
|
|
|
|
1183
|
+ console.log('params-----',params);
|
|
1127
|
App.PayOnline.CombineTransactionsByNewActivity(params).then(res => {
|
1184
|
App.PayOnline.CombineTransactionsByNewActivity(params).then(res => {
|
|
1128
|
console.log('付款信息', res.data);
|
1185
|
console.log('付款信息', res.data);
|
|
1129
|
if (res.ret != '200') {
|
1186
|
if (res.ret != '200') {
|
|
@@ -1204,7 +1261,7 @@ Page({ |
|
@@ -1204,7 +1261,7 @@ Page({ |
|
1204
|
}
|
1261
|
}
|
|
1205
|
})
|
1262
|
})
|
|
1206
|
},
|
1263
|
},
|
|
1207
|
- payFail() {
|
1264
|
+ payFail(isShow) {
|
|
1208
|
this.setData({
|
1265
|
this.setData({
|
|
1209
|
inputValue: '',
|
1266
|
inputValue: '',
|
|
1210
|
finalList: [],
|
1267
|
finalList: [],
|
|
@@ -1216,8 +1273,11 @@ Page({ |
|
@@ -1216,8 +1273,11 @@ Page({ |
|
1216
|
payType:'2',
|
1273
|
payType:'2',
|
|
1217
|
soothPrice: '',
|
1274
|
soothPrice: '',
|
|
1218
|
})
|
1275
|
})
|
|
1219
|
- this.getCoupon()
|
|
|
|
1220
|
- this.getUserInfo()
|
1276
|
+ // onShow触发时不提前拉券,等getCheckUserHavePhone拿到手机号后再拉,避免漏掉手机号维度的券
|
|
|
|
1277
|
+ if (!isShow) {
|
|
|
|
1278
|
+ this.getCoupon()
|
|
|
|
1279
|
+ this.getUserInfo(this.data.purePhoneNumber)
|
|
|
|
1280
|
+ }
|
|
1221
|
},
|
1281
|
},
|
|
1222
|
giftConsumeFun(priceSum, orderid) {
|
1282
|
giftConsumeFun(priceSum, orderid) {
|
|
1223
|
let isReturn = this.data.isReturn;
|
1283
|
let isReturn = this.data.isReturn;
|
|
@@ -1251,7 +1311,7 @@ Page({ |
|
@@ -1251,7 +1311,7 @@ Page({ |
|
1251
|
sellerid: this.data.seller.sid
|
1311
|
sellerid: this.data.seller.sid
|
|
1252
|
}).then(res => {
|
1312
|
}).then(res => {
|
|
1253
|
if(type == '1'){
|
1313
|
if(type == '1'){
|
|
1254
|
- this.getUserInfo()
|
1314
|
+ this.getUserInfo(this.data.purePhoneNumber)
|
|
1255
|
}
|
1315
|
}
|
|
1256
|
})
|
1316
|
})
|
|
1257
|
},
|
1317
|
},
|
|
@@ -1361,11 +1421,13 @@ Page({ |
|
@@ -1361,11 +1421,13 @@ Page({ |
|
1361
|
let consumeDiscount = this.data.consumeDiscount;
|
1421
|
let consumeDiscount = this.data.consumeDiscount;
|
|
1362
|
let inputValue = this.data.inputValue;
|
1422
|
let inputValue = this.data.inputValue;
|
|
1363
|
const amount = parseFloat(inputValue - consumeDiscount);
|
1423
|
const amount = parseFloat(inputValue - consumeDiscount);
|
|
|
|
1424
|
+ // 券唯一标识:手机号维度券没有 activity_id,用 phone_activity_id 区分,避免不同券互相误匹配
|
|
|
|
1425
|
+ const couponKey = coupon => (coupon.isinitial == '0' ? 'p_' + coupon.phone_activity_id : 'o_' + coupon.activity_id);
|
|
1364
|
const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount) && amount>=parseFloat(coupon.price));
|
1426
|
const validCoupons = arr.filter(coupon => (coupon.isOk == '1' && parseFloat(coupon.desc) <= amount) && amount>=parseFloat(coupon.price));
|
|
1365
|
// 排序后,优先选择最大优惠的券
|
1427
|
// 排序后,优先选择最大优惠的券
|
|
1366
|
validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
|
1428
|
validCoupons.sort((a, b) => parseFloat(b.price) - parseFloat(a.price));
|
|
1367
|
arr.forEach(item => {
|
1429
|
arr.forEach(item => {
|
|
1368
|
- const isValid = validCoupons.some(validCoupon => validCoupon.activity_id == item.activity_id);
|
1430
|
+ const isValid = validCoupons.some(validCoupon => couponKey(validCoupon) == couponKey(item));
|
|
1369
|
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
|
1431
|
item.canCheck = isValid ? '1' : '0'; // 如果在 validCoupons 中,设置 canCheck 为 1,否则为 0
|
|
1370
|
});
|
1432
|
});
|
|
1371
|
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
|
1433
|
console.log('可以勾选的券 && 满足付款条件的券', validCoupons);
|
|
@@ -1399,12 +1461,12 @@ Page({ |
|
@@ -1399,12 +1461,12 @@ Page({ |
|
1399
|
let maxCopies = Math.floor((amount - thresholdDescSum) / couponDesc)
|
1461
|
let maxCopies = Math.floor((amount - thresholdDescSum) / couponDesc)
|
|
1400
|
if (maxCopies > coupon.maxNum) maxCopies = coupon.maxNum
|
1462
|
if (maxCopies > coupon.maxNum) maxCopies = coupon.maxNum
|
|
1401
|
if (maxCopies > 0) {
|
1463
|
if (maxCopies > 0) {
|
|
1402
|
- selectCount[coupon.aid] = maxCopies
|
1464
|
+ selectCount[coupon._key] = maxCopies
|
|
1403
|
thresholdDescSum += couponDesc * maxCopies
|
1465
|
thresholdDescSum += couponDesc * maxCopies
|
|
1404
|
maxThresholdValue += couponPrice * maxCopies
|
1466
|
maxThresholdValue += couponPrice * maxCopies
|
|
1405
|
}
|
1467
|
}
|
|
1406
|
})
|
1468
|
})
|
|
1407
|
- list1 = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
1469
|
+ list1 = stackingCoupons.filter(i => (selectCount[i._key] || 0) > 0)
|
|
1408
|
console.log('可叠加优惠券组合', list1);
|
1470
|
console.log('可叠加优惠券组合', list1);
|
|
1409
|
// 3. 无门槛可叠加券:满减门槛之和小于输入金额时可以叠加,等于时和满减组合取优惠更大的
|
1471
|
// 3. 无门槛可叠加券:满减门槛之和小于输入金额时可以叠加,等于时和满减组合取优惠更大的
|
|
1410
|
// 先算无门槛券单独使用的优惠总额
|
1472
|
// 先算无门槛券单独使用的优惠总额
|
|
@@ -1417,7 +1479,7 @@ Page({ |
|
@@ -1417,7 +1479,7 @@ Page({ |
|
1417
|
let num = Math.floor((amount - noDescValue) / couponPrice)
|
1479
|
let num = Math.floor((amount - noDescValue) / couponPrice)
|
|
1418
|
if (num > coupon.maxNum) num = coupon.maxNum
|
1480
|
if (num > coupon.maxNum) num = coupon.maxNum
|
|
1419
|
if (num > 0) {
|
1481
|
if (num > 0) {
|
|
1420
|
- noDescCount[coupon.aid] = num
|
1482
|
+ noDescCount[coupon._key] = num
|
|
1421
|
noDescValue += couponPrice * num
|
1483
|
noDescValue += couponPrice * num
|
|
1422
|
}
|
1484
|
}
|
|
1423
|
}
|
1485
|
}
|
|
@@ -1432,21 +1494,21 @@ Page({ |
|
@@ -1432,21 +1494,21 @@ Page({ |
|
1432
|
let num = Math.floor((amount - maxStackableValue) / couponPrice)
|
1494
|
let num = Math.floor((amount - maxStackableValue) / couponPrice)
|
|
1433
|
if (num > coupon.maxNum) num = coupon.maxNum
|
1495
|
if (num > coupon.maxNum) num = coupon.maxNum
|
|
1434
|
if (num > 0) {
|
1496
|
if (num > 0) {
|
|
1435
|
- selectCount[coupon.aid] = num
|
1497
|
+ selectCount[coupon._key] = num
|
|
1436
|
maxStackableValue += couponPrice * num
|
1498
|
maxStackableValue += couponPrice * num
|
|
1437
|
}
|
1499
|
}
|
|
1438
|
}
|
1500
|
}
|
|
1439
|
})
|
1501
|
})
|
|
1440
|
- list1 = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
1502
|
+ list1 = stackingCoupons.filter(i => (selectCount[i._key] || 0) > 0)
|
|
1441
|
} else if (noDescValue > maxThresholdValue) {
|
1503
|
} else if (noDescValue > maxThresholdValue) {
|
|
1442
|
// 门槛等于输入金额,不能叠加,取无门槛券或满减券中优惠更大的
|
1504
|
// 门槛等于输入金额,不能叠加,取无门槛券或满减券中优惠更大的
|
|
1443
|
- list1 = stackingCoupons.filter(i => (noDescCount[i.aid] || 0) > 0)
|
1505
|
+ list1 = stackingCoupons.filter(i => (noDescCount[i._key] || 0) > 0)
|
|
1444
|
selectCount = noDescCount
|
1506
|
selectCount = noDescCount
|
|
1445
|
maxStackableValue = noDescValue
|
1507
|
maxStackableValue = noDescValue
|
|
1446
|
} else if (noDescValue == maxThresholdValue && noDescValue > 0) {
|
1508
|
} else if (noDescValue == maxThresholdValue && noDescValue > 0) {
|
|
1447
|
// 优惠相同取最早到期
|
1509
|
// 优惠相同取最早到期
|
|
1448
|
- let listThreshold = stackingCoupons.filter(i => (selectCount[i.aid] || 0) > 0)
|
|
|
|
1449
|
- let listNoDesc = stackingCoupons.filter(i => (noDescCount[i.aid] || 0) > 0)
|
1510
|
+ let listThreshold = stackingCoupons.filter(i => (selectCount[i._key] || 0) > 0)
|
|
|
|
1511
|
+ let listNoDesc = stackingCoupons.filter(i => (noDescCount[i._key] || 0) > 0)
|
|
1450
|
let min1 = listThreshold.length > 0 ? Math.min(...listThreshold.map(item => item.useEtime)) : Infinity
|
1512
|
let min1 = listThreshold.length > 0 ? Math.min(...listThreshold.map(item => item.useEtime)) : Infinity
|
|
1451
|
let min2 = listNoDesc.length > 0 ? Math.min(...listNoDesc.map(item => item.useEtime)) : Infinity
|
1513
|
let min2 = listNoDesc.length > 0 ? Math.min(...listNoDesc.map(item => item.useEtime)) : Infinity
|
|
1452
|
if (min2 < min1) {
|
1514
|
if (min2 < min1) {
|
|
@@ -1500,11 +1562,11 @@ Page({ |
|
@@ -1500,11 +1562,11 @@ Page({ |
|
1500
|
let discountPrice = 0;
|
1562
|
let discountPrice = 0;
|
|
1501
|
// 更新选中的优惠券
|
1563
|
// 更新选中的优惠券
|
|
1502
|
finalList.forEach(coupon => {
|
1564
|
finalList.forEach(coupon => {
|
|
1503
|
- let target = arr.findIndex(obj => obj.activity_id === coupon.activity_id);
|
1565
|
+ let target = arr.findIndex(obj => couponKey(obj) === couponKey(coupon));
|
|
1504
|
if (target>-1) {
|
1566
|
if (target>-1) {
|
|
1505
|
arr[target].showCpupon = 1;
|
1567
|
arr[target].showCpupon = 1;
|
|
1506
|
- arr[target].checkedNum = stackCount[coupon.aid] || 1;
|
|
|
|
1507
|
- discountPrice += parseFloat(coupon.price) * (stackCount[coupon.aid] || 1); // 使用 parseFloat 确保类型正确
|
1568
|
+ arr[target].checkedNum = stackCount[coupon._key] || 1;
|
|
|
|
1569
|
+ discountPrice += parseFloat(coupon.price) * (stackCount[coupon._key] || 1); // 使用 parseFloat 确保类型正确
|
|
1508
|
}
|
1570
|
}
|
|
1509
|
console.log('选中的券', {
|
1571
|
console.log('选中的券', {
|
|
1510
|
...coupon
|
1572
|
...coupon
|
|
@@ -1517,7 +1579,8 @@ Page({ |
|
@@ -1517,7 +1579,8 @@ Page({ |
|
1517
|
for (let k = 0; k < item.checkedNum; k++) {
|
1579
|
for (let k = 0; k < item.checkedNum; k++) {
|
|
1518
|
finalList.push({
|
1580
|
finalList.push({
|
|
1519
|
...item,
|
1581
|
...item,
|
|
1520
|
- activity_id: item.activityIds[k]
|
1582
|
+ activity_id: item.isinitial == '0' ? '' : item.activityIds[k],
|
|
|
|
1583
|
+ phone_activity_id: item.isinitial == '0' ? item.activityIds[k] : (item.phone_activity_id || ''),
|
|
1521
|
})
|
1584
|
})
|
|
1522
|
}
|
1585
|
}
|
|
1523
|
}
|
1586
|
}
|
|
@@ -1842,7 +1905,7 @@ Page({ |
|
@@ -1842,7 +1905,7 @@ Page({ |
|
1842
|
* 生命周期函数--监听页面显示
|
1905
|
* 生命周期函数--监听页面显示
|
|
1843
|
*/
|
1906
|
*/
|
|
1844
|
onShow() {
|
1907
|
onShow() {
|
|
1845
|
- this.payFail()
|
1908
|
+ this.payFail(true)
|
|
1846
|
this.getCheckUserHavePhone()
|
1909
|
this.getCheckUserHavePhone()
|
|
1847
|
this.getFreeMealConfigFun()
|
1910
|
this.getFreeMealConfigFun()
|
|
1848
|
},
|
1911
|
},
|