order.js 2.64 KB
'use strict';

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 = '个人';

    // 用户手机号处理
    if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
        mobile = orderInfo.receiverMobile;
    } else {
        _.forEach(addresslist, addressValue => {
            if (addressValue.address_id === crypto.encryption('', orderInfo.addressId)) {
                mobile = addressValue.mobile;
            }
        });
    }

    // 发票信息处理
    if (orderInfo.invoiceType && orderInfo.invoiceTitle) {
        invoices_title = orderInfo.invoiceText;
        invoiceType = orderInfo.invoiceType;
        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: '数码产品'
            },
        ]
    };

};

module.exports = {
    processInvoiceData
};