From: Alexander Smirnov Date: Fri, 13 Sep 2024 07:56:35 +0000 (+0300) Subject: [ERP-173] Добавлено поле telegram_unsubscribed_at X-Git-Tag: 1.5~10^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=be4e3e430b2a52b6a5a86e637061091a91ab0dbc;p=erp24_rep%2Fyii-erp24%2F.git [ERP-173] Добавлено поле telegram_unsubscribed_at --- diff --git a/erp24/api2/controllers/ClientController.php b/erp24/api2/controllers/ClientController.php index d8c84466..adfa7389 100644 --- a/erp24/api2/controllers/ClientController.php +++ b/erp24/api2/controllers/ClientController.php @@ -946,6 +946,13 @@ class ClientController extends BaseController { return $this->asJson(["error_id" => 3, "error" => "User fail to save: " . Json::encode($user->getErrors())]); } } + if ($result['telegram_is_subscribed'] == 0) { + $user->telegram_unsubscribed_at = date("Y-m-d H:i:s"); + $user->save(); + if ($user->getErrors()) { + return $this->asJson(["error_id" => 4, "error" => "User fail to save: " . Json::encode($user->getErrors())]); + } + } return $this->asJson(['response' => true]); } diff --git a/erp24/migrations/m240913_073353_alter_table_users_add_column_telegram_unsubscribed_at.php b/erp24/migrations/m240913_073353_alter_table_users_add_column_telegram_unsubscribed_at.php new file mode 100755 index 00000000..ab307eb3 --- /dev/null +++ b/erp24/migrations/m240913_073353_alter_table_users_add_column_telegram_unsubscribed_at.php @@ -0,0 +1,28 @@ +addColumn(self::TABLE_NAME, 'telegram_unsubscribed_at', $this->dateTime()->null() + ->after('telegram_is_subscribed')->comment('Время отписки от тг бота')); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn(self::TABLE_NAME, 'telegram_unsubscribed_at'); + } +} diff --git a/erp24/records/Users.php b/erp24/records/Users.php index 343c2f34..9ba3ca5d 100755 --- a/erp24/records/Users.php +++ b/erp24/records/Users.php @@ -59,6 +59,7 @@ use Yii; * @property string|null $store_id GUID магазина, который добавил клиента * @property int $source 0 - 1C, 1 - было 1С стало тг, 2 - сразу тг * @property int $telegram_is_subscribed 0 - не подписан в телеграмме, 1 - подписан + * @property string|null $telegram_unsubscribed_at Время отписки от тг бота * @property string $telegram_created_at Время регистрации в тг * @property int $black_list В черном списке - заблокировать * @property int $events Импортированы ли события @@ -134,7 +135,8 @@ class Users extends \yii\db\ActiveRecord [['date', 'name', 'name_name', 'name_last', 'name_family', 'comment', 'email', 'email_old', 'phone_old', 'card', 'password', 'keycode', 'check_id', 'check_id_forgot', 'sid_forgot', 'forgot_time', 'kod', 'created_id', 'created_name', 'created_store_id', 'balans_datetime', 'bonus_minus', 'bdate', 'date_last', 'date_last_sale', 'date_first_sale', 'sale_cnt', - 'sale_avg_price', 'sale_price', 'reklama_info', 'alerts_balans', 'alerts_date', 'alerts_reklama', 'ref_code', 'referral_id', 'seller_id', 'store_id', 'first_minus_balance'], 'safe'], + 'sale_avg_price', 'sale_price', 'reklama_info', 'alerts_balans', 'alerts_date', 'alerts_reklama', 'ref_code', 'referral_id', + 'seller_id', 'store_id', 'first_minus_balance', 'telegram_unsubscribed_at'], 'safe'], [['pol', 'info', 'telegram_created_at'], 'string'], [ [ @@ -234,6 +236,7 @@ class Users extends \yii\db\ActiveRecord 'seller_id' => 'Seller ID', 'black_list' => 'Black List', 'events' => 'Events', + 'telegram_unsubscribed_at' => 'Telegram Unsubscribed At', ]; }