From: fomichev Date: Wed, 25 Dec 2024 14:40:51 +0000 (+0300) Subject: Переименование таблиц X-Git-Tag: 1.7~94^2~35 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=5134a056c4335dcea5a325caf7566f38e624f214;p=erp24_rep%2Fyii-erp24%2F.git Переименование таблиц --- diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 45f54d90..20831862 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -16,7 +16,7 @@ use yii_app\records\ReplacementInvoiceProducts; use yii_app\records\SentKogort; use yii_app\records\Users; use yii_app\records\UsersMessageManagement; -use yii_app\records\UsersTelegramChatId; +use yii_app\records\UsersTelegram; use yii_app\records\UsersTelegramLog; class CronController extends Controller @@ -384,10 +384,10 @@ class CronController extends Controller $isBlocked = (int)$remoteUser['is_blocked']; $isRegistered = (int)$remoteUser['is_registered']; - $user = UsersTelegramChatId::findOne(['chat_id' => $chatId]); + $user = UsersTelegram::findOne(['chat_id' => $chatId]); if (!$user) { - $user = new UsersTelegramChatId([ + $user = new UsersTelegram([ 'chat_id' => $chatId, 'phone' => $phone, 'username' => $username ?? 'Клиент из чатбота', diff --git a/erp24/controllers/UsersMessageManagementController.php b/erp24/controllers/UsersMessageManagementController.php index 05e0d98d..da9daa0c 100644 --- a/erp24/controllers/UsersMessageManagementController.php +++ b/erp24/controllers/UsersMessageManagementController.php @@ -21,7 +21,7 @@ use yii_app\records\Users; use yii_app\records\UsersEvents; use yii_app\records\UsersMessageManagement; use yii_app\records\UsersMessageManagementLogs; -use yii_app\records\UsersTelegramChatId; +use yii_app\records\UsersTelegram; use yii_app\records\UsersTelegramLog; class UsersMessageManagementController extends Controller @@ -420,10 +420,10 @@ class UsersMessageManagementController extends Controller $isBlocked = (int)$remoteUser['is_blocked']; $isRegistered = (int)$remoteUser['is_registered']; - $user = UsersTelegramChatId::findOne(['chat_id' => $chatId]); + $user = UsersTelegram::findOne(['chat_id' => $chatId]); if (!$user) { - $user = new UsersTelegramChatId([ + $user = new UsersTelegram([ 'chat_id' => $chatId, 'phone' => $phone, 'username' => $username ?? 'Клиент из чатбота', diff --git a/erp24/migrations/m241224_140248_create_users_telegram_chat_id_table.php b/erp24/migrations/m241224_140248_create_users_telegram_chat_id_table.php deleted file mode 100644 index 53217ec1..00000000 --- a/erp24/migrations/m241224_140248_create_users_telegram_chat_id_table.php +++ /dev/null @@ -1,60 +0,0 @@ -db->getTableSchema(self::TABLE_NAME); - - if (!isset($tableSchema)) { - $this->createTable(self::TABLE_NAME, [ - 'chat_id' => $this->string()->notNull()->comment('Chat ID'), - 'phone' => $this->string()->null()->comment('Телефон'), - 'username' => $this->string()->null()->comment('Имя пользователя в Телеграм'), - 'first_name' => $this->string()->null()->comment('Имя пользователя'), - 'is_blocked' => $this->integer(1)->notNull()->defaultValue(0)->comment( - 'Заблокирован: 0 - нет, 1 - да' - ), - 'is_registered' => $this->integer(1)->notNull()->defaultValue(0)->comment( - 'Зарегистрирован: 0 - нет, 1 - да' - ), - ]); - } - } - - /** - * {@inheritdoc} - */ - public function safeDown() - { - $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); - if (isset($tableSchema)) { - $this->dropTable(self::TABLE_NAME); - } - } - - /* - // Use up()/down() to run migration code without a transaction. - public function up() - { - - } - - public function down() - { - echo "m241224_140248_add_telegram_chat_id_to_users_table cannot be reverted.\n"; - - return false; - } - */ -} diff --git a/erp24/migrations/m241224_140248_create_users_telegram_table.php b/erp24/migrations/m241224_140248_create_users_telegram_table.php new file mode 100644 index 00000000..075758d3 --- /dev/null +++ b/erp24/migrations/m241224_140248_create_users_telegram_table.php @@ -0,0 +1,60 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'chat_id' => $this->string()->notNull()->comment('Chat ID'), + 'phone' => $this->string()->null()->comment('Телефон'), + 'username' => $this->string()->null()->comment('Имя пользователя в Телеграм'), + 'first_name' => $this->string()->null()->comment('Имя пользователя'), + 'is_blocked' => $this->integer(1)->notNull()->defaultValue(0)->comment( + 'Заблокирован: 0 - нет, 1 - да' + ), + 'is_registered' => $this->integer(1)->notNull()->defaultValue(0)->comment( + 'Зарегистрирован: 0 - нет, 1 - да' + ), + ]); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m241224_140248_add_telegram_chat_id_to_users_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/erp24/records/Users.php b/erp24/records/Users.php index 0084b30f..9f9860c1 100755 --- a/erp24/records/Users.php +++ b/erp24/records/Users.php @@ -515,7 +515,7 @@ class Users extends \yii\db\ActiveRecord $step1 = $messagesSettings ? $messagesSettings->day_before_step1 : 10; $step2 = $messagesSettings ? $messagesSettings->day_before_step2 : 4; - $usersQuery = UsersTelegramChatId::find()->andWhere(['phone' => $phones]); + $usersQuery = UsersTelegram::find()->andWhere(['phone' => $phones]); $usersQuery->andWhere(['is_blocked' => 0]); $usersQuery->andWhere(['is_registered' => 1]); @@ -546,7 +546,7 @@ class Users extends \yii\db\ActiveRecord $step3 = $messagesSettings ? $messagesSettings->day_before_step3 : 2; // Подзапрос базы пользователей с учетом подписки на телеграм - $usersQuery = UsersTelegramChatId::find()->andWhere(['phone' => $phones]); + $usersQuery = UsersTelegram::find()->andWhere(['phone' => $phones]); $usersQuery->andWhere(['is_blocked' => 0]); $usersQuery->andWhere(['is_registered' => 1]); @@ -595,7 +595,7 @@ class Users extends \yii\db\ActiveRecord }, $phones); } - $users = UsersTelegramChatId::find() + $users = UsersTelegram::find() ->where(['phone' => $phones]) ->all(); diff --git a/erp24/records/UsersTelegram.php b/erp24/records/UsersTelegram.php new file mode 100644 index 00000000..46598797 --- /dev/null +++ b/erp24/records/UsersTelegram.php @@ -0,0 +1,54 @@ + null], + [['is_blocked', 'is_registered'], 'integer'], + [['chat_id', 'phone', 'username', 'first_name'], 'string', 'max' => 255], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'chat_id' => 'Chat ID', + 'phone' => 'Телефон', + 'username' => 'Имя пользователя в Телеграм', + 'first_name' => 'Имя пользователя', + 'is_blocked' => 'Заблокирован: 0 - нет, 1 - да', + 'is_registered' => 'Зарегистрирован: 0 - нет, 1 - да', + ]; + } +} diff --git a/erp24/records/UsersTelegramChatId.php b/erp24/records/UsersTelegramChatId.php deleted file mode 100644 index 43740d4f..00000000 --- a/erp24/records/UsersTelegramChatId.php +++ /dev/null @@ -1,54 +0,0 @@ - null], - [['is_blocked', 'is_registered'], 'integer'], - [['chat_id', 'phone', 'username', 'first_name'], 'string', 'max' => 255], - ]; - } - - /** - * {@inheritdoc} - */ - public function attributeLabels() - { - return [ - 'chat_id' => 'Chat ID', - 'phone' => 'Телефон', - 'username' => 'Имя пользователя в Телеграм', - 'first_name' => 'Имя пользователя', - 'is_blocked' => 'Заблокирован: 0 - нет, 1 - да', - 'is_registered' => 'Зарегистрирован: 0 - нет, 1 - да', - ]; - } -}