address.js
2.21 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
/**
* 个人中心---地址管理
* @author gaohongwei <hongwei.gao@yoho.cn>
* @date: 2016/9/5
*/
'use strict';
const mRoot = '../models';
const addressModel = require(`${mRoot}/address-service`); // user 页 model
const cleanHtml = require(`${global.utils}/cleanHtml`);
/**
* 地址管理列表
*/
exports.index = (req, res, next) => {
let uid = req.user.uid;
let responseData = {
module: 'home',
page: 'address'
};
// 真实数据输出
req.ctx(addressModel).getAddressInfo(uid).then(result => {
responseData.meAddressPage = true;
responseData.address = result.address;
res.render('home/address/address', responseData);
}).catch(next);
};
/**
* 编辑修改地址
*/
exports.editAddress = (req, res, next) => {
let uid = req.user.uid;
if (!req.body.id) {
return res.json({code: 400});
}
// 真实数据输出
req.ctx(addressModel).editAddress(req.body, uid).then(result => {
result.data.address = cleanHtml.htmlDecode(result.data.address);
result.data.consignee = cleanHtml.htmlDecode(result.data.consignee);
res.json(result);
}).catch(next);
};
/**
* 添加保存地址
*/
exports.saveAddress = (req, res, next) => {
let uid = req.user.uid;
req.body.addressName = cleanHtml.htmlEncode(req.body.addressName);
// 真实数据输出
req.ctx(addressModel).saveAddress(req.body, uid).then(result => {
res.json(result);
}).catch(next);
};
/**
* 删除地址
*/
exports.delAddress = (req, res, next) => {
let uid = req.user.uid;
if (!req.query.id) {
return res.json({
code: 400,
message: '缺失必填项'
});
}
// 真实数据输出
req.ctx(addressModel).delAddress(req.query, uid).then(result => {
res.json(result);
}).catch(next);
};
/**
* 设置默认地址
*/
exports.defaultAddress = (req, res, next) => {
let uid = req.user.uid;
if (!req.body.id) {
return res.json({
code: 400,
message: '缺失必填项'
});
}
// 真实数据输出
req.ctx(addressModel).defaultAddress(req.body, uid).then(result => {
res.json(result);
}).catch(next);
};