var System = require("../../system")
var settings = require("../../../config/settings");
const logCtl = System.getObject("web.oplogCtl");
const md5 = require("MD5");
class Xbg {
  constructor() {
    this.zxyAppSecretKey = settings.apiconfig.zxyAppSecretKey();
    this.oplogSve = System.getObject("service.oplogSve");
    this.oplogSve = System.getObject("service.oplogSve");
  }
  async transferNotify(obj) {
    //返回值
    // var tmpSignObj = {
    //   "accNo": "6214850112377038", "accType": "00", "amt": 100,
    //   "appId": "1103817785", "busiId": "1103817785420820481",
    //   "currency": "CNY", "idName": "宋毅", "idNo": "341221198504218256",
    //   "idType": "00", "mobile": "15010929366", "note": "知产平台转账操作",
    //   "notityUrl": "http://igirl.gongsibao.com/api/xbg/transferNotify",
    //   "outTradeNo": "fxfx_XxHqg5hLlP", "platformSeqNo": "1120991431960649729",
    //   "respCode": "00", "respDesc": "成功", "seqNo": "1001",
    //   "sign": "6E1F113FDBA02F37DB53C5273EF847AF", "signType": "MD5", "tradeStatus": "00",
    //   "tradeTime": "20190424180307", "tradeType": "00"
    // };
    //日志记录
    logCtl.info({
      optitle: "请求薪必果接口回调结果信息===info",
      op: "/app/base/api/impl/xbg.js/transferNotify",
      content: "param=" + JSON.stringify(obj),
      clientIp: ""
    });
    var respCode = obj.respCode || "";
    var outTradeNo = obj.outTradeNo || "";
    var sign = obj.sign || "";
    if (respCode && outTradeNo && sign) {
      var signArr = [];
      signArr.push("accNo=" + obj.accNo);
      signArr.push("accType=" + obj.accType);
      signArr.push("amt=" + obj.amt);
      signArr.push("appId=" + obj.appId);
      signArr.push("busiId=" + obj.busiId);
      signArr.push("currency=" + obj.currency);
      signArr.push("idName=" + obj.idName);
      signArr.push("idNo=" + obj.idNo);
      signArr.push("idType=" + obj.idType);
      signArr.push("mobile=" + obj.mobile);
      signArr.push("note=" + obj.note);
      signArr.push("notityUrl=" + obj.notityUrl);
      signArr.push("outTradeNo=" + obj.outTradeNo);
      signArr.push("platformSeqNo=" + obj.platformSeqNo);
      signArr.push("respCode=" + obj.respCode);
      signArr.push("respDesc=" + obj.respDesc);
      signArr.push("seqNo=" + obj.seqNo);
      signArr.push("signType=" + obj.signType);
      signArr.push("tradeStatus=" + obj.tradeStatus);
      signArr.push("tradeTime=" + obj.tradeTime);
      signArr.push("tradeType=" + obj.tradeType);
      signArr.push("key=" + this.zxyAppSecretKey);
      // accNo=6214850112377038&accType=00&amt=100&appId=1103817785&busiId=1103817785420820481&
      // currency=CNY&idName=宋毅&idNo=341221198504218256&idType=00&mobile=15010929366&note=测试-知圈圈&
      // notityUrl=http://bpohhr.gongsibao.com/api/econtractApi/transferNotify&outTradeNo=PRO201903251623VGjsy01&platformSeqNo=1116256506449272833&respCode=00&respDesc=成功&seqNo=1001&signType=MD5&tradeStatus=00&tradeTime=20190411162729&tradeType=00&key=ca47edd3ae8bac3f7a68d8126d891f52
      var tmpSign = md5(signArr.join("&")).toUpperCase();
      if (tmpSign == sign) {
        var tmpCount = await this.oplogSve.getCountBySourceOrderNo(outTradeNo);
        if (tmpCount > 0) {
          await this.oplogSve.updateByCallback(obj);
          return { code: "0000" };
        }
      }
    }
  }
}
module.exports = Xbg;
