order.js
3.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
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
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const crypto = global.yoho.crypto;
const processInvoiceData = (orderInfo, mobile, addresslist) => {
let invoices_title = '';
let invoiceType = '7';
let invoices_type = '2';
let invoice_Top = '个人';
let addressId = orderInfo.addressId &&
parseInt(crypto.encryption('', orderInfo.addressId), 10) || 0;
// 用户手机号处理
if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
mobile = orderInfo.receiverMobile;
} else {
_.forEach(addresslist, addressValue => {
if (addressValue.address_id === addressId) {
mobile = addressValue.mobile;
return false;
}
});
}
// 发票信息处理
if (orderInfo.invoiceType && orderInfo.invoiceTitle) {
invoices_title = orderInfo.invoiceText;
invoiceType = orderInfo.invoiceType * 1;
invoices_type = orderInfo.invoicesType * 1;
invoice_Top = orderInfo.invoiceTitle;
}
return {
invoiceNotice: '发票须知',
phone: mobile ? mobile : '', // TODO 字符串替换 ****
completeTel: mobile,
isCompany: invoice_Top !== '单位',
companyName: invoices_title,
isPaper: invoices_type === 1,
invoicesType: [
{
id: '2',
type: '电子发票',
choosed: !invoices_type || invoices_type === 2,
},
{
id: '1',
type: '纸质发票',
choosed: invoices_type === 1
}
],
invoiceTitle: [
{
type: '个人',
choosed: invoice_Top === '个人'
},
{
type: '单位',
choosed: invoice_Top === '单位'
}
],
content: [
{
choosed: !invoiceType || invoiceType === 7,
id: 7,
text: '服装'
},
{
choosed: invoiceType === 9,
id: 9,
text: '配件'
},
{
choosed: invoiceType === 11,
id: 11,
text: '日用品'
},
// 暂停办公用品开票
// {
// choosed: invoiceType === 3,
// id: 3,
// text: '办公用品'
// },
{
choosed: invoiceType === 6,
id: 6,
text: '体育用品'
},
{
choosed: invoiceType === 10,
id: 10,
text: '数码产品'
},
]
};
};
/**
* 判断用户是否是老用户
*/
const isNewUser = (uid) => {
return api.get('', {
method: 'app.SpaceOrders.get',
type: '5',
page: '1',
limit: '1',
uid: uid
}, {code: 200}).then(result => {
let order = _.get(result, 'data.order_list', []);
if (order.length > 0) {
return false;
} else {
return true;
}
});
};
module.exports = {
processInvoiceData,
isNewUser
};