coupons.js
1.54 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
// 优惠券 by acgpiano
'use strict';
const moment = require('moment');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const couponData = (params) => {
return api.get('', params).then(result => {
if (result && result.data && result.data.couponList) {
let times = moment().valueOf() / 1000;
let expireTime = 3600 * 24 * 3; //即将过期时间3天
let status0 = params.status === 0;
let status1 = params.status === 1;
return result.data.couponList.map(function(elem) {
delete elem.id;
elem.isNoLimit = elem.isNoLimit === 'true';// 全场通用
elem.isDiscount = (`,${elem.shopPriceLimits},`).indexOf(',1,') !== -1;// 三折以下
elem.isLimited = (`,${elem.shopPriceLimits},`).indexOf(',2,') !== -1;// 限量
if (status0) {
elem.isSoonExpire = (elem.endTime - times) < expireTime;
elem.bestowLink = helpers.urlFormat('/product/index/index',
{
coupon_id: elem.couponId,
title: '优惠活动商品',
intro_text: `以下商品可使用【${elem.couponDetailInfomation}】优惠券`
}
);
} else if (status1) {
elem.employbg = true;
}
return elem;
});
}
return [];
});
};
module.exports = {
couponData
};