invoice.js 1.09 KB
'use strict';

const ordersService = require('../models/orders-service');
const invoiceModel = require('../models/invoice');

const index = (req, res, next) => {
    let page = parseInt(req.query.page, 10) || 1;
    let limit = parseInt(req.query.limit, 10) || 10;

    return req.ctx(ordersService).index(req.user.uid, page, limit, 8).then(result => {
        res.render('invoice', {
            meOrders: result
        });
    }).catch(next);
};

const detail = (req, res, next) => {
    return req.ctx(invoiceModel).getInvoiceDetail(req.query.orderCode, req.user.uid).then(result => {
        res.send(result);
    }).catch(next);
};

const supply = (req, res, next) => {
    let params = req.body;

    // 5.8.1 发票优化需求
    // 只接受电子发票(1 纸质 2 电子),发票内容为明细(id 12:明细)
    Object.assign(params, {
        invoicesType: 2,
        contentId: 12
    });

    return req.ctx(invoiceModel).submitInvoiceSupply(params, req.user.uid).then(result => {
        res.send(result);
    }).catch(next);
};

module.exports = {
    index,
    detail,
    supply
};