<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>

<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>查询</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#statistics/channelQuality" name="stanpform">
                                        <input type="hidden" value="1" name="payuserpost"/>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($stime) echo $stime;?>" placeholder="开始时间" name="remain_stime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($etime) echo $etime;?>" placeholder="结束时间" name="remain_etime" />
                                        </div>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        
        <?php
        function formatChipRound($value, $round=2)
        {
            $value = ceil($value);

            if(1 <= abs($valueB = round($value / 1000000000, $round))) {
                return  $valueB . 'B';
            }else if(1 <= abs($valueM=round($value / 1000000, $round))) {
                return $valueM . 'M';
            }else if(1 <= abs($valueK = round($value / 1000), $round)) {
                return $valueK . 'K';
            }else {
                return $value;
            }
        }
        ?>
                                            
		
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>渠道质量评估</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="table-responsive">
                                    <table id="reportTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                        <thead>
	                                        <tr>
	                                            <th rowspan="2" style="text-align: center;vertical-align: middle;">日期</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">渠道</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">ROI_1d</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">ROI_30d</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">单价CPI</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">ARPU</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">日新增</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">LTV1</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">留存1</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">LTV3</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">留存3</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">LTV7</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">留存7</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">LTV15</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">留存15</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">LTV30</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">留存30</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">LTV60</th>
	                                            <th colspan="1" style="text-align: center;vertical-align: middle;">留存60</th>
	                                        </tr>
                                        
                                        </thead>
                                        <tbody id="reportBody">
                                        <?php
                                         if(is_array($daylist)){
                                            foreach($daylist as $k => $val){
                                                ?>
                                                <tr>
                                                	<!--<td style="white-space: nowrap" rowspan="3"><?php echo $val;?></td>-->
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $val;?></td>
                                                	<td style="white-space: nowrap" rowspan="1">渠道A</td>
                                                	
                                                	
                                                	<?php if($func == 1){ ?>
                                                	<!--方法一 LTV(n) = (收入n1 + 收入n2 + 收入n) / （新增n1 + 新增n2 + 新增n）（收入不包含广告的）-->
                                                	<td style="white-space: nowrap" rowspan="1">
                                                	<?php 
                                                		echo round(($revenue[$k] / $new_player[$k]) / $cpi[$k],4);
                                                	?>
                                                	</td>
                                                	<td style="white-space: nowrap" rowspan="1">
                                                	<?php 
                                                		echo round($ltv30[$k] / $cpi[$k],4);
                                                	?>
                                                	</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $cpi[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $arpu[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $new_player[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($revenue[$k] / $new_player[$k],4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day1Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv3[$k],4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day3Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv7[$k],4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day7Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv15[$k],4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day15Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv30[$k],4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day30Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv60[$k],4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day60Remain[$k];?>%</td>
                                                	<?php }else if($func == 2){ ?>
                                                	<!--方法二 LTV=LTV周期内平均活跃arpu*(1+次留百分比+3留百分比+7留百分比+……+N日留存百分比)-->
                                                	<td style="white-space: nowrap" rowspan="1">
                                                	<?php 
                                                		echo round(($arpu[$k]*1) / $cpi[$k],4);
                                                	?>
                                                	</td>
                                                	<td style="white-space: nowrap" rowspan="1">
                                                	<?php 
                                                		echo round($ltv30[$k]*(1+($day1Remain[$k]+$day3Remain[$k]+$day7Remain[$k]+$day15Remain[$k]+$day30Remain[$k])/100) / $cpi[$k],4);
                                                	?>
                                                	</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $cpi[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $arpu[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $new_player[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*1,4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day1Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv3[$k]*(1+($day1Remain[$k]+$day3Remain[$k])/100),4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day3Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv7[$k]*(1+($day1Remain[$k]+$day3Remain[$k]+$day7Remain[$k])/100),4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day7Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv15[$k]*(1+($day1Remain[$k]+$day3Remain[$k]+$day7Remain[$k]+$day15Remain[$k])/100),4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day15Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv30[$k]*(1+($day1Remain[$k]+$day3Remain[$k]+$day7Remain[$k]+$day15Remain[$k]+$day30Remain[$k])/100),4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day30Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($ltv60[$k]*(1+($day1Remain[$k]+$day3Remain[$k]+$day7Remain[$k]+$day15Remain[$k]+$day30Remain[$k]+$day60Remain[$k])/100),4);?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day60Remain[$k];?>%</td>
                                                	<?php }else if($func == 3){ ?>
                                                	<!--LTV = ARPU * (1 / N日留存百分比)-->
                                                	
                                                	<td style="white-space: nowrap" rowspan="1">
                                                	<?php 
                                                		echo round($arpu[$k]*(1 / ($day1Remain[$k] / 100)) / $cpi[$k],4);
                                                	?>
                                                	</td>
                                                	<td style="white-space: nowrap" rowspan="1">
                                                	<?php 
                                                		echo round($arpu[$k]*(1 / ($day30Remain[$k] / 100)) / $cpi[$k],4);
                                                	?>
                                                	</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $cpi[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $arpu[$k];?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $new_player[$k];?></td>
                                                	<!--LTV1-->
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*(1 / ($day1Remain[$k] / 100)),4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day1Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*(1 / ($day3Remain[$k] / 100)),4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day3Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*(1 / ($day7Remain[$k] / 100)),4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day7Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*(1 / ($day15Remain[$k] / 100)),4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day15Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*(1 / ($day30Remain[$k] / 100)),4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day30Remain[$k];?>%</td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo round($arpu[$k]*(1 / ($day60Remain[$k] / 100)),4); ?></td>
                                                	<td style="white-space: nowrap" rowspan="1"><?php echo $day60Remain[$k];?>%</td>
                                                	
                                                	<?php } ?>
                                                </tr>
                                                
                                                <?php
                                            }
                                         }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        
        
    </div>
</div>
</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/exporting.js"></script>

<script type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });
</script>