...
|
...
|
@@ -7,6 +7,7 @@ const co = Promise.coroutine; |
|
|
const UserData = require('./user-data');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const path = require('path');
|
|
|
const _ = require('lodash');
|
|
|
// 使用 product中的分页逻辑
|
|
|
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
const pager = require(pagerPath).handlePagerData;
|
...
|
...
|
@@ -19,11 +20,13 @@ 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;
|
|
|
|
|
|
if (!_.get(couponsInfo, 'data.couponList')) {
|
|
|
return {
|
|
|
list: result
|
|
|
};
|
|
|
}
|
|
|
let coupons = couponsInfo.data.couponList;
|
|
|
let coupons = _.get(couponsInfo, 'data.couponList');
|
|
|
if (coupons) {
|
|
|
coupons.forEach(function(item, i) {
|
|
|
result[i] = {};
|
...
|
...
|
@@ -53,14 +56,14 @@ const getCouponsList = (uid, type, page, limit)=>{ |
|
|
|
|
|
|
|
|
if (type === USED) {
|
|
|
result[i].orderNum = item.orderCode ? item.orderCode : '';
|
|
|
result[i].orderNum = _.get(item, 'orderCode', '');
|
|
|
result[i].orderDetailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: item.orderCode || ''});
|
|
|
result[i].orderSum = item.orderPrice.toFixed(2) ? item.orderPrice : 0;
|
|
|
result[i].payment = item.actuallyPaid.toFixed(2) ? item.actuallyPaid : 0;
|
|
|
result[i].orderSum = _.get(item, 'orderPrice', 0).toFixed(2);
|
|
|
result[i].payment = _.get(item, 'actuallyPaid', 0).toFixed(2);
|
|
|
let data = result[i].usedTime ? moment(result[i].usedTime).format('YYYY-MM-DD') : 0;
|
|
|
|
|
|
if (data) {
|
|
|
result[i].useTime = new Date(date).getTime();
|
|
|
result[i].useTime = new Date(data).getTime();
|
|
|
} else {
|
|
|
result[i].useTime = '';
|
|
|
}
|
...
|
...
|
@@ -101,28 +104,15 @@ const couponsData = (uid, params)=>{ |
|
|
return co(function*() {
|
|
|
let coupons = yield getCouponsList(uid, type, page, limit);
|
|
|
let data = {};
|
|
|
|
|
|
data.pager = coupons.pager;
|
|
|
console.log(coupons);
|
|
|
if (type === UNUSED) {
|
|
|
if (!coupons.list.length) {
|
|
|
data.unUseCoupons = {empty: '您没有优惠券'};
|
|
|
} else {
|
|
|
data.unUseCoupons = coupons.list;
|
|
|
}
|
|
|
data.unUseCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;
|
|
|
data.unUse = true;
|
|
|
} else if (type === USED) {
|
|
|
if (!coupons.list.length) {
|
|
|
data.usedCoupons = {empty: '您没有优惠券'};
|
|
|
} else {
|
|
|
data.usedCoupons = coupons.list;
|
|
|
}
|
|
|
data.usedCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;
|
|
|
data.used = true;
|
|
|
} else if (type === INVALID) {
|
|
|
if (!coupons.list.length) {
|
|
|
data.noValidCoupons = {empty: '您没有优惠券'};
|
|
|
} else {
|
|
|
data.noValidCoupons = coupons.list;
|
|
|
}
|
|
|
data.noValidCoupons = !coupons.list.length ? {empty: '您没有优惠券'} : coupons.list;
|
|
|
data.noValid = true;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -144,6 +134,8 @@ const couponsData = (uid, params)=>{ |
|
|
}
|
|
|
];
|
|
|
|
|
|
data.pager = coupons.pager;
|
|
|
|
|
|
return data;
|
|
|
})();
|
|
|
};
|
...
|
...
|
|