From: fomichev Date: Mon, 3 Mar 2025 15:12:32 +0000 (+0300) Subject: Таблица для хранения сообщений X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=eb66fea98a30e34941cab25db05148aa1d5ecf4c;p=erp24_rep%2Fyii-erp24%2F.git Таблица для хранения сообщений --- diff --git a/erp24/controllers/UsersWhatsappMessageController.php b/erp24/controllers/UsersWhatsappMessageController.php new file mode 100644 index 00000000..21f1d091 --- /dev/null +++ b/erp24/controllers/UsersWhatsappMessageController.php @@ -0,0 +1,134 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all UsersWhatsappMessage models. + * + * @return string + */ + public function actionIndex() + { + $searchModel = new UsersWhatsappMessageSearch(); + $dataProvider = $searchModel->search($this->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single UsersWhatsappMessage model. + * @param int $id ID + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new UsersWhatsappMessage model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new UsersWhatsappMessage(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing UsersWhatsappMessage 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($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing UsersWhatsappMessage 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($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the UsersWhatsappMessage 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 UsersWhatsappMessage the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = UsersWhatsappMessage::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/migrations/m250303_142459_create_users_whatsapp_message_table.php b/erp24/migrations/m250303_142459_create_users_whatsapp_message_table.php new file mode 100644 index 00000000..5356b4a9 --- /dev/null +++ b/erp24/migrations/m250303_142459_create_users_whatsapp_message_table.php @@ -0,0 +1,53 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->bigPrimaryKey()->comment('ID'), + 'request_id' => $this->string()->notNull()->comment('ID сообщения'), + 'phone' => $this->string()->notNull()->comment('Телефон'), + 'message' => $this->text()->notNull()->comment('Текст сообщения в WhatsApp'), + 'kogort_date' => $this->date()->notNull()->comment('Дата когорты'), + 'target_date' => $this->date()->notNull()->comment('Целевая дата'), + 'status' => $this->string(20)->notNull()->defaultValue('sent') + ->comment( + "Статус сообщения: " . + "sent - отправлено, " . + "delivered - доставлено, " . + "read - прочитано, " . + "undelivered - не доставлено, " . + "cancelled - отменено, " . + "expired - истек срок, " . + "failed - ошибка обработки" + ), // Статус сообщения в текстовом формате + 'created_at' => $this->dateTime()->notNull()->defaultExpression('CURRENT_TIMESTAMP') + ->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/UsersWhatsappMessage.php b/erp24/records/UsersWhatsappMessage.php new file mode 100644 index 00000000..923c9ab7 --- /dev/null +++ b/erp24/records/UsersWhatsappMessage.php @@ -0,0 +1,63 @@ + 'sent'], + [['request_id', 'phone', 'message', 'kogort_date', 'target_date'], 'required'], + [['message'], 'string'], + [['kogort_date', 'target_date', 'created_at'], 'safe'], + [['request_id', 'phone'], 'string', 'max' => 255], + [['status'], 'string', 'max' => 20], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'request_id' => 'ID сообщения', + 'phone' => 'Телефон', + 'message' => 'Текст сообщения в WhatsApp', + 'kogort_date' => 'Дата когорты', + 'target_date' => 'Целевая дата', + 'status' => 'Статус сообщения: sent - отправлено, delivered - доставлено, read - прочитано, undelivered - не доставлено, cancelled - отменено, expired - истек срок, failed - ошибка обработки', + 'created_at' => 'Дата создания записи', + ]; + } + +} diff --git a/erp24/records/UsersWhatsappMessageSearch.php b/erp24/records/UsersWhatsappMessageSearch.php new file mode 100644 index 00000000..be1e9c87 --- /dev/null +++ b/erp24/records/UsersWhatsappMessageSearch.php @@ -0,0 +1,75 @@ +load()` method. + * + * @return ActiveDataProvider + */ + public function search($params, $formName = null) + { + $query = UsersWhatsappMessage::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params, $formName); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'kogort_date' => $this->kogort_date, + 'target_date' => $this->target_date, + 'created_at' => $this->created_at, + ]); + + $query->andFilterWhere(['ilike', 'request_id', $this->request_id]) + ->andFilterWhere(['ilike', 'phone', $this->phone]) + ->andFilterWhere(['ilike', 'message', $this->message]) + ->andFilterWhere(['ilike', 'status', $this->status]); + + return $dataProvider; + } +} diff --git a/erp24/views/users-whatsapp-message/index.php b/erp24/views/users-whatsapp-message/index.php new file mode 100644 index 00000000..f4579bae --- /dev/null +++ b/erp24/views/users-whatsapp-message/index.php @@ -0,0 +1,50 @@ +title = 'Users Whatsapp Messages'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ + render('_search', ['model' => $searchModel]); ?> + + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'request_id', + 'phone', + 'message:ntext', + 'kogort_date', + //'target_date', + //'status', + //'created_at', + [ + 'class' => ActionColumn::className(), + 'urlCreator' => function ($action, UsersWhatsappMessage $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/users-whatsapp-message/view.php b/erp24/views/users-whatsapp-message/view.php new file mode 100644 index 00000000..485b42b4 --- /dev/null +++ b/erp24/views/users-whatsapp-message/view.php @@ -0,0 +1,43 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Users Whatsapp Messages', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'request_id', + 'phone', + 'message:ntext', + 'kogort_date', + 'target_date', + 'status', + 'created_at', + ], + ]) ?> + +