invoice.js 1.44 KB
/**
 * 我的消息model
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/8/29
 */
'use strict';

const _ = require('lodash');

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    getInvoiceDetail(orderCode, uid) {
        return this.get({data: {
            method: 'app.invoice.detail',
            uid: uid,
            order_code: orderCode
        }}).then(result => {
            if (result.code === 200) {
                _.unset(result, 'data.uid');
                _.set(result, 'data.invoicesType', _.get(result, 'data.invoices_type') === 2 ? '电子发票' : '纸质发票');

                if (!_.get(result, 'data.pdfUrl')) {
                    _.set(result, 'data.showInvoice', false);
                }
            }

            return result;
        });
    }

    submitInvoiceSupply(info, uid) {
        let param = {
            order_code: info.orderCode,
            invoices_type: info.invoicesType,
            invoices_title: info.titleName,
            invoice_content: info.contentId,
            receiverMobile: info.receiver,
            buyerTaxNumber: info.taxNumber,
            invoice_payable_type: info.taxNumber ? 2 : 1
        };

        return this.get({data: Object.assign(param, {
            method: 'app.invoice.supply',
            uid: uid
        })}).then(result => {
            _.unset(result, 'data.uid');

            return result;
        });
    }
};