From 2e65629cbb749619a983c13538132421825c511f Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 23 Jan 2025 18:39:54 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20updated=5Fat?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 14 ++++-- erp24/jobs/SendTelegramMessageJob.php | 2 +- ...updated_at_column_to_sent_kogort_table.php | 45 +++++++++++++++++++ erp24/records/SentKogort.php | 11 +++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 erp24/migrations/m250123_133454_add_updated_at_column_to_sent_kogort_table.php diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 7d81f14c..31bc4dfc 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -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'], diff --git a/erp24/jobs/SendTelegramMessageJob.php b/erp24/jobs/SendTelegramMessageJob.php index 74da300a..b94251ca 100644 --- a/erp24/jobs/SendTelegramMessageJob.php +++ b/erp24/jobs/SendTelegramMessageJob.php @@ -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 index 00000000..6096d083 --- /dev/null +++ b/erp24/migrations/m250123_133454_add_updated_at_column_to_sent_kogort_table.php @@ -0,0 +1,45 @@ +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'); + } + } +} diff --git a/erp24/records/SentKogort.php b/erp24/records/SentKogort.php index 1c05074b..2fa033dc 100644 --- a/erp24/records/SentKogort.php +++ b/erp24/records/SentKogort.php @@ -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')]); + } + } } -- 2.39.5