<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>FB素材成效数据</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#adjuststa/facebookAds" name="stanpform">
                                        <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="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="etime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>版本</label>
                                            <select class="form-control" name="user_os">
                                                <option value="" <?php echo $user_os == ""?"selected":""; ?> >all</option>
                                                <option value="Android" <?php echo $user_os == "Android"?"selected":""; ?> >Android</option>
                                                <option value="iOS" <?php echo $user_os == "iOS"?"selected":""; ?> >iOS</option>
                                                <option value="windows" <?php echo $user_os == "windows"?"selected":""; ?> >windows</option>
                                            </select>
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>国家</label>
                                            <input type="text" class="form-control" value="<?php if($address) echo $address;?>" placeholder="国家" name="address" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>广告渠道</label>
                                            <select class="form-control" name="trackers_group_type">
                                                <option value="" <?php echo $trackers_group_type == ""?"selected":""; ?> >all</option>
                                                <option value="fb_ads" <?php echo $trackers_group_type == "fb_ads"?"selected":""; ?> >fb_ads</option>
                                                <option value="google_ads" <?php echo $trackers_group_type == "google_ads"?"selected":""; ?> >google_ads</option>
                                                <option value="ins_ads" <?php echo $trackers_group_type == "ins_ads"?"selected":""; ?> >ins_ads</option>
                                                <option value="orignic_all" <?php echo $trackers_group_type == "orignic_all"?"selected":""; ?> >orignic_all</option>
                                            </select>
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>广告系列</label>
                                            <input type="text" class="form-control" value="<?php if($campaigns_name) echo $campaigns_name;?>" placeholder="广告系列" name="campaigns_name" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>广告组</label>
                                            <input type="text" class="form-control" value="<?php if($adgroups_name) echo $adgroups_name;?>" placeholder="广告组" name="adgroups_name" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>广告</label>
                                            <input type="text" class="form-control" value="<?php if($creatives_name) echo $creatives_name;?>" placeholder="广告" name="creatives_name" />
                                        </div>
                                        <span class="gap"></span>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <div class="table-responsive">
                        <table id="reportTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                            <thead>
                            <tr>
                                <th style="text-align: center;vertical-align: middle;width:200px;">日期</th>
                                <th style="text-align: center;vertical-align: middle;">版本</th>
                                <th style="text-align: center;vertical-align: middle;">国家</th>
                                <th style="text-align: center;vertical-align: middle;">广告渠道</th>
                                <th style="text-align: center;vertical-align: middle;">广告系列</th>
                                <th style="text-align: center;vertical-align: middle;">广告组</th>
                                <th style="text-align: center;vertical-align: middle;">广告名</th>
                                <th style="text-align: center;vertical-align: middle;">广告成本</th>
                                <th style="text-align: center;vertical-align: middle;">推广安装</th>
                                <th style="text-align: center;vertical-align: middle;">推广CPI</th>
                                <th style="text-align: center;vertical-align: middle;">推广次留CPI</th>
                                <th style="text-align: center;vertical-align: middle;">次日留存</th>
                                <th style="text-align: center;vertical-align: middle;">3日留存</th>
                                <th style="text-align: center;vertical-align: middle;">7日留存</th>
                                <th style="text-align: center;vertical-align: middle;">次留人数</th>
                                <th style="text-align: center;vertical-align: middle;">3留人数</th>
                                <th style="text-align: center;vertical-align: middle;">7留人数</th>
                                <th style="text-align: center;vertical-align: middle;">点击率(CTR)</th>
                                <th style="text-align: center;vertical-align: middle;">转化率(CVR)</th>
                                <th style="text-align: center;vertical-align: middle;">成效率(RR)</th>
                                <th style="text-align: center;vertical-align: middle;">每千次展示费用(CPM)</th>
                                <th style="text-align: center;vertical-align: middle;">覆盖人数</th>
                                <th style="text-align: center;vertical-align: middle;">展示次数</th>
                                <th style="text-align: center;vertical-align: middle;">链接点击数</th>
                                <th style="text-align: center;vertical-align: middle;">视频平均观看时长(s)</th>
                                <th style="text-align: center;vertical-align: middle;">视频播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频前3秒播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频25%处播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频50%处播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频15s处播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频75%处播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频95%处播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">视频100%处播放次数</th>
                                <th style="text-align: center;vertical-align: middle;">3日内购ROI</th>
                                <th style="text-align: center;vertical-align: middle;">7日内购ROI</th>
                                <th style="text-align: center;vertical-align: middle;">15日内购ROI</th>
                                <th style="text-align: center;vertical-align: middle;">30日内购ROI</th>
                                <th style="text-align: center;vertical-align: middle;">3日广告ROI</th>
                                <th style="text-align: center;vertical-align: middle;">7日广告ROI</th>
                                <th style="text-align: center;vertical-align: middle;">15日广告ROI</th>
                                <th style="text-align: center;vertical-align: middle;">30日广告ROI</th>
                                <th style="text-align: center;vertical-align: middle;">3日内购收入</th>
                                <th style="text-align: center;vertical-align: middle;">7日内购收入</th>
                                <th style="text-align: center;vertical-align: middle;">15日内购收入</th>
                                <th style="text-align: center;vertical-align: middle;">30日内购收入</th>
                                <th style="text-align: center;vertical-align: middle;">3日广告收入</th>
                                <th style="text-align: center;vertical-align: middle;">7日广告收入</th>
                                <th style="text-align: center;vertical-align: middle;">15日广告收入</th>
                                <th style="text-align: center;vertical-align: middle;">30日广告收入</th>
                            </tr>
                            </thead>
                            <tbody id="reportBody">
                            <?
                            if(!empty($list)){ foreach($list as $row){
                                ?>
                                <tr>
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['date']; ?></td>
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['user_os'];//版本 ?></td>
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['address'];//地区 ?></td>
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['trackers_group_type']; ?></td>
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['campaigns_name'] ?? 0; ?></td><!--广告系列-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['adgroups_name']; ?></td><!--广告组-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['creatives_name']; ?></td><!--广告名-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['spend'] ?? 0; ?></td><!--广告成本-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--推广安装-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--推广CPI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--推广次留CPI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['period_1_kpis'][1]) ? 0 :number_format($row['period_1_kpis'][1] / $row['period_0_kpis'][1] * 100,2,'.',''); ?>%</td><!--次日留存-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['period_2_kpis'][1]) ? 0 :number_format($row['period_2_kpis'][1] / $row['period_0_kpis'][1] * 100,2,'.',''); ?>%</td><!--3日留存-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['period_6_kpis'][1]) ? 0 :number_format($row['period_6_kpis'][1] / $row['period_0_kpis'][1] * 100,2,'.',''); ?>%</td><!--7日留存-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_1_kpis'][1]; ?></td><!--次留人数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_2_kpis'][1]; ?></td><!--3留人数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_6_kpis'][1]; ?></td><!--7留人数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['reach']) ? 0 :number_format($row['inline_link_clicks'] / $row['reach'],2,'.',''); ?></td><!--点击率(CTR) = 链接点击数 / 展示次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--转化率(CVR) CVR=推广安装/链接点击数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--成效率(RR) RR=点击率x转化率，或 推广安装除以展示次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['impressions'])? 0 : number_format($row['spend']/$row['impressions']*1000,2,'.',''); ?></td><!--每千次展示费用(CPM) CPM=广告成本/展示次数X1000-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--覆盖人数 FB平台数据自定义栏的广告覆盖到的人数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['reach'] ?? 0; ?></td><!--展示次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['inline_link_clicks'] ?? 0; ?></td><!--链接点击数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_avg_time_watched_actions'] ?? 0; ?></td><!--视频平均观看时长-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_play_actions'] ?? 0; ?></td><!--视频观看总次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['three_sec_video_view'] ?? 0; ?></td><!--视频前3秒播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_p25_watched_actions'] ?? 0; ?></td><!--视频25%处播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_p50_watched_actions'] ?? 0; ?></td><!--视频50%处播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;">-</td><!--视频15s处播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_p75_watched_actions'] ?? 0; ?></td><!--视频75%处播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_p95_watched_actions'] ?? 0; ?></td><!--视频95%处播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['video_p100_watched_actions'] ?? 0; ?></td><!--观看视频100%处播放次数-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['period_2_kpis'][4] / $row['spend'],2,'.',''); ?></td><!--3日内购ROI = 3日内购收入 / 广告成本-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['period_6_kpis'][4] / $row['spend'],2,'.',''); ?></td><!--7日内购ROI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['period_14_kpis'][4] / $row['spend'],2,'.',''); ?></td><!--15日内购ROI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['period_29_kpis'][4] / $row['spend'],2,'.',''); ?></td><!--30日内购ROI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['advert_2'] / $row['spend'],2,'.',''); ?></td><!--3日广告ROI = 广告收入 / 广告成本-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['advert_6'] / $row['spend'],2,'.',''); ?></td><!--7日广告ROI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['advert_14'] / $row['spend'],2,'.',''); ?></td><!--15日广告ROI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo empty($row['spend']) ? 0 : number_format($row['advert_29'] / $row['spend'],2,'.',''); ?></td><!--30日广告ROI-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_2_kpis'][4] ?? 0; ?></td><!--3日内购收入-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_6_kpis'][4] ?? 0; ?></td><!--7日内购收入-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_14_kpis'][4] ?? 0; ?></td><!--15日内购收入-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo $row['period_29_kpis'][4] ?? 0; ?></td><!--30日内购收入-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo number_format($row['advert_2'],2,'.','') ?? 0; ?></td><!--3日广告收入 规模*用户平均生命周期价值 - 内购收入 大于0 则有广告收入 -->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo number_format($row['advert_6'],2,'.','') ?? 0; ?></td><!--7日广告收入-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo number_format($row['advert_14'],2,'.','') ?? 0; ?></td><!--15日广告收入-->
                                    <td style="text-align: center;vertical-align: middle;width:200px;"><?php echo number_format($row['advert_29'],2,'.','') ?? 0; ?></td><!--30日广告收入-->
                                </tr>
                            <?php } } ?>
                            </tbody>
                        </table>
                    </div>

                    <nav>
                        <ul class="pagination">
                            <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo $total;?></span>条</a></li>
                            <?php echo $pageurl;?>
                        </ul>
                    </nav>
                </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">


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