|
|
'use strict';
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
const _ = require('lodash');
|
|
|
const crypto = global.yoho.crypto;
|
|
|
|
|
|
const processInvoiceData = (orderInfo, mobile, addresslist) => {
|
|
|
let invoices_title = false;
|
|
|
let invoices_title_personal = false;
|
|
|
let invoices_type = '2';
|
|
|
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;
|
|
|
}
|
|
|
});
|
|
|
class orderModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
// 发票信息处理
|
|
|
if (orderInfo.invoices_type && orderInfo.invoices_title) {
|
|
|
invoices_title = orderInfo.invoices_title;
|
|
|
invoices_type = orderInfo.invoices_type * 1;
|
|
|
}
|
|
|
processInvoiceData(orderInfo, mobile, addresslist) {
|
|
|
let invoices_title = false;
|
|
|
let invoices_title_personal = false;
|
|
|
let invoices_type = '2';
|
|
|
let addressId = orderInfo.addressId &&
|
|
|
parseInt(crypto.encryption('', orderInfo.addressId), 10) || 0;
|
|
|
|
|
|
invoices_title_personal = orderInfo.invoices_title_personal || '个人(可修改)';
|
|
|
// 用户手机号处理
|
|
|
if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
|
|
|
mobile = orderInfo.receiverMobile;
|
|
|
} else {
|
|
|
_.forEach(addresslist, addressValue => {
|
|
|
if (addressValue.address_id === addressId) {
|
|
|
mobile = addressValue.mobile;
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let isCompany = invoices_title && invoices_title !== '个人';
|
|
|
// 发票信息处理
|
|
|
if (orderInfo.invoices_type && orderInfo.invoices_title) {
|
|
|
invoices_title = orderInfo.invoices_title;
|
|
|
invoices_type = orderInfo.invoices_type * 1;
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
phone: mobile ? mobile : '',
|
|
|
completeTel: mobile,
|
|
|
isCompany: isCompany,
|
|
|
companyName: isCompany ? invoices_title : invoices_title_personal,
|
|
|
buyerTaxNumber: orderInfo.buyerTaxNumber,
|
|
|
isPaper: invoices_type === 1,
|
|
|
invoicesType: [
|
|
|
{
|
|
|
id: '2',
|
|
|
type: '电子发票'
|
|
|
}
|
|
|
],
|
|
|
invoiceTitle: [
|
|
|
{
|
|
|
type: '个人',
|
|
|
choosed: !isCompany
|
|
|
},
|
|
|
{
|
|
|
type: '单位',
|
|
|
choosed: isCompany
|
|
|
}
|
|
|
]
|
|
|
};
|
|
|
invoices_title_personal = orderInfo.invoices_title_personal || '个人(可修改)';
|
|
|
|
|
|
};
|
|
|
let isCompany = invoices_title && invoices_title !== '个人';
|
|
|
|
|
|
/**
|
|
|
* 判断用户是否是老用户
|
|
|
*/
|
|
|
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', []);
|
|
|
return {
|
|
|
phone: mobile ? mobile : '',
|
|
|
completeTel: mobile,
|
|
|
isCompany: isCompany,
|
|
|
companyName: isCompany ? invoices_title : invoices_title_personal,
|
|
|
buyerTaxNumber: orderInfo.buyerTaxNumber,
|
|
|
isPaper: invoices_type === 1,
|
|
|
invoicesType: [
|
|
|
{
|
|
|
id: '2',
|
|
|
type: '电子发票'
|
|
|
}
|
|
|
],
|
|
|
invoiceTitle: [
|
|
|
{
|
|
|
type: '个人',
|
|
|
choosed: !isCompany
|
|
|
},
|
|
|
{
|
|
|
type: '单位',
|
|
|
choosed: isCompany
|
|
|
}
|
|
|
]
|
|
|
};
|
|
|
|
|
|
if (order.length > 0) {
|
|
|
return false;
|
|
|
} else {
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断用户是否是老用户
|
|
|
*/
|
|
|
isNewUser(uid) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.SpaceOrders.get',
|
|
|
type: '5',
|
|
|
page: '1',
|
|
|
limit: '1',
|
|
|
uid: uid
|
|
|
},
|
|
|
param: {code: 200}
|
|
|
}).then(result => {
|
|
|
let order = _.get(result, 'data.order_list', []);
|
|
|
|
|
|
module.exports = {
|
|
|
processInvoiceData,
|
|
|
isNewUser
|
|
|
}; |
|
|
if (order.length > 0) {
|
|
|
return false;
|
|
|
} else {
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
module.exports = orderModel; |
...
|
...
|
|