/** * 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'))) { return self::RESPONSE_TYPE_AGE_LIMIT; } //kiểm tra giới tính if ($flight->sex && !$this->checkGender($flight->sex, \Input::get('g'))) { 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( $flight->frequency_cap && (!$this->checkFrequencyCap($flight->id, $flight->frequency_cap) || Cookie::get(md5("FrequencyCap:$flightWebsite->id")) ) ){ return self::RESPONSE_TYPE_FREQUENCY_CAPPED; }*/ if (!empty($dateRange) && (!$this->checkFrequencyCap($flight, $dateRange) || Cookie::get(md5("FrequencyCap:{$flightWebsite->id}")))) { return self::RESPONSE_TYPE_FREQUENCY_CAPPED; } // TODO : kiểm tra channel 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 00:00:00')); foreach ($dateRange as $date) { if (strtotime($date->start) <= $now && strtotime($date->end) >= $now) { if ($date->frequency_cap > 0 && $todayCapped >= $date->frequency_cap - 1 && $date->frequency_cap_time > 0) { $trackingModel->rememberFrequencyCap($flightWebsite->id, $date->frequency_cap_time); $trackingModel->setTimeFreeCap($flight, $date->frequency_cap_time); } } } /*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; }