spark-server/internal/module/energy/model/rows.go
DESKTOP-L8OUL9F\gfl0034 753c276496 feat: PopAdmin 拉取管理、签到能量 API 与图片 150KiB 硬上限
管理端按用户查询开启通讯录/相册/媒体拉取;服务端写入路径自动压图;新增 /v1/sign 与 /v1/energy。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-02 12:44:06 +08:00

68 lines
2.0 KiB
Go

package model
import (
"time"
"spark-server/internal/module/energy/entity"
)
// WalletRow maps t_user_wallets.
type WalletRow struct {
UserID int64 `gorm:"column:user_id;primaryKey"`
Energy int64 `gorm:"column:energy"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
func (WalletRow) TableName() string { return "t_user_wallets" }
func (r WalletRow) Entity() *entity.Wallet {
return &entity.Wallet{UserID: r.UserID, Energy: r.Energy, UpdatedMS: r.UpdatedAt.UnixMilli()}
}
// SignRow maps t_sign_records.
type SignRow struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement"`
UserID int64 `gorm:"column:user_id"`
DayKey int `gorm:"column:day_key"`
Kind int16 `gorm:"column:kind"`
Reward int `gorm:"column:reward"`
CreatedAt time.Time `gorm:"column:created_at"`
}
func (SignRow) TableName() string { return "t_sign_records" }
func (r SignRow) Entity() *entity.SignRecord {
return &entity.SignRecord{
ID: r.ID, UserID: r.UserID, DayKey: r.DayKey, Kind: r.Kind,
Reward: r.Reward, CreatedMS: r.CreatedAt.UnixMilli(),
}
}
func signFromEntity(e *entity.SignRecord) *SignRow {
return &SignRow{
ID: e.ID, UserID: e.UserID, DayKey: e.DayKey, Kind: e.Kind, Reward: e.Reward,
CreatedAt: time.UnixMilli(e.CreatedMS),
}
}
// EnergyLogRow maps t_energy_logs.
type EnergyLogRow struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement"`
UserID int64 `gorm:"column:user_id"`
Delta int64 `gorm:"column:delta"`
BalanceAfter int64 `gorm:"column:balance_after"`
Reason string `gorm:"column:reason"`
DayKey int `gorm:"column:day_key"`
Source string `gorm:"column:source"`
CreatedAt time.Time `gorm:"column:created_at"`
}
func (EnergyLogRow) TableName() string { return "t_energy_logs" }
func (r EnergyLogRow) Entity() *entity.EnergyLog {
return &entity.EnergyLog{
ID: r.ID, UserID: r.UserID, Delta: r.Delta, BalanceAfter: r.BalanceAfter,
Reason: r.Reason, DayKey: r.DayKey, Source: r.Source, CreatedMS: r.CreatedAt.UnixMilli(),
}
}