const ServiceBase = require("../../sve.base");
const system = require("../../../system");
const moment = require('moment');

/**
 * 平台提交的信息
 */
class SaasinvoiceService extends ServiceBase {
    constructor() {
        super("invoice", ServiceBase.getDaoName(SaasinvoiceService));
         this.dictionary = system.getObject("util.dictionary");
    }

    async merchantinvoicePage(params) {
        params.currentPage = Number(params.currentPage || 1);
        params.pageSize = Number(params.pageSize || 10);
        params.startRow = Number((params.currentPage - 1) * params.pageSize);

        let total = await this.dao.countByParams(params);
        if (total == 0) {
            return system.getResult({count: 0, rows: []});
        }

        let list = await this.dao.pageByParams(params);
        if (list) {
            for (var item of list) {
                this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
                this.handleDate(item, ['invoice_time'], 'YYYY-MM-DD');
                this.dictionary.setRowName("SAAS_INTEVOICE",item,["owner_type","fee_type","invoice_type","invoice_join"]);
            }
        }
        return system.getResultSuccess({count: total, rows: list});
    }

    async platforminvoicePage(params) {
        params.currentPage = Number(params.currentPage || 1);
        params.pageSize = Number(params.pageSize || 10);
        params.startRow = Number((params.currentPage - 1) * params.pageSize);

        let total = await this.dao.countByParams(params);
        if (total == 0) {
            return system.getResult({count: 0, rows: []});
        }

        let list = await this.dao.pageByParams(params);
        if (list) {
            for (var item of list) {
                this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
                this.handleDate(item, ['invoice_time'], 'YYYY-MM-DD');
                this.dictionary.setRowName("SAAS_INTEVOICE",item,["owner_type","fee_type","invoice_type","invoice_join"]);
            }
        }
        return system.getResultSuccess({count: total, rows: list});
    }


}

module.exports = SaasinvoiceService;
