Ejemplo n.º 1
0
 /**
  * 单个广告某周期统计
  * @param $id
  */
 public function get_the_ad_stat($id)
 {
     $ad = new AD();
     if (!$ad->check_ad_owner($id)) {
         $this->exit_with_error(20, '您无法查询此广告', 401);
     }
     list($start, $end) = $this->getFilter($id);
     $info = $ad->get_ad_info(array('id' => $id), 0, 1);
     $service = new Transfer();
     $transfer_res = $service->get_ad_transfer(array('start' => $start, 'end' => $end, 'ad_id' => $id), 'transfer_date');
     if ($info['ad_app_type'] == ADModel::ANDROID) {
         $android = new AndroidStat();
         $click_res = $android->get_ad_click(array('start' => $start, 'end' => $end, 'ad_id' => $id), AndroidStat::TIME_FIELD);
     } else {
         $ios = new IOS_Stat();
         $click_res = $ios->get_ad_click(array('start' => $start, 'end' => $end, 'ad_id' => $id), IOS_Stat::TIME_FIELD);
     }
     $start = strtotime($start);
     $end = strtotime($end);
     $result = array();
     for ($i = $start; $i <= $end; $i += 86400) {
         $date = date('Y-m-d', $i);
         $transfer = (int) $transfer_res[$date];
         if (!$transfer && !$click_res[$date]) {
             continue;
         }
         $result[] = array('ad_id' => $id, 'date' => $date, 'transfer' => $transfer, 'click' => (int) $click_res[$date], 'cost' => $transfer * $info['quote_rmb']);
     }
     $this->output(array('code' => 0, 'msg' => 'fetched', 'total' => count($result), 'start' => 0, 'list' => $result));
 }
Ejemplo n.º 2
0
 private function get_fullness(array &$progress)
 {
     if (!array_key_exists('fullness', $progress)) {
         $transfer = new AndroidStat();
         $yesterday = date('Y-m-d', time() - 86400);
         $hourly = $transfer->get_ad_transfer(array('ad_id' => $progress['ad'], 'date' => $yesterday));
         $count = 0;
         foreach ($hourly as $hour) {
             if ($hour > 30) {
                 $count++;
             }
         }
         $progress['fullness'] = $count > 14;
     }
     return $progress['fullness'];
 }