order-ensure.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* 订单结算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 addressList = (req, res, next) => {
oeModel.addressList(req.user.uid).then(data => {
res.send(data);
}).catch(next);
};
// 获取区域列表
const getAreaList = (req, res, next) => {
oeModel.areaList(req.query.id).then(data => {
res.send(data);
}).catch(next);
};
// 地址删除
const delAddress = (req, res, next) => {
oeModel.delAddress(req.user.uid, req.body.id).then(data => {
res.send(data);
}).catch(next);
};
// 地址/更新新增
const saveAddress = (req, res, next) => {
oeModel.saveAddress(req.user.uid, req.body).then(data => {
res.send(data);
}).catch(next);
};
// 设置默认地址
const setDefault = (req, res, next) => {
oeModel.setDefault(req.user.uid, req.body.id).then(data => {
res.send(data);
}).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 cartType = req.query.cartType === '2' ? 'advance' : 'ordinary';
oeModel.compute(req.user.uid, cartType, req.query).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,
addressList,
getAreaList,
delAddress,
saveAddress,
setDefault,
getCoupons,
compute,
submit
};