public function actionIndex($subs_id)
 {
     $subs = \Subscription::model()->findByAttributes(array('ID' => $subs_id));
     $lowestPrice = new \D_LowestPrice();
     $subs->CurrentPrice = (int) $lowestPrice->searchFlight($subs);
     echo "now subs " . $subs_id . " current price is " . $subs->CurrentPrice . "\n";
     try {
         if (!$subs->save()) {
             new \Error(5, null, json_encode($subs->getErrors()));
         }
     } catch (Exception $e) {
         new \Error(5, null, $e->getMessage());
     }
     $date = new \DateGenerater();
     $date = $date->getDateYMD("-");
     $price = $subs->CurrentPrice;
     $history_price = \HistoryPrice::model()->findAllByAttributes(array('ID_subscription' => $subs->ID, 'Date' => $date));
     if ($history_price == NULL || count($history_price) == 0) {
         $history_price = new HistoryPrice();
         $history_price->ID_subscription = $subs->ID;
         $history_price->Price = $price;
         $history_price->Date = $date;
         try {
             $history_price->save();
         } catch (Exception $e) {
             new \Error(5, NULL, $e->getMessage());
         }
     } else {
         //var_dump($history_price);
         $history_price = $history_price[0];
         if ($history_price->Price == $price) {
             return;
         }
         $history_price->Price = $price < $history_price->Price ? $price : $history_price;
         try {
             $history_price->save();
         } catch (Exception $e) {
             new \Error(5, NULL, $e->getMessage());
         }
     }
 }
 private function createHistoryPrice(Subscription $subs, $price)
 {
     $date = getDateYMD("-");
     $history_price = HistoryPrice::model()->findByAttributes(array('ID_subscription' => $subs->ID, 'Date' => $date));
     //var_dump($history_price);
     if ($history_price == NULL) {
         $history_price = new HistoryPrice();
         $history_price->ID_subscription = $subs->ID;
         $history_price->Price = $price;
         $history_price->Date = $date;
         if (!$history_price->save()) {
             throw new CDbException("update old history_price fail");
         }
     } else {
         //var_dump($history_price);
         //return;
         //$history_price = $history_price[0];
         $history_price->Price = $price < $history_price->Price ? $price : $history_price->Price;
         if (!$history_price->save()) {
             new \Error(5, null, json_encode($history_price->getErrors()));
         }
     }
 }
예제 #3
0
 private function createHistoryPrice(Subscription $subs, $price)
 {
     $date = getDateYMD("-");
     $history_price = HistoryPrice::model()->findByAttributes(array('ID_subscription' => $subs->ID, 'Date' => $date));
     if ($history_price == NULL || $history_price->count() == 0) {
         $history_price = new HistoryPrice();
         $history_price->ID_subscription = $subs->ID;
         $history_price->Price = $price;
         $history_price->Date = $date;
         if (!$history_price->save()) {
             throw new CDbException("update old history_price fail");
         }
     } else {
         var_dump($history_price);
         return;
         $history_price = $history_price[0];
         $history_price->Price = $price < $history_price->Price ? $price : $history_price;
         if (!$history_price->save()) {
             throw new CDbException("save new history_price fail");
         }
     }
 }