74 lines
1.8 KiB
Go
74 lines
1.8 KiB
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)
|
|
}
|
|
|
|
orderID := 4695
|
|
fmt.Printf("--- Inspecting Order %d ---\n", orderID)
|
|
|
|
type Order struct {
|
|
ID int64
|
|
OrderNo string
|
|
ActualAmount int64
|
|
DiscountAmount int64
|
|
Remark string
|
|
}
|
|
var order Order
|
|
err = db.Table("orders").Where("id = ?", orderID).First(&order).Error
|
|
if err != nil {
|
|
log.Fatalf("Order not found: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Order No: %s\n", order.OrderNo)
|
|
fmt.Printf("Actual Pay: %d cents\n", order.ActualAmount)
|
|
fmt.Printf("Discount: %d cents\n", order.DiscountAmount)
|
|
fmt.Printf("Remark: %s\n", order.Remark)
|
|
|
|
total := order.ActualAmount + order.DiscountAmount
|
|
fmt.Printf("Total implied: %d cents\n", total)
|
|
|
|
var logs []map[string]interface{}
|
|
db.Table("activity_draw_logs").
|
|
Select("activity_draw_logs.*, products.price as product_price").
|
|
Joins("JOIN activity_reward_settings ON activity_reward_settings.id = activity_draw_logs.reward_id").
|
|
Joins("JOIN products ON products.id = activity_reward_settings.product_id").
|
|
Where("order_id = ?", orderID).
|
|
Scan(&logs)
|
|
|
|
fmt.Printf("Draw Logs Found: %d\n", len(logs))
|
|
var sumPrice int64
|
|
for i, l := range logs {
|
|
var price int64
|
|
// Extract price carefully
|
|
switch p := l["product_price"].(type) {
|
|
case int64:
|
|
price = p
|
|
case int32:
|
|
price = int64(p)
|
|
case float64:
|
|
price = int64(p)
|
|
default:
|
|
fmt.Printf(" Item %d: Unknown price type %T\n", i, p)
|
|
}
|
|
|
|
sumPrice += price
|
|
fmt.Printf(" Item %d: Price=%v (parsed: %d)\n", i, l["product_price"], price)
|
|
}
|
|
fmt.Printf("Sum of Products: %d cents\n", sumPrice)
|
|
}
|