Пример #1
0
 public function ad_stat_by_date($ymd, $monthly)
 {
     $value = array();
     if ($monthly) {
         $start = $ymd . '-01';
         $end = date('Y-m-d', mktime(0, 0, 0, substr($ymd, 5, 2) + 1, 0, substr($ymd, 0, 4)));
     } else {
         $start = $ymd;
         $end = $ymd;
     }
     $transferStat_service = new TransferStat();
     $transfer_res = $transferStat_service->get_ad_transfer_by_ads($start, $end, "");
     $happy_lock_transfer = $transferStat_service->get_all_ad_happy_lock_transfer($start, $end);
     $click = $transferStat_service->get_offer_click_total($start, $end);
     $adminStat_service = new AdminTaskStat();
     $task = $adminStat_service->get_ad_task_stat($start, $end);
     $limited_task = $adminStat_service->get_ad_limited_task_stat($start, $end);
     $es_task = $adminStat_service->get_all_ad_happy_lock_task($start, $end);
     $es_limited_task = $adminStat_service->get_all_ad_happy_lock_limited_task($start, $end);
     $nativeStat_service = new NativeStat();
     $native = $nativeStat_service->get_native_stat_ad($start, $end);
     $native_transfer = $nativeStat_service->get_native_transfer_stat_by_ad($start, $end);
     $callback = $transferStat_service->get_income_stat_ios($start, $end);
     $install = $transferStat_service->get_offer_install_stat_ad($start, $end);
     $happy_lock_task = array();
     foreach ($es_task['aggregations']['all_ad_ids']['buckets'] as $ad_task) {
         $happy_lock_task[$ad_task['key']] = $ad_task['sum_rmb']['value'];
     }
     $happy_lock_limited_task = array();
     foreach ($es_limited_task['aggregations']['all_ad_ids']['buckets'] as $ad_task) {
         $happy_lock_limited_task[$ad_task['key']] = $ad_task['sum_rmb']['value'];
     }
     $ad_ids = array_unique(array_merge(array_keys((array) $transfer_res), array_keys((array) $click), array_keys((array) $task), array_keys((array) $limited_task), array_keys((array) $install), array_keys((array) $native), array_keys((array) $native_transfer), array_keys((array) $callback)));
     foreach ($ad_ids as $ad_id) {
         $stat = array('id' => $ad_id, 'rmb1' => round((isset($transfer_res[$ad_id]) ? ($transfer_res[$ad_id]['rmb'] - $happy_lock_transfer[$ad_id]['rmb'] / 2) / 100 : 0) + ($task[$ad_id]['rmb'] + $limited_task[$ad_id]['rmb'] - $happy_lock_task[$ad_id] / 2 - $happy_lock_limited_task[$ad_id] / 2) / 100, 2), 'device1' => (int) $transfer_res[$ad_id]['transfer'], 'native' => (int) $native[$ad_id], 'native_transfer' => (int) $native_transfer[$ad_id], 'task_num' => $task[$ad_id]['num'] + $limited_task[$ad_id]['num'], 'task_rmb' => ($task[$ad_id]['rmb'] + $limited_task[$ad_id]['rmb'] - $happy_lock_task[$ad_id] / 2 - $happy_lock_limited_task[$ad_id] / 2) / 100, 'task_ready' => $task[$ad_id]['ready'], 'click' => $click[$ad_id], 'install' => $install[$ad_id], 'callback' => $callback[$ad_id]);
         $value[$ad_id] = $stat;
     }
     return $value;
 }
 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']));
 }
 private function get_corp_data($start, $end, $me)
 {
     $transfer_service = new TransferStat();
     $my_transfer = $transfer_service->get_ad_transfer_by_sale($start, $end, $me);
     $corp_transfer = $transfer_service->get_transfer_by_app_day($start, $end, "");
     $quote_service = new Quote();
     $corp_quote = $quote_service->get_by_ads($start, $end, "", true);
     $corp = array();
     $corp_stat = 0;
     foreach ($corp_transfer as $date => $value) {
         $item = array('date' => $date, 'transfer' => (int) $value['transfer'], 'my_transfer' => (int) $my_transfer[$date]['transfer']);
         $corp_stat += (int) $value['transfer'];
         $corp[] = $item;
     }
     array_pop($corp);
     // 不要画今天的点
     $corp_cpa = 0;
     foreach ($corp_quote as $value) {
         $corp_cpa += (int) $value['cpa'];
     }
     return array($corp, $corp_stat, $corp_cpa);
 }