public function get_stat_by_hour($id) { $ad_service = new AD(); $ad = $ad_service->select_ad_join_source_create_time($id); $today = date("Y-m-d"); $date = empty($_GET['start']) ? $today : $_GET['start']; $transferService = new TransferStat(); $install_res = $transferService->get_offer_install_stat_ad_h($date, $id); $transfer_res = $transferService->get_transfer_stat_ad_h($date, $id); $click_res = $transferService->get_offer_click_stat_ad_h($date, $id); if ($ad['ad_app_type'] == 2) { $cpa_res = $transferService->get_income_transfer_stat_ios_h($date, $id); } $ymd = explode('-', $date); $datestamp = mktime(0, 0, 0, (int) $ymd[1], (int) $ymd[2], (int) $ymd[0]); $yesterday = date('Y-m-d', $datestamp - 3600 * 24); $tomorrow = date('Y-m-d', $datestamp + 3600 * 24); $hours = array_unique(array_merge(array_keys($transfer_res), array_keys($install_res), array_keys($click_res))); if ($ad['ad_app_type'] == 2) { $hours = array_unique(array_merge($hours, array_keys($cpa_res))); } sort($hours); $click = 0; $install = 0; $transfer = 0; $cpa = 0; foreach ($hours as $hour) { $stat[] = array('hour' => $hour, 'click' => $click_res[$hour], 'install' => $install_res[$hour], 'transfer' => $transfer_res[$hour], 'cpa' => $cpa_res[$hour], 'ratio' => $click_res[$hour] ? round($transfer_res[$hour] * 100 / $click_res[$hour], 2) : 0, 'click_ratio' => $click_res[$hour] ? round($cpa_res[$hour] * 100 / $click_res[$hour], 2) : 0); $click += $click_res[$hour]; $install += $install_res[$hour]; $transfer += $transfer_res[$hour]; $cpa += $cpa_res[$hour]; } $ratio = $click == 0 ? 0 : round($transfer * 100 / $click, 2); $click_ratio = $click == 0 ? 0 : round($cpa * 100 / $click, 2); $transfer_stat = array('hour' => '总计', 'click' => $click, 'install' => $install, 'transfer' => $transfer, 'cpa' => $cpa, 'ratio' => $ratio, 'click_ratio' => $click_ratio); $result = array_merge($ad, array('date' => $date, 'cid' => $ad['cid'], 'channel' => $ad['channel'], 'ctime' => substr($ad['create_time'], 5, 5), 'hour' => $stat, 'yesterday' => $date < date('Y-m-d', $today - 86400 * 90) ? NULL : $yesterday, 'tomorrow' => $date == $today ? NULL : $tomorrow, 'is_ios' => $ad['ad_app_type'] == 2, 'stat' => $transfer_stat)); $this->output(array('code' => 0, 'msg' => 1, 'list' => $result['hour'])); }