bindbox-game/scripts/check_duplicates.go
2026-01-27 01:33:32 +08:00

59 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
func main() {
dsn := "root:bindbox2025kdy@tcp(150.158.78.154:3306)/bindbox_game"
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatal(err)
}
defer db.Close()
// 1. 检查直播间抽奖是否有重复 (Draw Count > Product Count)
// 注意shop_order_id 是字符串join 时注意字符集,不过这里都是 utf8mb4 应该没问题
query := `
SELECT
o.shop_order_id,
o.product_count,
COUNT(l.id) as draw_count,
o.user_nickname
FROM douyin_orders o
JOIN livestream_draw_logs l ON CONVERT(o.shop_order_id USING utf8mb4) = CONVERT(l.shop_order_id USING utf8mb4)
GROUP BY o.shop_order_id, o.product_count, o.user_nickname
HAVING draw_count > o.product_count
`
rows, err := db.Query(query)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
fmt.Println("--- Duplicate Rewards Check (Livestream) ---")
found := false
for rows.Next() {
var orderID, nickname string
var pCount, dCount int
if err := rows.Scan(&orderID, &pCount, &dCount, &nickname); err != nil {
log.Fatal(err)
}
fmt.Printf("Order: %s | Nickname: %s | Bought: %d | Issued: %d\n", orderID, nickname, pCount, dCount)
found = true
}
if !found {
fmt.Println("No duplicate rewards found in livestream_draw_logs.")
}
// 2. 额外检查:是否有同一个 shop_order_id 在极短时间内产生多条 log (并发问题特质)
// 这里简单检查是否有完全重复的 log (除了主键不同,其他关键字段相同)
// 或者检查是否有订单在非直播抽奖表也发了奖 (如果两边系统混用)
}