<extend name="Public/base"/>

<block name="body">
  <link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
  <script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
  <script type="text/javascript" src="__JS__/select2.min.js"></script>
  <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>


  <div class="cf main-place top_nav_list navtab_list">

    <h3 class="page_title">
      
    {$title}</h3>
    <p class="description_text">
      <if condition="isset($_GET['promote_id'])">
        <if condition="$_GET['promote_type'] eq 1">
            统计推广员及其下属推广员的游戏订单相关统计
          <else/>
          仅统计推广员自己 <span style="color: red;">不含其下属推广员</span>的游戏订单相关统计
        </if>
    <else/>
    游戏订单统计
    </if>
    </p>
  </div>

  <div class="cf top_nav_list">

    <!-- 高级搜索 -->
    <div class="jssearch fl cf search_list">
      <!--游戏类型搜索END-->

      <div class="input-list  search-title-box">
        <a class="sch-btn" href="javascript:history.go(-1)" style="background:#fff;color: #000;border: #000 solid 1px;width: 100px">返回</a>
      </div>
      <div class="input-list search-title-box">
        <label>搜索:</label>
      </div>
      <div class="input-list input-list-server search_label_rehab">
        <select id="partner_id" name="partner_id" class="select_gallery"  style="width:120px;">
          <option value="">请选择合作公司</option>
          <volist name=":getPartner()" id="vo">
            <option partner-id="{$vo.id}" value="{$vo.id}" <if condition="$vo.id eq $_GET['partner_id']">selected=selected</if>>{$vo.partner}</option>
          </volist>
        </select>
      </div>
      <div class="input-list input-list-game search_label_rehab">
        <select id="game_name" name="game_name" class="select_gallery" >
          <option value="">游戏名称</option>
        </select>
      </div>
      <div class="input-list input-list-game search_label_rehab">
          <select id="game_type" name="game_type" class="select_gallery" >
              <option value="">请选择设备类型</option>
              <option value="1">安卓</option>
              <option value="2">苹果</option>
          </select>   
      </div>
      <div class="input-list search_item input-list-gamenoticestatus">
          <select name="promote_level" style="color:#444" class="select_gallery" id="promote_level">
              <option value="">请选择推广员等级</option>
              <option value="1" <?php if ($_POST['promote_level'] == 1):?>selected<?php endif;?>>会长</option>
              <option value="2" <?php if ($_POST['promote_level'] == 2):?>selected<?php endif;?>>部门长</option>
              <option value="3" <?php if ($_POST['promote_level'] == 3):?>selected<?php endif;?>>组长</option>
              <option value="4" <?php if ($_POST['promote_level'] == 4):?>selected<?php endif;?>>组员</option>
          </select>
          -
      </div>
      <div class="input-list search_item input-list-gamenoticestatus">
          <select name="promote_id" style="color:#444" class="select_gallery" id="promote_id">
              <option value="">请选择推广员</option>
              <option value="0" <?php if ($_POST['promote_id'] == 0):?>selected<?php endif;?>>{:C('OFFICIEL_CHANNEL')}</option>
          </select>
      </div>
      <div class="input-list input-list-server search_label_rehab">
        <select id="admin_id" name="admin_id" class="select_gallery"  style="width:120px;">
          <option value="">请选择市场专员</option>
          <?php foreach(getMarketAdmins() as $item):?>
          <option value="<?=$item['id']?>" <?php if($item['id'] == I('admin_id')):?>selected<?php endif;?>><?=$item['username']?></option>
          <?php endforeach;?>
        </select>
      </div>
      <input type="hidden" name="promote_type" value="{$_GET['promote_type']}"/>
      <input type="hidden" name="company_id" value="{$_GET['company_id']}"/>
      <input type="hidden" name="company_belong" value="{$_GET['company_belong']}"/>
      

      <div class="input-list">
        <input type="text"  name="pay_order_number" placeholder="请输入支付订单号" class="" value="{:I('pay_order_number')}" style="width: 180px"/>&nbsp;
      </div>
      <div class="input-list">

        <input type="text"  name="user_account" placeholder="请输入玩家账号" class="" value="{:I('user_account')}" style="width: 180px"/>&nbsp;
      </div>
      <div class="input-list">

        <input type="text"  name="user_nickname" placeholder="请输入角色名称" class="" value="{:I('user_nickname')}" style="width: 180px"/>&nbsp;
      </div>
      <div class="input-list">
        <input type="text" readonly id="time_start" name="time_start" class="" value="{:I('time_start')}"
            placeholder="开始时间" />
        &nbsp;-&nbsp;
        <div class="input-append date" id="datetimepicker" style="display:inline-block">
            <input type="text" readonly id="time_end" name="time_end" class="" value="{:I('time_end')}"
                placeholder="结束时间" />
            <span class="add-on"><i class="icon-th"></i></span>
        </div>
      </div>

      <div class="input-list input-list-server search_label_rehab">
        <select id="pay_way" name="pay_way" class="select_gallery"  style="width:120px;">
          <option value="">请选择支付渠道</option>
          <option value="1">支付宝</option>
          <option value="2">微信(扫码)</option>
          <option value="3">微信app</option>
          <option value="4">威富通</option>
          <option value="5">聚宝云</option>
          <option value="6">竣付通</option>
          <option value="7">金猪</option>
          <option value="9">双乾支付-支付宝</option>
          <option value="10">双乾支付-银联</option>
          <option value="15">双乾支付-快捷</option>
          <option value="0">平台币</option>
          <option value="-1">绑币</option>
          <option value="17">易宝支付</option>
        </select>
      </div>

      <div class="input-list">

        <a class="sch-btn" href="javascript:;" id="search" url="{:U('FinancePromote/gameStatisticsDetail','model='.$model['name'].'&row='.I('row'),false)}"
           style="">搜索</a>
      </div>
    </div>
  </div>


  <!-- 数据列表 -->
  <div class="data_list">
    <div class="">
      <table>
        <!-- 表头 -->
        <thead>
        <tr>
          <th >支付订单号</th>

          <th>充值时间</th>

          <th >玩家账号</th>

          <th >游戏名称</th>
          <th >设备名称</th>

          <th >所属推广员</th>
          <th >所属市场专员</th>
          <th >充值ip</th>

          <th >游戏区服</th>

          <th >角色名称</th>

          <th >订单金额</th>

          <th >实付金额</th>

          <th >充值方式</th>
        </tr>
        </thead>
        <!-- 列表 -->
        <tbody>
        <style>
          .data-table thead th, .data-table tbody td{text-align:center}
          .data-table tbody td{border-right:1px solid #DDDDDD;}
          .d_list .drop-down ul {z-index:999;}
        </style>
                <if condition = "empty($data)">
                  <tr>
                    <td colspan="15" class="text-center">aOh! 暂时还没有内容!</td>
                  </tr>
                </if>
        <notemtpy name = "data">
          <volist name="data" id="data">
            <tr>
              <td >{$data.pay_order_number}</td>
              <td >{$data.pay_time}</td>
              <td >{$data.user_account}</td>
              <td >{$data.game_name}</td>
              <td >{$data.sdk_version}</td>
              <td >{$data.promote_account}</td>
              <td >{$data.market_admin_username}</td>
              <td >{$data.spend_ip}</td>
              <td >{$data.server_name}</td>
              <td >{$data.game_player_name}</td>
              <td >{$data.cost}</td>
              <td >{$data.pay_amount}</td>
              <td >{$data.pay_way}</td>
            </tr>
          </volist>
          <tr>
            <td ><span>总计</span></td>
            <td colspan="12" ><span><if condition="$sumAll neq ''">累计充值:{$sumAll}<else/>0</if>
            (现金金额:{$sumCash} 平台币:{$sumBalance} 绑币:{$sumInside})
            </span></td>
          </tr>
        </notemtpy>

        </tbody>
      </table>
    </div>
  </div>
  <div class="page">
    <if condition="$role_export_check eq true ">
      <a class="sch-btn" href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a>
    </if>
    {$_page|default=''}
  </div>
</block>

<block name="script">
  <script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
  <script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js" ></script>
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
  <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
  <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
  <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>
    <volist name=":I('get.')" id="vo">
      Think.setValue('{$key}',"{$vo}");
    </volist>
  </script>
  <script type="text/javascript">
  $(".select_gallery").select2();
    //导航高亮
    highlight_subnav('{:U("FinancePromote/index")}');
    $(function(){
      
      $('.page a').click(function () {
        var href = $(this).attr('href');
        $(this).removeAttr('href');
        window.location.replace(href)
        console.log(href)
      });

      $('#time_start').datetimepicker({
          format: 'yyyy-mm-dd',
          language: "zh-CN",
          minView: 2,
          autoclose: true
      });

      $('#datetimepicker').datetimepicker({
          format: 'yyyy-mm-dd',
          language: "zh-CN",
          minView: 2,
          autoclose: true,
          pickerPosition: 'bottom-left'
      })

      //搜索功能
      $("#search").click(function(){
        var starttime = $.trim($('#time_start').val());
        var endtime = $.trim($('#time_end').val());

        if (starttime && endtime && starttime > endtime) {layer.msg('开始时间必须小于等于结束时间');return false;}


        var url = $(this).attr('url');
        var query  = $('.jssearch').find('input').serialize();
        query  += "&" + $('.jssearch').find('select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
          url += '&' + query;
        }else{
          url += '?' + query;
        }
        window.location.replace(url);
      });

      //回车自动提交
      $('.jssearch').find('input').keyup(function(event){
        if(event.keyCode===13){
          $("#search").click();
        }
      });
      $(".ljcz").click(function(){
        var id = $(this).attr('data-value');
        var game_name = "{:I('game_name')}";
        var server_name = "{:I('server_id')}";
        layer.open({
          type: 2,
          title: '游戏消费记录',
          shadeClose: true,
          shade: 0.8,
          area: ['70%', '80%'],
          content: 'admin.php?s=/Platform/chongzhi_detail/promote_id/'+id+'/game_name/'+game_name+'/server_name/'+server_name+''//iframe的url
        });
      });

      function get_game_list()
      {
        var game_name = "{:I('game_name')}";
        $.ajax({
          url:"{:U('Finance/getGameList')}",
          type:"post",
          data:{partner_id:$("#partner_id option:selected").val(), sdk_type:$("#sdk_version1 option:selected").val()},
          dataType:'json',
          success:function(data){
            var str = "<option value=''>请选择游戏</option>";
            for (var i in data){
              str += "<option value='"+data[i].game_name+"'"+(game_name && data[i].game_name == game_name?'selected':'')+">"+data[i].game_name+"</option>"
            }
            // console.log(str);
            $("#game_name").empty();
            $("#game_name").append(str);
            $("#game_name").select2();
            // $("#game_type").empty();

          }
        })
      }
      //设置设备类型
      function gameTypeInit() {
        // var game_type = "{:I('game_type')}";
        var str = "<option value=''>请选择设备类型</option><option value='1'>安卓</option><option value='2'>苹果</option>";
        
        $("#game_type").empty();
        $("#game_type").append(str);
        $("#game_type").select2();
      }
      var seleinit = 0;
      $("#partner_id").change(function(){
        get_game_list();
        if(seleinit > 0){
          gameTypeInit();
        }
        seleinit++;
      });
      $("#partner_id").change();

      var promote_id = "{:I('promote_id')}";
     $("#promote_level").change(function(){
        $.ajax({
             url:"{:U('Ajax/getPromotersByLevel')}",
             type:"get",
             data:{level:$("#promote_level option:selected").val()},
             dataType:'json',
             success:function(response){
                str = '<option value="">请选择推广员</option><option value="0"'+(promote_id && 0 == promote_id?'selected':'')+'>{:C(\'OFFICIEL_CHANNEL\')}</option>';
                //  $.each(response.data, function(index, item){
                //      console.log(item.id);
                //     str += '<option value="'+item.id+' '+(promote_id && item.id == promote_id?'selected':'')+'">'+item.nickname+'</option>';
                //  });
                data = response.data;
                 for (var i in data){
                     str += "<option value='"+data[i].id+"' "+(promote_id && data[i].id == promote_id?'selected':'')+">"+data[i].nickname+"</option>"
                 }
                 $("#promote_id").empty();
                 $("#promote_id").append(str);
                 $("#promote_id").select2();
             }
         })
     });
     $("#promote_level").change();
    })
  </script>
</block>