order.js
1.92 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
/**
* 个人中心-订单列表 controller
* @author: jing.li<jing.li@yoho.cn>
* @date: 2016/08/15
*/
'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const orderModel = require('../models/order');
/**
* 订单页面
* @param req
* @param res
* @param next
*/
exports.order = (req, res, next) => {
let params = {
type: req.query.type || 1,
page: req.query.page || 1,
gender: req.query.gender || '1,3',
yh_channel: req.query.channel || 1,
uid: req.user.uid
};
// 获取第一页数据做服务端渲染
let initialData = {
type: 1,
page: 1,
gender: req.query.gender || '1,3',
yh_channel: req.query.channel || 1,
uid: req.user.uid
};
return Promise.all([
orderModel.order(params),
orderModel.getOrders(initialData)
]).then(result => {
res.render('order', {
module: 'home',
page: 'order',
pageHeader: headerModel.setNav({
navTitle: '我的订单'
}),
title: 'Yoho!Buy 有货',
pageFooter: true,
order: result[0] || [],
firstPageOrdersList: result[1] || []
});
}).catch(next);
};
/**
* 获取订单
* @param req
* @param res
* @param next
*/
exports.getOrders = (req, res, next) => {
let start = req.query.start || 0;
let params = {
type: req.query.type || 1,
page: req.query.page || 1,
gender: req.query.gender || '1,3',
yh_channel: req.query.channel || 1,
uid: req.user.uid
};
orderModel.getOrders(params).then(result => {
if (result && parseInt(params.page, 10) === 1 && parseInt(start, 10) > 0) {
result = result.slice(start || 0);
}
res.render('order-content', {
layout: false,
orders: result
});
}).catch(next);
};