var system=require("../../system")
var settings=require("../../../config/settings");
const CtlBase = require("../ctl.base");
const fs = require("fs");
const moment = require("moment");

class BmuserbizCtl extends CtlBase{
   constructor(){
     super(CtlBase.getServiceName(BmuserbizCtl));
     //this.appS=system.getObject("service.appSve");
     this.excelClient = system.getObject("util.excelClient");
   }

  async exportAll(query, req, res){
    try {
      let list = await this.service.findExportAll();
      let csvobj = {
        fileName: "恒昌小程序数据" + moment().format("YYYYMMDDHHmmss") + ".csv",
        rows: list,
        opts: {
          fields: ['id', 'legal_name', 'legal_mobile', 'idcard', 'idcard_front', 'idcard_back', 'names',
            'bank', 'bankno', 'bank_front', 'bank_back', 'bankMobile',
            'front_half_img', 'declaration_file', 'submit_time', 'audit_status_name', 'reject_reason'],
          unwind: [],
          unwindBlank: true,
          excelStrings: true,
        },
        headers: {
          'id': '编号',
          'legal_name': '姓名',
          'legal_mobile': '手机号',
          'idcard': '身份证',
          'idcard_front': '身份证正面',
          'idcard_back': '身份证反面',
          'names': '注册名称',
          'bank': '开户行',
          'bankno': '银行卡号',
          'bank_front': '银行卡正面',
          'bank_back': '银行卡背面',
          'bankMobile': '预留手机号',
          'front_half_img': '半身照',
          'declaration_file': '声明书',
          'submit_time': '提交时间',
          'audit_status_name': '审核状态',
          'reject_reason': '不通过原因',
        },
      };
      await this.excelClient.exportCsv(req, res, csvobj);
    } catch (e) {
      console.log(e);
      return system.getErrResult2("您的网络不稳, 请稍后重试");
    }
  }
}
module.exports=BmuserbizCtl;
