<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <meta charset="UTF-8">
  <title>充值查询列表|----软件管理平台</title>
  <link rel="stylesheet" type="text/css" href="__CSS__/base.css" media="all">
  <link rel="stylesheet" type="text/css" href="__CSS__/common.css" media="all">
  <link rel="stylesheet" type="text/css" href="__CSS__/style.css" media="all">
  <link rel="stylesheet" type="text/css" href="__CSS__/default_color.css" media="all">
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
  <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />

  <script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
  <script type="text/javascript" src="__JS__/select2.min.js"></script>
  <script type="text/javascript" src="__STATIC__/layer3/layer.js"></script>
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"charset="UTF-8"></script>
  <script src="__STATIC__/juicer-min.js" type="text/javascript"></script>
</head>
<style>
  body {
    padding: 0px;
  }
  .input-list, .i_list {
    /*float: none;*/
    margin: 0;
  }
  .search_list>div {
    margin-top: 9px;
    line-height: 40px;
  }
</style>
<style>
  .select2-container--default .select2-selection--single {
    color: #000;
    resize: none;
    border-width: 1px;
    border-style: solid;
    border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
    box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
    height:28px;border-radius:3px;font-size:12px;
  }
  .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height:35px;
    line-height:28px;
  }
  .select2-container--default .select2-selection--single .select2-selection__arrow {
    height:26px;
  }
  .select2-container--default .select2-search--dropdown .select2-search__field {
    height:26px;line-height:26px;font-size:12px;
  }
  .select2-results__option[aria-selected] {font-size:12px;}
</style>
<body>
<div id="main" class="main" style="min-height: 342px;width: 92.5%;">
  <script src="__STATIC__/layer/layer.js" type="text/javascript"></script>

  <link rel="stylesheet" type="text/css" href="__CSS__/admin_table.css" media="all">
  <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>

  <div class="cf top_nav_list" style="height: 250px;margin-left: 5px">
    <!-- 高级搜索 -->
    <div class="jssearch cf search_list" >
<!--      <div class="input-list search-title-box">-->
<!--        <label>乙方:</label>-->
<!--      </div>-->
      <div class="input-list input-list-game search_label_rehab" style="width: 50%;">
        提现单号:
        <select id="ext_field" name="ext_field" class="select_gallery" style="width: 50%">
          <option value="">提现单号</option>
          <volist name=":getWithdrawNumber()" id="vo">
            <option value="{$vo.widthdraw_number}" <if condition="$vo eq $_GET['count_date']">selected=selected</if>>{$vo.widthdraw_number}</option>
          </volist>
        </select>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        银行账号:
        <input type="text" id="bank_card" name="bank_card" class="" value="" placeholder="银行账号"  style="width: 50%"/>
      </div>

      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        乙 方:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <select id="company_name" name="company_name" class="select_gallery" style="width: 50%">
        <option value="">乙 方</option>
        <volist name=":getPromoteCompanyList()" id="vo">
          <option  company_id="{$vo.id}" value="{$vo.company_name}">{$vo.company_name}</option>
        </volist>
      </select>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        户 名:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="text" id="bank_account_name" name="bank_account_name" class="" value="" placeholder="户名"  style="width: 50%"/>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        开 户 行:&nbsp;
        <input type="text" id="account_openin" name="account_openin" class="" value="" placeholder="开户行"  style="width: 50%"/>
      </div>

      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        订单类型:&nbsp;
        <input type="text" name="settlement_type_value" id="settlement_type_value" style="display: none" value="默认"/>
        <span  style="width: 50%" id="settlement_type">默认</span>
      </select>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        邮寄地址:
        <input type="text" id="address" name="address" class="" value="" placeholder="邮寄地址"  style="width: 50%"/>
      </div>

      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        联 系 人:&nbsp;&nbsp;&nbsp;
        <input type="text" id="real_name" name="real_name" class="" value="" placeholder="联系人"  style="width: 50%"/>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        开票项目:
        <input type="text" id="invoice_item" name="invoice_item" class="" value="信息技术服务费" placeholder="信息技术服务费"  style="width: 50%"/>
      </div>

      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        联系电话:&nbsp;&nbsp;
        <input type="text" id="mobile_phone" name="mobile_phone" class="" value="{:I('time_start')}" placeholder="请输入联系电话"  style="width: 50%"/>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 50%">
        发票类型:
        <input type="text" id="invoice_type" name="invoice_type" class="" value="增值税专用发票" placeholder="增值税专用发票"  style="width: 50%"/>
      </div>
    </div>
  </div>

  <!-- 数据列表 -->
  <div class="data_list box_mt" style="margin-top: 30px">
    <div class="">
      <table>
        <!-- 表头 -->
        <thead>
        <tr>
          <th>结算时间</th>
          <th>合作产品</th>
          <th >平台总额</th>
          <th>分成比例</th>
          <th>税费费率</th>
          <th >结算金额(元)</th>

        </thead>
        <!-- 列表 -->
        <tbody style="overflow: hidden;height: 300px" class="getData">
        <if condition = "empty($list_data)">
          <tr>
            <td colspan="16" class="text-center">aOh! 暂时还没有内容!</td>
          </tr>
        </if>
        <volist name="list_data" id="data">
          <tr>

          </tr>
        </volist>
        </tbody>
      </table>
    </div>
  </div>
  <div class="cf top_nav_list" style="height: 250px;margin-left: 5px">
    <!-- 高级搜索 -->
    <div class="wesearch cf search_list" >
      <!--      <div class="input-list search-title-box">-->
      <!--        <label>乙方:</label>-->
      <!--      </div>-->
      <div class="input-list input-list-promote search_label_rehab" style="width: 100%;">
        甲方:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="text" id="jfCompany" name="jfCompany" class="" value="海南万盟天下科技有限公司" style="width: 30%;display: none"/>
        <span>海南万盟天下科技有限公司</span>
      </div>
      <div class="input-list input-list-promote search_label_rehab" style="width: 100%;">
        联系人:&nbsp;&nbsp;&nbsp;
        <input type="text" id="jfPerson" name="jfPerson" class="" value="" placeholder="请输入联系人"  style="width: 30%"/>
      </div>

      <div class="input-list input-list-promote search_label_rehab" style="width: 100%;">
        联系电话:
        <input type="text" id="jfTel" name="jfTel" class="" value="" placeholder="请输入电话号码"  style="width: 30%"/>
      </div>
    </div>
  </div>
  <div class="cf top_nav_list" style="width:50px;position: relative;top: -160px;left: 60%;">
    <!-- 高级搜索 -->
    <div class="jssearch fl cf search_list">
      <div class="input-list">
        <a class="sch-btn" href="javascript:;" id="search" url="{:U('Query/marketList','model='.$model['name'] .'&row='.I('row'),false)}" style="width: 120px">生成结算订单</a>
      </div>
    </div>
  </div>

  <div class="page">
    {$_page|default=''}
  </div>
</div>
<script type="text/javascript">

  $(function(){

    var CHECK = {
      number: /^\d+(\.{1}\d+)?$/,
      mobile: /^1[3456789]\d{9}$/,
      BankNo: /^([1-9]{1})\d{10,19}$/,
      money: /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/
    }

    var queryData = [];
    var statement = [];
    var key = 0;
    $(".select_gallery").select2();
    // $("#tax").change(function () {
    //   console.log(1)
    //   console.log($(this).next());
    // })

    //搜索功能
    $("#ext_field").change(function(){
      key = 0;
      var ext_field = $("#ext_field").val();
      console.log(ext_field);
      $("tbody").empty();

      $("#company_name").val("");
      $("#settlement_type").text("");
      $("#bank_card").val("");
      $("#account_openin").val("");
      $("#address").val("");
      $("#real_name").val("");
      $("#mobile_phone").val("");

      $("tbody").append('<tr>\n' +
        '            <td colspan="16" class="text-center">aOh! 暂时还没有内容!</td>\n' +
        '          </tr>');

      if (ext_field)
      $.ajax({
        url:"{:U('Ajax/getDownstreamData')}",
        type:"get",
        data:{withdraw_number:ext_field},
        dataType:'json',
        success:function(data){
          console.log($("#company_name option:selected").attr('company-type'))

          $("#company_name").val(data.data.company_name);
          $("#settlement_type").text(data.data.settlement_type);
          $("#bank_card").val(data.data.bank_card);
          $("#account_openin").val(data.data.account_openin);
          $("#address").val(data.data.address);
          $("#real_name").val(data.data.real_name);
          $("#mobile_phone").val(data.data.mobile_phone);
          $("#settlement_type_value").val(data.data.settlement_type);
          $("#bank_account_name").val(data.data.bank_account);

          var add = '';
          $("#company_name").empty();
          $.ajax({
            url: "{:U('Ajax/getPromoteCompanyList')}",
            type: "get",
            data: {withdraw_number: ext_field},
            dataType: 'json',
            success: function (response) {
              add +='<option value="">请选择推广公司</option>';
              data = response.data;
              console.log(data)
              for (var i in data){
                if (data[i].company_id) {
                  add += "<option company_id='" + data[i].company_id + "'  value='" + data[i].company_name + "' " + ('selected') + ">" + data[i].company_name + "</option>"
                }
              }
              $("#company_name").empty();
              $("#company_name").append(add);
              $("#company_name").select2();
            }
          });

          $("#jfCompany").val(data.data.yfpartner);
          $("#jfCompany").next().text(data.data.yfpartner);
          $("#jfPerson").val(data.data.yflink_man);
          $("#jfTel").val(data.data.yflink_phone);

          var game_ratio = data.data.game_ratio;

          var str = '';
          var sumAmount = 0;
          var sum = 0;

          for(var p in game_ratio){
            for(var i in game_ratio[p]) {
              queryData['pay_amount'] = game_ratio[p][i].sum_amount;
              queryData['game_id'] = p;
              queryData['game_name'] = game_ratio[p][i].game_name;
              queryData['sum_money'] = (game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2);
              queryData['statement_begin_time'] = game_ratio[p][i].begin_time;
              queryData['statement_end_time'] = game_ratio[p][i].end_time;
              queryData['second_ratio'] = game_ratio[p][i].selle_ratio;
              queryData['fax_ratio'] = 0;
              statement.push(queryData);
              queryData=[];
              // game_name = "<?php echo get_gamename('"+game_id+"')?>";
              sumAmount=sumAmount+parseFloat(game_ratio[p][i].sum_amount);
                str+="<tr class='statement_data_"+key+"'><td class='time_"+key+"' begin_time='"+game_ratio[p][i].begin_time+"' end_time='"+game_ratio[p][i].end_time+
                  "'>"+game_ratio[p][i].begin_time+"-"+game_ratio[p][i].end_time+"</td>" +
                  "<td class='game_name_"+key+"' game_id='"+p+"'>"+game_ratio[p][i].game_name+"</td>" +
                  "<td class='pay_amount_"+key+"'>"+game_ratio[p][i].sum_amount+"</td>" +
                  "<td class='second_ratio_"+key+"' second_ratio='"+game_ratio[p][i].selle_ratio+"'>"+game_ratio[p][i].selle_ratio+"%</td>" +
                  "<td><input value='0' style='width: 30px' class='tax tax_"+key+"'/>%</td>" +
                  "<td id='sum_"+key+"' data-value='"+(game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2)+"'>"+(game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2)+"</td></tr>";
                sum = sum +parseFloat((game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2));
              key++;
            }
          }

          str+="<tr class=''><td>-</td><td>罚款</td>" +
            "<td class = 'forfeit'>"+data.data.forfeit+"</td>" +
            "<td>-</td>" +
            "<td>-</td>" +
            "<td>"+data.data.forfeit+"</td>" +
            "</tr>" +
            "<tr class=''><td>-</td><td>奖励</td>" +
            "<td class = 'reward'>"+data.data.reward+"</td>" +
            "<td>-</td>" +
            "<td>-</td>" +
            "<td>"+data.data.reward+"</td>" +
            "</tr>" +
            "<tr><td>合计</td>" +
            "<td>---</td>" +
            "<td class='sumAmount' data-value='"+sumAmount+"'>"+sumAmount+"</td>" +
            "<td>-</td>" +
            "<td>-</td>" +
            "<td class='sumAll' data-value='"+sum.toFixed(2)+"'>"+sum.toFixed(2)+"</td>" +
            "</tr>"+
            "<tr><td colspan='3'>\n" +
            "本月分成总金额(人民币大写):</td>" +
            "<td>-</td>" +
            "<td>-</td>" +
            "<td  data-value='"+sum+"'>"+number_chinese(sum)+"</td>" +
            "</tr>";

          $("tbody").empty();
          $("tbody").append(str);


          console.log(parseFloat($(".reward").text()))

          $('.sumAmount').text((parseFloat($('.sumAmount').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));
          $('.sumAmount').attr('data-value',(parseFloat($('.sumAmount').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));


          $('.sumAll').text((parseFloat($('.sumAll').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));
          $('.sumAll').attr('data-value',(parseFloat($('.sumAll').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));

          eventnew();
        }
      })

    });

    //搜索功能
    $("#company_name").change(function(){
      key = 0;
      var ext_field = $("#company_name option:selected").attr('company_id');
      console.log(ext_field);
      $("tbody").empty();

      // $("#company_name").val("");
      $("#settlement_type").text("");
      $("#bank_card").val("");
      $("#account_openin").val("");
      $("#address").val("");
      $("#real_name").val("");
      $("#mobile_phone").val("");
      $("#bank_account_name").val("");

      $("tbody").append('<tr>\n' +
        '            <td colspan="16" class="text-center">aOh! 暂时还没有内容!</td>\n' +
        '          </tr>');

      if (ext_field)
        $.ajax({
          url:"{:U('Ajax/getDownstreamData')}",
          type:"get",
          data:{company_id:ext_field},
          dataType:'json',
          success:function(data){
            console.log($("#company_name option:selected").attr('company-type'))

            // $("#company_name").val(data.data.company_name);
            $("#settlement_type").text(data.data.settlement_type);
            $("#bank_card").val(data.data.bank_card);
            $("#account_openin").val(data.data.account_openin);
            $("#address").val(data.data.address);
            $("#real_name").val(data.data.real_name);
            $("#mobile_phone").val(data.data.mobile_phone);
            $("#settlement_type_value").val(data.data.settlement_type);
            $("#bank_account_name").val(data.data.bank_account);

            var add = '';
            $("#ext_field").empty();
            $.ajax({
              url: "{:U('Ajax/getPromoteCompanyList')}",
              type: "get",
              data: {company_id: ext_field},
              dataType: 'json',
              success: function (response) {
                add +='<option value="">体现单号</option>';
                var datas = response.data;

                var widthdrawNumber = datas[0].widthdraw_number;

                console.log(datas)
                for (var i in datas){

                  add += "<option value='"+datas[i].widthdraw_number+"' "+(datas[i].widthdraw_number == widthdrawNumber?'selected':'')+">"+datas[i].widthdraw_number+"</option>"
                }
                $("#ext_field").empty();
                $("#ext_field").append(add);
                $("#ext_field").select2();
              }
            });

            $("#jfCompany").val(data.data.yfpartner);
            $("#jfCompany").next().text(data.data.yfpartner);
            $("#jfPerson").val(data.data.yflink_man);
            $("#jfTel").val(data.data.yflink_phone);

            var game_ratio = data.data.game_ratio;

            var str = '';
            var sumAmount = 0;
            var sum = 0;

            for(var p in game_ratio){
              for(var i in game_ratio[p]) {
                queryData['pay_amount'] = game_ratio[p][i].sum_amount;
                queryData['game_id'] = p;
                queryData['game_name'] = game_ratio[p][i].game_name;
                queryData['sum_money'] = (game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2);
                queryData['statement_begin_time'] = game_ratio[p][i].begin_time;
                queryData['statement_end_time'] = game_ratio[p][i].end_time;
                queryData['second_ratio'] = game_ratio[p][i].selle_ratio;
                queryData['fax_ratio'] = 0;
                statement.push(queryData);
                queryData=[];
                // game_name = "<?php echo get_gamename('"+game_id+"')?>";
                sumAmount=sumAmount+parseFloat(game_ratio[p][i].sum_amount);
                str+="<tr class='statement_data_"+key+"'><td class='time_"+key+"' begin_time='"+game_ratio[p][i].begin_time+"' end_time='"+game_ratio[p][i].end_time+
                  "'>"+game_ratio[p][i].begin_time+"-"+game_ratio[p][i].end_time+"</td>" +
                  "<td class='game_name_"+key+"' game_id='"+p+"'>"+game_ratio[p][i].game_name+"</td>" +
                  "<td class='pay_amount_"+key+"'>"+game_ratio[p][i].sum_amount+"</td>" +
                  "<td class='second_ratio_"+key+"' second_ratio='"+game_ratio[p][i].selle_ratio+"'>"+game_ratio[p][i].selle_ratio+"%</td>" +
                  "<td><input value='0' style='width: 30px' class='tax tax_"+key+"'/>%</td>" +
                  "<td id='sum_"+key+"' data-value='"+(game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2)+"'>"+(game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2)+"</td></tr>";
                sum = sum +parseFloat((game_ratio[p][i].sum_amount*(game_ratio[p][i].selle_ratio/100)).toFixed(2));
                key++;
              }
            }

            str+="<tr class=''><td>-</td><td>罚款</td>" +
              "<td class = 'forfeit'>"+data.data.forfeit+"</td>" +
              "<td>-</td>" +
              "<td>-</td>" +
              "<td>"+data.data.forfeit+"</td>" +
              "</tr>" +
              "<tr class=''><td>-</td><td>奖励</td>" +
              "<td class = 'reward'>"+data.data.reward+"</td>" +
              "<td>-</td>" +
              "<td>-</td>" +
              "<td>"+data.data.reward+"</td>" +
              "</tr>" +
              "<tr><td>合计</td>" +
              "<td>---</td>" +
              "<td class='sumAmount' data-value='"+sumAmount+"'>"+sumAmount+"</td>" +
              "<td>-</td>" +
              "<td>-</td>" +
              "<td class='sumAll' data-value='"+sum+"'>"+sum+"</td>" +
              "</tr>"+
              "<tr><td colspan='3'>\n" +
              "本月分成总金额(人民币大写):</td>" +
              "<td>-</td>" +
              "<td>-</td>" +
              "<td  data-value='"+sum+"'>"+number_chinese(sum)+"</td>" +
              "</tr>";
            $("tbody").empty();
            $("tbody").append(str);


            $('.sumAmount').text((parseFloat($('.sumAmount').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));
            $('.sumAmount').attr('data-value',(parseFloat($('.sumAmount').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));


            $('.sumAll').text((parseFloat($('.sumAll').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));
            $('.sumAll').attr('data-value',(parseFloat($('.sumAll').text())+parseFloat($(".reward").text())-parseFloat($(".forfeit").text())).toFixed(2));

            eventnew();
          }
        })

    });


  function eventnew(){
      $(".tax").off("blur");
      $(".tax").on("blur", function() {

        if (!CHECK.number.test($(this).val())) {
          layer.msg("结算单的罚款与税率必须是数字且不能为空");
          $(this).val('0');
        }

        var lastNum = (parseFloat($(this).parent().next().text())).toFixed(2);
        $(this).parent().next().text(($(this).parent().next().attr('data-value')*(1-$(this).val()/100)).toFixed(2));
        var nowNum = (parseFloat($(this).parent().next().text())).toFixed(2);
        console.log((nowNum-lastNum))
          $(".sumAll").text((parseFloat($(".sumAll").text())+(nowNum-lastNum)).toFixed(2));
    });

      $(".forfeit").off("blur");
    $(".forfeit").on("blur", function() {

      var lastNumber = $(this).parent().next().next().next().text();

      if(!$(this).val()||!CHECK.number.test($(this).val())) {
        layer.msg("结算单的罚款与税率必须是数字且不能为空");
        $(this).val(lastNumber);
        return;
      }

      $(this).parent().next().next().next().text(parseFloat($(this).val()).toFixed(2));
      $(".sumAmount").text($(".sumAmount").attr("data-value")-$(this).val());

      $(".sumAll").text((parseFloat($(".sumAll").text())+parseFloat(lastNumber)-parseFloat($(this).val())).toFixed(2));

    });
  }


    $("#search").click(function(){
      var query  = $('.jssearch').find('input').serializeArray();

      var weQuery = $('.wesearch').find('input').serializeArray();

      query = $.merge(query,$('.jssearch').find('select').serializeArray());

      // query = $.merge(query,weQuery);

      // console.log(statement)
      var ext_field = '';
      var second_party_info = {};
      var first_party_info = {};
      var statement_info = {};
      var pushStatement = [];
      var sumData = {};
      var company_id = $("#company_name option:selected").attr('company_id');

      ext_field=$("#ext_field").val();
      console.log(ext_field)

      second_party_info['partner'] = $("#company_name").val();
      second_party_info["bank_account"] = $("#bank_card").val();
      second_party_info["opening_bank"] = $("#account_openin").val();
      // if ($("#settlement_type_value").val()=='周结订单') {
      //   second_party_info['settlement_type'] = 1;
      // } else if ($("#settlement_type_value").val()=='月结订单') {
      //   second_party_info['settlement_type'] = 2;
      // } else {
      //   second_party_info['settlement_type'] = 3;
      // }
      second_party_info['settlement_type'] = $("#settlement_type_value").val();
      second_party_info['address'] = $("#address").val();
      second_party_info['link_man'] = $("#real_name").val();
      second_party_info['link_phone'] = $("#mobile_phone").val();
      second_party_info['invoice_item'] = $("#invoice_item").val();
      second_party_info['invoice_type'] = $("#invoice_type").val();
      second_party_info['bank_account_name'] = $("#bank_account_name").val();

      first_party_info['jfCompany'] = $("#jfCompany").val();
      first_party_info['jfPerson'] = $("#jfPerson").val();
      first_party_info['jfTel'] = $("#jfTel").val();
      var i = 0;
      for(i=0;i<key;i++) {

        var _this = $(".statement_data_"+i);
        statement_info['statement_begin_time'] = _this.children().attr('begin_time');
        statement_info['statement_end_time'] = _this.children().attr('end_time');
        statement_info['game_id'] = _this.children().next().attr('game_id');
        statement_info['game_name'] = $(".statement_data_"+i+' .game_name_'+i).text();
        statement_info['pay_amount'] = $(".statement_data_"+i+' .pay_amount_'+i).text();
        statement_info['sum_money'] = $(".statement_data_"+i+' #sum_'+i).text();
        statement_info['fax_ratio'] = $(".statement_data_"+i+' .tax_'+i).val();
        statement_info['second_ratio'] = $(".statement_data_"+i+' .second_ratio_'+i).attr('second_ratio');

        statement_info['statement_type'] = 0;
        pushStatement.push(statement_info);
        statement_info = {};
        // console.log(statement_info);
      }
      var forfeit = {};

      forfeit['type_name'] = '罚款';
      forfeit['sum_money'] = $('.forfeit').text();
      forfeit['statement_type'] = 1;

      pushStatement.push(forfeit);

      var reward = {};

      reward['type_name'] = '奖励';
      reward['sum_money'] = $('.reward').text();
      reward['statement_type'] = 2;

      pushStatement.push(reward);

      // console.log(pushStatement);

      sumData['statement_money'] = $(".sumAll").text();
      sumData['pay_amount'] = $(".sumAmount").text();

      if (!ext_field) {
        layer.msg("提现单号不能为空");
        return;
      }

      if (!second_party_info['partner']) {
        layer.msg("乙方不能为空");
        return;
      }

      if (!second_party_info['link_man']) {
        layer.msg("联系人不能为空");
        return;
      }
      var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
      if (!second_party_info['link_phone']) {
        layer.msg("乙方联系电话不能为空");
        return;
      }
      if (!second_party_info["bank_account"]) {
        layer.msg("银行账号不能为空");
        return;
      }
      if (!second_party_info["opening_bank"]) {
        layer.msg("开户行不能为空");
        return;
      }
      if(!second_party_info['address']) {
        layer.msg("邮寄地址不能为空");
        return;
      }

      if(!first_party_info['jfPerson']) {
        layer.msg("甲方联系人不能为空");
        return;
      }

      if(!first_party_info['jfTel']) {
        layer.msg("甲方联系电话不能为空");
        return;
      }

      $.ajax({
        url: "{:U('StatementMangement/saveDownstreamOrder')}",
        type: "post",
        data: {"second_party_info": second_party_info,"first_party_info":first_party_info,
          "statement_info":pushStatement,"sum_data":sumData,"ext_field":ext_field,"company_id":company_id},
        dataType: 'json',
        success: function (data) {
          layer.msg(data.msg);
          setTimeout(function(){
            window.parent.reload();
          },1500);
        }
      });
      
    });
  })

  function number_chinese(str) {
    var num = parseFloat(str);
    var strOutput = "",
      strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分';
    num += "00";
    var intPos = num.indexOf('.');
    if (intPos >= 0){
      num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
    }
    strUnit = strUnit.substr(strUnit.length - num.length);
    for (var i=0; i < num.length; i++){
      strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(num.substr(i,1),1) + strUnit.substr(i,1);
    }
    return strOutput.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元")

  }


</script>
</body>
</html>