order.js 2.04 KB
'use strict';

const api = global.yoho.API;
const _ = require('lodash');
const crypto = global.yoho.crypto;

const processInvoiceData = (orderInfo, mobile, addresslist) => {
    let invoices_title = '';
    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;
        invoices_type = orderInfo.invoicesType * 1;
        invoice_Top = orderInfo.invoiceTitle;
    }

    return {
        phone: mobile ? mobile : '', // TODO 字符串替换 ****
        completeTel: mobile,
        isCompany: invoice_Top !== '单位',
        companyName: invoices_title,
        isPaper: invoices_type === 1,
        invoicesType: [
            {
                id: '2',
                type: '电子发票'
            }
        ],
        invoiceTitle: [
            {
                type: '个人',
                choosed: invoice_Top === '个人'
            },
            {
                type: '单位',
                choosed: invoice_Top === '单位'
            }
        ]
    };

};

/**
 * 判断用户是否是老用户
 */
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
};