コード例 #1
0
ファイル: DefaultController.php プロジェクト: roman1970/lis
 /**
  * Изменить параметр
  * @return string
  * @throws \Exception
  */
 public function actionChangeParam()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         $start_day = strtotime('now 00:00:00', time() + 7 * 60 * 60);
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (Yii::$app->getRequest()->getQueryParam('param_id') && Yii::$app->getRequest()->getQueryParam('val')) {
             $rec_param = DiaryRecDayParams::findOne((int) Yii::$app->getRequest()->getQueryParam('param_id'));
             $rec_param->value = (double) Yii::$app->getRequest()->getQueryParam('val');
             if ($rec_param->update()) {
                 $today_acts = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_day} and user_id = " . $user->id . " and model_id = 4")->all(), 'id', 'id'));
                 //return var_dump($today_acts);
                 $params = [];
                 $recorded_params_in = [];
                 $recorded_params = [];
                 $recorded = [];
                 if ($today_acts) {
                     $recorded = DiaryRecDayParams::find()->where("act_id  IN (" . $today_acts . ")")->all();
                     $param_array = implode(',', ArrayHelper::map($recorded, 'id', 'day_param_id'));
                     if ($param_array) {
                         $recorded_params_in = DiaryDayParams::find()->where("id  IN (" . $param_array . ")")->all();
                         $params = DiaryDayParams::find()->where("id NOT IN (" . $param_array . ")")->all();
                     }
                     foreach ($recorded_params_in as $param) {
                         $recorded_params[DiaryRecDayParams::findOne($param->id)->value] = $param->name;
                     }
                     //return var_dump($recorded_params);
                 } else {
                     $params = DiaryDayParams::find()->all();
                 }
                 //$params = DiaryDayParams::find()->all();
                 //return var_dump($params);
                 return $this->renderPartial('today_params', ['params' => $params, 'recorded_params' => $recorded, 'user' => $user->id]);
             }
             return 'НЕ получилось';
         }
         //return var_dump($user);
     }
 }
コード例 #2
0
ファイル: DiaryDayParams.php プロジェクト: roman1970/lis
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRecDayParams()
 {
     return $this->hasMany(DiaryRecDayParams::className(), ['day_param_id' => 'id']);
 }
コード例 #3
0
ファイル: ParsersController.php プロジェクト: roman1970/lis
 /**
  * Снимок дня
  * @throws \Exception
  */
 public function actionSnapshot()
 {
     //$data = $this->cut_content($this->get_page("http://redday.ru/moon/"),'maintext', '/sun/sunrise.asp');
     //var_dump($data); exit;
     $start_time = strtotime('now 00:00:00', time() + 7 * 60 * 60);
     $snapshot = new Snapshot();
     $today_mark = DiaryActs::find()->select('SUM(mark)')->where("user_id = 8 and time > " . $start_time)->scalar();
     if ($today_mark) {
         $snapshot->oz = $today_mark;
     } else {
         $snapshot->weight = 0;
     }
     $snapshot->doll = Helper::currencyAdapter(1, 11);
     $snapshot->euro = Helper::currencyAdapter(1, 12);
     if (DiaryRecDayParams::find()->where(['day_param_id' => 1])->orderBy('id DESC')->one()) {
         $snapshot->weight = (double) DiaryRecDayParams::find()->where(['day_param_id' => 1])->orderBy('id DESC')->one()->value;
     } else {
         $snapshot->weight = 0;
     }
     $mish_mark = DiaryActs::find()->select('SUM(mark)')->where("time > {$start_time} and user_id = 11")->scalar();
     if ($mish_mark) {
         $snapshot->mish_oz = $mish_mark;
     } else {
         $snapshot->mish_oz = 0;
     }
     $today_acts = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_time} and user_id = 8 and model_id = 1")->all(), 'id', 'id'));
     $snapshot->kkal = DiaryAte::find()->select('SUM(kkal)')->where("act_id  IN (" . $today_acts . ")")->scalar();
     $not_curr_sum = Incomes::find()->select('SUM(money)')->where("income_id  IN (1,2,7,10)")->scalar();
     $dollar = Incomes::find()->select('SUM(money)')->where("income_id  = 8")->scalar();
     $euro = Incomes::find()->select('SUM(money)')->where("income_id  = 9")->scalar();
     $snapshot->useful_bal = (int) ($not_curr_sum + Helper::currencyAdapter($dollar, 11) + Helper::currencyAdapter($euro, 12));
     $snapshot->sun_rise = date_sunrise(time(), SUNFUNCS_RET_STRING, 55, 82, 90, 7);
     $snapshot->sun_set = date_sunset(time(), SUNFUNCS_RET_STRING, 55, 82, 90, 7);
     $today_acts_bought = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_time} and user_id = 8 and model_id = 3")->all(), 'id', 'id'));
     $bought_today = [];
     $sum_spent = 0;
     if ($today_acts_bought) {
         try {
             //return var_dump($bought_today);
             $snapshot->spent = Bought::find()->select('SUM(spent)')->where("act_id  IN (" . $today_acts_bought . ")")->scalar();
         } catch (\ErrorException $e) {
             return $e->getMessage();
         }
         // return var_dump($sum_spent );
     }
     if ($snapshot->save()) {
         $act = new DiaryActs();
         $act->model_id = 12;
         $act->user_id = 8;
         $klavaro_balls = 0;
         $today_acts_of_day_params = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_time} and user_id = 8 and model_id = 4")->all(), 'id', 'id'));
         if ($today_acts_of_day_params) {
             $klavaro_eng_today = DiaryRecDayParams::find()->where("act_id  IN (" . $today_acts_of_day_params . ") and day_param_id = 22")->one();
             $klavaro_ru_today = DiaryRecDayParams::find()->where("act_id  IN (" . $today_acts_of_day_params . ") and day_param_id = 23")->one();
         }
         if (isset($klavaro_eng_today) && $klavaro_eng_today->value > 95) {
             $klavaro_balls = 1;
         }
         if (isset($klavaro_ru_today) && $klavaro_ru_today->value > 95) {
             $klavaro_balls += 1;
         }
         //$klavaro_balls = ( isset($klavaro_eng_today) ? $klavaro_eng_today->value : 0 ) + ( isset($klavaro_ru_today) ? $klavaro_eng_today->value : 0 );
         //echo $klavaro_balls;
         if (DiaryRecDayParams::find()->where(['day_param_id' => 18])->orderBy('id DESC')->one()) {
             $act->mark = (int) round(DiaryRecDayParams::find()->where(['day_param_id' => 18])->orderBy('id DESC')->one()->value / 2000) + $klavaro_balls;
         } else {
             $act->mark = 0;
         }
         $snapshot->oz += $act->mark;
         $snapshot->update();
         // var_dump($act);
         if ($act->save(false)) {
             echo 'ok';
         }
     }
     //var_dump($snapshot);
 }