package main import ( "fmt" "time" "gorm.io/driver/mysql" "gorm.io/gorm" ) // 简单的 struct 映射 type Orders struct { ID int64 OrderNo string SourceType int32 Status int32 Remark string UserID int64 TotalAmount int64 ActualAmount int64 CreatedAt time.Time } type IssuePositionClaims struct { ID int64 IssueID int64 SlotIndex int64 OrderID int64 UserID int64 } // 表名映射 func (Orders) TableName() string { return "orders" } func (IssuePositionClaims) TableName() string { return "issue_position_claims" } func main() { // 尝试使用 config 中的密码 dsn := "root:api2api..@tcp(sh-cynosdbmysql-grp-88th45wy.sql.tencentcdb.com:28555)/bindbox_game?charset=utf8mb4&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil { panic("failed to connect database: " + err.Error()) } targetOrderNo := "O20260107092217073" var order Orders if err := db.Where("order_no = ?", targetOrderNo).First(&order).Error; err != nil { fmt.Printf("Error finding order: %v\n", err) return } fmt.Printf("========== Order Info ==========\n") fmt.Printf("ID: %d\n", order.ID) fmt.Printf("OrderNo: %s\n", order.OrderNo) fmt.Printf("UserID: %d\n", order.UserID) fmt.Printf("SourceType: %d\n", order.SourceType) fmt.Printf("Status: %d (2=Paid)\n", order.Status) fmt.Printf("Amount: Total=%d, Actual=%d\n", order.TotalAmount, order.ActualAmount) fmt.Printf("Remark Length: %d\n", len(order.Remark)) fmt.Printf("Remark Content: %s\n", order.Remark) fmt.Printf("================================\n") var claims []IssuePositionClaims if err := db.Where("order_id = ?", order.ID).Find(&claims).Error; err != nil { fmt.Printf("Error checking claims: %v\n", err) } fmt.Printf("========== Claims Info ==========\n") fmt.Printf("Claims Count: %d\n", len(claims)) for _, c := range claims { fmt.Printf("- Claim: SlotIndex=%d IssueID=%d\n", c.SlotIndex, c.IssueID) } fmt.Printf("=================================\n") }