...
|
...
|
@@ -6,7 +6,10 @@ const co = Promise.coroutine; |
|
|
|
|
|
const UserData = require('./user-data');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const path = require('path');
|
|
|
// 使用 product中的分页逻辑
|
|
|
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
const pager = require(pagerPath).handlePagerData;
|
|
|
|
|
|
const UNUSED = 'notuse';
|
|
|
const USED = 'use';
|
...
|
...
|
@@ -16,6 +19,7 @@ const getCouponsList = (uid, type, page, limit)=>{ |
|
|
return co(function*() {
|
|
|
let couponsInfo = yield UserData.getCouponsList(uid, type, page, limit);
|
|
|
let result = [];
|
|
|
|
|
|
if (!couponsInfo.data.couponList) {
|
|
|
return result;
|
|
|
}
|
...
|
...
|
@@ -71,17 +75,79 @@ const getCouponsList = (uid, type, page, limit)=>{ |
|
|
}
|
|
|
});
|
|
|
}
|
|
|
return {list: result, pager: {
|
|
|
total: couponsInfo.data.total,
|
|
|
pageTotal: couponsInfo.data.totalPageNum,
|
|
|
page: page
|
|
|
}};
|
|
|
|
|
|
let pageNum = pager(couponsInfo.data.total, {
|
|
|
page: page,
|
|
|
limit: limit,
|
|
|
type: type
|
|
|
})
|
|
|
|
|
|
return {
|
|
|
list: result,
|
|
|
pager: Object.assign({
|
|
|
count: couponsInfo.data.total || 0,
|
|
|
curPage: page,
|
|
|
totalPages: couponsInfo.data.totalPageNum
|
|
|
}, pageNum)
|
|
|
};
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
const couponsData = (uid, params)=>{
|
|
|
let type = params.type || UNUSED;
|
|
|
let page = params.page || 1;
|
|
|
let limit = params.limit || 10;
|
|
|
|
|
|
return co(function*() {
|
|
|
let coupons = yield getCouponsList(uid, type, page, limit);
|
|
|
let data = {};
|
|
|
|
|
|
data.pager = coupons.pager;
|
|
|
if (type === UNUSED) {
|
|
|
if (!coupons.list.length) {
|
|
|
data.unUseCoupons = {empty: '您没有优惠券'};
|
|
|
} else {
|
|
|
data.unUseCoupons = coupons.list;
|
|
|
}
|
|
|
data.unUse = true;
|
|
|
} else if (type === USED) {
|
|
|
if (!coupons.list.length) {
|
|
|
data.usedCoupons = {empty: '您没有优惠券'};
|
|
|
} else {
|
|
|
data.usedCoupons = coupons.list;
|
|
|
}
|
|
|
data.used = true;
|
|
|
} else if (type === INVALID) {
|
|
|
if (!coupons.list.length) {
|
|
|
data.noValidCoupons = {empty: '您没有优惠券'};
|
|
|
} else {
|
|
|
data.noValidCoupons = coupons.list;
|
|
|
}
|
|
|
data.noValid = true;
|
|
|
}
|
|
|
|
|
|
data.tabs = [
|
|
|
{
|
|
|
active: type === UNUSED ? true : false,
|
|
|
url: helpers.urlFormat('/home/coupons', {type: UNUSED}),
|
|
|
name: '未使用优惠券'
|
|
|
},
|
|
|
{
|
|
|
active: type === USED ? true : false,
|
|
|
url: helpers.urlFormat('/home/coupons', {type: USED}),
|
|
|
name: '已使用优惠券'
|
|
|
},
|
|
|
{
|
|
|
active: type === INVALID ? true : false,
|
|
|
url: helpers.urlFormat('/home/coupons', {type: INVALID}),
|
|
|
name: '已失效优惠券'
|
|
|
}
|
|
|
];
|
|
|
|
|
|
return data;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getCouponsList,
|
|
|
UNUSED,
|
|
|
USED,
|
|
|
INVALID
|
|
|
couponsData
|
|
|
}; |
...
|
...
|
|