$log->save(false);
}
+ /**
+ * Обновление статуса подписки пользователя в Телеграмм.
+ */
+ protected function actionUpdateUserSubscribe()
+ {
+ $time_start = microtime(true);
+ $batchSize = 500;
+ $offset = 0;
+
+ while (true) {
+ $usersTelegram = UsersTelegram::find()
+ ->select(['phone','is_blocked','is_registered'])
+ ->where('phone IS NOT NULL')
+ ->limit($batchSize)
+ ->offset($offset)
+ ->asArray()
+ ->all();
+
+ /*TODO Отключить при выкатке*/
+ // Для тестирования
+ if ($offset > 0) {
+ break;
+ }
+ if (empty($usersTelegram)) {
+ break;
+ }
+
+ foreach ($usersTelegram as $userTelegram) {
+ $isBlocked = (int)$userTelegram['is_blocked'];
+ $isRegistered = (int)$userTelegram['is_registered'];
+
+ $phoneRow = $userTelegram['phone'];
+
+ //Тело цикла
+ $client = Users::find()
+ ->where(['phone' => $phoneRow])
+ ->one();
+
+ if (!empty($client)) {
+ $clientDateIsChanged = false;
+ $telegramIsSubscribed = ($isBlocked == 0 && $isRegistered == 1) ? 1 : 0;
+
+ /** @var Users $client */
+ if ($client->telegram_is_subscribed == 1 && $telegramIsSubscribed == 0) {
+ $client->telegram_unsubscribed_at = date('Y-m-d H:i:s');
+ $clientDateIsChanged = true;
+ }
+
+ /** @var Users $client */
+ if ($client->telegram_is_subscribed != $telegramIsSubscribed) {
+ $client->telegram_is_subscribed = $telegramIsSubscribed;
+ $client->telegram_updated_at = date('Y-m-d H:i:s');
+ $clientDateIsChanged = true;
+ }
+
+ /** @var Users $client */
+ if (empty($client->telegram_created_at) ?? $telegramIsSubscribed == 1) {
+ $client->telegram_created_at = date('Y-m-d H:i:s');
+ $clientDateIsChanged = true;
+ }
+
+ if ($clientDateIsChanged) {
+ $validate = $client->validate();
+
+// $client->save(false);
+ }
+ }
+ }
+
+ $offset += $batchSize;
+
+ $this->stdout("Обработано записей: {$offset}\n", BaseConsole::FG_GREEN);
+ }
+
+ $time_end = microtime(true);
+ $execution_time = ($time_end - $time_start)/60;
+ $this->stdout("Total Execution Time: {$execution_time} Mins \n", BaseConsole::FG_GREEN);
+ }
+
// обновление уровней по продажам
public function actionUpdateBonusLevels()
{
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles adding columns to table `{{%users}}`.
+ */
+class m250522_155213_add_column_telegram_updated_at_to_users_table extends Migration
+{
+ const TABLE_NAME = 'erp24.users';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+ if ($table === null) {
+ return;
+ }
+
+ if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('telegram_updated_at')) {
+ $this->addColumn(
+ self::TABLE_NAME,
+ 'telegram_updated_at',
+ $this->timestamp()->null()->defaultExpression('CURRENT_TIMESTAMP')->comment('дата изменения подписки в Телеграмм'),
+ );
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('telegram_updated_at')) {
+ $this->dropColumn(self::TABLE_NAME, 'telegram_updated_at');
+ }
+ }
+}
* @property string $info
* @property string|null $bonus_level Уровань клиента в БС
* @property string|null $check_id_last_sale GUID последнего чека
+ * @property string|null $telegram_updated_at Изменение подписки в Телеграм
*/
class Users extends \yii\db\ActiveRecord
{
],
'safe'
],
- [['pol', 'check_id_last_sale', 'info', 'telegram_created_at'], 'string'],
+ [
+ [
+ 'pol',
+ 'check_id_last_sale',
+ 'info',
+ 'telegram_created_at',
+ 'telegram_updated_at'
+ ],
+ 'string'
+ ],
[
[
'forgot',
'events' => 'Events',
'telegram_unsubscribed_at' => 'Telegram Unsubscribed At',
'bonus_level' => 'Bonus Level',
- 'check_id_last_sale' => 'GUID Last Check'
+ 'check_id_last_sale' => 'GUID Last Check',
+ 'telegram_updated_at' => 'telegram_updated_at'
];
}