]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавление updated_at
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 23 Jan 2025 15:39:54 +0000 (18:39 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 23 Jan 2025 15:39:54 +0000 (18:39 +0300)
erp24/commands/CronController.php
erp24/jobs/SendTelegramMessageJob.php
erp24/migrations/m250123_133454_add_updated_at_column_to_sent_kogort_table.php [new file with mode: 0644]
erp24/records/SentKogort.php

index 7d81f14c243c00a2a37e5f7a7305769f87e2e407..31bc4dfcf864d750e7e5d8ac129bc260b58d7ffa 100644 (file)
@@ -382,9 +382,13 @@ class CronController extends Controller
                         ]));
                     }
                 }
-
+                //TODO - перенос в отправку
                 $updatedCount = SentKogort::updateAll(
-                    ['status' => SentKogort::STATUSES['first']], // Устанавливаем статус "первая рассылка"
+                    [
+                        'status' => SentKogort::STATUSES['first'], // Устанавливаем статус "первая рассылка"
+                        'updated_at' => date('Y-m-d H:i:s'),
+
+                    ],
                     [
                         'kogort_date'   => $kogortDate,
                         'target_date'   => $targetDate,
@@ -636,8 +640,12 @@ class CronController extends Controller
                         ]));
                     }
                 }
+                //TODO - перенос в отправку
                 $updatedCount = SentKogort::updateAll(
-                    ['status' => SentKogort::STATUSES['second']], // Устанавливаем статус "вторая рассылка"
+                    [
+                        'status' => SentKogort::STATUSES['second'], // Устанавливаем статус "вторая рассылка"
+                        'updated_at' => date('Y-m-d H:i:s'),
+                    ],
                     [
                         'target_date' => $targetDate,
                         'kogort_number' => SentKogort::KOGORT_NUMBERS['target'],
index 74da300a125e5524a39aae69095b66dd2a251a26..b94251cae290efcfe28d3387ba09f8f07fe4a927 100644 (file)
@@ -40,7 +40,7 @@ class SendTelegramMessageJob extends \yii\base\BaseObject implements JobInterfac
             if ($result == "OK") {
                 try {
                     $result = TelegramService::saveSentMessageToDB($this->messageData);
-
+                    //TODO - перенос сюда обновления статусов записей когорт
                     if ($result) {
                         Yii::warning("Сообщение успешно сохранено для пользователя с ID {$chatId} телефон {$phone}", 'telegram');
                     } else {
diff --git a/erp24/migrations/m250123_133454_add_updated_at_column_to_sent_kogort_table.php b/erp24/migrations/m250123_133454_add_updated_at_column_to_sent_kogort_table.php
new file mode 100644 (file)
index 0000000..6096d08
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles adding columns to table `{{%sent_kogort}}`.
+ */
+class m250123_133454_add_updated_at_column_to_sent_kogort_table extends Migration
+{
+    const TABLE_NAME  = 'erp24.sent_kogort';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME) === null) {
+            return;
+        }
+
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME)->getColumn('updated_at') === null) {
+            $this->addColumn(
+                self::TABLE_NAME,
+                'updated_at',
+                $this->timestamp()
+                    ->null()
+                    ->defaultExpression('CURRENT_TIMESTAMP')
+                    ->comment('Дата обновления')
+            );
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME) === null) {
+            return;
+        }
+
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME)->getColumn('updated_at') !== null) {
+            $this->dropColumn(self::TABLE_NAME, 'updated_at');
+        }
+    }
+}
index 1c05074b0620764447fe791df7fda8916e5472f3..2fa033dc7f778ff270b0da6a831df6ae76a1b522 100644 (file)
@@ -50,6 +50,7 @@ class SentKogort extends \yii\db\ActiveRecord
             [['kogort_unixtime', 'status', 'contact', 'purchase'], 'default', 'value' => null],
             [['kogort_unixtime', 'status', 'contact', 'purchase', 'kogort_number'], 'integer'],
             [['phone'], 'string', 'max' => 15],
+            [['updated_at'], 'safe'],
         ];
     }
 
@@ -69,6 +70,7 @@ class SentKogort extends \yii\db\ActiveRecord
             'contact' => 'Контакт с клиентом',
             'purchase' => 'Покупка',
             'created_at' => 'Дата создания записи',
+            'updated_at' => 'Дата обновления записи',
         ];
     }
 
@@ -76,4 +78,13 @@ class SentKogort extends \yii\db\ActiveRecord
     {
         return ['id'];
     }
+
+    public function afterSave($insert, $changedAttributes)
+    {
+        parent::afterSave($insert, $changedAttributes);
+
+        if (!$insert) {
+            $this->updateAttributes(['updated_at' => date('Y-m-d H:i:s')]);
+        }
+    }
 }