address.js
2 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
/**
* address model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/09/27
*/
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const addressApi = require('../models/address-api');
const getAreaListData = (id) => {
return addressApi.getAreaListAsync(id);
};
const getAddressListData = (uid) => {
return addressApi.getAddressListAsync(uid).then(result => {
if (result.code !== 200) {
return result;
}
let d = result.data;
_.forEach(d, dd => {
if (dd.is_default === 'Y') {
dd.default = true;
}
// 地址加密
let id = dd.address_id;
dd.id = crypto.encryption('', `${id}`);
delete dd.address_id;
delete dd.uid; // 删除uid,用户数据保密
});
return result;
});
};
const delAddressById = (uid, id) => {
id = crypto.decrypt('', `${id}`);
return addressApi.delAddressAsync(uid, id);
};
const saveAddressData = (uid, info) => {
if (info.id) {
let id = crypto.decrypt('', `${info.id}`);
return addressApi.updateAddressAsync(uid, id, info.consignee, info.areaCode, info.address,
info.mobile, info.phone, info.zipCode, info.email);
} else {
return addressApi.addAddressAsync(uid, info.consignee, info.areaCode, info.address, info.mobile,
info.phone, info.zipCode, info.email).then(result => {
if (result.code === 200) {
let d = result.data;
d.id = crypto.encryption('', `${d.address_id}`);
delete d.address_id;
delete d.uid;
}
return result;
});
}
};
const setDefaultAddress = (uid, id) => {
id = crypto.decrypt('', `${id}`);
return addressApi.setDefaultAddressAsync(uid, id);
};
module.exports = {
getAreaListData,
getAddressListData,
delAddressById,
saveAddressData,
setDefaultAddress
};