<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task id="__8fsTqwsRdZvHzwO2fiT">
  <name>确认成绩后台补偿平台费</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <description>补偿订单表中完成了报名费的缴费却未完成平台费缴费的数据</description>
  <type>1</type>
  <runningTime>2023-04-24T09:22:24.000+08:00</runningTime>
  <interval>10</interval>
  <period>34</period>
  <runtimes>0</runtimes>
  <terminateScript><![CDATA[]]></terminateScript>
  <taskScript><![CDATA[#include "payChack";
#include "payFunction";
#include "payPlatform";
(function(){
  var sql = "select a.created,a.item_trainname,a.item_learnname,a.item_trainid,a.item_learnid,a.item_price,a.item_bcx,a.id from tlk_learn_order_person a inner join tlk_system_exam_person b on a.item_appid = b.item_applyid where a.item_orderstate = '1' and a.item_price != '0' and a.lastflowoperation is null and b.item_scorestate = '1' and a.item_statusorder = '1' ORDER BY 	a.item_trainname,a.	item_learnname,a.created desc limit 100";
  var strs = "";//公司id数组
  var strs2 = "";//公司名称数组
  var process = getDocumentProcess();
  var formProcess = getFormProcess();
  var subform = formProcess.doView("__7fyG90RxjIFYpUmxocN");//转账组后台日志表
  var datas = queryByDSName("tms",sql);
  var i = 0;
  if(datas!="[]"){
    for(var iterator = datas.iterator();iterator.hasNext();){
      var map1 = iterator.next();//取值
      var learnid = map1.get("item_learnid");//保安公司id
      var trainid = map1.get("item_trainid");//培训机构id
      var learnname = map1.get("item_learnname");
      var trainname = map1.get("item_trainname");
      var string = learnid+";"+trainid;
      var string2 = learnname+";"+trainname
      if(!isNotNull(strs)){
        strs+=string;
        strs2=string2;
      }
      if(isNotNull(strs)){
        if(strs.indexOf(string) == -1){
          strs+=",";
          strs+=string;
          strs2+=",";
          strs2+=string2;
        }
      }
    }
    println("strs-----------------"+strs);
    var strarrto = strs.split(",");
    var namearrto = strs2.split(",");
    println("strarrto------"+strarrto[0]);
    var p = 1;
    var d = 0;
    for(var i=0;i<strarrto.length;i++){
      println("i----------------"+i);
      println("strarrto.length-----------------"+strarrto.length)
      var arrto = [];
      var sumprice = 0;
      var sumbcx = 0;
      if(datas!=null){
        for(var iterator = datas.iterator();iterator.hasNext();){
          var map1 = iterator.next();//取值
          var learnid = map1.get("item_learnid");//保安公司id
          var trainid = map1.get("item_trainid");//培训机构id
          var price = map1.get("item_price");
          var bcx = map1.get("item_bcx");
          var id = map1.get("id");
          var string = learnid+";"+trainid;
          if(string.equals(strarrto[i])){
            arrto.push(id);
            d+=1;
            sumprice+=parseInt(price);
            sumbcx+=parseInt(bcx);
          }
        }
      }
      println("第"+p+"组"+strarrto[i]+"里有"+arrto);
      println("查了多少人："+d)
      println("第"+p+"组"+strarrto[i]+"里的报名费总额是"+sumprice);
      println("第"+p+"组"+strarrto[i]+"里的平台费总额是"+sumbcx);
      p+=1;
      var errorreason = "";
      var companyid = strarrto[i].split(";");
      var companyname = namearrto[i].split(";");
      println("companyid1---------"+companyid[0]);
      println("companyid2---------"+companyid[1]);
      println("companyname1---------"+companyname[0]);
      println("companyname2---------"+companyname[1]);
      var sqlout = "select comId from com_base_info where tlkComId='"+companyid[1]+"'"
      var datasoutId = queryByDSName("pay", sqlout);
      if (datasoutId.size() > 0) {
        for (var iterator = datasoutId.iterator(); iterator.hasNext();) {
          var map1 = iterator.next();//取值
          var outid = map1.get("comid");//获取本企业的id
        }
      } else {
        errorreason = "平台费出账方未开通账户";
      }
      //转账平台费
      var doc = process.doNew(subform, getWebUser(), createParamsTable());
      var logid = doc.getId();
      var uuid = new Packages.cn.myapps.util.sequence.Sequence().getSequence();  //流水号
      println("lym+++++++++arrto------------"+arrto.toString());
      doc.addStringItem("uuid", uuid);//流水号
      doc.addStringItem("orderid", arrto.toString());//订单id
      doc.addStringItem("orderstate", "0");//转账状态：0为未转账，1为转账成功
      doc.addStringItem("outid", outid);//出账id
      //var inid = "961981641130291200";//测试
      var inid = "821420231244144641";//生产
      doc.addStringItem("inid", inid);//入账id
      doc.addStringItem("learnid", companyid[0]);//保安公司id
      doc.addStringItem("trainid", companyid[1]);//培训机构id
      doc.addStringItem("learnname", companyname[0]);//保安公司名称
      doc.addStringItem("trainname", companyname[1]);//培训机构名称
      doc.addStringItem("ordertype", "1");//转账类型:0为报名费，1为平台费
      doc.addStringItem("sumprice", sumprice);//报名费总额
      doc.addStringItem("sumbcx", sumbcx);//平台费总金额
      doc.addStringItem("errorreason", errorreason);//失败原因
      doc.addStringItem("number",arrto.length);
      doc.setDomainid(companyid[1]);
      println("doc-------------"+doc);
      process.doCreate(doc);
      var chackflag = payChack(companyid[1],companyid[1]);
      if(!"success".equals(chackflag)){
        var errorsql = "update tlk_pay_group_log set item_errorreason = '"+chackflag+"' where id = '"+logid+"'";
        println("errorsql1------------"+errorsql);
        updateByDSName("tms",errorsql);
        continue;
      }
      //到这里就说明可以转平台费了
      var platformflag = payPlatform(companyid[1],outid,sumbcx,uuid,arrto.length);
      //var platformflag = "success";
      if("success".equals(platformflag)){
        var idarrto = arrto.toString().split(",");
        var ids = "";
        for(var o=0;o<idarrto.length;o++){
          ids+="'";
          ids+=idarrto[o];
          ids+="'";
          ids+=",";
        }
        ids = ids.substr(0,ids.length-1);
        var successordersql = "update tlk_learn_order_person set item_statusorder = '2' where id in ("+ids+")";
        println("successordersql---------------"+successordersql); 
        updateByDSName("tms",successordersql);
        var successsql = "update tlk_pay_group_log set item_orderstate = '1' where id = '"+logid+"'"
        println("successsql---------------"+successsql);
        updateByDSName("tms",successsql);
      }else{
        var errorsql = "update tlk_pay_group_log set item_errorreason = '"+platformflag+"' where id = '"+logid+"'";
        println("errorsql1------------"+errorsql);
        updateByDSName("tms",errorsql);
      }
    }
  }
})()]]></taskScript>
  <modifyTime>2023-04-24T09:22:22.000+08:00</modifyTime>
  <creator>Admin</creator>
  <creatorid>Ai6hllhNjS2ull9TKGb</creatorid>
  <totalRuntimes>0</totalRuntimes>
  <state>0</state>
  <startupType>2</startupType>
  <dayOfMonth>1</dayOfMonth>
  <repeatTimes>0</repeatTimes>
  <frequency>0</frequency>
  <executedCount>0</executedCount>
  <rDate></rDate>
  <rTime></rTime>
</task>