public function actionCancelInvoice()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::toRoute(['intro/index']));
         return;
     }
     if (Yii::$app->user->identity->role == User::ROLE_DEMO) {
         $this->redirect(Url::toRoute(['user/signup-demo']));
         return;
     }
     $id = Yii::$app->request->get('id');
     if (!$id) {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не верный id'));
         $this->redirect(Url::toRoute(['photobooks/index']));
         return;
     }
     $invoice = new InvoiceForm();
     if (!$invoice->loadById($id)) {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Счет не найден'));
         $this->redirect(Url::toRoute(['photobooks/index']));
         return;
     }
     if ($invoice->status == Invoice::STATUS_PAID || $invoice->status == Invoice::STATUS_TIMEOUT || $invoice->status == Invoice::STATUS_CANCEL) {
         if ($invoice->status == Invoice::STATUS_PAID) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Счет уже оплачен. Вы не можите его отменить.'));
         } else {
             if ($invoice->status == Invoice::STATUS_CANCEL) {
                 Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Счет уже отменен.'));
             } else {
                 if ($invoice->status == Invoice::STATUS_TIMEOUT) {
                     Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Счет уже отменен.'));
                 }
             }
         }
         $this->redirect(Url::toRoute(['photobooks/index']));
     }
     $invoice->status = Invoice::STATUS_CANCEL;
     if (!$invoice->save()) {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось отменить счет'));
         $this->redirect(Url::toRoute(['photobooks/index']));
         return;
     }
     // Отвязываем фотокниги от id счета и вернуть им статус new
     $photobooks = Photobook::find()->where(['invoice_id' => $invoice->id])->all();
     if ($photobooks) {
         foreach ($photobooks as $key => $photobook) {
             $photobook->invoice_id = null;
             $photobook->status = Photobook::STATUS_NEW;
             $photobook->update();
         }
     }
     $this->redirect(Url::toRoute(['photobooks/invoice', 'id' => $invoice->id]));
 }
 public function actionPhotobooks()
 {
     $this->layout = 'default';
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::toRoute(['user/logout']));
         return;
     }
     if (Yii::$app->user->identity->role != User::ROLE_ADMIN) {
         $this->redirect(Url::toRoute(['user/logout']));
         return;
     }
     $status = Yii::$app->request->get('status', Photobook::STATUS_NEW);
     /*if($status==Photobook::STATUS_DEMO){
     
                 $this->redirect(Url::toRoute(['photobooks/index']));
                 return;
             }*/
     // $user_id=Yii::$app->user->identity->getId();
     //  $photobooks=new Photobook();
     $sort = new Sort(['attributes' => ['updated_at' => SORT_ASC]]);
     $query = Photobook::find()->where(['status' => $status]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $orders = $query->orderBy(['updated_at' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->all();
     /*
     *
     *   const  STATUS_NEW = 1;
         const  STATUS_SENT_TO_CUSTOMER=2;
         const  STATUS_WAIT_EDIT_FROM_CUSTOMER=3;
         const  STATUS_SENT_TO_PRINT=4;
         const  STATUS_READY_FOR_PRINT_WAIT_PAYMENT=5;
         const  STATUS_READY_SENT_TO_PRINT=6;
         const  STATUS_READY=7;
         const  STATUS_SENT_TO_CLIENT=8;
         const  STATUS_RECEIVED_FEEDBACK=9;
         const  STATUS_ARCHIVE = 10;
     */
     $sidemenus = [['title' => Yii::t('app', 'Новые заказы'), 'status' => Photobook::STATUS_NEW, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_NEW])->count()], ['title' => Yii::t('app', 'Отправленные на согласование с клиентом'), 'status' => Photobook::STATUS_SENT_TO_CUSTOMER, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_SENT_TO_CUSTOMER])->count()], ['title' => Yii::t('app', 'Ожидающие правок'), 'status' => Photobook::STATUS_WAIT_EDIT_FROM_CUSTOMER, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_WAIT_EDIT_FROM_CUSTOMER])->count()], ['title' => Yii::t('app', 'Утвержденные клиентом'), 'status' => Photobook::STATUS_SENT_TO_PRINT, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_SENT_TO_PRINT])->count()], ['title' => Yii::t('app', 'Готовы к печати, ожидает оплаты'), 'status' => Photobook::STATUS_READY_FOR_PRINT_WAIT_PAYMENT, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_READY_FOR_PRINT_WAIT_PAYMENT])->count()], ['title' => Yii::t('app', 'Готовы к печати, оплачено'), 'status' => Photobook::STATUS_READY_FOR_PRINT_PAID, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_READY_FOR_PRINT_PAID])->count()], ['title' => Yii::t('app', 'В производстве'), 'status' => Photobook::STATUS_READY_SENT_TO_PRINT, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_READY_SENT_TO_PRINT])->count()], ['title' => Yii::t('app', 'Готовые'), 'status' => Photobook::STATUS_READY, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_READY])->count()], ['title' => Yii::t('app', 'Отправленные'), 'status' => Photobook::STATUS_READY_SENT_TO_CLIENT, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_READY_SENT_TO_CLIENT])->count()], ['title' => Yii::t('app', 'Полученные'), 'status' => Photobook::STATUS_RECEIVED_FEEDBACK, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_RECEIVED_FEEDBACK])->count()], ['title' => Yii::t('app', 'Архив'), 'status' => Photobook::STATUS_ARCHIVE, 'count' => Photobook::find()->where(['status' => Photobook::STATUS_ARCHIVE])->count()]];
     $settingForm = new SettingForm();
     $photobook_thumb_as_object = $settingForm->getValue('photobook_thumb_as_object', false);
     return $this->render('photobooks', ['pages' => $pages, 'orders' => $orders, 'status' => $status, 'sidemenus' => $sidemenus, 'photobook_thumb_as_object' => $photobook_thumb_as_object]);
 }
Exemple #3
0
 public function save()
 {
     Yii::getLogger()->log('start save photobook:' . $this->id, YII_DEBUG);
     $photobook = Photobook::findOne(['id' => $this->id]);
     if (empty($photobook)) {
         $photobook = new Photobook();
         $photobook->user_id = $this->user_id;
         $photobook->name = $this->name;
         $photobook->status = $this->status;
         $photobook->data = PhotobookForm::photosEncode($this->data);
         $photobook->template = $this->template;
         $photobook->style_id = $this->style_id;
         $photobook->cover_id = $this->cover_id;
         $photobook->title_line_1 = $this->title_line_1;
         $photobook->title_line_2 = $this->title_line_2;
         $photobook->title_line_3 = $this->title_line_3;
         $photobook->title_line_4 = $this->title_line_4;
         $photobook->photos_zip_hash = $this->photos_zip_hash;
         $photobook->change_status_at = $this->change_status_at;
         $photobook->view_access_key = $this->view_access_key;
         $photobook->invoice_id = $this->invoice_id;
         $this->photos = $this->addTextGroupIfNotExists($this->photos);
         $photobook->photos = PhotobookForm::photosEncode($this->photos);
         Yii::getLogger()->log('save:', YII_DEBUG);
         if ($photobook->save()) {
             $this->id = $photobook->id;
             return $photobook;
         } else {
             Yii::getLogger()->log('save error', YII_DEBUG);
         }
     } else {
         $photobook->user_id = $this->user_id;
         $photobook->name = $this->name;
         $photobook->status = $this->status;
         $photobook->data = PhotobookForm::photosEncode($this->data);
         $photobook->template = $this->template;
         $this->photos = $this->addTextGroupIfNotExists($this->photos);
         $photobook->photos = PhotobookForm::photosEncode($this->photos);
         $photobook->style_id = $this->style_id;
         $photobook->cover_id = $this->cover_id;
         $photobook->title_line_1 = $this->title_line_1;
         $photobook->title_line_2 = $this->title_line_2;
         $photobook->title_line_3 = $this->title_line_3;
         $photobook->title_line_4 = $this->title_line_4;
         $photobook->photos_zip_hash = $this->photos_zip_hash;
         $photobook->change_status_at = $this->change_status_at;
         $photobook->view_access_key = $this->view_access_key;
         $photobook->invoice_id = $this->invoice_id;
         Yii::getLogger()->log('update:', YII_DEBUG);
         //$photobook->id=$this->id;
         if ($photobook->update()) {
             return $photobook;
         } else {
             Yii::getLogger()->log('update error:' . print_r($photobook, true), YII_DEBUG);
         }
     }
     return null;
 }
 public function actionServerNotify()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $invoice_id = Yii::$app->request->get('id');
     if (!$invoice_id) {
         Yii::getLogger()->log('actionServerNotify return:' . Yii::t('app', 'Не верный id'), YII_DEBUG);
         return ['error' => ['msg' => Yii::t('app', 'Не верный id')]];
     }
     $invoice = new InvoiceForm();
     if (!$invoice->loadById($invoice_id)) {
         Yii::getLogger()->log('actionServerNotify return:' . Yii::t('app', 'Счет не найден'), YII_DEBUG);
         return ['error' => ['msg' => Yii::t('app', 'Счет не найден')]];
     }
     $data = Yii::$app->request->post('data', null);
     $signature = Yii::$app->request->post('signature', null);
     if (empty($data) || empty($signature)) {
         Yii::getLogger()->log('actionServerNotify return:' . Yii::t('app', 'Не полные данные'), YII_DEBUG);
         return ['error' => ['msg' => Yii::t('app', 'Не полные данные')]];
     }
     $settings = new SettingForm();
     // $public_key=$settings->getValue('liqpay_public_key', null);
     $private_key = $settings->getValue('liqpay_private_key', null);
     if (empty($private_key)) {
         Yii::getLogger()->log('actionServerNotify return:' . Yii::t('app', 'Liqpay не настроен.'), YII_DEBUG);
         return ['error' => ['msg' => Yii::t('app', 'Liqpay не настроен.')]];
     }
     $sign = base64_encode(sha1($private_key . $data . $private_key, 1));
     Yii::getLogger()->log('actionServerNotify sign:' . $sign, YII_DEBUG);
     Yii::getLogger()->log('actionServerNotify signature:' . $signature, YII_DEBUG);
     if ($sign != $signature) {
         Yii::getLogger()->log('actionServerNotify return:' . Yii::t('app', 'Подпись не верна'), YII_DEBUG);
         return ['error' => ['msg' => Yii::t('app', 'Подпись не верна')]];
     }
     //Получаем статус платежа
     $data = json_decode(base64_decode($data), true);
     $liqpay_status = $data['status'];
     Yii::getLogger()->log('actionServerNotify data:' . print_r($data, true), YII_DEBUG);
     Yii::getLogger()->log('actionServerNotify liqpay_status:' . $liqpay_status, YII_DEBUG);
     if ($liqpay_status == 'sandbox' || $liqpay_status == 'success') {
         $invoice->status = Invoice::STATUS_PAID;
         if ($invoice->save()) {
             $photobooks = Photobook::find()->where(['invoice_id' => $invoice->id])->all();
             $error = false;
             if ($photobooks) {
                 foreach ($photobooks as $key => $photobook) {
                     $photobook->status = Photobook::STATUS_READY_FOR_PRINT_PAID;
                     $photobook->change_status_at = time();
                     if (!$photobook->update()) {
                         $error = true;
                     }
                 }
             }
             if (!$error) {
                 return ['response' => ['status' => true]];
             }
         } else {
             return ['error' => ['msg' => Yii::t('app', 'Не удалось обновить статус счета')]];
         }
     } else {
         return ['response' => ['status' => true]];
     }
 }