33 lines
804 B
Go
33 lines
804 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"gorm.io/driver/mysql"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const (
|
|
DbDSN = "root:bindbox2025kdy@tcp(150.158.78.154:3306)/dev_game?charset=utf8mb4&parseTime=True&loc=Local"
|
|
)
|
|
|
|
func main() {
|
|
db, err := gorm.Open(mysql.Open(DbDSN), &gorm.Config{})
|
|
if err != nil {
|
|
log.Fatalf("DB connection failed: %v", err)
|
|
}
|
|
|
|
userID := 9090
|
|
var userCoupons []map[string]interface{}
|
|
db.Table("user_coupons").Where("user_id = ?", userID).Order("id DESC").Find(&userCoupons)
|
|
|
|
fmt.Printf("--- All Coupons for User %d ---\n", userID)
|
|
for _, uc := range userCoupons {
|
|
var sc map[string]interface{}
|
|
db.Table("system_coupons").Where("id = ?", uc["coupon_id"]).First(&sc)
|
|
fmt.Printf("ID: %v, Name: %v, Status: %v, ValidEnd: %v\n",
|
|
uc["id"], sc["name"], uc["status"], uc["valid_end"])
|
|
}
|
|
}
|