public function actionCreateMany() { $model = new ReservationinfoMany(); if ($model->load(Yii::$app->request->post())) { $dateBegin = Yii::$app->formatter->asTimestamp($model->dateBegin); $dateEnd = Yii::$app->formatter->asTimestamp($model->dateEnd); $daysOfWeek = [$model->monday ? true : null, $model->tuesday ? true : null, $model->wednesday ? true : null, $model->thursday ? true : null, $model->friday ? true : null, $model->saturday ? true : null, $model->sunday ? true : null]; $qty = (int) ($dateEnd - $dateBegin) / 86400; if ($qty > 60) { Yii::$app->session->setFlash('danger', 'Вы пытаетесь создать экскурсии больше чем на 60 дней. Невозможно создать!'); } else { for ($i = 0; $i < $qty; $i++) { if (isset($daysOfWeek[date('N', $dateBegin)])) { $reservationInfo = new Reservationinfo(); $reservationInfo->date_begin = $dateBegin; $reservationInfo->date_end = $dateBegin + $model->hour * 3600; $reservationInfo->objreservation_id = $model->objreservationId; $reservationInfo->qty = $model->qty; $reservationInfo->price = $model->price; $reservationInfo->save(); } $dateBegin += 86400; } return $this->redirect(['index']); } } else { Yii::$app->session->setFlash('danger', 'Не все поля заполнены. Невозможно создать!'); } return $this->render('create-many', ['model' => $model]); }