コード例 #1
0
ファイル: Delivery.php プロジェクト: huycao/yodelivery
 /**
  * check delivery status and condition of requested flight
  */
 public function deliveredAdStatus($adID, $flightWebsite, $flight, $dateRange)
 {
     $trackingModel = new Tracking();
     //kiểm tra độ tuổi
     if ($flight->age && !$this->checkAge(json_decode($flight->age), Input::get('age')) && !isLocal()) {
         return self::RESPONSE_TYPE_AGE_LIMIT;
     }
     //kiểm tra giới tính
     if ($flight->sex && !$this->checkGender($flight->sex, Input::get('g')) && !isLocal()) {
         return self::RESPONSE_TYPE_GENDER_LIMIT;
     }
     //kiểm tra vị trí địa lí
     if ($flight->country && $flight->province && !$this->checkGeo($flight->country, $flight->province)) {
         return self::RESPONSE_TYPE_GEO_LIMIT;
     }
     //kiểm tra frequency capping
     if (!empty($dateRange) && !$this->checkFrequencyCap($flight, $dateRange, $flightWebsite->id) && !isLocal()) {
         return self::RESPONSE_TYPE_FREQUENCY_CAPPED;
     }
     //TODO : kiểm tra channel
     // to do kiểm tra theo loại campaign : CPC hay CPM
     //if( $flight->cost_type == 'cpm' || $flight->cost_type == 'cpc' ){
     $event = Tracking::getTrackingEventType($flight->cost_type);
     $overReport = FALSE;
     $checkInventory = $this->checkInventory($flight, $flightWebsite, $event, $dateRange);
     if ($checkInventory !== TRUE) {
         //full inventory trong ngày
         // $checkOverInventory = $this->checkOverInventory($flight, $flightWebsite, $event);
         // if($checkOverInventory !== TRUE){
         return $checkInventory;
         // }
         // else{
         // 	$overReport = TRUE;
         // }
     } else {
         $checkOvrInventory = $this->checkOverInventory($flight, $flightWebsite, $event);
         pr($checkOvrInventory);
         if ($checkOvrInventory === TRUE) {
             $overReport = TRUE;
         }
     }
     //}
     // WHEN READY TO DELIVERY
     //if( $flight->frequency_cap ){
     if (!empty($dateRange)) {
         $todayCapped = $trackingModel->getTodayFreCap($flight);
         $now = strtotime(date('Y-m-d H:i'));
         pr($dateRange);
         foreach ($dateRange as $date) {
             if (strtotime($date->start) <= $now && strtotime($date->end) >= $now) {
                 if ($date->frequency_cap > 0) {
                     if ($trackingModel->getTimeFreCap($flight) == 0) {
                         $redis = new RedisBaseModel(env('REDIS_HOST', '127.0.0.1'), env('REDIS_PORT_2', '6379'), false);
                         $visitorId = $trackingModel->getVisitorId();
                         $cacheKey = "Tracking:TimeFrequencyCap_{$flight->id}_{$visitorId}_{$flight->event}";
                         $cacheField = date('Y_m_d');
                         $redis->hSet($cacheKey, $cacheField, 0);
                         if ($date->frequency_cap_time > 0) {
                             $redis->expire($cacheKey, $date->frequency_cap_time * 60);
                         } else {
                             $redis->expire($cacheKey, 2);
                         }
                     }
                     if ($todayCapped >= $date->frequency_cap - 1) {
                         $time = time();
                         $expire = round((strtotime(date('Y-m-d 23:59:59', $time)) - $time) / 60);
                         $trackingModel->setTimeFreCap($flight, $expire);
                     }
                 }
             }
         }
         /*if(  $todayCapped >= $flight->frequency_cap_free &&  $flight->frequency_cap_time > 0 ){
         			$trackingModel->rememberFrequencyCap($flightWebsite->id, $flight->frequency_cap_time);
         		}*/
     }
     return $overReport ? self::DELIVERY_STATUS_OVER_REPORT : self::DELIVERY_STATUS_OK;
 }
コード例 #2
0
 public function retargeting()
 {
     $adv = Input::get("adv");
     if ($adv <= 0) {
         return "";
     }
     $referer_url = "";
     if (isset($_SERVER['HTTP_REFERER'])) {
         $referer_url = $_SERVER['HTTP_REFERER'];
     }
     if ($referer_url != "") {
         $tracking = new Tracking();
         $cacheKey = "retargeting";
         $cacheField = "{$adv}_{$tracking->getVisitorId()}";
         $key_referer_url = $referer_url;
         $cache = RedisHelper::hGet($cacheKey, $cacheField, false);
         if ($cache == null) {
             $array = new stdClass();
             $array->{$referer_url} = $referer_url;
             RedisHelper::hSet($cacheKey, $cacheField, $array);
         } else {
             $array = $cache;
             $array->{$referer_url} = $referer_url;
             RedisHelper::hSet($cacheKey, $cacheField, $array);
         }
     }
 }