order.js
3.29 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
115
116
117
118
119
120
121
122
123
124
125
126
/**
* 订单 controller
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/07/04
*/
'use strict';
const orderModel = require('../models/order');
const cleanHtml = require(`${global.utils}/cleanHtml`);
const _ = require('lodash');
const helper = global.yoho.helpers;
const crypto = global.yoho.crypto;
const config = global.yoho.config;
const logger = global.yoho.logger;
// 结算页面
const index = (req, res, next) => {
orderModel.index(req.user.uid).then(result => {
let data = result.data;
if (data.goods_list && data.goods_list.length > 0) {
// 设置头部路径索引focus
data.bcNavFocus = 2;
data.delivery_way = _.concat(_.find(data.delivery_way, {
delivery_way_id: 1
}));
// 发票抬头
data.invoices.invoiceTitle = [{
name: '个人',
value: 1,
myClass: 'personal'
}, {
name: '单位',
value: 2
}];
// 返回购物车链接
data.goCartLink = helper.urlFormat('/shopping/cart');
// 拆单是否显示左右切换
_.forEach(data.shopping_cart_data.package_list, i => {
if (i.goods_list.length > 4) {
i.showToggle = true;
}
});
// 是否打印价格radio
data.printPriceRadio = [{
value: '1',
name: '是'
}, {
value: '0',
name: '否',
checked: true
}];
if (data.delivery_address) {
data.delivery_address.address = cleanHtml.htmlDecode(data.delivery_address.address);
}
// is_limit_skn=Y 不支持7天无理由退换货
_.forEach(data.goods_list, item => {
item.isLimitSkn = item.is_limit_skn === 'Y';
});
res.header('Cache-Control', 'no-store');
res.display('order', {
content: data,
defaultHeader: false
});
} else {
res.redirect('/shopping/cart');
}
}).catch(next);
};
// 订单金额计算
const compute = (req, res, next) => {
orderModel.compute(req.user.uid, req.body.coin).then(result => {
res.send(result);
}).catch(next);
};
// 订单提交
const orderSub = (req, res, next) => {
var other = req.body;
// 参数校验
if (!other.address_id) {
res.send({
code: 500,
message: '配送地址不能为空'
});
return;
} else {
logger.info(`order submit, address_id decrypt. address_id = ${other.address_id}`);
other.address_id = crypto.decrypt(config.crypto.common, other.address_id);
}
other.remark = cleanHtml.htmlEncode(other.remark);
other.invoices_title = cleanHtml.htmlEncode(other.invoices_title);
orderModel.submit(req.user.uid, other).then(result => {
// 拼接地址
if (result.code === 200) {
result.data.payUrl = helper.urlFormat('/shopping/pay/online', {
code: result.data.order_code
});
}
res.send(result);
}).catch(next);
};
module.exports = {
index,
compute,
orderSub
};