var system = require("../../../system")
const CtlBase = require("../../ctlms.base");
class InvoiceCtl extends CtlBase {
  constructor() {
    super();
    this.orderSve = system.getObject("service.saas.orderSve");
    this.tradeSve = system.getObject("service.trade.tradeSve");
    this.invoiceSve = system.getObject("service.saas.invoiceSve");
  }

  // 注册订单列表
  async orderPage(params, pobj2, req) {
    try {
      params.unInvoice = 1;
      params.handle_statuses = ['20', '30'];
      this.doTimeCondition(params, ["createBegin", "createEnd"]);
      return await this.orderSve.page(params);
    } catch (error) {
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  // 平台交易列表
  async platformPage(params, pobj2, req) {
    try {
      params.unInvoice = 1;
      params.order_type = "10";
      params.trade_status = "00";
      this.doTimeCondition(params, ["createBegin", "createEnd"]);
      return await this.tradeSve.itemPage(params);
    } catch (error) {
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  // 商户交易列表
  async merchantPage(params, pobj2, req) {
    try {
      params.unInvoice = 1;
      params.order_type = "20";
      params.trade_status = "00";
      this.doTimeCondition(params, ["createBegin", "createEnd"]);
      return await this.tradeSve.itemPage(params);
    } catch (error) {
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  // 发票申请
  async apply(params, pobj2, req) {
    try {
      return await this.orderSve.page(params);
    } catch (error) {
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  //发票列表
  async invoicePage(params, pobj2, req) {
  try {
      let rs = await this.invoiceSve.saasinvoicePage(params);
      return rs;
    } catch (error) {
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }
}
module.exports = InvoiceCtl;
