order-ensure.js
1.71 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
/**
* 订单结算controller
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/12/21
*/
'use strict';
const headerModel = require('../../../doraemon/models/simple-header');
const oeModel = require('../models/order-ensure');
const stepper = [
{name: '查看购物车', focus: true},
{name: '填写订单', focus: true},
{name: '付款,完成购买'}
];
const index = (req, res, next) => {
let cartType = req.query.cartType === '2' ? 'advance' : 'ordinary';
oeModel.index(req.user.uid, cartType).then(result => {
let header = headerModel.setSimpleHeaderData() || {};
Object.assign(result, {
stepper: stepper
});
res.render('order-ensure2016', {
page: 'ensure',
content: result,
simpleHeader: header
});
}).catch(next);
};
// 获取优惠券列表
const getCoupons = (req, res, next) => {
oeModel.getCoupons(req.user.uid).then(data => {
res.send(data);
}).catch(next);
};
// 订单金额计算
const compute = (req, res, next) => {
let params = req.body;
let cartType = params.cartType === '2' ? 'advance' : 'ordinary';
oeModel.compute(req.user.uid, cartType, params).then(data => {
res.send(data);
}).catch(next);
};
// 提交订单
const submit = (req, res, next) => {
let cartType = req.body.cartType === '2' ? 'advance' : 'ordinary';
if (!req.body.addressId) {
res.send({
code: 500,
message: '配送地址不能为空'
});
return;
}
oeModel.submit(req.user.uid, cartType, req.body).then(data => {
res.send(data);
}).catch(next);
};
module.exports = {
index,
getCoupons,
compute,
submit
};