<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task id="__XVIeSkqjo7Qk1BEFxWk">
  <name>确认成绩后台支付</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <description>确认成绩变更业务数据后，后台进行支付</description>
  <type>1</type>
  <runningTime>2023-04-25T10:52:40.000+08:00</runningTime>
  <interval>3</interval>
  <period>34</period>
  <runtimes>0</runtimes>
  <terminateScript><![CDATA[]]></terminateScript>
  <taskScript><![CDATA[#include "payChack";
#include "payFunction";
#include "payPlatform";
#include "payFind";
(function(){
  var sql = "select id,item_orderid,item_learnid,item_trainid,item_outid,item_inid,item_sumprice,item_uuid,item_number,item_ordertype,item_prodstatus,item_sumbcx from tlk_pay_group_log  where item_orderstate = '0'  order by created limit 50";
  var datas = queryByDSName("tms",sql);
  if(datas!="[]"){
    for(var iterator = datas.iterator();iterator.hasNext();){
      var map1 = iterator.next();//取值
      var id = map1.get("id");
      var learnid = map1.get("item_learnid");//保安公司id
      var trainid = map1.get("item_trainid");//培训机构id
      var outid = map1.get("item_outid");
      var inid = map1.get("item_inid");
      var uuid = map1.get("item_uuid");
      var number = map1.get("item_number");
      var ordertype = map1.get("item_ordertype");
      var sumprice = map1.get("item_sumprice");
      var orderid = map1.get("item_orderid");
      var sumbcx = map1.get("item_sumbcx");
      var prodstatus = map1.get("item_prodstatus");
      if(isNotNull(prodstatus)){
      }else{
        prodstatus = "1";
      }
      if(!isNotNull(orderid)||!isNotNull(learnid)||!isNotNull(sumprice)||!isNotNull(trainid)||!isNotNull(outid)||!isNotNull(inid)||!isNotNull(uuid)||!isNotNull(number)||!isNotNull(sumbcx)||!isNotNull(ordertype)){
        var upsql = "update tlk_pay_group_log set item_errorreason = '数据不全，请排查' where id = '"+id+"'";
        updateByDSName("tms",upsql);
        continue;
      }
      if("0".equals(ordertype)){//报名费
        println("ordertype----------"+ordertype);
        //1.先查询雪峰/wallet/find-wallet-trade-info-by-business有没有成功的数据
        var idarrto = orderid.split(",");
        var ids = "";
        for(var u=0;u<idarrto.length;u++){
          ids+="'";
          ids+=idarrto[u];
          ids+="'";
          ids+=",";
        }
        ids = ids.substr(0,ids.length-1);
        var findresponse = payFind(uuid,"01001",prodstatus);
        println("findresponse----------"+findresponse);
        if("success".equals(findresponse)){
          var updatesql = "update tlk_learn_order_person a inner join tlk_pay_group_log b on a.item_paygroupid = b.id set a.item_statusorder = '1',b.item_orderstate = '1' where a.id in ("+ids+")";
          println("updatesql----------"+updatesql);
          updateByDSName("tms",updatesql);
        }else if("fail".equals(findresponse)){//没有的话就先调用payChack再调用payFuntion缴报名费
          var chackflag = payChack(learnid,trainid,prodstatus);
          println("chackflag----------"+chackflag);
          if("success".equals(chackflag)){
            var tlkDomainId = learnid;
            var functionflag = payFunction(tlkDomainId,outid,inid,sumprice,uuid,number,prodstatus)
            println("functionflag----------"+functionflag);
            if("success".equals(functionflag)){
              var successordersql = "update tlk_learn_order_person a inner join tlk_pay_group_log b on a.item_paygroupid = b.id set a.item_statusorder = '1',b.item_orderstate = '1' where a.id in ("+ids+")";
              println("successordersql---------------"+successordersql); 
              updateByDSName("tms",successordersql);
            }else{
              var errorsql = "update tlk_pay_group_log set item_errorreason = '"+functionflag+"' where id = '"+id+"'";
              println("errorsql1------------"+errorsql);
              updateByDSName("tms",errorsql);
            }
          }else{
            var errorsql = "update tlk_pay_group_log set item_errorreason = '"+chackflag+"' where id = '"+id+"'";
            println("errorsql1------------"+errorsql);
            updateByDSName("tms",errorsql);
          }
        }else{
          var errorsql = "update tlk_pay_group_log set item_errorreason = '"+findresponse+"' where id = '"+id+"'";
          println("errorsql1------------"+errorsql);
          updateByDSName("tms",errorsql);
        }
      }else if("1".equals(ordertype)){//平台费
        //1.先查询雪峰/wallet/find-wallet-trade-info-by-business有没有成功的数据
        var idarrto = orderid.split(",");
        var ids = "";
        for(var u=0;u<idarrto.length;u++){
          ids+="'";
          ids+=idarrto[u];
          ids+="'";
          ids+=",";
        }
        ids = ids.substr(0,ids.length-1);
        var findresponse = payFind(uuid,"01901",prodstatus);
        println("findresponse----------"+findresponse);
        if("success".equals(findresponse)){
          var updatesql = "update tlk_learn_order_person a inner join tlk_pay_group_log b on a.item_paygroupptid = b.id set a.item_ptpaystatus = '1',b.item_orderstate = '1' where a.id in ("+ids+")";
          updateByDSName("tms",updatesql);
        }else if("fail".equals(findresponse)){//没有的话就先调用payChack再调用payPlatform缴平台费
          var chackflag = payChack(learnid,trainid,prodstatus);
          println("chackflag----------"+chackflag);
          if("success".equals(chackflag)){
            var tlkDomainId = trainid;
            var tradeType = "03";
            if(learnid.equals(trainid)){
              tradeType = "05";
            }
            var platformflag = payPlatform(tlkDomainId,outid,sumbcx,uuid,number,prodstatus,tradeType);
            println("platformflag----------"+platformflag);
            if("success".equals(platformflag)){
              var successordersql = "update tlk_learn_order_person a inner join tlk_pay_group_log b on a.item_paygroupptid = b.id set a.item_ptpaystatus = '1',b.item_orderstate = '1' where a.id in ("+ids+")";
              println("successordersql---------------"+successordersql); 
              updateByDSName("tms",successordersql);
            }else{
              var errorsql = "update tlk_pay_group_log set item_errorreason = '"+platformflag+"' where id = '"+id+"'";
              println("errorsql1------------"+errorsql);
              updateByDSName("tms",errorsql);
            }
          }else{
            var errorsql = "update tlk_pay_group_log set item_errorreason = '"+chackflag+"' where id = '"+id+"'";
            println("errorsql1------------"+errorsql);
            updateByDSName("tms",errorsql);
          }
        }else{
          var errorsql = "update tlk_pay_group_log set item_errorreason = '"+findresponse+"' where id = '"+id+"'";
          println("errorsql1------------"+errorsql);
          updateByDSName("tms",errorsql);
        }
      }
    }
  }
})()]]></taskScript>
  <modifyTime>2023-04-25T10:52:40.000+08:00</modifyTime>
  <creator>Admin</creator>
  <creatorid>Ai6hllhNjS2ull9TKGb</creatorid>
  <totalRuntimes>0</totalRuntimes>
  <state>0</state>
  <startupType>1</startupType>
  <dayOfMonth>1</dayOfMonth>
  <repeatTimes>0</repeatTimes>
  <frequency>0</frequency>
  <executedCount>0</executedCount>
  <rDate></rDate>
  <rTime></rTime>
</task>