public function deleteLinkForCustomer() { if (!empty($this->view_access_key)) { //если у нас было состояние до этого активное, то после удаления ссылки возможно нужно сменить статус $photobookState = PhotobookState::findOne(['view_access_key' => $this->view_access_key]); if ($photobookState) { $photobookState->status = PhotobookState::STATUS_CLOSE; $photobookState->update(); } } $this->view_access_key = null; $this->status = Photobook::STATUS_NEW; $this->change_status_at = time(); if ($this->save()) { return ['response' => ['status' => true]]; } else { return ['error' => ['msg' => Yii::t('app', 'Не удалось удалить')]]; } }
public function actionView() { $this->layout = 'editor'; $view_access_key = Yii::$app->request->get('key'); $ref = ''; //Yii::$app->request->get('ref'); $id = ''; //Yii::$app->request->get('id'); if (!empty($view_access_key)) { $photobookState = PhotobookState::findOne(['view_access_key' => $view_access_key]); if (!$photobookState) { //Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена')); $this->redirect(Url::toRoute(['photobooks/not-found'])); return; } if ($photobookState->status == PhotobookState::STATUS_CLOSE) { if (Yii::$app->user->identity) { // Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Ссылка закрыта')); $this->redirect(Url::toRoute(['photobooks/access-close-not-found'])); return; } else { if (Yii::$app->user->identity->id != $photobookState->user_id) { //Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Ссылка закрыта')); $this->redirect(Url::toRoute(['photobooks/access-close-not-found'])); return; } } } $model = new PhotobookForm(); if (!$model->loadById($photobookState->photobook_id)) { //Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена')); $this->redirect(Url::toRoute(['photobooks/not-found'])); return; } $model->style_id = $photobookState->style_id; $model->cover_id = $photobookState->cover_id; $model->data = PhotobookForm::photosDecode($photobookState->data); $model->photos = PhotobookForm::photosDecode($photobookState->photos); $model->title_line_1 = $photobookState->title_line_1; $model->title_line_2 = $photobookState->title_line_2; $model->title_line_3 = $photobookState->title_line_3; $model->title_line_4 = $photobookState->title_line_4; $photobookState->comments = PhotobookForm::photosDecode($photobookState->comments); $user_id = $model->user_id; $pb_id = $model->id; $ref = AlphaId::id($user_id, false); $id = AlphaId::id($pb_id, false); $style_id = $model->style_id; $style = new StyleForm(); if (!$style->loadById($style_id)) { //Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Стиль для данной фотокниги не найден.')); $this->redirect(Url::toRoute(['photobooks/not-found'])); return; } $selected_cover = new CoverForm(); if (!$selected_cover->loadById($model->cover_id)) { //Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Обложка для данной фотокниги не найден.')); $this->redirect(Url::toRoute(['photobooks/not-found'])); return; } $covers = Cover::find()->where(['status' => 1])->all(); $new_covers = []; foreach ($covers as $key => $cover) { $new_covers[$cover->material_type][] = $cover; } $pages = $model->data['pages']; $base_price = (count($pages) - 2) * $style->price_spread; $cover_price_sign = $selected_cover->price_sign; $selected_cover->price; $total_price = $base_price; if ($cover_price_sign == "=") { $total_price = $selected_cover->price; } else { if ($cover_price_sign == "+") { $total_price += $selected_cover->price; } else { if ($cover_price_sign == "-") { $total_price -= $selected_cover->price; } } } return $this->render('view', ['model' => $model, 'photobook_state' => $photobookState, 'ref' => $ref, 'id' => $id, 'pb_id' => $pb_id, 'user_id' => $user_id, 'pages' => $pages, 'style' => $style, 'selected_cover' => $selected_cover, 'covers' => $new_covers, 'base_price' => $base_price, 'total_price' => $total_price]); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена')); $this->redirect(Url::toRoute(['photobooks/not-found'])); } }
public function actionSaveCustomerComments() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $key = Yii::$app->request->get('key'); $index = Yii::$app->request->post('index'); $comment = Yii::$app->request->post('comment'); if (!empty($key)) { $photobookState = PhotobookState::findOne(['view_access_key' => $key]); if (!$photobookState) { return ['error' => ['msg' => Yii::t('app', 'Состояние не найдено')]]; } $comments = PhotobookForm::photosDecode($photobookState->comments); if (empty($comments[$index])) { return ['error' => ['msg' => Yii::t('app', 'Индекс не найден ' . $index)]]; } $comments[$index]['comment'] = $comment; $photobookState->comments = PhotobookForm::photosEncode($comments); if (!$photobookState->update()) { return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу')]]; } else { return ['response' => ['status' => true]]; } } else { return ['error' => ['msg' => Yii::t('app', 'Состояние не найдено')]]; } }