Taio_O 3 settimane fa
parent
commit
fdf68332e7
2 ha cambiato i file con 16 aggiunte e 11 eliminazioni
  1. 5 2
      admin/config/initDb.js
  2. 11 9
      admin/index.js

+ 5 - 2
admin/config/initDb.js

@@ -82,12 +82,15 @@ async function initDatabase() {
         await pool.query(`
             CREATE TABLE IF NOT EXISTS trx_addresses (
                 id INT AUTO_INCREMENT PRIMARY KEY,
-                address VARCHAR(50) NOT NULL UNIQUE COMMENT 'TRX地址',
+                address VARCHAR(50) NOT NULL COMMENT 'TRX地址',
+                group_id VARCHAR(255) NOT NULL COMMENT '群组ID',
                 first_seen_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '首次出现时间',
                 last_seen_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后出现时间',
                 usage_count INT DEFAULT 1 COMMENT '使用次数',
                 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-                updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
+                updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+                FOREIGN KEY (group_id) REFERENCES groups(group_id),
+                UNIQUE KEY unique_address_group (address, group_id)
             )
         `);
 

+ 11 - 9
admin/index.js

@@ -368,10 +368,12 @@ bot.on('message', async (msg) => {
     // 处理TRX地址
     else if (/^T[A-Za-z0-9]{33}$/.test(text)) {
         try {
+            const groupId = msg.chat.id.toString();
+            
             // 检查地址是否已存在
             const [existingAddress] = await pool.query(
-                'SELECT * FROM trx_addresses WHERE address = ?',
-                [text]
+                'SELECT * FROM trx_addresses WHERE address = ? AND group_id = ?',
+                [text, groupId]
             );
 
             if (existingAddress && existingAddress.length > 0) {
@@ -380,21 +382,21 @@ bot.on('message', async (msg) => {
                     UPDATE trx_addresses 
                     SET usage_count = usage_count + 1,
                         last_seen_time = CURRENT_TIMESTAMP
-                    WHERE address = ?
-                `, [text]);
+                    WHERE address = ? AND group_id = ?
+                `, [text, groupId]);
 
                 const newCount = existingAddress[0].usage_count + 1;
                 await sendMessage(msg.chat.id, `此地址累计发送第${newCount}次`);
-                console.log(`TRX地址使用次数更新 - 地址: ${text}, 次数: ${newCount}, 时间: ${new Date().toLocaleString()}`);
+                console.log(`TRX地址使用次数更新 - 群组: ${msg.chat.title}, 地址: ${text}, 次数: ${newCount}, 时间: ${new Date().toLocaleString()}`);
             } else {
                 // 插入新地址记录
                 await pool.query(`
-                    INSERT INTO trx_addresses (address)
-                    VALUES (?)
-                `, [text]);
+                    INSERT INTO trx_addresses (address, group_id)
+                    VALUES (?, ?)
+                `, [text, groupId]);
 
                 await sendMessage(msg.chat.id, '此地址累计发送第1次');
-                console.log(`新TRX地址记录 - 地址: ${text}, 时间: ${new Date().toLocaleString()}`);
+                console.log(`新TRX地址记录 - 群组: ${msg.chat.title}, 地址: ${text}, 时间: ${new Date().toLocaleString()}`);
             }
         } catch (error) {
             console.error('处理TRX地址失败:', error);