修改git

This commit is contained in:
liuxiaobo 2025-06-21 00:58:22 +08:00
parent f0de77bd10
commit 5758223b93
7 changed files with 259 additions and 1 deletions

@ -1 +0,0 @@
Subproject commit 314f58680be0d9ed55f1b0fe52234f16da93c7cd

View File

@ -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
}

View File

@ -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)
`
}

View File

@ -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)
`
}

24
common/model/user/user.go Normal file
View File

@ -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
}

View File

@ -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
`
}

View File

@ -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[资源名]增加值
}