const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")

class SaasorderbusinessmenService extends ServiceBase {
  constructor() {
    super("saas", ServiceBase.getDaoName(SaasorderbusinessmenService));

    this.saasorderbminfoDao = system.getObject("db.saas.saasorderbminfoDao");
    this.saasorderpayDao = system.getObject("db.saas.saasorderpayDao");
    this.saasorderdeliverinfoDao = system.getObject("db.saas.saasorderdeliverinfoDao");
    this.redisClient = system.getObject("util.redisClient");
  }

  /**
   * 查询个体户列表
   * @param params
   * @returns {Promise<{msg: *, data, bizmsg: *|string, status: number}>}
   */
  async saasorderbusinessmenPage(params){
    let where = {};
    if (params.credit_code) {
      where.credit_code = this.trim(params.credit_code);
    }
    if (params.name) {
      where.name = this.trim(params.name);
    }
    if (params.legal_idcard) {
      where.legal_idcard = this.trim(params.legal_idcard);
    }
    params.currentPage = Number(params.currentPage || 1);
    params.pageSize = Number(params.pageSize || 10);
    params.startRow = (params.currentPage - 1) * params.pageSize;

    try {
      let countRes = await  this.dao.saasorderbusinessmenCount(params);
      if(countRes.count==0){
        return system.getResult({count:0, rows: []});
      }
      let res = await this.dao.saasorderbusinessmenPage(params);

      for (let item of res) {
        this.handleDate(item, ["created_at", "reg_date", "service_begin_time", "service_end_time", "sign_time"], "YYYY-MM-DD HH:mm:ss", -8);
        item.is_bank_name = item.is_bank ? "已开户" : "未开户";
        item.common_tax_ladder = JSON.parse(item.common_tax_ladder);
        item.common_other_ladder = JSON.parse(item.common_other_ladder);
        item.special_tax_ladder = JSON.parse(item.special_tax_ladder);
        item.special_other_ladder = JSON.parse(item.special_other_ladder);
      }
      return system.getResult({count:countRes.count, rows: res});
    }catch (e) {
      console.log(e);
      return system.getResult(nul, `系统错误`);
    }
  }


}

module.exports = SaasorderbusinessmenService;