예제 #1
0
 public static function getCurs($valute)
 {
     $param = Setup::find()->where(['param_name' => $valute . date("d-m-Y", time())])->one();
     if ($param) {
         return $param->param_value;
     } else {
         $rates = new Exchange(time());
         $curs = $rates->GetRate($valute);
         // Обновить курс
         $model = new Setup();
         $model->param_name = (string) $valute . date("d-m-Y", time());
         $model->param_value = (string) $curs;
         //$model->validate();
         //vd($model->getErrors());
         $model->save();
         return $curs;
     }
 }
예제 #2
0
 public static function changeLangTo($lang)
 {
     $indef = isset(Yii::$app->user->id) ? Yii::$app->user->id : Yii::$app->session->id;
     //vd($indef);
     $model = self::find()->where(['user_id' => $indef, 'param_name' => 'lang', 'param_value' => [self::RU, self::EN]])->one();
     //vd($model);
     if ($model) {
         // сравнить и изменить
         if ($model->param_value != $lang) {
             $model->param_value = $lang;
             $model->updateAttributes(['param_value']);
             return $model->param_value;
         } else {
             return self::RU;
         }
     } else {
         //vd(4);
         $_model = new Setup();
         $_model->param_name = 'lang';
         $_model->param_value = (string) $lang;
         $_model->user_id = (string) $indef;
         //vd(yii::$app->user->id);
         //$_model->validate();
         //vd($_model->getErrors());
         $_model->save();
         return $lang;
     }
 }