From 426569bae58b1c3612217109a12e89dcad2b3d26 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 18 Apr 2025 13:41:31 +0300 Subject: [PATCH] =?utf8?q?[ERP-405]=20=D0=BD=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?utf8?q?=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B0=20=D1=81=D1=82=D0=BE?= =?utf8?q?=D0=BF=20=D0=BB=D0=B8=D1=81=D1=82=D0=B0=20=D0=BA=D0=BE=D0=B3?= =?utf8?q?=D0=BE=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../UsersMessageManagementController.php | 3 +- .../crud/KogortStopListController.php | 144 ++++++++++++++++++ ...8_094900_create_table_kogort_stop_list.php | 43 ++++++ erp24/records/KogortStopList.php | 86 +++++++++++ erp24/views/crud/kogort-stop-list/_form.php | 25 +++ erp24/views/crud/kogort-stop-list/create.php | 20 +++ erp24/views/crud/kogort-stop-list/index.php | 58 +++++++ erp24/views/crud/kogort-stop-list/update.php | 19 +++ erp24/views/crud/kogort-stop-list/view.php | 54 +++++++ .../views/users-message-management/index.php | 32 ++-- 10 files changed, 472 insertions(+), 12 deletions(-) create mode 100644 erp24/controllers/crud/KogortStopListController.php create mode 100755 erp24/migrations/m250418_094900_create_table_kogort_stop_list.php create mode 100644 erp24/records/KogortStopList.php create mode 100644 erp24/views/crud/kogort-stop-list/_form.php create mode 100644 erp24/views/crud/kogort-stop-list/create.php create mode 100644 erp24/views/crud/kogort-stop-list/index.php create mode 100644 erp24/views/crud/kogort-stop-list/update.php create mode 100644 erp24/views/crud/kogort-stop-list/view.php diff --git a/erp24/controllers/UsersMessageManagementController.php b/erp24/controllers/UsersMessageManagementController.php index 231beae1..550ced6c 100644 --- a/erp24/controllers/UsersMessageManagementController.php +++ b/erp24/controllers/UsersMessageManagementController.php @@ -15,6 +15,7 @@ use yii\helpers\ArrayHelper; use yii\helpers\BaseConsole; use yii\helpers\Json; use yii\web\Controller; +use yii_app\records\KogortStopList; use yii_app\records\Sales; use yii_app\records\SentKogort; use yii_app\records\Users; @@ -164,7 +165,7 @@ class UsersMessageManagementController extends Controller } } - $userStopList = UsersStopList::find()->with('author')->all(); + $userStopList = KogortStopList::find()->with(['updatedBy', 'createdBy'])->all(); return $this->render('index', [ 'model' => $model, diff --git a/erp24/controllers/crud/KogortStopListController.php b/erp24/controllers/crud/KogortStopListController.php new file mode 100644 index 00000000..ba2576ca --- /dev/null +++ b/erp24/controllers/crud/KogortStopListController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all KogortStopList models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => KogortStopList::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single KogortStopList model. + * @param int $id ID + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($phone) + { + return $this->render('view', [ + 'model' => $this->findModel($phone), + ]); + } + + /** + * Creates a new KogortStopList model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new KogortStopList(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'phone' => $model->phone]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing KogortStopList model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param int $id ID + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($phone) + { + $model = $this->findModel($phone); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'phone' => $model->phone]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing KogortStopList model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param int $id ID + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($phone) + { + $this->findModel($phone)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the KogortStopList model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param int $id ID + * @return KogortStopList the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($phone) + { + if (($model = KogortStopList::findOne(['phone' => $phone])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/migrations/m250418_094900_create_table_kogort_stop_list.php b/erp24/migrations/m250418_094900_create_table_kogort_stop_list.php new file mode 100755 index 00000000..9fdb69f3 --- /dev/null +++ b/erp24/migrations/m250418_094900_create_table_kogort_stop_list.php @@ -0,0 +1,43 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey(), + 'phone' => $this->string(20)->notNull()->comment('Телефон'), + 'comment' => $this->text()->null()->comment('Комментарий'), + 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'), + 'updated_at' => $this->dateTime()->null()->comment('Дата обновления'), + 'created_by' => $this->integer()->notNull()->comment('ИД создателя'), + 'updated_by' => $this->integer()->null()->comment('ИД редактировавшего'), + ]); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } +} diff --git a/erp24/records/KogortStopList.php b/erp24/records/KogortStopList.php new file mode 100644 index 00000000..14c9c6e3 --- /dev/null +++ b/erp24/records/KogortStopList.php @@ -0,0 +1,86 @@ + TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + [ + 'class' => BlameableBehavior::class, + 'createdByAttribute' => 'created_by', + 'updatedByAttribute' => 'updated_by', + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['phone'], 'required'], + [['comment'], 'string'], + [['created_at', 'updated_at', 'created_by'], 'safe'], + [['created_by', 'updated_by'], 'default', 'value' => null], + [['created_by', 'updated_by'], 'integer'], + [['phone'], 'string', 'max' => 20], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'phone' => 'Телефон', + 'comment' => 'Комментарий', + 'created_at' => 'Создано в', + 'updated_at' => 'Обновлено в', + 'created_by' => 'Создано', + 'updated_by' => 'Обновлено', + ]; + } + + public function getUpdatedBy() { + return $this->hasOne(Admin::class, ['id' => 'updated_by']); + } + + public function getCreatedBy() { + return $this->hasOne(Admin::class, ['id' => 'created_by']); + } +} diff --git a/erp24/views/crud/kogort-stop-list/_form.php b/erp24/views/crud/kogort-stop-list/_form.php new file mode 100644 index 00000000..e62afdd3 --- /dev/null +++ b/erp24/views/crud/kogort-stop-list/_form.php @@ -0,0 +1,25 @@ + + +
+ + + + field($model, 'phone')->textInput(['maxlength' => true]) ?> + + field($model, 'comment')->textarea(['rows' => 6]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/erp24/views/crud/kogort-stop-list/create.php b/erp24/views/crud/kogort-stop-list/create.php new file mode 100644 index 00000000..1bb88d90 --- /dev/null +++ b/erp24/views/crud/kogort-stop-list/create.php @@ -0,0 +1,20 @@ +title = 'Создание стоп листа когорт'; +$this->params['breadcrumbs'][] = ['label' => 'Kogort Stop Lists', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/crud/kogort-stop-list/index.php b/erp24/views/crud/kogort-stop-list/index.php new file mode 100644 index 00000000..edd96740 --- /dev/null +++ b/erp24/views/crud/kogort-stop-list/index.php @@ -0,0 +1,58 @@ +title = 'Стоп лист когорт'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'phone', + 'comment:ntext', + 'updated_at', + 'created_at', + [ + 'label' => 'Обновлено кем', + 'attribute' => 'updated_by', + 'value' => function ($model) { + return $model->updatedBy->name ?? '-'; + } + ], + [ + 'label' => 'Создано кем', + 'attribute' => 'created_by', + 'value' => function ($model) { + return $model->createdBy->name ?? '-'; + } + ], + [ + 'class' => ActionColumn::className(), + 'urlCreator' => function ($action, KogortStopList $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/crud/kogort-stop-list/update.php b/erp24/views/crud/kogort-stop-list/update.php new file mode 100644 index 00000000..82ba2010 --- /dev/null +++ b/erp24/views/crud/kogort-stop-list/update.php @@ -0,0 +1,19 @@ +title = 'Редактировать запись в стоп листе когорт: ' . $model->phone . ' : ' . $model->comment; +?> +
+ +

'btn btn-secondary']) ?> + title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/crud/kogort-stop-list/view.php b/erp24/views/crud/kogort-stop-list/view.php new file mode 100644 index 00000000..42034bce --- /dev/null +++ b/erp24/views/crud/kogort-stop-list/view.php @@ -0,0 +1,54 @@ +title = $model->phone; + +\yii\web\YiiAsset::register($this); +?> +
+ +

'btn btn-secondary']) ?> + title) ?>

+ +

+ $model->phone], ['class' => 'btn btn-primary']) ?> + $model->phone], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы действительно хотите удалить этот элемент?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'phone', + 'comment:ntext', + 'created_at', + 'updated_at', + [ + 'attribute' => 'created_by', + 'format' => 'raw', + 'value' => function ($model) { + return $model->createdBy->name ?? '-'; + }, + ], + [ + 'attribute' => 'updated_by', + 'format' => 'raw', + 'value' => function ($model) { + return $model->updatedBy->name ?? '-'; + }, + ], + ], + ]) ?> + +
diff --git a/erp24/views/users-message-management/index.php b/erp24/views/users-message-management/index.php index 2dd61a11..62db3a2f 100644 --- a/erp24/views/users-message-management/index.php +++ b/erp24/views/users-message-management/index.php @@ -7,7 +7,7 @@ use dosamigos\datetimepicker\DateTimePicker; use yii_app\records\Admin; use yii_app\records\UsersMessageManagement; -use yii_app\records\UsersStopList; +use yii_app\records\KogortStopList; /* @var $model UsersMessageManagement */ /* @var $tab integer */ @@ -15,7 +15,7 @@ use yii_app\records\UsersStopList; /** @var array $links */ /** @var string $month */ /** @var string $year */ -/** @var UsersStopList[] $userStopList */ +/** @var KogortStopList[] $userStopList */ $this->registerJs('var tab = ' . \yii\helpers\Json::encode(['tab' => $tab]), \yii\web\View::POS_END); $this->registerJsFile('/js/users-message-management/index.js', ['position' => \yii\web\View::POS_END]); @@ -342,31 +342,41 @@ $this->registerCss('
+
+
+ 'btn btn-success', 'target' => '_blank']) ?> +
+
- - + + + + - + - - - + + + + + -- 2.39.5
Телефон КомментарийДатаАвторДата обновленияДата созданияОбновлено кемСоздано кем
', - ['/crud/users-stop-list/view', 'phone' => $userStop->phone], ['class' => 'btn btn-link', 'style' => 'max-width: 20px', 'target' => '_blank']) ?> + ['/crud/kogort-stop-list/view', 'phone' => $userStop->phone], ['class' => 'btn btn-link', 'style' => 'max-width: 20px', 'target' => '_blank']) ?> ', - ['/crud/users-stop-list/update', 'phone' => $userStop->phone], ['class' => 'btn btn-link', 'style' => 'max-width: 20px', 'target' => '_blank']) ?> + ['/crud/kogort-stop-list/update', 'phone' => $userStop->phone], ['class' => 'btn btn-link', 'style' => 'max-width: 20px', 'target' => '_blank']) ?> ', - ['/crud/users-stop-list/delete', 'phone' => $userStop->phone], ['class' => 'btn btn-link', 'style' => 'max-width: 20px', 'target' => '_blank', 'data-confirm' => 'Вы действительно хотите удалить этот элемент?', 'data-method' => 'POST']) ?> + ['/crud/kogort-stop-list/delete', 'phone' => $userStop->phone], ['class' => 'btn btn-link', 'style' => 'max-width: 20px', 'target' => '_blank', 'data-confirm' => 'Вы действительно хотите удалить этот элемент?', 'data-method' => 'POST']) ?> phone ?>name ?>date ?>author->name ?? '-' ?>comment ?>updated_at ?>created_at ?>updatedBy->name ?? '-' ?>createdBy->name ?? '-' ?>