/** * Сделал дело * @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'); } } } }