コード例 #1
0
ファイル: DefaultController.php プロジェクト: roman1970/lis
 /**
  * Приходы
  * @return string
  */
 public function actionIncomes()
 {
     if (Yii::$app->getRequest()->getQueryParam('user')) {
         // $start_day = strtotime('now 00:00:00');
         $user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
         if (!$user) {
             return 'Доступ запрещен!';
         }
         if (Yii::$app->getRequest()->getQueryParam('name') && Yii::$app->getRequest()->getQueryParam('value') !== null) {
             if (Income::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('name')])) {
                 $income = Income::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('name')])->one();
             } else {
                 return 'Ошибка при наборе';
             }
             $act = new DiaryActs();
             $act->model_id = 9;
             $act->user_id = $user->id;
             //return var_dump($act);
             if ($act->save(false)) {
                 $incomes = new Incomes();
                 try {
                     $incomes->income_id = $income->id;
                 } catch (\ErrorException $e) {
                     return 'Такой статьи в базе нет!';
                 }
                 $incomes->act_id = $act->id;
                 $incomes->user_id = $act->user_id;
                 $incomes->money = (double) Yii::$app->getRequest()->getQueryParam('value');
                 if (!$incomes->validate()) {
                     return 'Данные введены некорректно';
                 } else {
                     if ($incomes->save()) {
                         $all_incomes_grouped = Incomes::find()->select(['income_id, COUNT(*) as cnt, SUM(money) as sum '])->groupBy('income_id')->orderBy('sum DESC')->all();
                         //var_dump($all_incomes_grouped);
                         $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();
                         $bal_sum = $not_curr_sum + Helper::currencyAdapter($dollar, 11) + Helper::currencyAdapter($euro, 12);
                         return $this->renderPartial('all_incomes', ['user' => $user, 'incomes' => $all_incomes_grouped, 'bal_sum' => $bal_sum]);
                     } else {
                         return 'Ошибка сохранения';
                     }
                 }
             }
         }
         $all_incomes_grouped = Incomes::find()->select(['income_id, COUNT(*) as cnt, SUM(money) as sum '])->groupBy('income_id')->orderBy('sum DESC')->all();
         //var_dump($all_incomes_grouped);
         $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();
         $bal_sum = $not_curr_sum + Helper::currencyAdapter($dollar, 11) + Helper::currencyAdapter($euro, 12);
         //sreturn Helper::currencyAdapter($dollar, 11);
         return $this->renderPartial('income', ['user' => $user, 'incomes' => $all_incomes_grouped, 'bal_sum' => $bal_sum]);
     } else {
         return 'Ошибка';
     }
 }
コード例 #2
0
ファイル: Income.php プロジェクト: roman1970/lis
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIncomes()
 {
     return $this->hasMany(Incomes::className(), ['income_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);
 }