示例#1
0
 /**
  * Сделал дело
  * @return string
  */
 public function actionDoneDeal()
 {
     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('deal')) {
             try {
                 $deal = DiaryDeals::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('deal')) . "'")->one();
             } catch (\ErrorException $e) {
                 $deal = [];
             }
             if (!$deal) {
                 return 'Ошибка!';
             }
             //return var_dump($deal);
             $act = new DiaryActs();
             $act->model_id = 5;
             $act->user_id = $user->id;
             $act->mark = $deal->mark;
             $act->mark_status = 0;
             //return var_dump($act);
             if ($act->save(false)) {
                 $done_deal = new DiaryDoneDeal();
                 $done_deal->deal_id = $deal->id;
                 $done_deal->act_id = $act->id;
                 $done_deal->user_id = $user->id;
                 //return var_dump($done_deal);
                 if ($done_deal->save()) {
                     $today_acts = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_day} and user_id = " . $user->id)->all(), 'id', 'id'));
                     $deals = [];
                     $sum_mark = 0;
                     $deal_cats = [];
                     $cat_deal = [];
                     if ($today_acts) {
                         $today_deals = DiaryDoneDeal::find()->where("act_id IN (" . $today_acts . ")")->all();
                         $sum_mark = DiaryActs::find()->select('SUM(mark)')->where("time > {$start_day} and user_id = " . $user->id)->scalar();
                         $mark_accumul = DiaryActs::find()->select('SUM(mark)')->where("time > " . mktime(0, 0, 0, 9, 1, 2016) . " and user_id = " . $user->id)->scalar();
                         $users_money = MarkUser::findOne(11)->money;
                         $money = $mark_accumul + $users_money;
                         foreach ($today_deals as $done_deal) {
                             $deals[] = DiaryDeals::findOne($done_deal->deal_id);
                             $deal_cats[Categories::findOne($done_deal->deal->cat_id)->name][] = DiaryDeals::findOne($done_deal->deal_id)->mark;
                             //return var_dump($done_deal->deal->cat_id);
                         }
                         foreach ($deal_cats as $cat => $marks) {
                             $mark = 0;
                             foreach ($marks as $mrk) {
                                 $mark += $mrk;
                             }
                             $cat_deal[$cat][] = $mark;
                         }
                     }
                     $all_deals = DiaryDeals::find()->all();
                     //return var_dump($deals);
                     return $this->renderPartial('deals', ['deal_cats' => $cat_deal, 'sum_mark' => $sum_mark, 'user' => $user, 'money' => $money]);
                 }
                 return $this->renderPartial('error');
             }
         }
     }
 }
示例#2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDoneDeals()
 {
     return $this->hasMany(DiaryDoneDeal::className(), ['deal_id' => 'id']);
 }
示例#3
0
 /**
  * Генератор дневника знаний
  */
 public function actionDiaryGenerator()
 {
     $arr = [];
     $arr['ate_sum_kkal'] = 0;
     $article_time = '00:00';
     $start_day = strtotime('now 00:00:00');
     $today = date('Ymd', $start_day);
     //$today = '20161011_01';
     //echo $today.PHP_EOL; exit;
     $today_acts = DiaryActs::find()->where("time > {$start_day} and user_id = 8")->all();
     //var_dump($today_acts); exit;
     $f = 0;
     foreach ($today_acts as $act) {
         switch ($act->model_id) {
             case 1:
                 if (DiaryAte::find()->where(['act_id' => $act->id])->one()) {
                     $arr['ate'][$act->time] = DiaryAte::find()->where(['act_id' => $act->id])->one();
                 }
                 $arr['ate_sum_kkal'] += DiaryAte::find()->where(['act_id' => $act->id])->one()->kkal;
                 break;
             case 2:
                 $arr['tasked'][$act->time] = Tasked::find()->where(['act_id' => $act->id])->one();
                 break;
             case 3:
                 $arr['bought'][$act->time] = Bought::find()->where(['act_id' => $act->id])->one();
                 break;
             case 4:
                 $arr['day_params'][$act->time] = DiaryRecDayParams::find()->where(['act_id' => $act->id])->one();
                 break;
             case 5:
                 $arr['deals'][$act->time] = DiaryDoneDeal::find()->where(['act_id' => $act->id])->one();
                 break;
             case 6:
                 if (Articles::find()->where(['act_id' => $act->id])->one()) {
                     if ($f == 0) {
                         echo $f . " " . $today . PHP_EOL;
                         $articles = ArticlesContent::find()->where(['articles_id' => Articles::find()->where(['act_id' => $act->id])->one()->id])->all();
                         //var_dump($articles); exit;
                         //$article_time = $act->time;
                         $arr['article_title'] = Articles::find()->where(['act_id' => $act->id])->one()->title;
                         $f = 1;
                     }
                 }
                 break;
             case 7:
                 if (Items::find()->where(['act_id' => $act->id])->one()) {
                     $arr['items'][$act->time] = Items::find()->where(['act_id' => $act->id])->one();
                 }
                 break;
             case 9:
                 if (Incomes::find()->where(['act_id' => $act->id])->one()) {
                     $arr['incomes'][$act->time] = Incomes::find()->where(['act_id' => $act->id])->one();
                 }
                 break;
             case 10:
                 if (Event::find()->where(['act_id' => $act->id])->one()) {
                     $arr['events'][$act->time] = Event::find()->where(['act_id' => $act->id])->one();
                 }
                 break;
         }
     }
     $ate_sum_kkal = $arr['ate_sum_kkal'];
     //print_r($arr['articles']); var_dump($articles); exit;
     $file = fopen("/home/romanych/www/vrs/diary/2016/{$today}.html", "w");
     //хэдер
     fwrite($file, '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                         <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css">
                         <meta name="viewport" content="width=device-width, initial-scale=1.0">
                         <style>.item_head{font-weight: bold;} 
                                 body{padding-left: 20px; padding-top: 20px; background-color: rgba(78, 82, 65, 0.11);}
                                 img {width: 100%;min-height: 100px;}
                                 h3,h4,h5 {color: #994b43; text-align: left; margin-top: 1px; margin-bottom: 5px;}
                                 .mini{font-size: 10px; margin: 0; }
                                 .image img{width: auto;}
                         </style>
                         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
                         ');
     if (isset($arr['article_title'])) {
         fwrite($file, "<hr><h3>" . date('d-m-Y', $start_day) . " " . $arr['article_title'] . "</h3><div class=\"btn-group\">\n            <button type=\"button\" class=\"btn btn-default\"><span class=\"glyphicon glyphicon-star\"></button>\n            \n          </div>                <script>\n                                  \$('.mw-editsection-visualeditor').hide();\n                                </script>");
     }
     /*блок еды
            if(isset($arr['ate'])){ fwrite($file, "<p>Съел $ate_sum_kkal kkal</p> 
                    <table class='table'>
                    <tbody>
                        <tr >
                            <td>м</td>
                            <td>блюдо</td>
                            <td>кол-во</td>
                            <td>ккал</td>
                          
                        </tr>");
                foreach ($arr['ate'] as $key => $ate){
                    $dish = $ate->dish->name;
                    $time = date('H:i',$key+7*3600);
                    fwrite($file, "
                        <tr >
                            <td> $time </td>
                            <td> $dish </td>
                            <td> $ate->measure </td>
                            <td> $ate->kkal </td>
                        </tr>
                   
                    ");
                }
                fwrite($file, "</tbody></table>");
     
            }
            */
     // блок статей
     $i = 0;
     if (isset($articles) && $arr['article_title']) {
         fwrite($file, "<hr><h4>**Статьи**</h4>");
         foreach ($articles as $article) {
             $i++;
             fwrite($file, "<hr><h4>*" . $i . " " . $article->source->author->name . " - - " . $article->source->title . "</h4>");
             fwrite($file, "<h4>" . $article->minititle . "</h4>");
             fwrite($file, $article->body);
         }
     }
     //блок айтемов
     if (isset($arr['items'])) {
         fwrite($file, "<hr><h4>**Краткости талантов**</h4>");
         foreach ($arr['items'] as $time => $item) {
             $i++;
             fwrite($file, "<p class='mini'>*" . $i . " " . date('H:i', $time) . " ");
             fwrite($file, $item->title . "<br>");
             fwrite($file, " " . $item->source->title . " - " . $item->source->author->name . " - " . $item->cat->name . "</p>");
             if ($item->old_data) {
                 fwrite($file, "<p class='mini'>" . $item->old_data . "</p>");
             }
             if ($item->img) {
                 fwrite($file, "<img src=/" . $item->img . ">");
             }
             fwrite($file, "<p>" . nl2br($item->text) . "</p>");
         }
     }
     //блок событий
     //var_dump($arr['events']);
     if (isset($arr['events'])) {
         fwrite($file, "<hr><h4>**События**</h4>");
         foreach ($arr['events'] as $time => $event) {
             $i++;
             fwrite($file, "<p class='mini'>*" . $i . " " . date('H:i', $time) . " -");
             fwrite($file, $event->cat->name . " - ");
             if ($event->old_data) {
                 fwrite($file, " " . $event->old_data . "</p>");
             } else {
                 fwrite($file, "</p>");
             }
             if ($event->img) {
                 fwrite($file, "<img src=/" . $event->img . ">");
             }
             fwrite($file, "<p>" . nl2br($event->text) . "</p>");
         }
     }
     fwrite($file, self::$footer);
     fclose($file);
 }