coupons.js
2.12 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
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
let CouponsModel=require('../models/CouponsModel');
const helpers = global.yoho.helpers;
const index=(req,res,next)=>{
let uid='8041246';
let type=req.query.type||CouponsModel.UNUSED;
let page='';
let limit='';
co(function*(){
let coupons= yield CouponsModel.getCouponsList(uid,type,page,limit);
let data={};
data.pager={
hasCheckAll:false,
count:coupons.pager.total||0,
curPage:coupons.pager.page||0,
totalPages:coupons.pager.pageTotal||0
};
if(type===CouponsModel.UNUSED){
if(!coupons.list.length){
data.unUseCoupons={empty:'您没有优惠券'};
}else{
data.unUseCoupons=coupons.list;
}
data.unUse=true;
}else if(type===CouponsModel.USED){
if(!coupons.list.length){
data.usedCoupons={empty:'您没有优惠券'};
}else{
data.usedCoupons=coupons.list;
}
data.used=true;
}
else if(type===CouponsModel.INVALID){
if(!coupons.list.length){
data.noValidCoupons={empty:'您没有优惠券'};
}else{
data.noValidCoupons=coupons.list;
}
data.noValid=true;
}
data.tabs=[
{
active:type===CouponsModel.UNUSED?true:false,
url:helpers.urlFormat('/home/coupons',{type:CouponsModel.UNUSED}),
name:'未使用优惠券'
},
{
ctive:type===CouponsModel.USED?true:false,
url:helpers.urlFormat('/home/coupons',{type:CouponsModel.USED}),
name:'已使用优惠券'
},
{
ctive:type===CouponsModel.INVALID?true:false,
url:helpers.urlFormat('/home/coupons',{type:CouponsModel.INVALID}),
name:'已失效优惠券'
}
];
res.render("coupons",data);
})();
}
module.exports = {
index
};