<extend name="Public/base"/>
<block name="css">
</block>
<block name="body">
    <link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
    <script type="text/javascript" src="__JS__/select2.min.js"></script>
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <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>
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>     
        
	<div class="cf main-place top_nav_list navtab_list">
			<h3 class="page_title">LTV统计</h3>
			<p class="description_text">说明:计算用户生命周期价值的相关数据(充值金额统计用户在平台内/游戏内进行现金充值的数据汇总,游戏内通过平台币/绑币进行消费的计算在内 )</p>
	</div>
        
	<div class="cf jssearch top_nav_list">
		<!-- 高级搜索 -->
		<div class=" fl cf search_list">
      <div class="input-list search-title-box">
              <label>搜索:</label>
            </div>
            <div class="input-list">
                <input type="text" id="time-start" name="start" class="" value="{:I('start',date('Y-m-d',strtotime('-30 day')))}" placeholder="选择开始时间" />
                &nbsp;-&nbsp;
                <div class="input-append date" id="datetimepicker"  style="display:inline-block">
                <input type="text" readonly id="time-end" name="end" class="" value="{:I('end',date('Y-m-d',strtotime('-1 day')))}" placeholder="选择结束时间" />
                <span class="add-on"><i class="icon-th"></i></span>
                </div>
            </div>
			<div class="input-list input-list-game search_label_rehab">
                <select id="game_name" name="game_name" class="select_gallery" >
                    <option value="">游戏名称</option>
                    <volist name=":getAllGame()" id="vo">
                        <option value="{$vo.game_name}" <if condition="$vo.game_name eq I('game_name')">selected</if> >{$vo.game_name}</option>
                    </volist>
                </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" <?php echo I('game_type') == 1 ? "selected" : ''?>>安卓</option>
                    <option value="2" <?php echo I('game_type') == 2 ? "selected" : ''?>>苹果</option>
                </select>   
            </div>
            <div class="input-list input-list-server search_label_rehab">
                <select id="server_name" name="server_name" class="select_gallery" >
                    <option value="">区服名称</option>
                </select>
            </div>
            <div class="input-list">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('Statistics/ltv','model='.$model['name'] .'&row='.I('row'),false)}">搜索</a>
                
            </div>
		</div>
	</div>	
	
	<!-- 数据列表 -->
	<div class="data_list">
			<div class="">
					<table>
							<!-- 表头 -->
							<thead>
									<tr>
											<th>日期</th>
											<th>充值金额</th>
											<th>活跃用户</th>
											<th>LTV1</th>
											<th>LTV2</th>
											<th>LTV3</th>
											<th>LTV4</th>
											<th>LTV5</th>
											<th>LTV6</th>
											<th>LTV7</th>
											<th>LTV14</th>
											<th>LTV30</th>
									</tr>
							</thead>
							<!-- 列表 -->
							<tbody>
							<empty name ="data">
							<tr><td colspan="12" class="text-center">aOh! 暂时还没有内容!</td></tr>
							<else/>
								<volist name="data" id="vo">
								<tr>
										<td>{$vo.date}</td>
										<td>{$vo.total_amt}</td>
										<td>{$vo.user_count}</td>
										<td>{$vo.ltv_1}</td>
										<td>{$vo.ltv_2}</td>
										<td>{$vo.ltv_3}</td>
										<td>{$vo.ltv_4}</td>
										<td>{$vo.ltv_5}</td>
										<td>{$vo.ltv_6}</td>
										<td>{$vo.ltv_7}</td>
										<td>{$vo.ltv_14}</td>
										<td>{$vo.ltv_30}</td>
								</tr>
								</volist>
							</empty>
							</tbody>
					</table>
			</div>
	</div>
	<div class="page">
			<a class="sch-btn" href="{:U('Export/ltv',array(
                    'start'=>I('start',date('Y-m-d',strtotime('-30 day'))),
                    'end'=>I('end',date('Y-m-d',strtotime('-1 day'))),
                    'game_name'=>I('game_name'),
                    'game_type'=>I('game_type'),
                    'server_name'=>I('server_name'),
					'xlsname'=>'统计_ltv统计'
                ),false)}">导出</a>
			{$_page|default=''}
	</div>
	
	
	
</block>

<block name="script">
<script>
Think.setValue('start',"{$Think.get.start|default=''}");
Think.setValue('end',"{$Think.get.end|default=''}");
Think.setValue('row',"{$Think.get.row|default='10'}");
</script>
<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 src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav('{:U('Statistics/ltv')}');
$(function(){
    $(".select_gallery").select2();
    //计算天数差的函数,通用
    function GetDateDiff(startDate,endDate)
    {
        var startTime = new Date(Date.parse(startDate.replace(/-/g,   "/"))).getTime();
        var endTime = new Date(Date.parse(endDate.replace(/-/g,   "/"))).getTime();
        var dates = Math.abs((startTime - endTime))/(1000*60*60*24);
        return  dates;
    }

    //搜索功能
	$("#search").click(function(){

        var start = $("#time-start").val();
        start = start.substring(0,19);
        var end = ($("#time-end").val() == "") ?  "{:date('Y-m-d')}" : $("#time-end").val();
        end = end.substring(0,19);
        var interval = GetDateDiff(start,end);
        if(interval < 0 || start == ''){
            layer.msg('请选择搜索时间');
            return false;
        }else if(interval>90){
            layer.msg('请选择90日内的时间段');
            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;
        }
         var start = $("#time-start").val();
            var end =   $("#time-end").val();
            if (start !='' && end != ''){
                if (Date.parse(start) > Date.parse(end)){
                    layer.msg('开始时间必须小于等于结束时间');
                    return false;
                }
            }
		window.location.href = url;
	});
    
    //回车自动提交
    $('.jssearch').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
    $('#time-start').datetimepicker({
         format: 'yyyy-mm-dd',
         language:"zh-CN",
         minView:2,
        autoclose:1,
    });

    $('#time-end').datetimepicker({
       format: 'yyyy-mm-dd',
        language:"zh-CN",
        minView:2,
        autoclose:1,endDate:new Date(new Date().getTime()-24*60*60*1000),
        pickerPosition:'bottom-right'
    });

    var game_server = "{:I('server_name')}";
    $("#game_type").change(function(){
        console.log({sdk_version:$("#game_type option:selected").val(), game_name:$("#game_name option:selected").val()})
         $.ajax({
             url:"{:U('Ajax/getGmeServer')}",
             type:"post",
             data:{sdk_version:$("#game_type option:selected").val(), game_name:$("#game_name option:selected").val()},
             dataType:'json',
             success:function(data){
                 console.log(data)
                 str = "<option value=''>请选择区服</option>";
                 for (var i in data){
                     str += "<option value='"+data[i].server_name+"' "+(game_server && data[i].server_name == game_server?'selected':'')+">"+data[i].server_name+"</option>"
                 }
                 $("#server_name").empty();
                 $("#server_name").append(str);
                 $("#server_name").select2();
             }
         })
     });

     $("#game_name").change(function(){
        $("#game_type").change();
     });

     $("#game_name").change();
    
})
</script>
</block>