var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctlms.base");
const logCtl = system.getObject("web.common.oplogCtl");

var cacheBaseComp = null;
class ManagerCtl extends CtlBase {
  constructor() {
    super();
    this.orderSve = system.getObject("service.order.orderSve");
    this.invoiceSve = system.getObject("service.invoice.invoiceSve");
  }

  /**
   * 首页交易数据
   * @param {*} pobj 
   */
  async transData(pobj, pobj2, req) {
    try {
      var params = {
        type: pobj.type || 1,
      };
      // 交易数据
      return await this.orderSve.statManageData(params);
    } catch (e) {
      console.log(e);
      return system.getResultFail(500, "接口错误");
    }
  }

  /**
   * 首页业务数据
   * @param {*} pobj 
   */
  async businessData(pobj, pobj2, req) {
    try {
      var params = {
        type: pobj.type || 1,
      };
      // 业务数据
      return await this.orderSve.statBusinessData(params);
    } catch (e) {
      console.log(e);
      return system.getResultFail(500, "接口错误");
    }
  }

  async deliverData(pobj, pobj2, req) {
    try {
      var params = {
        type: pobj.type || 1,
        currentPage: pobj.currentPage || 1,
        pageSize: pobj.pageSize || 10,
      }
      // 业务办理概览
      return await this.orderSve.statDeliverData(params);

    } catch (e) {
      console.log(e);
      return system.getResultFail(500, "接口错误");
    }
  }


  // 数据简报
  async statTransData(params) {
    if (!params.current_date) {
      return system.getResult(null, `参数错误 当前时间不能为空`);
    }
    try {
      return await this.orderSve.statTransData(params);
    } catch (error) {
      console.log(error);
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }
  //待办事项
  async needToBeDealtWith(params) {
    if (!params.current_date) {
      return system.getResult(null, `参数错误 当前时间不能为空`);
    }
    try {
      return await this.orderSve.needToBeDealtWith(params);
    } catch (error) {
      console.log(error);
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  //交付商统计
  async statDeliverData(params) {
    if (!params.current_date) {
      return system.getResult(null, `参数错误 当前时间不能为空`);
    }
    try {
      return await this.orderSve.statDeliverData(params);
    } catch (error) {
      console.log(error);
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  // 交付商统计
  async deliverStatTransData(params) {
    if (!params.current_date) {
      return system.getResult(null, `参数错误 当前时间不能为空`);
    }
    if (!params.deliver_id) {
      return system.getResult(null, `参数错误 交付商不能为空`);
    }
    try {
      return await this.orderSve.deliverStatTransData(params);
    } catch (error) {
      console.log(error);
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  // 业务办理
  async businessManagement(params) {
    if (!params.current_date) {
      return system.getResult(null, `参数错误 当前时间不能为空`);
    }
    if (!params.deliver_id) {
      return system.getResult(null, `参数错误 交付商不能为空`);
    }
    try {
      return await this.orderSve.businessManagement(params);
    } catch (error) {
      console.log(error);
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }

  }
}
module.exports = ManagerCtl;