Пример #1
0
 public static function rubAsCurrency($currency_id, $ammount)
 {
     if (!$currency_id && !$ammount) {
         return;
     }
     $query = CurrencyCur::find();
     $query->where(['currency_id' => $currency_id]);
     $query->orderBy(['id' => SORT_DESC]);
     $query->limit(1);
     $rate = $query->one();
     if ($rate) {
         return $ammount / $rate->rate;
     } else {
         return false;
     }
 }
Пример #2
0
 public function actionUpdateRates($active = null)
 {
     $models = $active && $active == true ? Currency::findAll(['active' => 1]) : Currency::find()->all();
     $i = 0;
     foreach ($models as $currency) {
         if ($currency->code == 643) {
             continue;
         }
         if (($rate = $this->GetRate($currency->code)) !== false) {
             $curs = new CurrencyCur();
             $curs->currency_id = $currency->id;
             $curs->curs = floatval($rate['curs']);
             $curs->nom = (int) $rate['nom'];
             $curs->rate = floatval($rate['rate']);
             $curs->save(false);
             $i++;
         }
     }
     echo "Insert currency_curs: " . $i . PHP_EOL;
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCurrencyCurs()
 {
     return $this->hasMany(\app\models\CurrencyCur::className(), ['currency_id' => 'id']);
 }