Esempio n. 1
0
 private function createPhotobookState()
 {
     //$view_access_key='';
     $number = time() + rand(0, 9999999);
     $view_access_key = AlphaId::id($this->user_id) . AlphaId::id($number);
     $photobookState = new PhotobookState();
     $photobookState->user_id = $this->user_id;
     $photobookState->photobook_id = $this->id;
     $photobookState->status = PhotobookState::STATUS_WAIT_CUSTOMER_COMMENTS;
     $photobookState->data = PhotobookForm::photosEncode($this->data);
     //$photobookState->template=$this->template;
     $photobookState->style_id = $this->style_id;
     $photobookState->cover_id = $this->cover_id;
     $photobookState->title_line_1 = $this->title_line_1;
     $photobookState->title_line_2 = $this->title_line_2;
     $photobookState->title_line_3 = $this->title_line_3;
     $photobookState->title_line_4 = $this->title_line_4;
     //$photobookState->photos_zip_hash=$this->photos_zip_hash;
     //$photobookState->change_status_at=$this->change_status_at;
     $photobookState->view_access_key = $view_access_key;
     $this->photos = $this->addTextGroupIfNotExists($this->photos);
     $photobookState->photos = PhotobookForm::photosEncode($this->photos);
     $photobookState->comments = [];
     if (empty($this->data['pages'])) {
         return false;
     }
     //Создаем массив данных где будут хранится коменты к каждой странице
     if (empty($photobookState->comments)) {
         $comments = [];
         for ($i = 0; $i < count($this->data['pages']); $i++) {
             $type = "spreads";
             $page_name = 'Комментарий к развороту ' . $i;
             if ($i == 0) {
                 $type = "cover";
                 $page_name = 'Комментарий к обложке';
             }
             if ($i == count($this->data['pages']) - 1) {
                 $type = "total";
                 $page_name = 'Общий комментарий';
             }
             $comments[$i] = ['title' => $page_name, 'comment' => '', 'type' => $type];
             if ($type == 'spreads') {
                 $comments[$i]['print'] = true;
             }
             $photobookState->comments = $comments;
         }
     }
     $photobookState->comments = PhotobookForm::photosEncode($photobookState->comments);
     //Yii::getLogger()->log('save:', YII_DEBUG);
     if ($photobookState->save()) {
         return $view_access_key;
     } else {
         return false;
         //Yii::getLogger()->log('save error', YII_DEBUG);
     }
 }
Esempio n. 2
0
 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', 'Состояние не найдено')]];
     }
 }