public function init() { $this->name = \Yii::t('skeeks/shop/app', 'Buyers'); $this->modelShowAttribute = "displayName"; $this->modelClassName = CmsUser::className(); parent::init(); }
/** * @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(); }]]]]); }
<?php /** * @author Semenov Alexander <*****@*****.**> * @link http://skeeks.com/ * @copyright 2010 SkeekS (СкикС) * @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) {
*/ use yii\helpers\Html; use skeeks\cms\modules\admin\widgets\form\ActiveFormUseTab as ActiveForm; /* @var $this yii\web\View */ ?> <?php $form = ActiveForm::begin(); ?> <?php echo $form->fieldSet(\skeeks\cms\shop\Module::t('app', 'Main')); ?> <?php echo $form->fieldSelect($model, 'cms_user_id', \yii\helpers\ArrayHelper::map(\skeeks\cms\models\CmsUser::find()->all(), 'id', 'displayName')); ?> <?php echo $form->fieldSelect($model, 'shop_person_type_id', \yii\helpers\ArrayHelper::map(\skeeks\cms\shop\models\ShopPersonType::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'name')->textInput(); ?> <?php echo $form->fieldSetEnd(); ?> <?php echo $form->buttonsCreateOrUpdate($model);
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(CmsUser::className(), ['id' => 'user_id']); }
/** * Returns the list of attribute names. * By default, this method returns all public non-static properties of the class. * You may override this method to change the default behavior. * @return array list of attribute names. */ public function attributes() { $class = new \ReflectionClass($this); $names = []; foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { if (!$property->isStatic()) { $names[] = $property->getName(); } } return ArrayHelper::merge(parent::attributes(), $names); }
/** * Процесс отправки формы * @return array */ public function actionShopPersonTypeSubmit() { $rr = new RequestResponse(); try { if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) { if (\Yii::$app->request->post('shop_person_type_id')) { $shop_person_type_id = \Yii::$app->request->post('shop_person_type_id'); $shop_buyer_id = \Yii::$app->request->post('shop_buyer_id'); /** * @var $shopPersonType ShopPersonType */ $modelBuyer = ShopBuyer::findOne($shop_buyer_id); $shopPersonType = ShopPersonType::find()->active()->andWhere(['id' => $shop_person_type_id])->one(); if (!$shopPersonType) { throw new Exception(\Yii::t('skeeks/shop/app', 'This payer is disabled or deleted. Refresh the page.')); } if (!$modelBuyer) { $modelBuyer = $shopPersonType->createModelShopBuyer(); } $validateModel = $modelBuyer->relatedPropertiesModel; if ($validateModel->load(\Yii::$app->request->post()) && $validateModel->validate()) { $modelBuyerName = []; //Проверка свойств foreach ($validateModel->toArray($validateModel->attributes()) as $code => $value) { /** * @var $property ShopPersonTypeProperty */ $property = $validateModel->getRelatedProperty($code); if ($property->is_buyer_name == Cms::BOOL_Y) { $modelBuyerName[] = $value; } if ($property->is_user_email == Cms::BOOL_Y) { $userEmail = $value; } if ($property->is_user_name == Cms::BOOL_Y) { $userName = $value; } if ($property->is_user_username == Cms::BOOL_Y) { $userUsername = $value; } if ($property->is_user_phone == Cms::BOOL_Y) { $userPhone = $value; } } //Нужно создать польозвателя if (\Yii::$app->user->isGuest) { if (!$userEmail) { throw new Exception(\Yii::t('skeeks/shop/app', 'Unknown email address user')); } if ($userEmail) { if ($userExist = CmsUser::find()->where(['email' => $userEmail])->one()) { throw new Exception(\Yii::t('skeeks/shop/app', 'In our database, there are already a user with this email. Login to your account, or enter a different email address.')); } } $newUser = new SignupForm(); $newUser->scenario = SignupForm::SCENARION_ONLYEMAIL; $newUser->email = $userEmail; if (!($user = $newUser->signup())) { throw new Exception(\Yii::t('skeeks/shop/app', 'Do not create a user profile.')); } if ($userName) { $user->name = $userName; } //Авторизация пользователя \Yii::$app->user->login($user, 0); } $modelBuyer->name = $modelBuyerName ? implode(", ", $modelBuyerName) : $shopPersonType->name . " от (" . \Yii::$app->formatter->asDate(time(), 'medium') . ")"; $modelBuyer->cms_user_id = \Yii::$app->user->identity->id; $modelBuyer->shop_person_type_id = $shopPersonType->id; if (!$modelBuyer->save()) { throw new Exception(\Yii::t('skeeks/shop/app', 'The data for the buyer are not saved.')); } $validateModel->save(); \Yii::$app->shop->shopFuser->buyer_id = $modelBuyer->id; \Yii::$app->shop->shopFuser->person_type_id = $modelBuyer->shopPersonType->id; \Yii::$app->shop->shopFuser->save(); $rr->success = true; $rr->message = \Yii::t('skeeks/shop/app', 'Successfully sent'); } else { throw new Exception(\Yii::t('skeeks/shop/app', 'Check the correctness of filling the form fields')); } } } } catch (\Exception $e) { $rr->success = false; $rr->message = $e->getMessage(); } return (array) $rr; }
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"); } }
/** * @return \yii\db\ActiveQuery */ public function getUpdatedBy() { return $this->hasOne(CmsUser::className(), ['id' => 'updated_by']); }
return this; } }); sx.SelectCmsElement = new sx.classes.SelectCmsElement(); })(sx, sx.$, sx._); JS ); ?> <? $search = new \skeeks\cms\models\Search(\skeeks\cms\models\CmsUser::className()); $dataProvider = $search->getDataProvider(); $dataProvider->sort->defaultOrder = [ 'created_at' => SORT_DESC ]; $dataProvider = $search->search(\Yii::$app->request->queryParams); $searchModel = $search->loadedModel; ?> <?php echo \skeeks\cms\modules\admin\widgets\GridViewStandart::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'adminController' => @$controller, 'enabledCheckbox' => false, 'columns' => [['class' => \yii\grid\DataColumn::className(), 'value' => function (\skeeks\cms\models\User $model) { return \yii\helpers\Html::a('<i class="glyphicon glyphicon-circle-arrow-left"></i> ' . \Yii::t('skeeks/cms', 'Choose'), '#', ['class' => 'btn btn-primary sx-row-action', 'onclick' => 'sx.SelectCmsElement.submit(' . \yii\helpers\Json::encode($model->toArray([], ['displayName'])) . '); return false;', 'data-pjax' => 0]);