You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
// 选择有收藏产品的用户并重置同步状态
|
|
const mysql = require('mysql2/promise');
|
|
const config = require('./src/config/config');
|
|
|
|
async function resetSyncStatus() {
|
|
console.log('===== 重置有收藏产品用户的同步状态 =====');
|
|
|
|
try {
|
|
// 连接数据库
|
|
const connection = await mysql.createConnection(config.db);
|
|
console.log('数据库连接成功');
|
|
|
|
// 查询有收藏产品的用户
|
|
const [usersWithFavorites] = await connection.execute(
|
|
'SELECT DISTINCT u.id, u.userId, u.phoneNumber FROM users u INNER JOIN favorites f ON u.phoneNumber = f.user_phone LIMIT 1'
|
|
);
|
|
|
|
if (usersWithFavorites.length === 0) {
|
|
console.log('没有找到有收藏产品的用户');
|
|
await connection.end();
|
|
return;
|
|
}
|
|
|
|
const testUser = usersWithFavorites[0];
|
|
const phoneNumber = testUser.phoneNumber;
|
|
const userId = testUser.userId;
|
|
|
|
console.log('选择测试用户:', JSON.stringify(testUser));
|
|
|
|
// 重置同步状态
|
|
await connection.execute(
|
|
'UPDATE users SET sync_statuss = 0 WHERE phoneNumber = ?',
|
|
[phoneNumber]
|
|
);
|
|
|
|
console.log(`已将用户 ${phoneNumber} 的同步状态重置为未同步`);
|
|
|
|
// 验证重置结果
|
|
const [updatedUser] = await connection.execute(
|
|
'SELECT id, userId, phoneNumber, sync_statuss FROM users WHERE phoneNumber = ?',
|
|
[phoneNumber]
|
|
);
|
|
|
|
if (updatedUser.length > 0) {
|
|
console.log('重置后的用户状态:', updatedUser[0]);
|
|
}
|
|
|
|
await connection.end();
|
|
console.log('\n✅ 操作完成!');
|
|
|
|
} catch (error) {
|
|
console.error('操作过程中发生错误:', error.message);
|
|
if (error.sql) {
|
|
console.error('SQL语句:', error.sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 执行操作
|
|
resetSyncStatus().catch(error => {
|
|
console.error('操作执行失败:', error.message);
|
|
process.exit(1);
|
|
});
|
|
|