public function actionNotify() { \Yii::info("POST: " . Json::encode(\Yii::$app->request->post()), self::className()); try { if (!\Yii::$app->request->post('OrderId')) { throw new Exception('Некорректны запрос от банка.'); } /** * @var $shopOrder ShopOrder */ if (!($shopOrder = ShopOrder::findOne(\Yii::$app->request->post('OrderId')))) { throw new Exception('Заказ не найден в базе.'); } if ($shopOrder->id != \Yii::$app->request->post('OrderId')) { throw new Exception('Не совпадает номер заказа.'); } if ($shopOrder->money->getAmount() != \Yii::$app->request->post('Amount')) { throw new Exception('Не совпадает сумма заказа.'); } if (\Yii::$app->request->post('Status') == "CONFIRMED") { \Yii::info("Успешный платеж", self::className()); $shopOrder->processNotePayment(); } } catch (\Exception $e) { \Yii::error($e->getMessage(), self::className()); } $this->layout = false; return "OK"; }
public function init() { $this->name = \skeeks\cms\shop\Module::t('app', 'Orders'); $this->modelShowAttribute = "id"; $this->modelClassName = ShopOrder::className(); parent::init(); }
public function actionPay() { /** * @var $shopOrder ShopOrder */ $shopOrder = ShopOrder::findOne(\Yii::$app->request->get('id')); //TODO: проверки return $shopOrder->paySystem->paySystemHandler->paymentResponse($shopOrder); }
public function run() { $rr = new RequestResponse(); $errors = []; if ($post = \Yii::$app->request->post()) { $this->shopFuser->load($post); $this->shopFuser->save(); } $this->shopBuyer = $this->shopFuser->personType->createModelShopBuyer(); $shopBuyer = $this->shopBuyer; if ($shopBuyer) { if ($post = \Yii::$app->request->post()) { $this->shopBuyer->load($post); $this->shopBuyer->relatedPropertiesModel->load($post); } } if ($rr->isRequestPjaxPost()) { if (!\Yii::$app->request->post($this->notSubmitParam)) { if ($this->shopFuser->validate() && $this->shopBuyer->validate() && $this->shopBuyer->relatedPropertiesModel->validate()) { if ($this->shopBuyer->isNewRecord) { if (!$this->shopBuyer->save()) { throw new Exception('Not save buyer'); } } if (!$this->shopBuyer->relatedPropertiesModel->save()) { throw new Exception('Not save buyer data'); } $this->shopFuser->buyer_id = $this->shopBuyer->id; $newOrder = ShopOrder::createOrderByFuser($this->shopFuser); $orderUrl = $newOrder->publicUrl; $this->view->registerJs(<<<JS location.href='{$orderUrl}'; JS ); } else { /*print_r($this->shopFuser->firstErrors); print_r($this->shopBuyer->firstErrors); print_r($this->shopBuyer->relatedPropertiesModel->firstErrors);*/ } } } return $this->render($this->viewFile); }
public function getOrder() { if (!\Yii::$app->request->post('orderNumber')) { throw new Exception('Некорректный запрос от банка. Не указан orderNumber.'); } /** * @var $shopOrder ShopOrder */ if (!($shopOrder = ShopOrder::findOne(\Yii::$app->request->post('orderNumber')))) { throw new Exception('Заказ не найден в базе.'); } if ($shopOrder->id != \Yii::$app->request->post('orderNumber')) { throw new Exception('Не совпадает номер заказа.'); } if ((double) $shopOrder->money->getValue() != (double) \Yii::$app->request->post('orderSumAmount')) { throw new Exception('Не совпадает сумма заказа.'); } return $shopOrder; }
/** * @inheritdoc */ public function actions() { return ArrayHelper::merge(parent::actions(), ['index' => ["dataProviderCallback" => function (ActiveDataProvider $dataProvider) { $query = $dataProvider->query; /** * @var \yii\db\ActiveQuery $query */ //$query->select(['app_company.*', 'count(`app_company_officer_user`.`id`) as countOfficer']); $query->groupBy([CmsUser::tableName() . '.id']); $query->innerJoin(ShopBuyer::tableName(), '`shop_buyer`.`cms_user_id` = `cms_user`.`id`'); }, "columns" => [['class' => UserColumnData::className(), 'attribute' => 'id', 'label' => \skeeks\cms\shop\Module::t('app', 'Buyer')], 'email', 'phone', ['class' => DateTimeColumnData::className(), 'attribute' => 'created_at', 'label' => \skeeks\cms\shop\Module::t('app', 'Date of registration')], ['class' => DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'Date of last order'), 'value' => function (CmsUser $model) { if ($order = ShopOrder::find()->where(['user_id' => $model->id])->orderBy(['created_at' => SORT_DESC])->one()) { return \Yii::$app->formatter->asDatetime($order->created_at); } return null; }], ['class' => DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'The amount paid orders'), 'value' => function (CmsUser $model) { return ShopOrder::find()->where(['user_id' => $model->id, 'payed' => Cms::BOOL_Y])->count(); }]]]]); }
public function actionIpn() { $custom = (int) \Yii::$app->request->post('custom'); \Yii::info('Ipn post data: ' . serialize(\Yii::$app->request->post()), 'paypal'); \Yii::info('Ipn custom: ' . $custom, 'paypal'); /*if (!$custom) { $custom = (int) \Yii::$app->request->get('custom'); }*/ if (!$custom) { \Yii::error('Order id not found', 'paypal'); return false; } $shopOrder = ShopOrder::findOne($custom); \Yii::info('Ordder id: ' . $shopOrder->id); if (!$shopOrder) { \Yii::error('Ordder not found: ' . $custom, 'paypal'); } /** * @var $payPal PayPalPaySystem * @var $shopOrder ShopOrder */ $payPal = $shopOrder->paySystem->paySystemHandler; if (!$payPal instanceof PayPalPaySystem) { \Yii::error('Order handler not paypal: ', 'paypal'); } if ($payPal->initIpn()) { if ($shopOrder->payed != "Y") { \Yii::info('Order processNotePayment', 'paypal'); $shopOrder->processNotePayment(); } $shopOrder->ps_status = "STATUS_SUCCESS"; $shopOrder->payed = "Y"; $shopOrder->save(); } else { \Yii::error('Ipn false: ', 'paypal'); } return ""; }
* @date 02.06.2015 */ /* @var $this yii\web\View */ /* @var $searchModel \skeeks\cms\models\Search */ /* @var $dataProvider yii\data\ActiveDataProvider */ $query = $dataProvider->query; $query->groupBy([\skeeks\cms\models\CmsUser::tableName() . '.id']); $query->leftJoin(\skeeks\cms\shop\models\ShopOrder::tableName(), '`shop_order`.`user_id` = `cms_user`.`id`'); ?> <? $pjax = \skeeks\cms\modules\admin\widgets\Pjax::begin(); ?> <?php echo $this->render('_search', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); ?> <?php echo \skeeks\cms\modules\admin\widgets\GridViewStandart::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pjax' => $pjax, 'adminController' => \Yii::$app->controller, 'columns' => [['class' => \skeeks\cms\grid\UserColumnData::className(), 'attribute' => 'id', 'label' => \Yii::t('skeeks/shop/app', 'Buyer')], 'email', 'phone', ['class' => \skeeks\cms\grid\DateTimeColumnData::className(), 'attribute' => 'created_at', 'label' => \Yii::t('skeeks/shop/app', 'Date of registration')], ['class' => \yii\grid\DataColumn::className(), 'label' => \Yii::t('skeeks/shop/app', 'Date of last order'), 'value' => function (\skeeks\cms\models\CmsUser $model) { if ($order = \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id])->orderBy(['created_at' => SORT_DESC])->one()) { return \Yii::$app->formatter->asDatetime($order->created_at); } return null; }], ['class' => \yii\grid\DataColumn::className(), 'label' => \Yii::t('skeeks/shop/app', 'The amount paid orders'), 'value' => function (\skeeks\cms\models\CmsUser $model) { return \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id, 'payed' => \skeeks\cms\components\Cms::BOOL_Y])->count(); }], ['class' => \yii\grid\DataColumn::className(), 'label' => \Yii::t('skeeks/shop/app', 'The amount paid orders'), 'value' => function (\skeeks\cms\models\CmsUser $model) { return \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id, 'payed' => \skeeks\cms\components\Cms::BOOL_Y])->count(); }]]]); ?> <? $pjax::end(); ?>
/** * @return \yii\db\ActiveQuery */ public function getShopOrders() { return $this->hasMany(ShopOrder::className(), ['person_type_id' => 'id']); }
/** * Создание заказа * @return array|\yii\web\Response */ public function actionCreateOrder() { $rr = new RequestResponse(); if ($rr->isRequestAjaxPost()) { try { $fuser = \Yii::$app->shop->shopFuser; if (!$fuser->shopBaskets) { throw new Exception(\skeeks\cms\shop\Module::t('app', 'Your basket is empty')); } if ($fuser->load(\Yii::$app->request->post()) && $fuser->save()) { $rr->success = true; $rr->message = ""; $fuser->scenario = ShopFuser::SCENARIO_CREATE_ORDER; if ($fuser->validate()) { $order = ShopOrder::createOrderByFuser($fuser); if (!$order->isNewRecord) { $rr->message = \skeeks\cms\shop\Module::t('app', 'The order #{order_id} created successfully', ['order_id' => $order->id]); $rr->success = true; $rr->redirect = Url::to(['/shop/order/view', 'id' => $order->id]); $rr->data = ['order' => $order]; } else { throw new Exception(\skeeks\cms\shop\Module::t('app', 'Incorrect data of the new order') . ": " . array_shift($order->getFirstErrors())); } } else { throw new Exception(\skeeks\cms\shop\Module::t('app', 'Not enogh data for ordering') . ": " . array_shift($fuser->getFirstErrors())); } } else { throw new Exception(\skeeks\cms\shop\Module::t('app', 'Not enogh data for ordering') . ": " . array_shift($fuser->getFirstErrors())); } } catch (Exception $e) { $rr->message = $e->getMessage(); $rr->success = false; } $rr->data = \Yii::$app->shop->shopFuser->toArray([], \Yii::$app->shop->shopFuser->extraFields()); return (array) $rr; } else { return $this->goBack(); } }
/** * @return \yii\db\ActiveQuery */ public function getShopOrder() { return $this->hasOne(ShopOrder::className(), ['id' => 'shop_order_id']); }
/** * @return \yii\db\ActiveQuery */ public function getShopOrders() { return $this->hasMany(ShopOrder::className(), ['status_code' => 'code']); }
<?php echo $form->fieldSetEnd(); ?> <?php echo $form->fieldSet("Заказы (" . \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id])->count() . ")"); ?> <?php echo \skeeks\cms\modules\admin\widgets\BlockTitleWidget::widget(['content' => 'Последние заказы']); ?> <?php echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id])]), 'columns' => ['id', ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'status_code', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopOrder $order) { return Html::label($order->status->name, null, ['style' => "background: {$order->status->color}", 'class' => "label"]) . "<br />" . Html::tag("small", \Yii::$app->formatter->asDatetime($order->status_at) . " (" . \Yii::$app->formatter->asRelativeTime($order->status_at) . ")"); }], ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => 'payed', 'format' => 'raw'], ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => 'canceled', 'format' => 'raw'], ['class' => \yii\grid\DataColumn::className(), 'format' => 'raw', 'attribute' => 'price', 'label' => \skeeks\cms\shop\Module::t('app', 'Sum'), 'value' => function (\skeeks\cms\shop\models\ShopOrder $model) { return \Yii::$app->money->intlFormatter()->format($model->money); }], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'site_id', 'format' => 'raw', 'label' => \skeeks\cms\shop\Module::t('app', 'Site'), 'value' => function (\skeeks\cms\shop\models\ShopOrder $model) { return $model->site->name . " [{$model->site->code}]"; }], ['class' => \skeeks\cms\grid\CreatedAtColumn::className()]]]); echo $form->fieldSetEnd(); ?> <?php $fuser = \skeeks\cms\shop\models\ShopFuser::find()->where(['user_id' => $model->id])->one(); ?>
/** * @param integer $id * @return ShopOrder * @throws \yii\web\BadRequestHttpException */ protected function loadModel($id) { $model = ShopOrder::findOne($id); if ($model === null) { throw new BadRequestHttpException(); } return $model; }
<?php /** * @author Semenov Alexander <*****@*****.**> * @link http://skeeks.com/ * @copyright 2010 SkeekS (—кик—) * @date 01.11.2015 */ /* @var $this yii\web\View */ echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \skeeks\cms\shop\models\ShopOrder::find()]), 'columns' => ['id']]); ?>
public function actionPayPal() { return $this->render($this->action->id, ['model' => ShopOrder::findOne(\Yii::$app->request->get('id'))]); }
public function createOrder() { $cmsUser = null; if ($userId = \Yii::$app->request->get('cmsUserId')) { $cmsUser = CmsUser::findOne($userId); } if ($cmsUser) { /** * @var $shopFuser ShopFuser */ $shopFuser = ShopFuser::getInstanceByUser($cmsUser); $model = $shopFuser; $rr = new RequestResponse(); if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER; return $rr->ajaxValidateForm($model); } if ($rr->isRequestPjaxPost()) { try { if ($model->load(\Yii::$app->request->post()) && $model->save()) { $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER; if ($model->validate()) { $order = ShopOrder::createOrderByFuser($model); if (!$order->isNewRecord) { \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'The order #{order_id} created successfully', ['order_id' => $order->id])); if (\Yii::$app->request->post('submit-btn') == 'apply') { return $this->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->requestPkParamName => $order->id])->toString()); } else { return $this->redirect($this->indexUrl); } } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Incorrect data of the new order') . ": " . array_shift($order->getFirstErrors())); } } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Not enogh data for ordering') . ": " . array_shift($model->getFirstErrors())); } } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Could not save')); } } catch (\Exception $e) { \Yii::$app->getSession()->setFlash('error', $e->getMessage()); } } return $this->render($this->action->id, ['cmsUser' => $cmsUser, 'shopFuser' => $model]); } else { return $this->render($this->action->id . "-select-user"); } }