public function actionDelete()
 {
     $this->layout = 'default';
     $id = Yii::$app->request->get('id', 0);
     if (!empty($id)) {
         $model = new StyleForm();
         if ($model->loadById($id)) {
             if ($model->delete()) {
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Стиль успешно удален.'));
                 $this->redirect(Url::toRoute(['styles/index']));
             } else {
                 Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось удалить.'));
                 $this->redirect(Url::toRoute(['styles/index']));
             }
         }
     } else {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось удалить.'));
         $this->redirect(Url::toRoute(['styles/index']));
     }
 }
 public function actionViewBook()
 {
     $this->layout = 'editor';
     $ref = Yii::$app->request->get('ref');
     $id = Yii::$app->request->get('id');
     $selected_style_id = Yii::$app->request->get('style_id', 0);
     if (!empty($ref) && !empty($id)) {
         $user_id = AlphaId::id($ref, true);
         $pb_id = AlphaId::id($id, true);
         if ($user_id != Yii::$app->user->identity->getId()) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена'));
             $this->redirect(Url::toRoute(['photobooks/index']));
             return;
         }
         $model = new PhotobookForm();
         if (!$model->loadById($pb_id)) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Фотокнига не найдена'));
             $this->redirect(Url::toRoute(['photobooks/index']));
             return;
         }
         if (empty($model->data['pages'])) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'В фотокниги нет ни одного разворота'));
             $this->redirect(Url::toRoute(['photobooks/index', 'status' => $model->status]));
             return;
         }
         $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/index']));
             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/index']));
             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;
                 }
             }
         }
         $user = User::findOne(['id' => $user_id]);
         $total_price = CurrencyConvertor::conv($total_price, $user->default_currency);
         $curse = CurrencyConvertor::getCurse($user->default_currency);
         return $this->render('viewBook', ['model' => $model, 'ref' => $ref, 'id' => $id, 'pb_id' => $pb_id, 'user_id' => $user_id, 'pages' => $pages, 'style' => $style, 'selected_cover' => $selected_cover, 'covers' => $new_covers, 'total_price' => $total_price, 'default_currency' => $user->default_currency, 'cover_price_sign' => $cover_price_sign, 'cover_price' => $selected_cover->price, 'price_spread' => $style->price_spread, 'curse' => $curse]);
     } else {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена'));
         $this->redirect(Url::toRoute(['photobooks/index']));
     }
 }
Exemple #3
0
 public function getProductInfo()
 {
     $cover = new CoverForm();
     if (!$cover->loadById($this->cover_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Обложка для книги не найдена')]];
     }
     $style = new StyleForm();
     if (!$style->loadById($this->style_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Стиль для книги не найдена')]];
     }
     if (empty($this->data)) {
         return ['error' => ['msg' => Yii::t('app', 'Ошибка данных')]];
     }
     if (empty($this->data['pages'])) {
         return ['error' => ['msg' => Yii::t('app', 'Страниц не найдено')]];
     }
     $pages = $this->data['pages'];
     $print_count = 0;
     foreach ($pages as $key => $page) {
         if ($key == 0 || $key == count($pages) - 1) {
             continue;
         }
         if ($page['action'] == 'print') {
             $print_count++;
         }
     }
     if ($print_count <= 0) {
         return ['error' => ['msg' => Yii::t('app', 'Разворотов для печати не найдено')]];
     }
     $base_price = (count($pages) - 2) * $style->price_spread;
     $cover_price_sign = $cover->price_sign;
     $total_price = $base_price;
     if ($cover_price_sign == "=") {
         $total_price = $cover->price;
     } else {
         if ($cover_price_sign == "+") {
             $total_price += $cover->price;
         } else {
             if ($cover_price_sign == "-") {
                 $total_price -= $cover->price;
             }
         }
     }
     $text_info = Yii::t('app', 'Код товара:') . ' ' . $this->id . '. ' . Yii::t('app', 'Фотокнига:') . ' ' . $this->name . ', ' . Yii::t('app', 'обложка:') . ' ' . $cover->material_type . '/' . $cover->name . ', ' . Yii::t('app', '1 калька') . ', ' . $print_count . ' ' . Utils::getInclinationByNumber($print_count, ['разворот', 'разворота', 'разворотов']);
     return ['response' => ['status' => true, 'price' => $total_price, 'text_info' => $text_info]];
 }
 public function actionChangeStyle()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $photobook_id = Yii::$app->request->get('photobook_id', 0);
     $style_id = Yii::$app->request->get('style_id', 0);
     $model = new PhotobookForm();
     if (empty($photobook_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Не верный photobook_id')]];
     }
     if (!$model->loadById($photobook_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
     }
     $styleModel = new StyleForm();
     if (!$styleModel->loadById($style_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Стиль не найден')]];
     }
     $model->style_id = $style_id;
     if (!$model->save()) {
         return ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу данных')]];
     }
     return ['response' => ['status' => true]];
 }