]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Таблица для хранения сообщений
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 3 Mar 2025 15:12:32 +0000 (18:12 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 3 Mar 2025 15:12:32 +0000 (18:12 +0300)
erp24/controllers/UsersWhatsappMessageController.php [new file with mode: 0644]
erp24/migrations/m250303_142459_create_users_whatsapp_message_table.php [new file with mode: 0644]
erp24/records/UsersWhatsappMessage.php [new file with mode: 0644]
erp24/records/UsersWhatsappMessageSearch.php [new file with mode: 0644]
erp24/views/users-whatsapp-message/index.php [new file with mode: 0644]
erp24/views/users-whatsapp-message/view.php [new file with mode: 0644]

diff --git a/erp24/controllers/UsersWhatsappMessageController.php b/erp24/controllers/UsersWhatsappMessageController.php
new file mode 100644 (file)
index 0000000..21f1d09
--- /dev/null
@@ -0,0 +1,134 @@
+<?php
+
+namespace app\controllers;
+
+use yii_app\records\UsersWhatsappMessage;
+use yii_app\records\UsersWhatsappMessageSearch;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\filters\VerbFilter;
+
+/**
+ * UsersWhatsappMessageController implements the CRUD actions for UsersWhatsappMessage model.
+ */
+class UsersWhatsappMessageController extends Controller
+{
+    /**
+     * @inheritDoc
+     */
+    public function behaviors()
+    {
+        return array_merge(
+            parent::behaviors(),
+            [
+                'verbs' => [
+                    '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 (file)
index 0000000..5356b4a
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%users_whatsapp_message}}`.
+ */
+class m250303_142459_create_users_whatsapp_message_table extends Migration
+{
+    const TABLE_NAME = 'erp24.users_whatsapp_message';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $tableSchema = $this->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 (file)
index 0000000..923c9ab
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "users_whatsapp_message".
+ *
+ * @property int $id ID
+ * @property string $request_id ID сообщения
+ * @property string $phone Телефон
+ * @property string $message Текст сообщения в WhatsApp
+ * @property string $kogort_date Дата когорты
+ * @property string $target_date Целевая дата
+ * @property string $status Статус сообщения: sent - отправлено, delivered - доставлено, read - прочитано, undelivered - не доставлено, cancelled - отменено, expired - истек срок, failed - ошибка обработки
+ * @property string $created_at Дата создания записи
+ */
+class UsersWhatsappMessage extends \yii\db\ActiveRecord
+{
+
+
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'users_whatsapp_message';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['status'], 'default', 'value' => '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 (file)
index 0000000..be1e9c8
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+namespace yii_app\records;
+
+use yii\base\Model;
+use yii\data\ActiveDataProvider;
+use yii_app\records\UsersWhatsappMessage;
+
+/**
+ * UsersWhatsappMessageSearch represents the model behind the search form of `yii_app\records\UsersWhatsappMessage`.
+ */
+class UsersWhatsappMessageSearch extends UsersWhatsappMessage
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id'], 'integer'],
+            [['request_id', 'phone', 'message', 'kogort_date', 'target_date', 'status', 'created_at'], 'safe'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function scenarios()
+    {
+        // bypass scenarios() implementation in the parent class
+        return Model::scenarios();
+    }
+
+    /**
+     * Creates data provider instance with search query applied
+     *
+     * @param array $params
+     * @param string|null $formName Form name to be used into `->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 (file)
index 0000000..f4579ba
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+
+use yii_app\records\UsersWhatsappMessage;
+use yii\helpers\Html;
+use yii\helpers\Url;
+use yii\grid\ActionColumn;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\UsersWhatsappMessageSearch $searchModel */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Users Whatsapp Messages';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="users-whatsapp-message-index">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Create Users Whatsapp Message', ['create'], ['class' => 'btn btn-success']) ?>
+    </p>
+
+    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
+
+    <?= GridView::widget([
+        'dataProvider' => $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]);
+                 }
+            ],
+        ],
+    ]); ?>
+
+
+</div>
diff --git a/erp24/views/users-whatsapp-message/view.php b/erp24/views/users-whatsapp-message/view.php
new file mode 100644 (file)
index 0000000..485b42b
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\DetailView;
+
+/** @var yii\web\View $this */
+/** @var yii_app\records\UsersWhatsappMessage $model */
+
+$this->title = $model->id;
+$this->params['breadcrumbs'][] = ['label' => 'Users Whatsapp Messages', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+\yii\web\YiiAsset::register($this);
+?>
+<div class="users-whatsapp-message-view">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Delete', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Are you sure you want to delete this item?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+
+    <?= DetailView::widget([
+        'model' => $model,
+        'attributes' => [
+            'id',
+            'request_id',
+            'phone',
+            'message:ntext',
+            'kogort_date',
+            'target_date',
+            'status',
+            'created_at',
+        ],
+    ]) ?>
+
+</div>