var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const uuidv4 = require('uuid/v4');
var svgCaptcha = require('svg-captcha');

var cacheBaseComp = null;
class MerchantrechargeCtl extends CtlBase {
  constructor() {
    super("merchant", CtlBase.getServiceName(MerchantrechargeCtl));

    this.redisClient = system.getObject("util.redisClient");

    this.merchantSve = system.getObject("service.merchant.merchantSve");
  }
  async rechargeList(pobj, pobj2, req) {
    try {
      var condition = {
        currentPage: pobj.currentPage,
        pageSize: pobj.pageSize,
        merchantName: this.trim(pobj.merchantName),
        merchantId: pobj.merchantId
      }
      this.doTimeCondition(condition, ["createdBegin", "createdEnd"]);

      if(pobj.status) {
        condition.status = Number(pobj.status);
      }
      var page = await this.service.pageByCondition(condition);
      return system.getResultSuccess(page);
    } catch (error) {
      console.log(error);
      return system.getResultFail(500, "接口异常：" + error.message);
    }
  }

  async rechargeAudit(pobj, pobj2, req) {
    try {
      var loginUser = req.loginUser;
      var id = Number(pobj.id);
      var auditStatus = Number(pobj.status);
      var remark = this.trim(pobj.remark);
      if(auditStatus != 1 && auditStatus != 2) {
        return system.getResult(null, "审核状态错误");
      }

      if(auditStatus == 2 && !remark) {
        return system.getResult(null, "请填写审核备注");
      }

      var page = await this.service.audit(id, auditStatus, remark);
      return system.getResultSuccess(page);
    } catch (error) {
      console.log(error);
      return system.getResultFail(500, "接口异常：" + error.message);
    }
  }
}
module.exports = MerchantrechargeCtl;