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()));
         }
     }
 }
 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");
         }
     }
 }