From 5758223b93dc7e9760b5cd2d9e8893c6d796ae78 Mon Sep 17 00:00:00 2001 From: liuxiaobo <1224730913@qq.com> Date: Sat, 21 Jun 2025 00:58:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/model | 1 - common/model/jackpot/jackpot.go | 54 ++++++++++++++++++++++++++ common/model/user/logGameRecord.go | 43 +++++++++++++++++++++ common/model/user/logUserRecord.go | 35 +++++++++++++++++ common/model/user/user.go | 24 ++++++++++++ common/model/user/userAccount.go | 62 ++++++++++++++++++++++++++++++ common/model/user/userResources.go | 41 ++++++++++++++++++++ 7 files changed, 259 insertions(+), 1 deletion(-) delete mode 160000 common/model create mode 100644 common/model/jackpot/jackpot.go create mode 100644 common/model/user/logGameRecord.go create mode 100644 common/model/user/logUserRecord.go create mode 100644 common/model/user/user.go create mode 100644 common/model/user/userAccount.go create mode 100644 common/model/user/userResources.go diff --git a/common/model b/common/model deleted file mode 160000 index 314f586..0000000 --- a/common/model +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 314f58680be0d9ed55f1b0fe52234f16da93c7cd diff --git a/common/model/jackpot/jackpot.go b/common/model/jackpot/jackpot.go new file mode 100644 index 0000000..3b3badf --- /dev/null +++ b/common/model/jackpot/jackpot.go @@ -0,0 +1,54 @@ +package jackpot + +import ( + "context" + "fmt" + "github.com/go-redis/redis/v8" + "strconv" +) + +func JackpotSet(rdb *redis.Client, gameId int, chips int64) { + key := fmt.Sprintf("Jackpot:%d", gameId) + _, _ = rdb.Set(context.Background(), key, chips, 0).Result() +} + +func JackpotAdd(rdb *redis.Client, gameId int, chips int64) int64 { + key := fmt.Sprintf("Jackpot:%d", gameId) + v, _ := rdb.IncrBy(context.Background(), key, chips).Result() + return v +} + +func JackpotGet(rdb *redis.Client, gameId int) int64 { + key := fmt.Sprintf("Jackpot:%d", gameId) + jp := rdb.Get(context.Background(), key).Val() + result, _ := strconv.ParseInt(jp, 10, 64) + return result +} + +// jp系统池,玩家部分利润进入该池,重置jackpot池时,从这里扣除。系统池反映系统盈亏 +func JackpotSystemAdd(rdb *redis.Client, gameId int, chips int64) int64 { + key := fmt.Sprintf("JackpotSystem:%d", gameId) + value, _ := rdb.IncrBy(context.Background(), key, chips).Result() + return value +} + +func JackpotSystemGet(rdb *redis.Client, gameId int) int64 { + key := fmt.Sprintf("JackpotSystem:%d", gameId) + jp := rdb.Get(context.Background(), key).Val() + result, _ := strconv.ParseInt(jp, 10, 64) + return result +} + +// 玩家总赎回 +func JackpotUserRepaidAdd(rdb *redis.Client, gameId int, chips int64) int64 { + key := fmt.Sprintf("JackpotUserRepaid:%d", gameId) + value, _ := rdb.IncrBy(context.Background(), key, chips).Result() + return value +} + +// jp池重置次数 +func JackpotInitCountAdd(rdb *redis.Client, gameId int) int64 { + key := fmt.Sprintf("JackpotInitCount:%d", gameId) + count, _ := rdb.IncrBy(context.Background(), key, 1).Result() + return count +} diff --git a/common/model/user/logGameRecord.go b/common/model/user/logGameRecord.go new file mode 100644 index 0000000..3ac8a2e --- /dev/null +++ b/common/model/user/logGameRecord.go @@ -0,0 +1,43 @@ +package user + +import ( + "gorm.io/datatypes" + "time" +) + +type UserLog struct { + ID int64 `json:"id"` + Nickname string `json:"nickname"` // 昵称 + AvatarUrl string `json:"avatar_url"` // 头像 + AvatarFrame string `json:"avatar_frame"` // 头像框 + Gold int32 `json:"gold"` // 金币 +} + +type GameRecordLog struct { + GameNo string `gorm:"primaryKey;type:String" json:"game_no"` + GameId int32 `gorm:"type:Int32;default:0" json:"game_id"` + RoomId int32 `gorm:"type:Int32;default:0" json:"room_id"` + RoomType int32 `gorm:"type:Int32;default:0" json:"room_type"` + StartTime time.Time `gorm:"type:DateTime;default:now()" json:"start_time"` // 开始时间 + EndTime time.Time `gorm:"type:DateTime;default:now()" json:"end_time"` // 结束时间 + Users datatypes.JSONType[[]UserLog] `json:"users"` + UserTotalBet int64 `gorm:"type:Int64;default:0" json:"user_total_bet"` // 所有玩家总投注额 + UserTotalNetWin int64 `gorm:"type:Int64;default:0" json:"user_total_net_win"` // 所有玩家总净胜分 + TotalTax int64 `gorm:"type:Int64;default:0" json:"total_tax"` // 税 + GameData string `gorm:"type:String" json:"game_data"` // 游戏数据(JSON格式) +} + +func (u GameRecordLog) GetId() int64 { + return 0 +} + +func (u GameRecordLog) TableName() string { + return "game_record_log" +} + +func (u GameRecordLog) TableOptions() string { + return `ENGINE=MergeTree() + ORDER BY (game_no, game_id, room_type) + PARTITION BY toYYYYMM(start_time) + ` +} diff --git a/common/model/user/logUserRecord.go b/common/model/user/logUserRecord.go new file mode 100644 index 0000000..df401f6 --- /dev/null +++ b/common/model/user/logUserRecord.go @@ -0,0 +1,35 @@ +package user + +import ( + "gorm.io/datatypes" + "time" +) + +type UserRecordLog struct { + GameNo string `gorm:"primaryKey;type:String" json:"game_no"` + GameId int32 `gorm:"type:Int32;default:0" json:"game_id"` + RoomId int32 `gorm:"type:Int32;default:0" json:"room_id"` + RoomType int32 `gorm:"type:Int32;default:0" json:"room_type"` + StartTime time.Time `gorm:"type:DateTime;default:now()" json:"start_time"` // 开始时间 + EndTime time.Time `gorm:"type:DateTime;default:now()" json:"end_time"` // 结束时间 + Users datatypes.JSONType[UserLog] `json:"user"` + TotalBet int64 `gorm:"type:Int64;default:0" json:"total_bet"` // 玩家总投注额 + TotalNetWin int64 `gorm:"type:Int64;default:0" json:"total_net_win"` // 玩家总净胜分 + Tax int64 `gorm:"type:Int64;default:0" json:"tax"` // 税 + GameData string `gorm:"type:String" json:"game_data"` // 游戏数据(JSON格式) +} + +func (u UserRecordLog) GetId() int64 { + return 0 +} + +func (u UserRecordLog) TableName() string { + return "user_record_log" +} + +func (u UserRecordLog) TableOptions() string { + return `ENGINE=MergeTree() + ORDER BY (game_no, game_id, room_type) + PARTITION BY toYYYYMM(start_time) + ` +} diff --git a/common/model/user/user.go b/common/model/user/user.go new file mode 100644 index 0000000..f80ed5e --- /dev/null +++ b/common/model/user/user.go @@ -0,0 +1,24 @@ +package user + +// 玩家账户表 +type User struct { + ID int64 `gorm:"primarykey;autoIncrement" json:"id"` + AccountId int64 `gorm:"uniqueIndex;not null" json:"account_id"` // 帐号id + Nickname string `gorm:"type:varchar(32);uniqueIndex;not null" json:"nickname"` // 昵称 + AvatarUrl string `gorm:"type:varchar(255)" json:"avatar_url"` // 头像 + AvatarFrame string `gorm:"type:varchar(255)" json:"avatar_frame"` // 头像框 + VipExp int32 `gorm:"type:int" json:"vip_exp"` // vip经验值 +} + +func (u User) GetId() int64 { + return u.ID +} + +func (u User) TableName() string { + return "user" +} + +type GameUser struct { + User + UserResources +} diff --git a/common/model/user/userAccount.go b/common/model/user/userAccount.go new file mode 100644 index 0000000..c751f84 --- /dev/null +++ b/common/model/user/userAccount.go @@ -0,0 +1,62 @@ +package user + +import ( + "time" +) + +const ( + // AccountNormal = 1 // 正常 + AccountFrozen = 2 // 冻结 + AccountBanned = 3 // 封禁 +) + +// 玩家账户表 +type UserAccount struct { + ID int64 `gorm:"primarykey;autoIncrement" json:"id"` + Username string `gorm:"type:varchar(32);uniqueIndex;not null" json:"username"` // 用户名 + Password string `gorm:"type:varchar(255);not null" json:"password"` // 密码哈希 + Email string `gorm:"type:varchar(100)" json:"email"` // 邮箱(可选) + Phone string `gorm:"type:varchar(20)" json:"phone"` // 手机号(可选) + DeviceID string `gorm:"type:varchar(64);index" json:"device_id"` // 设备ID + LastLoginIP string `gorm:"type:varchar(45)" json:"last_login_ip"` // 最后登录IP(支持IPv6) + LastLoginTime time.Time `json:"last_login_time"` // 最后登录时间 + Status int `gorm:"type:tinyint;default:1" json:"status"` // 账号状态 1-正常 2-冻结 3-封禁 + RegisterIP string `gorm:"type:varchar(45)" json:"register_ip"` // 注册IP + RegisterTime time.Time `gorm:"type:TIMESTAMP;default:CURRENT_TIMESTAMP" json:"register_time"` // 注册时间 +} + +func (u UserAccount) GetId() int64 { + return u.ID +} + +func (u UserAccount) TableName() string { + return "user_account" +} + +// 玩家登录记录表 +type UserLoginLog struct { + AccountID int64 `gorm:"type:Int64;index" json:"account_id"` // 关联帐号ID + LoginIP string `gorm:"type:String;not null" json:"login_ip"` // 登录IP + LoginTime time.Time `gorm:"type:DateTime;default:now()" json:"login_time"` // 登录或登出时间 + IsLogin bool `gorm:"type:Int8" json:"is_login"` // 登录或登出 true-登录 false-登出 + DeviceInfo string `gorm:"type:String" json:"device_info"` // 设备信息(JSON格式) + LoginResult bool `gorm:"type:Int8" json:"login_result"` // 登录结果 true-成功 false-失败 + FailReason string `gorm:"type:String" json:"fail_reason"` // 失败原因 +} + +func (u UserLoginLog) GetId() int64 { + return 0 +} + +func (u UserLoginLog) TableName() string { + return "user_login_log" +} + +func (u UserLoginLog) TableOptions() string { + // "ENGINE=MergeTree() ORDER BY tuple()" + return `ENGINE=MergeTree() + ORDER BY (account_id, login_time) + PARTITION BY toYYYYMM(login_time) + TTL login_time + INTERVAL 6 MONTH + ` +} diff --git a/common/model/user/userResources.go b/common/model/user/userResources.go new file mode 100644 index 0000000..480f00f --- /dev/null +++ b/common/model/user/userResources.go @@ -0,0 +1,41 @@ +package user + +// 玩家账户表 +type UserResources struct { + UID int64 `gorm:"uniqueIndex" json:"uid"` + Gold int64 `gorm:"default:0" json:"gold"` // 金币 + Diamond int64 `gorm:"default:0" json:"diamond"` // 钻石 +} + +func (u UserResources) GetId() int64 { + return u.UID +} + +func (u UserResources) TableName() string { + return "user_resources" +} + +type UserResourcesLog struct { + UID int64 `gorm:"uniqueIndex" json:"uid"` + ResName string `gorm:"default:0" json:"res_name"` // 资源名 + ResAddValue int64 `gorm:"default:0" json:"res_value"` // 资源增加值 + ResAfterValue int64 `gorm:"default:0" json:"res_after_value"` // 资源增加后的值 + GameId int `gorm:"default:0" json:"game_id"` // 添加资源的玩法id,充值等非玩法操作资源,则为0 + GameNo string `json:"game_no"` // 游戏局id,同上 + Reason string `json:"reason"` // 原因 +} + +func (u UserResourcesLog) GetId() int64 { + return 0 +} + +func (u UserResourcesLog) TableName() string { + return "user_resources_log" +} + +type AddUserRes struct { + GameId int `json:"game_id"` // 添加资源的玩法id,充值等非玩法操作资源,则为0 + GameNo string `json:"game_no"` // 游戏局id,同上 + Reason string `json:"reason"` // 原因 + AddRes map[string]int64 `json:"add_res"` // map[资源名]增加值 +}