public static function getCurse($currency) { $settings = new SettingForm(); $currencies = $settings->getValue('currencies', null); if (empty($currencies)) { return 1; } foreach ($currencies as $key => $currencyObj) { if ($currencyObj['code'] == $currency) { return $currencyObj['value']; //$value=$value/ } } return 1; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signupDemo() { if ($this->validate()) { $user = User::findOne(['id' => $this->id]); //new User(); // $user->id=$this->id; $user->username = $this->username; $user->email = $this->email; $user->role = User::ROLE_USER; if (!empty($this->default_currency)) { $user->default_currency = $this->default_currency; } else { $settingForm = new SettingForm(); $default_currency = $settingForm->getValue('default_currency', 'UAH'); $user->default_currency = $default_currency; } $user->setPassword($this->password); $user->generateAuthKey(); return $user->update(false); } return null; }
public function actionEdit() { // [ 'Группа 1'=>['photo1', 'photo2', 'photo3'], 'Группа 2'=>['photo1', 'photo2', 'photo3'], 'Группа 3'=>['photo1', 'photo2', 'photo3'] ] if (Yii::$app->user->isGuest) { $this->redirect(Url::toRoute(['photobooks/index'])); return; } $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'])) { $this->redirect(Url::toRoute(['photobooks/upload-photos', 'ref' => $ref, 'id' => $id])); 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); $product_info = $model->getProductInfo(); $total_price = $product_info['response']['price'] * $curse; $settingForm = new SettingForm(); $photobook_thumb_as_object = $settingForm->getValue('photobook_thumb_as_object', false); return $this->render('edit', ['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, 'photobook_thumb_as_object' => $photobook_thumb_as_object]); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена')); $this->redirect(Url::toRoute(['photobooks/index'])); } }
/** * Finds user by [[ROLE_DEMO]] * * @return User|null */ public function getDemoUser() { if ($this->_user === false) { //$this->_user = User::findOne(['role' => User::ROLE_DEMO]); //return $this->_user; $settingForm = new SettingForm(); $demo_account_id = $settingForm->getValue('demo_account_id', 0); $default_currency = $settingForm->getValue('default_currency', 'UAH'); if ($demo_account_id) { $user = User::findOne(['id' => $demo_account_id]); if ($user) { $new_demo_user = new User(); // $new_demo_user->id=0; $new_demo_user->username = $user->username; // $new_demo_user->auth_key=$user->auth_key; $new_demo_user->email = md5(time() . rand(0, 1.0E+20)) . '@sensation.com.ua'; //$user->email; $new_demo_user->role = User::ROLE_DEMO; $new_demo_user->status = User::STATUS_ACTIVE; //$user->status; $new_demo_user->default_currency = $default_currency; //$user->default_currency; $new_demo_user->setPassword('123456'); $new_demo_user->generateAuthKey(); if ($new_demo_user->save(false)) { //Нужно скопирывать фотокнигу $settingUserForm = new UserSettingForm(); $settingUserForm->user_id = $new_demo_user->id; $settingUserForm->save(); /* * * * $settingForm=new SettingForm(); $demo_account_id=$settingForm->getValue('demo_account_id', 0); $photobooks=Photobook::find()->where(['status'=>Photobook::STATUS_NEW])->all(); if(count($photobooks)>0){ $photobook=$photobooks[0]; $photobookForm=new PhotobookForm(); if($photobookForm->loadById($photobook->id)){ $photobookForm->copyToUser($new_demo_user->id); } }*/ $this->_user = $new_demo_user; } } //$this->_user = User::findOne(['role' => User::ROLE_DEMO]); } /*if(!$this->_user) $this->_user = User::findByEmail($this->username);*/ } return $this->_user; }
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]); }
public function actionProfile() { 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; } $this->layout = 'default'; $model = new ProfileForm(); if ($model->load(Yii::$app->request->post(), 'ProfileForm')) { if ($model->validate()) { if ($model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Изменения успешно сохранены.')); return $this->redirect(Url::toRoute('user/profile')); } else { } } else { } } else { if (!$model->loadByUserId(Yii::$app->user->identity->getId())) { } } $settings = new SettingForm(); $currencies = $settings->getValue('currencies', []); $currencies_new = []; foreach ($currencies as $key => $currency) { $currencies_new[$currency['code']] = $currency['code']; } return $this->render('profile', ['model' => $model, 'currencies' => $currencies_new]); }
public function save() { $setting = Setting::findOne(['id' => $this->id]); if (empty($setting)) { $setting = new Setting(); $setting->name = $this->name; $setting->value = SettingForm::encodeValue($this->value); $oldRules = $this->_value_rules; $this->_value_rules = [[['value'], 'string']]; Yii::getLogger()->log('save:', YII_DEBUG); if ($setting->save()) { $this->_value_rules = $oldRules; $this->id = $setting->id; return $setting; } else { $this->_value_rules = $oldRules; Yii::getLogger()->log('save error', YII_DEBUG); } } else { $setting->name = $this->name; $setting->value = SettingForm::encodeValue($this->value); $oldRules = $this->_value_rules; $this->_value_rules = [[['value'], 'string']]; Yii::getLogger()->log('update:', YII_DEBUG); if ($setting->update()) { $this->_value_rules = $oldRules; return $setting; } else { $this->_value_rules = $oldRules; Yii::getLogger()->log('update error:' . print_r($setting, 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]]; } }