currency.js
2.6 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
/**
* [个人中心]yoho币
* @author: jiangmin
* @date: 2016/07/11
*/
'use strict';
const mcHandler = require('../models/menu-crumb-handler');
const currencyModel = require('../models/currency');
/**
* 时间格式化
* @param time
* @param a
* @returns {string}
*/
const getTime = (time, a)=> {
let newDate = new Date(time.getFullYear(), time.getMonth() + 1, time.getDate() - 30 * a);
return newDate.getFullYear() + '-' + newDate.getMonth() + '-' + newDate.getDate();
};
/**
* 取时间的秒数
* @param time
* @returns {number}
*/
const getDate = (time)=> {
if (typeof (time) === 'string') {
return new Date(time).getTime() / 1000;
} else {
return new Date(time.getFullYear() + '-' + time.getMonth() + '-' + time.getDate()).getTime() / 1000;
}
};
/**
* yoho币页面加载
*/
const index = (req, res, next) => {
let uid = req.user.uid;
let page = parseInt(req.query.page, 10) || 1;
let queryType = parseInt(req.query.queryType, 10) || 0;
let beginTime = req.query.beginTime || getTime(new Date(), 3);
let date1 = getDate(new Date());
let date2 = getDate(beginTime);
let selectIndex = parseInt((date1 - date2) / (90 * 3600 * 24), 10);
Promise.all([currencyModel.getIndexData(uid, page, queryType, beginTime), mcHandler.getMeThumb()]).then(result => {
const thumb = result[1];
result[0].list.tabs[queryType].isActive = true;
result[0].list.coinList.forEach(function(x) {
x.date = x.date.replace(/\-/g, '.');
});
result[0].list.selects[selectIndex > 2 ? 2 : selectIndex].isSelected = 'selected';
if (result[0].list.paginationOpts) {
result[0].list.paginationOpts.queryParams = {
queryType: queryType,
beginTime: beginTime
};
}
res.display('index', {
module: 'me',
page: 'currency',
isMe: true,
content: {
nav: mcHandler.getMeCrumb('我的YOHO币'),
navigation: mcHandler.getSideMenu('我的YOHO币'),
banner: thumb,
currency: true,
tabs: result[0].list.tabs,
title: '我的YOHO币',
currentYear: new Date().getFullYear(),
data: result[0].list.coinList,
paginationOpts: result[0].list.paginationOpts,
num: result[0].num.data,
selects: result[0].list.selects,
total: result[0].list.total ? result[0].list.total : 0
}
});
}).catch(next);
};
module.exports = {
index
};