Sfoglia il codice sorgente

上传后的修改版本

Taio_O 3 settimane fa
parent
commit
2da5f0b1b3

+ 1 - 0
admin/.htaccess

@@ -0,0 +1 @@
+# 请将伪静态规则或自定义Apache配置填写到此处

+ 1 - 1
admin/config/database.js

@@ -1,7 +1,7 @@
 const mysql = require('mysql2/promise');
 
 const pool = mysql.createPool({
-    host: process.env.DB_HOST || '47.94.130.207',
+    host: process.env.DB_HOST || '127.0.0.1',
     user: process.env.DB_USER || 'notebot',
     password: process.env.DB_PASSWORD || 'NZWdAr4neDPrWm5k',
     database: process.env.DB_NAME || 'notebot',

+ 8 - 7
admin/controllers/settingsController.js

@@ -10,8 +10,8 @@ const getSettings = async (req, res) => {
         if (settings.length === 0) {
             // 如果没有设置记录,创建默认设置
             await pool.query(`
-                INSERT INTO settings (id, site_name, admin_email, deposit_fee_rate, withdrawal_fee_rate)
-                VALUES (1, '后台管理系统', 'admin@example.com', 0.01, 0.01)
+                INSERT INTO settings (id, site_name, admin_email)
+                VALUES (1, '后台管理系统', 'admin@example.com')
             `);
             
             const [newSettings] = await pool.query('SELECT * FROM settings WHERE id = 1');
@@ -30,14 +30,15 @@ const getSettings = async (req, res) => {
 // @access  Private/Admin
 const updateSettings = async (req, res) => {
     try {
-        const { siteName, adminEmail } = req.body;
+        const { siteName, adminEmail,adminTG } = req.body;
         
         await pool.query(`
             UPDATE settings 
             SET site_name = ?, 
-                admin_email = ?
+                admin_email = ?,
+                admin_tg = ?
             WHERE id = 1
-        `, [siteName, adminEmail]);
+        `, [siteName, adminEmail,adminTG]);
         
         const [settings] = await pool.query('SELECT * FROM settings WHERE id = 1');
         res.json(settings[0]);
@@ -67,8 +68,8 @@ const updatePassword = async (req, res) => {
         }
 
         // 更新密码
-        const hashedPassword = await require('../models/User').hashPassword(newPassword);
-        await pool.query('UPDATE users SET password = ? WHERE id = ?', [hashedPassword, userId]);
+        const hashedPassword = await require('../models/User').updatePassword(userId,newPassword);
+        // await pool.query('UPDATE users SET password = ? WHERE id = ?', [hashedPassword, userId]);
         
         res.json({ message: '密码修改成功' });
     } catch (error) {

+ 22 - 21
admin/index.js

@@ -9,7 +9,7 @@ const {
     pool,
     testConnection
 } = require('./config/database');
-const initDatabase = require('./config/initDb');
+// const initDatabase = require('./config/initDb');
 const Group = require('./models/Group');
 const Transaction = require('./models/Transaction');
 
@@ -99,8 +99,10 @@ async function checkUserPermission(chatId, userId) {
             console.error('解析操作人列表失败:', e);
             operators = [];
         }
-        
-        const isOperator = operators.some(op => op.operator_id === userIdStr);
+        // console.log(groupInfo.operators)
+        // console.log(operators);
+        // console.log(userIdStr);
+        const isOperator = operators.some(op => op.operator_id == userIdStr);
         
         // 只在权限检查失败时输出详细日志
         if (!isCreator && !isOperator) {
@@ -151,7 +153,7 @@ bot.on('message', async (msg) => {
 
     const text = msg.text?.trim();
     if (!text) return;
-
+    console.error(msg);
     // 0. 检查用户权限
     const hasPermission = await checkUserPermission(msg.chat.id, msg.from.id);
     if (!hasPermission) {
@@ -419,18 +421,18 @@ bot.on('message', async (msg) => {
     else if (text.startsWith('设置操作人')) {
         try {
             const groupId = msg.chat.id.toString();
-            const mentionedUser = msg.entities?.find(e => e.type === 'mention');
+            // const mentionedUser = msg.entities?.find(e => e.type === 'mention');
             
-            if (!mentionedUser) {
+            if (!msg.reply_to_message.from.id) {
                 // 如果没有@用户,回复原消息并提示设置用户名
-                await bot.sendMessage(msg.chat.id, '请设置您的Telegram用户名后再试', {
+                await bot.sendMessage(msg.chat.id, '请通过回复要添加操作人的消息设置', {
                     reply_to_message_id: msg.message_id
                 });
                 return;
             }
 
             // 获取被@的用户名
-            const username = text.slice(mentionedUser.offset + 1, mentionedUser.offset + mentionedUser.length);
+            const username = msg.reply_to_message.from.first_name;//text.slice(mentionedUser.offset + 1, mentionedUser.offset + mentionedUser.length);
             
             // 获取群组信息
             const [group] = await pool.query(
@@ -475,15 +477,16 @@ bot.on('message', async (msg) => {
                 [username]
             );
 
-            let newOperatorId;
+            let newOperatorId=msg.reply_to_message.from.id;
+            let newOperatorUid=msg.reply_to_message.from.username; 
             if (!user || !user[0]) {
                 // 如果用户不存在,创建新用户
                 try {
                     const [result] = await pool.query(
-                        'INSERT INTO users (username, password, role) VALUES (?, ?, ?)',
-                        [username, '', 'user']
+                        'INSERT INTO users (id,uid,username, password, role) VALUES (?,?,?, ?, ?)',
+                        [newOperatorId,newOperatorUid,username, '', 'user']
                     );
-                    newOperatorId = result.insertId.toString();
+                    // newOperatorId = result.insertId.toString();
                     console.log(`创建新用户成功 - 用户名: ${username}, ID: ${newOperatorId}`);
                 } catch (error) {
                     console.error('创建新用户失败:', error);
@@ -491,7 +494,7 @@ bot.on('message', async (msg) => {
                     return;
                 }
             } else {
-                newOperatorId = user[0].id.toString();
+                // newOperatorId = user[0].id.toString();
             }
 
             // 检查是否已经是操作人
@@ -504,6 +507,7 @@ bot.on('message', async (msg) => {
             operators.push({
                 operator_id: newOperatorId,
                 operator_username: username,
+                operator_uid:newOperatorUid,
                 added_by: userId,
                 added_at: new Date().toISOString()
             });
@@ -683,19 +687,16 @@ function generateInlineKeyboard(chatId) {
 bot.on('callback_query', async (callbackQuery) => {
     const chatId = callbackQuery.message.chat.id;
     const data = callbackQuery.data;
-
     try {
         if (data.startsWith('bill_page_')) {
             const groupId = data.split('_')[2];
-            await bot.answerCallbackQuery(callbackQuery.id, {
-                url: 'https://google.com'
-            });
+            console.log('https://jfpay.top/admin/views/statistics_bill.html?groupId='+groupId)
+            await bot.sendMessage(chatId, `点击查看完整账单:[完整账单](https://jfpay.top/admin/views/statistics_bill.html?groupId=${groupId})`, {parse_mode: 'Markdown'});
         } else if (data === 'business_contact') {
-            await bot.answerCallbackQuery(callbackQuery.id, {
-                url: 'https://t.me/your_business_account'
-            });
+            await bot.sendMessage(chatId, `24小时商务对接:[点击跳转](https://t.me/yyyyaaaa123_bot)`, {parse_mode: 'Markdown'})
         }
     } catch (error) {
+        console.log(error)
         console.error(formatLog('处理内联按钮回调失败', error));
         await bot.answerCallbackQuery(callbackQuery.id, {
             text: '操作失败,请稍后重试',
@@ -840,7 +841,7 @@ function loadData() {
 }
 // 测试数据库连接并初始化
 testConnection().then(() => {
-    return initDatabase();
+    // return initDatabase();
 }).then(() => {
     // 加载数据
     loadData();

+ 2 - 0
admin/models/Transaction.js

@@ -43,6 +43,7 @@ const Transaction = {
                 SELECT 
                     t.*,
                     u.username as operator_name,
+                    u.uid as uid,
                     g.group_name
                 FROM transactions t
                 LEFT JOIN users u ON t.operator_id = u.id
@@ -298,6 +299,7 @@ const Transaction = {
             SELECT 
                 t.*,
                 u.username as operator_name,
+                u.uid as uid,
                 DATE_FORMAT(t.time, '%Y-%m-%d %H:%i:%s') as formatted_time
             FROM transactions t
             LEFT JOIN users u ON t.operator_id = u.id

+ 9 - 3
admin/views/settings.html

@@ -113,6 +113,10 @@
                                     <div class="mb-3">
                                         <label for="adminEmail" class="form-label">管理员邮箱</label>
                                         <input type="email" class="form-control" id="adminEmail">
+                                    </div>
+                                     <div class="mb-3">
+                                        <label for="adminTG" class="form-label">商务对接链接</label>
+                                        <input type="text" class="form-control" id="adminTG">
                                     </div>
                                     <button type="submit" class="btn btn-primary">保存设置</button>
                                 </form>
@@ -195,8 +199,9 @@
 
                 if (response.ok) {
                     const settings = await response.json();
-                    document.getElementById('siteName').value = settings.siteName;
-                    document.getElementById('adminEmail').value = settings.adminEmail;
+                    document.getElementById('siteName').value = settings.site_name;
+                    document.getElementById('adminEmail').value = settings.admin_email;
+                    document.getElementById('adminTG').value = settings.admin_tg;
                 } else if (response.status === 401) {
                     window.location.href = '/';
                 }
@@ -218,7 +223,8 @@
                     },
                     body: JSON.stringify({
                         siteName: document.getElementById('siteName').value,
-                        adminEmail: document.getElementById('adminEmail').value
+                        adminEmail: document.getElementById('adminEmail').value,
+                        adminTG: document.getElementById('adminTG').value
                     })
                 });
 

+ 12 - 4
admin/views/statistics_bill.html

@@ -165,6 +165,8 @@
                                         <th>交易ID</th>
                                         <th>时间</th>
                                         <th>金额</th>
+                                        <th>费率</th>
+                                        <th>汇率</th>
                                         <th>操作人</th>
                                         <th>回复人</th>
                                     </tr>
@@ -186,6 +188,8 @@
                                         <th>交易ID</th>
                                         <th>时间</th>
                                         <th>金额</th>
+                                        <th>费率</th>
+                                        <th>汇率</th>
                                         <th>操作人</th>
                                         <th>回复人</th>
                                     </tr>
@@ -313,8 +317,8 @@
             const withdrawalsList = document.getElementById('withdrawalsList');
             
             if (!transactions || transactions.length === 0) {
-                depositsList.innerHTML = '<tr><td colspan="5" class="text-center">暂无入款记录</td></tr>';
-                withdrawalsList.innerHTML = '<tr><td colspan="5" class="text-center">暂无下发记录</td></tr>';
+                depositsList.innerHTML = '<tr><td colspan="7" class="text-center">暂无入款记录</td></tr>';
+                withdrawalsList.innerHTML = '<tr><td colspan="7" class="text-center">暂无下发记录</td></tr>';
                 return;
             }
             
@@ -326,20 +330,24 @@
                     <td>${transaction.id}</td>
                     <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
                     <td class="text-success">¥${parseFloat(transaction.amount).toFixed(2)}</td>
+                    <td>${transaction.fee_rate ? transaction.fee_rate + '%' : '-'}</td>
+                    <td>${transaction.exchange_rate ? Number(transaction.exchange_rate).toFixed(4) : '-'}</td>
                     <td>${transaction.operator_id || '-'}</td>
                     <td>${transaction.replier_id || '-'}</td>
                 </tr>
-            `).join('') : '<tr><td colspan="5" class="text-center">暂无入款记录</td></tr>';
+            `).join('') : '<tr><td colspan="7" class="text-center">暂无入款记录</td></tr>';
             
             withdrawalsList.innerHTML = withdrawals.length ? withdrawals.map(transaction => `
                 <tr>
                     <td>${transaction.id}</td>
                     <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
                     <td class="text-danger">¥${parseFloat(transaction.amount).toFixed(2)}</td>
+                    <td>${transaction.fee_rate ? transaction.fee_rate + '%' : '-'}</td>
+                    <td>${transaction.exchange_rate ? Number(transaction.exchange_rate).toFixed(4) : '-'}</td>
                     <td>${transaction.operator_id || '-'}</td>
                     <td>${transaction.replier_id || '-'}</td>
                 </tr>
-            `).join('') : '<tr><td colspan="5" class="text-center">暂无下发记录</td></tr>';
+            `).join('') : '<tr><td colspan="7" class="text-center">暂无下发记录</td></tr>';
         }
 
         // 更新分页

+ 1 - 1
admin/views/transactions.html

@@ -353,7 +353,7 @@
                     <td>${transaction.fee_rate ? parseFloat(transaction.fee_rate).toFixed(2) + '%' : '-'}</td>
                     <td>${transaction.exchange_rate ? parseFloat(transaction.exchange_rate).toFixed(4) : '-'}</td>
                     <td>
-                        <a href="https://t.me/c/${transaction.group_id}/${transaction.operator_id}" target="_blank" class="text-primary">
+                        <a href="https://t.me/${transaction.uid}" target="_blank" class="text-primary">
                             ${transaction.operator_name || '未知用户'}
                         </a>
                     </td>

+ 2 - 1
admin/数据文件路径

@@ -48,6 +48,7 @@
     "-4750899185",
     "-4666274251",
     "-4662817029",
-    "-4779509671"
+    "-4779509671",
+    "-4831663656"
   ]
 }