sellerGift.js
25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
// pages/reserve/sellerGift.js
import util from '../../utils/util';
import App from '../../utils/api';
import RS from '../../utils/reserveStatus'
Page({
/**
* 页面的初始数据
*/
data: {
options: {},
marketing: {},
recharge_data: {},
coupon_dataList: [],
seller: {
name: '',
tablesText: '',
date: '',
addr: ''
},
StyleType: '',
priceInfo: '',
scoreInfo: '',
discount: '',
certificate: '',
dataStr: Date.now() * 1 / 1000,
is_comments: '0',
is_user_comments: false,
hasValueCertificate: false, //商家是否开通优惠券功能
hasValueRecharge: false, //商家是否开通充值功能
couponData: '', //评价赠送优惠券数据
},
give_user:'',
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.id = options.id
let param = {
options: options
}
console.log('options', options);
this.setData(param)
},
// 去评价
evaluateFun() {
let url = util.http_build_query({
sellerName: this.data.seller.name,
sellerid: this.data.seller.sid,
oid: this.data.options.id,
types: '1',
previousPage: '1',
}, '/pages/pinglun/createOpinion')
wx.navigateTo({
url
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getDetail()
},
// 获取店铺详情
getDetail() {
App.Reserve.Detail({
openid: getApp().openid,
rid: this.data.options.id
}).then(res => {
let reserev = RS.reserve(res.data)
this.give_user = reserev.give_user ? reserev.give_user : '2';
this.setData({
is_user_comments: res.data.is_user_comments,
seller: {
name: reserev.seller.sellername,
sid: reserev.sid,
}
})
console.log('reserev reserev', reserev);
setTimeout(() => {
this.getSellerVersionFun(reserev.sid);
this.getSellerTemplateConfFun(reserev.sid);
}, 0);
}).catch(res => {
console.log(res, '详情请求失败');
})
},
// 获取商家版本,不是超能版或者没有开通对应模块,不显示
getSellerVersionFun(sellerid) {
App.SellerVersion.GetSellerVersion({
sellerid
}).then((res) => {
let data = res.data;
console.log('版本列表', data);
if (data && data.length > 0) {
data.sort((a, b) => b.cdate * 1 - a.cdate * 1);
// 获取店铺当前版本 (cdate最大最后一个充入的 && 当前时间有效 && 当前版本)
let obj = data.find(item => item.vtype == 1 || item.vtype == 2 || item.vtype == 4);
console.log('当前版本', {
...obj
});
// 优惠券功能:超能版 || 高级版 || 有优惠券模块
const hasValueCertificate = obj.vtype == '1' || obj.vtype == '4' || data.some(item => item.vid == '8');
// 充值功能:超能版 || 有充值模块
const hasValueRecharge = obj.vtype == '1' || data.some(item => item.vid == '9');
this.setData({
hasValueCertificate,
hasValueRecharge,
})
}
})
},
// 获取商家设置营销信息
getSellerTemplateConfFun(sid) {
console.log(sid, 'sidsidsidsid');
App.Seller.GetSellerTemplateConf({
sid
}).then(res => {
let data = res.data
console.log('data', data);
let couponList = []
let StyleType, marketing, coupon, coupon_data_pay, coupon_data_free, is_comments;
marketing = util.determine(data.marketing);
StyleType = data.type;
if (marketing) {
is_comments = marketing.is_comments ? marketing.is_comments : '';
coupon = (marketing.coupon_data && marketing.is_coupon == '1') ? util.determine(marketing.coupon_data) : '';
coupon_data_pay = (marketing.coupon_data_pay && marketing.is_coupon_pay == '1') ? util.determine(marketing.coupon_data_pay) : '';
marketing.coupon_data_payList = coupon_data_pay
coupon_data_free = (marketing.coupon_data_free && marketing.is_coupon_free == '1') ? util.determine(marketing.coupon_data_free) : '';
marketing.coupon_data_freeList = coupon_data_free
let info = marketing.coupon_data_comments ? util.determine(marketing.coupon_data_comments) : '';
let couponDataId = info && info.length > 0 ? info[0].id : {}
// 根据券ID获取评价赠送的券详情
if(couponDataId) this.getEvaluateFun(couponDataId)
}
// is_cash 代金券 is_discount折扣券 is_dish菜品券 只有代金券有几折显示
// 获取全部的优惠券(商家券、个人券、免费券、付费券)
couponList = this.addCoupons(coupon,couponList);
couponList = this.addCoupons(coupon_data_pay,couponList);
couponList = this.addCoupons(coupon_data_free,couponList);
// 根据券ID获取券详情
this.getActivityByIdFun(couponList)
// 根据充值ID获取充值详情
if (marketing && marketing.is_recharge && marketing.is_recharge == '1' && marketing.recharge_data) {
this.getRechargeDetail(marketing.recharge_data.id)
}
let obj = {
marketing,
coupon,
is_comments,
StyleType,
}
console.log('获取数据', {
...obj
});
this.setData({
...obj
})
}).catch(res => {
console.log('GetSellerTemplateConf请求失败');
})
},
// 获取评价赠送的券最新详情
getEvaluateFun(id){
App.Activity.GetActivityById({
id
}).then(res => {
if (res.data.length > 0) {
let detail = res.data[0]
let data = detail.expiration_date ? util.determine(detail.expiration_date) : '';
detail.use = detail.use ? util.determine(detail.use) : '';
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
if ((detail.use && (!detail.use.is_cash || detail.use.is_cash == '1'))) {
let cash = detail.use.cash * 1;
let price = detail.price * 1;
detail.discount = cash != 0 ? ((price / cash) * 10).toFixed(1) : '';
}
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
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.use && (!detail.use.is_cash || detail.use.is_cash == '1'))) {
let cash = detail.use.cash * 1;
let price = detail.price * 1;
detail.discount = cash != 0 ? ((price / cash) * 10).toFixed(1) : '';
}
let num = detail.grant_num*1-detail.grant_last*1;
if (num > 0) {
detail.receiveNumText = ''
if (num >= 0 && num <= 100) {
detail.receiveNumText = num.toString();
} else if (num >= 101 && num <= 199) {
detail.receiveNumText = '100+';
} else if (num >= 200 && num <= 299) {
detail.receiveNumText = '200+';
} else {
detail.receiveNumText = Math.floor(num / 100) * 100 + '+';
}
}
if(num == 0){
let str = detail.grant_num*1
detail.receiveNumText = ''
if (str >= 0 && str <= 100) {
detail.receiveNumText = str.toString();
} else if (str >= 101 && str <= 199) {
detail.receiveNumText = '100+';
} else if (str >= 200 && str <= 299) {
detail.receiveNumText = '200+';
} else {
detail.receiveNumText = Math.floor(str / 100) * 100 + '+';
}
}
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.resultCoupon = '1'; // 显示已领取
detail.cdate = detail.cdate * 1;
detail.useStime = '';
detail.useEtime = '';
let condition = detail.aexpiration
if (condition.valid_forever === '0' && condition.stime && condition.etime) {
detail.useStime = util.unixtoTime(condition.stime, 'YYYY-MM-DD');
detail.useEtime = util.unixtoTime(condition.etime, 'YYYY-MM-DD');
}
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;
}
// showCoupon 代表赠送的券没过有效期 && 是开启状态
detail.showCoupon = (((data.valid_forever == '0' && this.data.dataStr < (data.etime * 1)) || data.valid_forever == '1') && detail.is_open == '1') ? '1' : '0';
console.log('邀请函--------------------评价赠送的优惠券',detail);
this.setData({
couponData:detail
})
}
})
},
// 根据充值ID获取充值详情
getRechargeDetail(id) {
App.Activity.GetNewRecharge({
id
}).then(res => {
let detail = res.data
let exp_date = res.data.exp_date ? JSON.parse(res.data.exp_date) : ''
let recharge_list = res.data.recharge_list ? JSON.parse(res.data.recharge_list) : ''
let priceInfo, scoreInfo, certificate;
detail.recharge_list = recharge_list;
detail.exp_date = exp_date;
if (recharge_list.is_price == '1') priceInfo = '会员充值满' + detail.recharge_money + '元赠送' + recharge_list.price + '元余额';
if (recharge_list.is_score == '1') scoreInfo = '会员充值满' + detail.recharge_money + '元赠送' + recharge_list.score + '积分';
if (recharge_list.is_coupons == '1' && recharge_list.coupons_names.length > 0) certificate = recharge_list.coupons_names.join('、');
let recharge_data = ((this.data.dataStr<detail.etime*1 || !detail.etime) && detail.is_open == '1') ? detail : ''
console.log('邀请函--------------充值',recharge_data);
this.setData({
recharge_data,
scoreInfo,
priceInfo,
certificate
})
})
},
// 根据券ID获取券详情
getActivityByIdFun(obj) {
App.Activity.GetActivityById({
id: obj.map(item => item.id).join(','),
}).then(res => {
if (res.data.length > 0) {
// valid_forever 1永久 0非永久
let list = res.data.filter(item => {
let data = item.expiration_date ? util.determine(item.expiration_date) : {};
let validForever = data.valid_forever === '1';
let isValid = item.is_type === '3' ?
(validForever || (data.valid_forever === '0' && this.data.dataStr < (data.etime * 1))) :
(this.data.dataStr < (item.etime * 1));
return isValid && item.is_open === '1';
});
list.forEach(detail => {
detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
detail.arule = detail.arule ? util.determine(detail.arule) : '';
detail.use = detail.use ? util.determine(detail.use) : '';
detail.expiration_date = detail.expiration_date ? util.determine(detail.expiration_date) : '';
detail.aexpiration = detail.aexpiration ? util.determine(detail.aexpiration) : '';
if ((detail.use && (!detail.use.is_cash || detail.use.is_cash == '1'))) {
let cash = detail.use.cash * 1;
let price = detail.price * 1;
detail.discount = cash != 0 ? ((price / cash) * 10).toFixed(1) : '';
}
let num = detail.grant_num*1-detail.grant_last*1;
if (num > 0) {
detail.receiveNumText = ''
if (num >= 0 && num <= 100) {
detail.receiveNumText = num.toString();
} else if (num >= 101 && num <= 199) {
detail.receiveNumText = '100+';
} else if (num >= 200 && num <= 299) {
detail.receiveNumText = '200+';
} else {
detail.receiveNumText = Math.floor(num / 100) * 100 + '+';
}
}
if(num == 0){
let str = detail.grant_num*1
detail.receiveNumText = ''
if (str >= 0 && str <= 100) {
detail.receiveNumText = str.toString();
} else if (str >= 101 && str <= 199) {
detail.receiveNumText = '100+';
} else if (str >= 200 && str <= 299) {
detail.receiveNumText = '200+';
} else {
detail.receiveNumText = Math.floor(str / 100) * 100 + '+';
}
}
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;
}
})
let freeCoupons = list.filter(item => {
return item.is_type == '3'
})
let give = this.give_user;
let couponShow = false;
switch (give) {
case '1':
couponShow = this.data.options.hasSellerShare == '1' ? true : false;
break;
case '2':
couponShow = true;
break;
case '3':
couponShow = this.data.options.hasSellerShare != '1' ? true : false;
break;
}
// 显示已领取
if (freeCoupons.length > 0 && couponShow) {
this.getCoupon(freeCoupons,obj)
}
console.log('邀请函--------------------优惠券', list);
this.setData({
coupon_dataList: list,
})
}
})
},
// 免费券显示已领取
getCoupon(arr) {
let str = arr.flatMap(item => Array(item.number).fill(item.id)).join(',');
App.Activity.ActivityListByOpenid({
aid: str,
sellerid:this.data.seller.sid,
}).then(res => {
if (res.ret == 200) {
let coupon_dataList = this.data.coupon_dataList;
let list = res.data;
list.forEach(item=>{
item.cdate = item.cdate * 1;
item.useStime = '';
item.useEtime = '';
let condition = item.aexpiration ? util.determine(item.aexpiration) : '';
if (condition.valid_forever === '0' && condition.stime && condition.etime) {
item.useStime = util.unixtoTime(condition.stime, 'YYYY-MM-DD');
item.useEtime = util.unixtoTime(condition.etime, 'YYYY-MM-DD');
}
if (condition.valid_forever === '1') {
item.foreverText = '永久有效';
}
if (condition.valid_forever === '0' && condition.today) {
let obj = this.setTimeRange(item.cdate, 0, parseInt(condition.today) - 1);
item.useStime = obj.useStimeNum;
item.useEtime = obj.useEtimeNum;
}
if (condition.valid_forever === '0' && condition.tomorrow) {
let obj = this.setTimeRange(item.cdate, 1, condition.tomorrow * 1);
item.useStime = obj.useStimeNum;
item.useEtime = obj.useEtimeNum;
}
if (condition.valid_forever === '0' && condition.sday && condition.eday) {
let obj = this.setTimeRange(item.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
item.useStime = obj.useStimeNum;
item.useEtime = obj.useEtimeNum;
}
})
list = list.filter(item => {
let condition = item.aexpiration ? util.determine(item.aexpiration) : '';
return (item.useEtime >= this.data.dataStr) || (item.foreverText == '永久有效') || (condition.valid_forever === '0' && condition.stime && condition.etime)
});
list.sort((a, b) => b.cdate - a.cdate);
list = list.reduce((accumulator, current) => {
if (!accumulator.some(item => item.aid === current.aid)) {
accumulator.push(current);
}
return accumulator;
}, []);
list.forEach(item=>{
let idx = coupon_dataList.findIndex(b => b.id === item.id);
if (idx !== null && idx !== undefined && coupon_dataList[idx]) {
const detail = coupon_dataList[idx];
detail.resultCoupon = '1'; // 显示已领取
detail.cdate = item.cdate * 1;
detail.useStime = '';
detail.useEtime = '';
let condition = detail.aexpiration
if (condition.valid_forever === '0' && condition.stime && condition.etime) {
detail.useStime = util.unixtoTime(condition.stime, 'YYYY-MM-DD');
detail.useEtime = util.unixtoTime(condition.etime, 'YYYY-MM-DD');
}
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;
}
}
})
this.setData({
coupon_dataList,
})
}
})
},
// 获取所有的券并且展示
addCoupons(coupons, couponList) {
if (coupons && util.getType(coupons) == 'object') {
couponList.push({
id: coupon.id,
number: coupon.number
});
}
if (coupons && util.getType(coupons) === 'array' && coupons.length > 0) {
coupons.forEach(item => {
couponList.push({
id: item.id,
number: item.number
});
});
}
return couponList
},
// 计算免费券有效期的起始、结束日期
setTimeRange(cdate, startOffset, endOffset) {
console.log(cdate, startOffset, endOffset);
const startDate = new Date((cdate + startOffset * 86400) * 1000);
startDate.setHours(0, 0, 0, 0);
const useStime = util.unixtoTime(startDate.getTime() / 1000, 'YYYY-MM-DD');
const endDate = new Date((cdate + endOffset * 86400) * 1000);
endDate.setHours(23, 59, 59, 0);
const useEtime = util.unixtoTime(endDate.getTime() / 1000, 'YYYY-MM-DD');
let useEtimeNum = endDate.getTime() / 1000;
return { useStime, useEtime,useEtimeNum };
},
// 处理优惠券不可用日期数据
hasConsecutiveSelect(arr, type) {
let firstTitle = null;
let lastTitle = null;
let rArr = []
let num = 0
for (let i = 0; i < arr.length; i++) {
let str = type == '1' ? arr[i].selectMor : type == '2' ? arr[i].selectNoon : type == '3' ? arr[i].selectNig : '';
if (str) {
rArr.push(arr[i].title)
num++
if (num == 1) {
firstTitle = arr[i].title
}
if (num >= 5) {
lastTitle = arr[i].title
}
if (num >= 5 && i >= (arr.length - 1)) {
let fi = rArr.findIndex((item) => {
return item == firstTitle
})
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
num = 0
}
} else {
if (num < 5) {
num = 0
firstTitle = null;
lastTitle = null;
} else {
let fi = rArr.findIndex((item) => {
return item == firstTitle
})
rArr.splice(fi, num, firstTitle + '至' + lastTitle)
num = 0
}
}
}
return {
rArr,
lastTitle,
firstTitle
};
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
})