Commit fbe6e0e97576a871b434dfa9c88d94ee66e486b5
1 parent
f3ea92d1
Exists in
master
and in
1 other branch
refactor♻️:项目目录重构
Showing
27 changed files
with
604 additions
and
611 deletions
Show diff stats
README.md
api-common/config/api.go
| ... | ... | @@ -1,209 +0,0 @@ |
| 1 | -package config | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/util/util-lx/lxalilog" | |
| 5 | - "apigame/util/util-lx/lxconv" | |
| 6 | - "apigame/util/util-lx/lxmysql" | |
| 7 | - "encoding/json" | |
| 8 | - "errors" | |
| 9 | - "fmt" | |
| 10 | -) | |
| 11 | - | |
| 12 | -type MApiGameConfig struct { | |
| 13 | - AppID string `json:"appid"` | |
| 14 | - Secret string `json:"secret"` | |
| 15 | - Appkey string `json:"appkey"` | |
| 16 | - Name string `json:"name"` | |
| 17 | -} | |
| 18 | - | |
| 19 | -// GetApiGameConfig 获取游戏配置文件 | |
| 20 | -func GetApiGameConfig(gameid string) (data MApiGameConfig, err error) { | |
| 21 | - | |
| 22 | - config := lxmysql.QueryCacheConfig{ | |
| 23 | - SQL: fmt.Sprintf("select appid,secret,appkey,name from s_game_config where isdel=0 and status=1 and gameid='%s' order by id desc limit 1", gameid), | |
| 24 | - DBIndex: CONST_APIDBINDEX, | |
| 25 | - Exexpire: CONST_CACHETIME, | |
| 26 | - } | |
| 27 | - | |
| 28 | - var datas []MApiGameConfig | |
| 29 | - | |
| 30 | - err = lxmysql.QueryWithCache(config, &datas) | |
| 31 | - if err != nil { | |
| 32 | - lxalilog.Errors(err, lxconv.JsonEncode(config)) | |
| 33 | - return | |
| 34 | - } | |
| 35 | - | |
| 36 | - if len(datas) < 1 { | |
| 37 | - err = errors.New("no rows") | |
| 38 | - lxalilog.Errors(err) | |
| 39 | - return | |
| 40 | - } | |
| 41 | - | |
| 42 | - data = datas[0] | |
| 43 | - | |
| 44 | - return | |
| 45 | -} | |
| 46 | - | |
| 47 | -type MApiServerConfig struct { | |
| 48 | - Egift MApiServerEgift `json:"egift"` //无尽轮换 | |
| 49 | - Membership []Membership `json:"membership"` //周卡 月卡 | |
| 50 | - Novicegift Novicegift `json:"novicegift"` // 新手礼包 | |
| 51 | - PassCheck []PassCheck `json:"pass_check"` //通行证 | |
| 52 | - Qixi QixiConfig `json:"qixi"` //七夕活动 | |
| 53 | - Thinkingdata ThinkingdataConfig `json:"thinkingdata"` //数数配置 | |
| 54 | -} | |
| 55 | - | |
| 56 | -// --------------------------- 无尽轮换礼包配置表 --------------------------- | |
| 57 | - | |
| 58 | -// MApiServerEgift 无尽轮换礼包配置表 | |
| 59 | -type MApiServerEgift struct { | |
| 60 | - Config []MApiServerEgiftConfig `json:"config"` | |
| 61 | - ListLength string `json:"list_length"` | |
| 62 | - Days string `json:"days"` | |
| 63 | - Date string `json:"date"` | |
| 64 | -} | |
| 65 | - | |
| 66 | -type MApiServerEgiftConfig struct { | |
| 67 | - ID string `json:"id"` | |
| 68 | - Award string `json:"award"` | |
| 69 | - Type string `json:"type"` | |
| 70 | - ShopID string `json:"shop_id"` | |
| 71 | - GroupID string `json:"group_id,omitempty"` | |
| 72 | -} | |
| 73 | - | |
| 74 | -// --------------------------- 无尽轮换礼包配置表 --------------------------- | |
| 75 | - | |
| 76 | -// --------------------------- 周卡 月卡 配置 --------------------------- | |
| 77 | - | |
| 78 | -type Membership struct { | |
| 79 | - Name string `json:"name"` // 模式名称 | |
| 80 | - Days string `json:"days"` // 第几天 | |
| 81 | - Goodid string `json:"goodid"` // 商品ID | |
| 82 | - Award string `json:"award"` // 奖励 | |
| 83 | - Naturalday string `json:"naturalday"` // 是否自然日 | |
| 84 | -} | |
| 85 | - | |
| 86 | -// --------------------------- 周卡 月卡 配置 --------------------------- | |
| 87 | - | |
| 88 | -// --------------------------- 新手 配置 --------------------------- | |
| 89 | - | |
| 90 | -type Novicegift struct { | |
| 91 | - Goodid string `json:"goodid"` // 商品ID | |
| 92 | - List []struct { | |
| 93 | - Days string `json:"days"` // 第几天 | |
| 94 | - Award string `json:"award"` // 奖励 | |
| 95 | - } `json:"list"` | |
| 96 | -} | |
| 97 | - | |
| 98 | -// --------------------------- 新手礼包 配置 --------------------------- | |
| 99 | - | |
| 100 | -type PassCheck struct { | |
| 101 | - ID string `json:"ID"` | |
| 102 | - Level string `json:"Level"` | |
| 103 | - GroupId string `json:"GroupId"` | |
| 104 | - GoodId string `json:"GoodId"` | |
| 105 | - Experience string `json:"Experience"` | |
| 106 | - AwardFree string `json:"AwardFree"` | |
| 107 | - AwardPay string `json:"AwardPay"` | |
| 108 | - DrawTime int64 `json:"DrawTime"` | |
| 109 | -} | |
| 110 | - | |
| 111 | -// --------------------------- 七夕活动 --------------------------- | |
| 112 | - | |
| 113 | -type QixiConfig struct { | |
| 114 | - ActivityId string `json:"activity_id"` | |
| 115 | - StartTime int64 `json:"start_time"` | |
| 116 | - EndTime int64 `json:"end_time"` | |
| 117 | - Awards []QixiConfigAwards `json:"awards"` | |
| 118 | - FalseProgress []QixiConfigFalseProgress `json:"false_progress"` | |
| 119 | - Mail QixiConfigMail `json:"mail"` | |
| 120 | - RankConfig QixiConfigRankConfig `json:"rank_config"` | |
| 121 | - AlilogName string `json:"alilog_name"` | |
| 122 | - AddMax int64 `json:"add_max"` | |
| 123 | -} | |
| 124 | - | |
| 125 | -type QixiConfigFalseProgress struct { | |
| 126 | - Day string `json:"day"` | |
| 127 | - Time string `json:"time"` | |
| 128 | - ChangeLowest string `json:"change_lowest"` | |
| 129 | - ChangeHighest string `json:"change_highest"` | |
| 130 | - Must string `json:"must"` | |
| 131 | -} | |
| 132 | - | |
| 133 | -type QixiConfigAwards struct { | |
| 134 | - Point string `json:"point"` | |
| 135 | - AwardType string `json:"award_type"` | |
| 136 | - AwardNumber string `json:"award_number"` | |
| 137 | - LowLimit string `json:"low_limit"` | |
| 138 | - HighLimit string `json:"high_limit"` | |
| 139 | -} | |
| 140 | - | |
| 141 | -type QixiConfigMail struct { | |
| 142 | - Title string `json:"title"` | |
| 143 | - Sender string `json:"sender"` | |
| 144 | - Content string `json:"content"` | |
| 145 | - Ex int64 `json:"ex"` | |
| 146 | -} | |
| 147 | - | |
| 148 | -type QixiConfigRankConfig struct { | |
| 149 | - MinPoint int64 `json:"min_point"` | |
| 150 | -} | |
| 151 | - | |
| 152 | -// --------------------------- 七夕活动 --------------------------- | |
| 153 | - | |
| 154 | -// --------------------------- 数数配置 --------------------------- | |
| 155 | - | |
| 156 | -type ThinkingdataConfig struct { | |
| 157 | - Appid string `json:"appid"` | |
| 158 | - Id int `json:"id"` | |
| 159 | - Swich struct { | |
| 160 | - Engine int `json:"engine"` | |
| 161 | - Order int `json:"order"` | |
| 162 | - Pass int `json:"pass"` | |
| 163 | - Recharge int `json:"recharge"` // 累计充值 开启 | |
| 164 | - } `json:"switch"` | |
| 165 | -} | |
| 166 | - | |
| 167 | -// --------------------------- 数数配置 --------------------------- | |
| 168 | - | |
| 169 | -// GetApiServerConfig 获取游服务端置文件 | |
| 170 | -func GetApiServerConfig(gameid string, dbindex ...string) (data MApiServerConfig, content string, err error) { | |
| 171 | - | |
| 172 | - var dindex = CONST_APIDBINDEX | |
| 173 | - if len(dbindex) > 0 { | |
| 174 | - dindex = dbindex[0] | |
| 175 | - } | |
| 176 | - | |
| 177 | - config := lxmysql.QueryCacheConfig{ | |
| 178 | - SQL: fmt.Sprintf("select * from s_server_config where gameid='%s' limit 1", gameid), | |
| 179 | - DBIndex: dindex, | |
| 180 | - Exexpire: CONST_CACHETIME, | |
| 181 | - } | |
| 182 | - | |
| 183 | - var datas []struct { | |
| 184 | - Content string `json:"content"` | |
| 185 | - } | |
| 186 | - | |
| 187 | - err = lxmysql.QueryWithCache(config, &datas) | |
| 188 | - if err != nil { | |
| 189 | - lxalilog.Errors(err, lxconv.JsonEncode(config)) | |
| 190 | - return | |
| 191 | - } | |
| 192 | - | |
| 193 | - if len(datas) < 1 { | |
| 194 | - err = errors.New("no rows") | |
| 195 | - lxalilog.Errors(err) | |
| 196 | - return | |
| 197 | - } | |
| 198 | - | |
| 199 | - if datas[0].Content == "" { | |
| 200 | - err = errors.New("content nil") | |
| 201 | - lxalilog.Errors(err) | |
| 202 | - } | |
| 203 | - | |
| 204 | - content = datas[0].Content | |
| 205 | - | |
| 206 | - _ = json.Unmarshal([]byte(content), &data) | |
| 207 | - | |
| 208 | - return | |
| 209 | -} |
api-common/config/const.go
common/svconfig/index.go
common/svconfig/interface.go
| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | -package svconfig | |
| 2 | - | |
| 3 | -import "gorm.io/gorm" | |
| 4 | - | |
| 5 | -const ( | |
| 6 | - MYSQL_TABLE_TEMPLATE = "all_table_template" // 表名模板 | |
| 7 | - REDIS_CACHEP_REFIX = "apigame" // 缓存前缀 | |
| 8 | -) | |
| 9 | - | |
| 10 | -// ConfigRule 配置数据 | |
| 11 | -type ConfigRule struct { | |
| 12 | - DbMysql *gorm.DB | |
| 13 | - TableNameTemplate string | |
| 14 | - TableName string | |
| 15 | - CacheKey string | |
| 16 | - CacheTime int | |
| 17 | -} | |
| 18 | - | |
| 19 | -// IConfigRule 配置数据 | |
| 20 | -type IConfigRule interface { | |
| 21 | - // GetRule 表名模板 | |
| 22 | - GetRule(gameId string) *ConfigRule | |
| 23 | -} |
common/svconst/vars.go
common/svdto/dto.go
| ... | ... | @@ -3,16 +3,16 @@ package svdto |
| 3 | 3 | import ( |
| 4 | 4 | "apigame/util/utdto" |
| 5 | 5 | "apigame/util/util-lx/lxalilog" |
| 6 | - "gorm.io/gorm" | |
| 7 | 6 | ) |
| 8 | 7 | |
| 9 | -func InitTable(db *gorm.DB, tb IDtoData, gameId string) { | |
| 10 | - tableName := tb.GetTableName(gameId) | |
| 11 | - utdto.InitTable(db, tb, tableName) | |
| 8 | +func InitTable(tb IDtoData, gameId string) { | |
| 9 | + rule := tb.GetRule(gameId) | |
| 10 | + utdto.InitTable(rule.DbMysql, tb, rule.TableName) | |
| 12 | 11 | } |
| 13 | 12 | |
| 14 | -func Insert(db *gorm.DB, data IDtoData, gameId string) (err error) { | |
| 15 | - result := utdto.Insert(db, data, data.GetTableName(gameId)) | |
| 13 | +func Insert(data IDtoData, gameId string) (err error) { | |
| 14 | + rule := data.GetRule(gameId) | |
| 15 | + result := utdto.Insert(rule.DbMysql, data, rule.TableName) | |
| 16 | 16 | err = result.Error |
| 17 | 17 | if err != nil { |
| 18 | 18 | lxalilog.Errors(err, gameId) |
| ... | ... | @@ -21,8 +21,9 @@ func Insert(db *gorm.DB, data IDtoData, gameId string) (err error) { |
| 21 | 21 | return |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -func Update(db *gorm.DB, data IDtoData, gameId string) (err error) { | |
| 25 | - result := utdto.Update(db, data, data.GetTableName(gameId)) | |
| 24 | +func Update(data IDtoData, gameId string) (err error) { | |
| 25 | + rule := data.GetRule(gameId) | |
| 26 | + result := utdto.Update(rule.DbMysql, data, rule.TableName) | |
| 26 | 27 | err = result.Error |
| 27 | 28 | if err != nil { |
| 28 | 29 | lxalilog.Errors(err, gameId) |
| ... | ... | @@ -31,8 +32,9 @@ func Update(db *gorm.DB, data IDtoData, gameId string) (err error) { |
| 31 | 32 | return |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | -func Save(db *gorm.DB, data IDtoData, gameId string) (err error) { | |
| 35 | - result := utdto.Save(db, data, data.GetTableName(gameId)) | |
| 35 | +func Save(data IDtoData, gameId string) (err error) { | |
| 36 | + rule := data.GetRule(gameId) | |
| 37 | + result := utdto.Save(rule.DbMysql, data, rule.TableName) | |
| 36 | 38 | err = result.Error |
| 37 | 39 | if err != nil { |
| 38 | 40 | lxalilog.Errors(err, gameId) |
| ... | ... | @@ -41,8 +43,9 @@ func Save(db *gorm.DB, data IDtoData, gameId string) (err error) { |
| 41 | 43 | return |
| 42 | 44 | } |
| 43 | 45 | |
| 44 | -func First(db *gorm.DB, data IDtoData, gameId string) (has bool, err error) { | |
| 45 | - result := utdto.First(db, data, data.GetTableName(gameId)) | |
| 46 | +func First(data IDtoData, gameId string) (has bool, err error) { | |
| 47 | + rule := data.GetRule(gameId) | |
| 48 | + result := utdto.First(rule.DbMysql, data, rule.TableName) | |
| 46 | 49 | has = result.RowsAffected != 0 |
| 47 | 50 | err = result.Error |
| 48 | 51 | if err != nil { |
| ... | ... | @@ -52,12 +55,13 @@ func First(db *gorm.DB, data IDtoData, gameId string) (has bool, err error) { |
| 52 | 55 | return |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | -func Find(db *gorm.DB, data any, tableName string) (has bool, err error) { | |
| 56 | - result := utdto.Find(db, data, tableName) | |
| 58 | +func Find(data any, dataTemp IDtoData, gameId string) (has bool, err error) { | |
| 59 | + rule := dataTemp.GetRule(gameId) | |
| 60 | + result := utdto.Find(rule.DbMysql, data, rule.TableName) | |
| 57 | 61 | has = result.RowsAffected != 0 |
| 58 | 62 | err = result.Error |
| 59 | 63 | if err != nil { |
| 60 | - lxalilog.Errors(err, tableName) | |
| 64 | + lxalilog.Errors(err, rule.TableName) | |
| 61 | 65 | return |
| 62 | 66 | } |
| 63 | 67 | return | ... | ... |
common/svdto/init.go
| 1 | 1 | package svdto |
| 2 | 2 | |
| 3 | -import ( | |
| 4 | - "apigame/common/svconst" | |
| 5 | - "apigame/dto" | |
| 6 | - "apigame/service/constd" | |
| 7 | -) | |
| 8 | - | |
| 9 | -func Init() { | |
| 10 | - | |
| 11 | - // create table | |
| 12 | - // 卡牌卡包 | |
| 13 | - for _, gameId := range constd.GameListCardHolder { | |
| 14 | - InitTable(svconst.DbCommon, new(dto.CardHolderData), gameId) | |
| 15 | - InitTable(svconst.DbCommon, new(dto.CardHolderRecordOpen), gameId) | |
| 16 | - InitTable(svconst.DbCommon, new(dto.CardHolderRecordRewardAlbum), gameId) | |
| 17 | - InitTable(svconst.DbCommon, new(dto.CardHolderRecordRewardRound), gameId) | |
| 18 | - } | |
| 19 | - | |
| 20 | -} | ... | ... |
common/svdto/interface.go
| 1 | 1 | package svdto |
| 2 | 2 | |
| 3 | +import "gorm.io/gorm" | |
| 4 | + | |
| 5 | +const ( | |
| 6 | + REDIS_CACHEP_REFIX = "apigame" // 缓存前缀 | |
| 7 | +) | |
| 8 | + | |
| 9 | +// DtoRule dto参数 | |
| 10 | +type DtoRule struct { | |
| 11 | + DbMysql *gorm.DB | |
| 12 | + TableName string | |
| 13 | + CacheKey string | |
| 14 | + CacheTime int | |
| 15 | +} | |
| 16 | + | |
| 3 | 17 | // IDtoData dto数据 |
| 4 | 18 | type IDtoData interface { |
| 5 | 19 | // TableName 表名模板 |
| 6 | 20 | TableName() string |
| 7 | - // GetTableName 表名 后缀是 gameId | |
| 8 | - GetTableName(gameId string) string | |
| 21 | + // GetRule 表名模板 | |
| 22 | + GetRule(gameId string) *DtoRule | |
| 9 | 23 | } | ... | ... |
common/svdto/record.go
| 1 | 1 | package svdto |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | - "apigame/common/svconst" | |
| 5 | 4 | "apigame/util/utdto" |
| 6 | 5 | ) |
| 7 | 6 | |
| 8 | 7 | func SaveRecord(gameId string, data IDtoData) { |
| 9 | - utdto.Insert(svconst.DbCommon, data, data.GetTableName(gameId)) | |
| 8 | + rule := data.GetRule(gameId) | |
| 9 | + utdto.Insert(rule.DbMysql, data, rule.TableName) | |
| 10 | 10 | } | ... | ... |
configs/api.go
| ... | ... | @@ -1,39 +0,0 @@ |
| 1 | -package configs | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/common/svconfig" | |
| 5 | - "apigame/common/svconst" | |
| 6 | - "apigame/service/constd" | |
| 7 | - "fmt" | |
| 8 | -) | |
| 9 | - | |
| 10 | -type ApiGameConfig struct { | |
| 11 | - AppId string `json:"appid"` | |
| 12 | - GameId string `json:"gameid"` | |
| 13 | - Secret string `json:"secret"` | |
| 14 | - AppKey string `json:"appkey"` | |
| 15 | - Name string `json:"name"` | |
| 16 | -} | |
| 17 | - | |
| 18 | -func (c *ApiGameConfig) GetRule(gameId string) *svconfig.ConfigRule { | |
| 19 | - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG | |
| 20 | - return &svconfig.ConfigRule{ | |
| 21 | - DbMysql: svconst.DbApi, | |
| 22 | - TableNameTemplate: svconfig.MYSQL_TABLE_TEMPLATE, | |
| 23 | - TableName: tableName + gameId, | |
| 24 | - CacheKey: fmt.Sprintf("%s::%s::%s", svconfig.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 25 | - CacheTime: 300, | |
| 26 | - } | |
| 27 | -} | |
| 28 | - | |
| 29 | -func (c *ApiGameConfig) ReadFromMysql(gameId string) *ApiGameConfig { | |
| 30 | - //rule := c.GetRule(gameId) | |
| 31 | - | |
| 32 | - return &ApiGameConfig{} | |
| 33 | -} | |
| 34 | - | |
| 35 | -func GetApiGameConfig(gameId string) (config *ApiGameConfig, err error) { | |
| 36 | - //rds := zredis.GetConn() | |
| 37 | - //zredis.HGetData(rds, player) | |
| 38 | - return | |
| 39 | -} |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +package configs | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/common/svconst" | |
| 5 | + "apigame/common/svdto" | |
| 6 | + "apigame/util/utdto" | |
| 7 | + "fmt" | |
| 8 | +) | |
| 9 | + | |
| 10 | +type ApiGameConfig struct { | |
| 11 | + AppId string `gorm:"column:appid"` | |
| 12 | + GameId string `gorm:"column:gameid"` | |
| 13 | + Secret string `gorm:"column:secret"` | |
| 14 | + AppKey string `gorm:"column:appkey"` | |
| 15 | + Name string `gorm:"column:name"` | |
| 16 | +} | |
| 17 | + | |
| 18 | +func (c *ApiGameConfig) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } | |
| 19 | + | |
| 20 | +func (c *ApiGameConfig) GetRule(gameId string) *svdto.DtoRule { | |
| 21 | + tableName := "s_game_config" | |
| 22 | + return &svdto.DtoRule{ | |
| 23 | + DbMysql: svconst.DbApi.Where("gameid = ?", gameId), | |
| 24 | + TableName: tableName, | |
| 25 | + CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 26 | + CacheTime: 300, | |
| 27 | + } | |
| 28 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,124 @@ |
| 1 | +package configs | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/common/svconst" | |
| 5 | + "apigame/common/svdto" | |
| 6 | + "apigame/service/constd" | |
| 7 | + "apigame/util/utdto" | |
| 8 | + "fmt" | |
| 9 | +) | |
| 10 | + | |
| 11 | +// CardActivityConfig 卡牌活动配置 分析后数据 | |
| 12 | +type CardActivityConfig struct { | |
| 13 | + Raw *CardActivityConfigRaw | |
| 14 | + Client *CardActivityConfigClient | |
| 15 | + GameId string // 所属游戏ID | |
| 16 | + Id int64 // ID | |
| 17 | + Awards map[string]string // 奖励配置 | |
| 18 | + AlbumConfig map[int]AlbumConfig // 卡组配置 | |
| 19 | + CardConfig map[int]CardConfig // 卡牌配置 | |
| 20 | + CardholderConfig map[string]OpenCardholderConfig // 卡包开卡规则 | |
| 21 | + NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 | |
| 22 | + CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 | |
| 23 | + StarShopConfig map[int]StarShopConfig // 星星商店配置 | |
| 24 | +} | |
| 25 | + | |
| 26 | +func (c *CardActivityConfigRaw) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } | |
| 27 | + | |
| 28 | +func (d *CardActivityConfigRaw) GetRule(gameId string) *svdto.DtoRule { | |
| 29 | + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG | |
| 30 | + return &svdto.DtoRule{ | |
| 31 | + DbMysql: svconst.DbConfig, | |
| 32 | + TableName: tableName + gameId, | |
| 33 | + CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 34 | + CacheTime: 300, | |
| 35 | + } | |
| 36 | +} | |
| 37 | + | |
| 38 | +// CardActivityConfigRaw 卡牌活动配置 原始数据 | |
| 39 | +type CardActivityConfigRaw struct { | |
| 40 | + Id int64 // ID | |
| 41 | + OpenLevel int // 开启等级 | |
| 42 | + PreviewTime int64 // 预告时间 | |
| 43 | + StartTime int64 // 开始时间 | |
| 44 | + EndTime int64 // 结束时间 | |
| 45 | + Round int // 轮数 | |
| 46 | + Awards string `json:"-"` // 奖励配置 | |
| 47 | + AlbumConfig string `json:"-"` // 卡组配置 | |
| 48 | + CardConfig string `json:"-"` // 卡牌配置 | |
| 49 | + CardHolderConfig string `json:"-"` // 卡包开卡规则 | |
| 50 | + NormalCardStarSequence string `json:"-"` // 卡片星级配置 | |
| 51 | + CardSequenceConfig string `json:"-"` // 卡片星级对应卡牌配置 | |
| 52 | + StarShopConfig string `json:"-"` // 星星商店配置 | |
| 53 | + Ver string // 版本号 | |
| 54 | + Status int // 状态 0=关闭 1=开启 | |
| 55 | + UpdateTime int64 // 修改时间戳 | |
| 56 | +} | |
| 57 | + | |
| 58 | +// CardActivityConfigClient 卡牌活动配置 给客户端数据 | |
| 59 | +type CardActivityConfigClient struct { | |
| 60 | + Id int64 `form:"id" json:"id"` // ID | |
| 61 | + RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 | |
| 62 | + Albums []AlbumConfig `form:"albums" json:"albums"` // 卡组配置 | |
| 63 | + Cards []CardConfig `form:"cards" json:"cards"` // 卡牌配置 | |
| 64 | + Holders []OpenCardholderConfig `form:"holders" json:"holders"` // 卡包开卡规则 | |
| 65 | + StarShop []StarShopConfig `form:"star_shop" json:"star_shop"` // 星星商店配置 | |
| 66 | +} | |
| 67 | + | |
| 68 | +// AlbumConfig 卡组表 | |
| 69 | +type AlbumConfig struct { | |
| 70 | + SetId int `json:"set_id"` // 卡组名 | |
| 71 | + Name int `json:"name"` // 卡组图片 | |
| 72 | + Icon string `json:"icon"` // 卡组id | |
| 73 | + Rewards map[string]string `json:"rewards"` // 集齐奖励 k=轮次 | |
| 74 | + StartTime int64 `json:"start_time"` // 开始时间 | |
| 75 | + EndTime int64 `json:"end_time"` // 结束时间 | |
| 76 | +} | |
| 77 | + | |
| 78 | +// CardConfig 卡牌表 | |
| 79 | +type CardConfig struct { | |
| 80 | + Id int `json:"id"` // ID | |
| 81 | + Name int `json:"name"` // 卡牌名字 | |
| 82 | + Icon int `json:"icon"` // 卡牌图标 | |
| 83 | + Desc int `json:"desc"` // 卡牌描述 | |
| 84 | + SetId int `json:"album_setid"` // 卡组id | |
| 85 | + Star int `json:"star"` // 星级 | |
| 86 | + IsGold int `json:"is_gold"` // 是否是金卡 | |
| 87 | + IsSend int `json:"is_send"` // 卡片是否可赠送 | |
| 88 | +} | |
| 89 | + | |
| 90 | +// OpenCardholderConfig 卡包开卡规则表 | |
| 91 | +type OpenCardholderConfig struct { | |
| 92 | + Id string `json:"id"` // ID | |
| 93 | + IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 | |
| 94 | + IsNew int `json:"is_new"` // 是否是新卡包 | |
| 95 | + GuaranteedStarCardId string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID | |
| 96 | + NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 | |
| 97 | + MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID | |
| 98 | + ActivityId int `json:"activity_id"` // 对应活动ID | |
| 99 | +} | |
| 100 | + | |
| 101 | +// NormalCardStarConfig 非保底卡星级ID | |
| 102 | +type NormalCardStarConfig struct { | |
| 103 | + Id string `json:"id"` // ID | |
| 104 | + SequenceId string `json:"user_sequence_id"` // 用户序列组ID | |
| 105 | + Cohort string `json:"cohort"` // 用户分组 | |
| 106 | + NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列 | |
| 107 | + NormalCardSequenceIds []string `json:"-"` // 非保底星级序列 | |
| 108 | +} | |
| 109 | + | |
| 110 | +// CardSequenceConfig 星级ID对应的卡片 | |
| 111 | +type CardSequenceConfig struct { | |
| 112 | + Id string `json:"id"` // ID | |
| 113 | + SequenceId string `json:"user_sequence_id"` // 用户序列组ID | |
| 114 | + Cohort string `json:"cohort"` // 用户分组 | |
| 115 | + CardIdList string `json:"card_id_list"` // 卡牌抽取序列 | |
| 116 | + CardIdLists []string `json:"-"` // 卡牌抽取序列 | |
| 117 | +} | |
| 118 | + | |
| 119 | +// StarShopConfig 星星商店配置 | |
| 120 | +type StarShopConfig struct { | |
| 121 | + Id int `json:"id"` // ID | |
| 122 | + NeedStarNumber int `json:"need_star_number"` // 需求星星数 | |
| 123 | + CardBagIds []int `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} | |
| 124 | +} | ... | ... |
configs/index.go
| 1 | 1 | package configs |
| 2 | 2 | |
| 3 | -import "apigame/common/svconfig" | |
| 3 | +import ( | |
| 4 | + "apigame/common/svdto" | |
| 5 | + "apigame/util/zjson" | |
| 6 | + "apigame/util/zredis" | |
| 7 | + "fmt" | |
| 8 | +) | |
| 4 | 9 | |
| 5 | -func Init() bool { | |
| 6 | - | |
| 7 | - return true | |
| 10 | +// func GetConfigRedis[T svconfig.IDtoData](gameId string) (result *T, has bool) { | |
| 11 | +// t = new(T) | |
| 12 | +// var rule = t.GetRule(gameId) | |
| 13 | +// return | |
| 14 | +// } | |
| 15 | +func GetConfigMysql[T svdto.IDtoData](gameId string, t T) (result *T, has bool) { | |
| 16 | + return | |
| 8 | 17 | } |
| 9 | 18 | |
| 10 | -func GetConfigRedis[T svconfig.IConfigRule](gameId string) { | |
| 19 | +func GetConfig[T svdto.IDtoData](gameId string, t T) (has bool) { | |
| 20 | + has = CacheLoad[T](gameId, t) | |
| 21 | + if !has { | |
| 11 | 22 | |
| 23 | + } | |
| 24 | + return | |
| 12 | 25 | } |
| 13 | 26 | |
| 14 | -func GetConfigMysql[T svconfig.IConfigRule](gameId string) { | |
| 27 | +func CacheSave(gameId string, conf svdto.IDtoData) { | |
| 28 | + rule := conf.GetRule(gameId) | |
| 29 | + _ = zredis.SetEx(zredis.GetConn(), rule.CacheKey, zjson.Str(conf), rule.CacheTime) | |
| 30 | +} | |
| 15 | 31 | |
| 32 | +func CacheLoad[T svdto.IDtoData](gameId string, t T) (has bool) { | |
| 33 | + has = true | |
| 34 | + rule := t.GetRule(gameId) | |
| 35 | + text, err := zredis.Get(zredis.GetConn(), rule.CacheKey) | |
| 36 | + if err != nil { | |
| 37 | + has = false | |
| 38 | + return | |
| 39 | + } | |
| 40 | + err = zjson.Obj(text, &t) | |
| 41 | + if err != nil { | |
| 42 | + fmt.Println(err) | |
| 43 | + has = false | |
| 44 | + return | |
| 45 | + } | |
| 46 | + return | |
| 16 | 47 | } | ... | ... |
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +package configs | |
| 2 | + | |
| 3 | +func Init() bool { | |
| 4 | + | |
| 5 | + //gameId := "10149" | |
| 6 | + ////{ | |
| 7 | + //// conf := &ApiGameConfig{AppId: "dsadsads", GameId: gameId, Name: "Name"} | |
| 8 | + //// CacheSave(gameId, conf) | |
| 9 | + ////} | |
| 10 | + //{ | |
| 11 | + // conf, has := CacheLoad(gameId, &ApiGameConfig{}) | |
| 12 | + // fmt.Println("dwjw🐸", conf, has) | |
| 13 | + //} | |
| 14 | + | |
| 15 | + //{ | |
| 16 | + // conf := &CardActivityConfigRaw{} | |
| 17 | + // rule := conf.GetRule(gameId) | |
| 18 | + // db := rule.DbMysql.Where("status = ?", 1) | |
| 19 | + // has, err := svdto.First(db, conf, gameId) | |
| 20 | + // fmt.Println("dwjw🐸", conf, has, err) | |
| 21 | + //} | |
| 22 | + | |
| 23 | + //for _, gameId := range svconst.GameListCardHolder { | |
| 24 | + // LoadConfig(gameId) | |
| 25 | + //} | |
| 26 | + | |
| 27 | + _, _ = GetApiGame("10149") | |
| 28 | + | |
| 29 | + return true | |
| 30 | +} | ... | ... |
configs/registry.go
| 1 | 1 | package configs |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/util/utdto" | |
| 5 | + "apigame/util/util-lx/lxalilog" | |
| 6 | + "fmt" | |
| 7 | +) | |
| 8 | + | |
| 9 | +func GetApiGame(gameId string) (conf *ApiGameConfig, err error) { | |
| 10 | + conf = new(ApiGameConfig) | |
| 11 | + has := CacheLoad(gameId, conf) | |
| 12 | + if has { | |
| 13 | + fmt.Println("GetApiGame use cache") | |
| 14 | + return | |
| 15 | + } | |
| 16 | + rule := conf.GetRule(gameId) | |
| 17 | + result := utdto.First(rule.DbMysql, conf, rule.TableName) | |
| 18 | + has = result.RowsAffected != 0 | |
| 19 | + err = result.Error | |
| 20 | + if err != nil { | |
| 21 | + lxalilog.Errors(err, gameId) | |
| 22 | + return | |
| 23 | + } | |
| 24 | + fmt.Println("GetApiGame save cache") | |
| 25 | + CacheSave(gameId, conf) | |
| 26 | + | |
| 27 | + return | |
| 28 | +} | ... | ... |
dto/cardholder-record.go
| ... | ... | @@ -1,101 +0,0 @@ |
| 1 | -package dto | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/service/constd" | |
| 5 | - "apigame/util/utdto" | |
| 6 | - "apigame/util/util-lx/lxtime" | |
| 7 | -) | |
| 8 | - | |
| 9 | -// CardHolderRecordBase 开卡包活动日志公共 | |
| 10 | -type CardHolderRecordBase struct { | |
| 11 | - Id int64 `gorm:"primaryKey;comment:日志ID"` | |
| 12 | - Uid int64 `gorm:"comment:玩家唯一ID"` | |
| 13 | - SequenceId string `gorm:"type:varchar(255);comment:用户序列组ID"` | |
| 14 | - Cohort string `gorm:"type:varchar(255);comment:用户分组ID"` | |
| 15 | - ActivityId int64 `gorm:"comment:当前活动ID"` | |
| 16 | - Round int `gorm:"comment:当前轮次"` | |
| 17 | - CreateTime int64 `gorm:"comment:创建时间戳"` | |
| 18 | - UpdateTime int64 `gorm:"comment:修改时间戳"` | |
| 19 | -} | |
| 20 | - | |
| 21 | -func NewCardHolderRecordBase(uid int64, sequenceId string, cohort string, activityId int64, round int) CardHolderRecordBase { | |
| 22 | - secNow := lxtime.NowUninx() | |
| 23 | - return CardHolderRecordBase{ | |
| 24 | - CreateTime: secNow, | |
| 25 | - UpdateTime: secNow, | |
| 26 | - Uid: uid, | |
| 27 | - SequenceId: sequenceId, | |
| 28 | - Cohort: cohort, | |
| 29 | - ActivityId: activityId, | |
| 30 | - Round: round, | |
| 31 | - } | |
| 32 | -} | |
| 33 | - | |
| 34 | -// CardHolderRecordOpen 开卡包活动日志开卡包 | |
| 35 | -type CardHolderRecordOpen struct { | |
| 36 | - CardHolderRecordBase | |
| 37 | - OpenMode int `gorm:"comment:开包类型0客户端驱动1星星商店购买2剩余星星兑换"` | |
| 38 | - CardholderId int `gorm:"comment:卡包ID"` | |
| 39 | - CardList string `gorm:"type:varchar(255);comment:开卡内容"` | |
| 40 | -} | |
| 41 | - | |
| 42 | -func (d *CardHolderRecordOpen) TableName() string { | |
| 43 | - return utdto.MYSQL_TABLE_TEMPLATE | |
| 44 | -} | |
| 45 | -func (d *CardHolderRecordOpen) GetTableName(gameId string) string { | |
| 46 | - return constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN + gameId | |
| 47 | -} | |
| 48 | - | |
| 49 | -func NewCardHolderRecordOpen(recordBase CardHolderRecordBase, | |
| 50 | - openMode int, cardholderId int, cardList string) *CardHolderRecordOpen { | |
| 51 | - return &CardHolderRecordOpen{ | |
| 52 | - CardHolderRecordBase: recordBase, | |
| 53 | - OpenMode: openMode, | |
| 54 | - CardholderId: cardholderId, | |
| 55 | - CardList: cardList, | |
| 56 | - } | |
| 57 | -} | |
| 58 | - | |
| 59 | -// CardHolderRecordRewardAlbum 开卡包活动日志领取卡组奖励 | |
| 60 | -type CardHolderRecordRewardAlbum struct { | |
| 61 | - CardHolderRecordBase | |
| 62 | - AlbumId int `gorm:"comment:卡组ID"` | |
| 63 | - Award string `gorm:"type:varchar(255);comment:奖励内容"` | |
| 64 | -} | |
| 65 | - | |
| 66 | -func (d *CardHolderRecordRewardAlbum) TableName() string { | |
| 67 | - return utdto.MYSQL_TABLE_TEMPLATE | |
| 68 | -} | |
| 69 | -func (d *CardHolderRecordRewardAlbum) GetTableName(gameId string) string { | |
| 70 | - return constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM + gameId | |
| 71 | -} | |
| 72 | - | |
| 73 | -func NewCardHolderRecordRewardAlbum(recordBase CardHolderRecordBase, | |
| 74 | - albumId int, award string) *CardHolderRecordRewardAlbum { | |
| 75 | - return &CardHolderRecordRewardAlbum{ | |
| 76 | - CardHolderRecordBase: recordBase, | |
| 77 | - AlbumId: albumId, | |
| 78 | - Award: award, | |
| 79 | - } | |
| 80 | -} | |
| 81 | - | |
| 82 | -// CardHolderRecordRewardRound 开卡包活动日志领取轮次奖励 | |
| 83 | -type CardHolderRecordRewardRound struct { | |
| 84 | - CardHolderRecordBase | |
| 85 | - Award string `gorm:"type:varchar(255);comment:奖励内容"` | |
| 86 | -} | |
| 87 | - | |
| 88 | -func (d *CardHolderRecordRewardRound) TableName() string { | |
| 89 | - return utdto.MYSQL_TABLE_TEMPLATE | |
| 90 | -} | |
| 91 | -func (d *CardHolderRecordRewardRound) GetTableName(gameId string) string { | |
| 92 | - return constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND + gameId | |
| 93 | -} | |
| 94 | - | |
| 95 | -func NewCardHolderRecordRewardRound(recordBase CardHolderRecordBase, | |
| 96 | - award string) *CardHolderRecordRewardRound { | |
| 97 | - return &CardHolderRecordRewardRound{ | |
| 98 | - CardHolderRecordBase: recordBase, | |
| 99 | - Award: award, | |
| 100 | - } | |
| 101 | -} |
dto/cardholder.go
| ... | ... | @@ -1,84 +0,0 @@ |
| 1 | -package dto | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/service/constd" | |
| 5 | - "apigame/util/utdto" | |
| 6 | - "apigame/util/util-lx/lxalilog" | |
| 7 | - "apigame/util/util-lx/lxtime" | |
| 8 | - "encoding/json" | |
| 9 | -) | |
| 10 | - | |
| 11 | -// CardHolderData 卡牌活动持久数据 | |
| 12 | -type CardHolderData struct { | |
| 13 | - Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` | |
| 14 | - ActivityId int64 `gorm:"comment:活动ID"` | |
| 15 | - Details *CardHolderDataDetails `gorm:"-"` // 活动详情 | |
| 16 | - DetailsText string `gorm:"comment:活动详情封装"` | |
| 17 | - CreateTime int64 `gorm:"comment:创建时间戳"` | |
| 18 | - UpdateTime int64 `gorm:"comment:修改时间戳"` | |
| 19 | -} | |
| 20 | - | |
| 21 | -// CardHolderDataDetails 卡牌活动详情 | |
| 22 | -type CardHolderDataDetails struct { | |
| 23 | - Cards map[int]int // 每张卡集了多少张 k=卡牌ID v=数量 | |
| 24 | - Album map[int]int // 卡组奖励领取 k=卡组ID v=数量 | |
| 25 | - StarSequenceScales map[string]int // 星级序列刻度 k=ID_用户序列_用户分组 v=刻度 | |
| 26 | - CardSequenceScales map[string]int // 卡牌序列刻度 k=ID_用户序列_用户分组 v=刻度 | |
| 27 | - Round int // 卡册当前轮次 | |
| 28 | - StarCount int // 星星点数 | |
| 29 | - LastStarCount int // 上期活动剩余星星点数 | |
| 30 | - AutoExchangeHolder []int // 活动切换时自动兑换的卡包列表 | |
| 31 | -} | |
| 32 | - | |
| 33 | -func NewCardHolderData(uid int64) *CardHolderData { | |
| 34 | - d := &CardHolderData{ | |
| 35 | - Uid: uid, | |
| 36 | - Details: NewCardHolderDataDetails(), | |
| 37 | - } | |
| 38 | - d.Encode() | |
| 39 | - return d | |
| 40 | -} | |
| 41 | - | |
| 42 | -func NewCardHolderDataDetails() *CardHolderDataDetails { | |
| 43 | - return &CardHolderDataDetails{ | |
| 44 | - Cards: make(map[int]int), | |
| 45 | - Album: make(map[int]int), | |
| 46 | - StarSequenceScales: make(map[string]int), | |
| 47 | - CardSequenceScales: make(map[string]int), | |
| 48 | - Round: 1, | |
| 49 | - StarCount: 0, | |
| 50 | - AutoExchangeHolder: make([]int, 0), | |
| 51 | - } | |
| 52 | -} | |
| 53 | - | |
| 54 | -func (d *CardHolderData) TableName() string { | |
| 55 | - return utdto.MYSQL_TABLE_TEMPLATE | |
| 56 | -} | |
| 57 | - | |
| 58 | -func (d *CardHolderData) GetTableName(gameId string) string { | |
| 59 | - return constd.MYSQL_TABLE_S_CARDHOLDER_DATA + gameId | |
| 60 | -} | |
| 61 | - | |
| 62 | -func (d *CardHolderData) Init(uid int64) { | |
| 63 | - d.Uid = uid | |
| 64 | - d.CreateTime = lxtime.NowUninx() | |
| 65 | -} | |
| 66 | - | |
| 67 | -// Encode 打包数据 | |
| 68 | -func (d *CardHolderData) Encode() { | |
| 69 | - details, err := json.Marshal(d.Details) | |
| 70 | - if err != nil { | |
| 71 | - lxalilog.Errors(err, "CardHolderData Encode Error", d.Uid, d.ActivityId) | |
| 72 | - return | |
| 73 | - } | |
| 74 | - d.DetailsText = string(details) | |
| 75 | -} | |
| 76 | - | |
| 77 | -// Decode 分包数据 | |
| 78 | -func (d *CardHolderData) Decode() { | |
| 79 | - err := json.Unmarshal([]byte(d.DetailsText), d.Details) | |
| 80 | - if err != nil { | |
| 81 | - lxalilog.Errors(err, "CardHolderData Decode Error", d.Uid, d.ActivityId) | |
| 82 | - return | |
| 83 | - } | |
| 84 | -} |
main.go
| 1 | 1 | package main |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | - "apigame/common/svconfig" | |
| 5 | 4 | "apigame/common/svconst" |
| 6 | - "apigame/common/svdto" | |
| 7 | 5 | "apigame/common/svlog" |
| 8 | 6 | "apigame/common/svmysql" |
| 9 | 7 | "apigame/common/svredis" |
| ... | ... | @@ -33,12 +31,14 @@ func main() { |
| 33 | 31 | beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" |
| 34 | 32 | } |
| 35 | 33 | |
| 36 | - Init() | |
| 34 | + if !Init() { | |
| 35 | + return | |
| 36 | + } | |
| 37 | 37 | |
| 38 | 38 | beego.Run() |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | -func Init() { | |
| 41 | +func Init() bool { | |
| 42 | 42 | |
| 43 | 43 | svconst.AppName = beego.AppConfig.String("appname") |
| 44 | 44 | |
| ... | ... | @@ -47,11 +47,11 @@ func Init() { |
| 47 | 47 | svlog.InitAliLog(svconst.AppName) |
| 48 | 48 | |
| 49 | 49 | if !svredis.Init() { |
| 50 | - return | |
| 50 | + return false | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | if !svmysql.Init() { |
| 54 | - return | |
| 54 | + return false | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | //// 初始化数数打点 |
| ... | ... | @@ -59,15 +59,11 @@ func Init() { |
| 59 | 59 | // |
| 60 | 60 | //_ = config.InitLxLimit() |
| 61 | 61 | |
| 62 | - if !svconfig.Init() { | |
| 63 | - return | |
| 64 | - } | |
| 65 | 62 | if !configs.Init() { |
| 66 | - return | |
| 63 | + return false | |
| 67 | 64 | } |
| 68 | 65 | |
| 69 | - svdto.Init() | |
| 70 | - | |
| 71 | - // 初始化配置 | |
| 72 | 66 | cardholder.Init() |
| 67 | + | |
| 68 | + return true | |
| 73 | 69 | } | ... | ... |
middleware/sign/index.go
| 1 | 1 | package sign |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | - "apigame/api-common/config" | |
| 4 | + "apigame/configs" | |
| 5 | 5 | "apigame/middleware/sdk" |
| 6 | 6 | "apigame/service/constd" |
| 7 | 7 | "apigame/util/util-lx/lxalilog" |
| ... | ... | @@ -59,7 +59,7 @@ func getTimeStamp(time_stamp interface{}) (timestamp int64) { |
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | -func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig config.MApiGameConfig, err error) { | |
| 62 | +func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig *configs.ApiGameConfig, err error) { | |
| 63 | 63 | |
| 64 | 64 | var ( |
| 65 | 65 | postGameId string |
| ... | ... | @@ -195,7 +195,7 @@ func Check(req []byte, postdata interface{}, checkSign bool, checkToken bool) (c |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // CheckSign 校验签名 |
| 198 | -func CheckSign(data interface{}, checkToken bool) (code string, gameconfig config.MApiGameConfig, err error) { | |
| 198 | +func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *configs.ApiGameConfig, err error) { | |
| 199 | 199 | |
| 200 | 200 | var ( |
| 201 | 201 | logstr string |
| ... | ... | @@ -223,7 +223,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig confi |
| 223 | 223 | |
| 224 | 224 | gameid := newdata["gameid"].(string) |
| 225 | 225 | |
| 226 | - gameconfig, err = config.GetApiGameConfig(gameid) | |
| 226 | + gameconfig, err = configs.GetApiGame(gameid) | |
| 227 | 227 | if err != nil { |
| 228 | 228 | lxalilog.Errors(err) |
| 229 | 229 | return |
| ... | ... | @@ -233,7 +233,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig confi |
| 233 | 233 | return |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - appkey := gameconfig.Appkey | |
| 236 | + appkey := gameconfig.AppKey | |
| 237 | 237 | |
| 238 | 238 | if appkey == "" { |
| 239 | 239 | code = constd.RECODE_SIGNERROR | ... | ... |
service/cardholder/config-load.go
| ... | ... | @@ -2,13 +2,10 @@ package cardholder |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 4 | "apigame/common/svconst" |
| 5 | - "apigame/common/svdto" | |
| 6 | - "apigame/service/constd" | |
| 7 | - "fmt" | |
| 8 | 5 | ) |
| 9 | 6 | |
| 10 | -// Init 初始化 | |
| 11 | -func Init() { | |
| 7 | +// Init1 初始化 | |
| 8 | +func Init1() { | |
| 12 | 9 | |
| 13 | 10 | NewConfigs() |
| 14 | 11 | |
| ... | ... | @@ -22,7 +19,7 @@ func TryUpdateConfigs() { |
| 22 | 19 | |
| 23 | 20 | // LoadConfigs 读取mysql配置 |
| 24 | 21 | func LoadConfigs() { |
| 25 | - for _, gameId := range constd.GameListCardHolder { | |
| 22 | + for _, gameId := range svconst.GameListCardHolder { | |
| 26 | 23 | LoadConfig(gameId) |
| 27 | 24 | } |
| 28 | 25 | } |
| ... | ... | @@ -35,46 +32,46 @@ func TryUpdateConfig(gameId string) (config *CardActivityConfig, has bool) { |
| 35 | 32 | |
| 36 | 33 | // LoadConfig 读取mysql配置 |
| 37 | 34 | func LoadConfig(gameId string) { |
| 38 | - // 找到当前开放的活动 | |
| 39 | - configOpen := CardActivityUpdateConfig{Id: 0} | |
| 40 | - { | |
| 41 | - conf := make([]CardActivityUpdateConfig, 0) | |
| 42 | - _, err := svdto.Find(svconst.DbConfig, &conf, new(CardActivityUpdateConfig).GetTableName(gameId)) | |
| 43 | - if err != nil { | |
| 44 | - return | |
| 45 | - } | |
| 46 | - for _, config := range conf { | |
| 47 | - if config.Status != 0 { | |
| 48 | - configOpen = config | |
| 49 | - continue | |
| 50 | - } | |
| 51 | - } | |
| 52 | - fmt.Println(configOpen) | |
| 53 | - } | |
| 54 | - // 没有开放的活动 | |
| 55 | - if configOpen.Id == 0 { | |
| 56 | - return | |
| 57 | - } | |
| 58 | - // 判断是否需要更新 | |
| 59 | - needUpdate := false | |
| 60 | - configOld, hasConfigOld := GetConfig(gameId) | |
| 61 | - if hasConfigOld { | |
| 62 | - if configOpen.Id != configOld.Raw.Id || configOpen.UpdateTime != configOld.Raw.UpdateTime { | |
| 63 | - needUpdate = true | |
| 64 | - } | |
| 65 | - } else { | |
| 66 | - needUpdate = true | |
| 67 | - } | |
| 68 | - // 更新数据 | |
| 69 | - if needUpdate { | |
| 70 | - confNew := &CardActivityConfigRaw{} | |
| 71 | - hasConfNew, err := svdto.First(svconst.DbConfig, confNew, gameId) | |
| 72 | - if err != nil { | |
| 73 | - return | |
| 74 | - } | |
| 75 | - if !hasConfNew { | |
| 76 | - return | |
| 77 | - } | |
| 78 | - ConfigDecode(gameId, confNew) | |
| 79 | - } | |
| 35 | + //// 找到当前开放的活动 | |
| 36 | + //configOpen := CardActivityUpdateConfig{Id: 0} | |
| 37 | + //{ | |
| 38 | + // conf := make([]CardActivityUpdateConfig, 0) | |
| 39 | + // _, err := svdto.Find(&conf, new(CardActivityUpdateConfig), gameId) | |
| 40 | + // if err != nil { | |
| 41 | + // return | |
| 42 | + // } | |
| 43 | + // for _, config := range conf { | |
| 44 | + // if config.Status != 0 { | |
| 45 | + // configOpen = config | |
| 46 | + // continue | |
| 47 | + // } | |
| 48 | + // } | |
| 49 | + // fmt.Println(configOpen) | |
| 50 | + //} | |
| 51 | + //// 没有开放的活动 | |
| 52 | + //if configOpen.Id == 0 { | |
| 53 | + // return | |
| 54 | + //} | |
| 55 | + //// 判断是否需要更新 | |
| 56 | + //needUpdate := false | |
| 57 | + //configOld, hasConfigOld := GetConfig(gameId) | |
| 58 | + //if hasConfigOld { | |
| 59 | + // if configOpen.Id != configOld.Raw.Id || configOpen.UpdateTime != configOld.Raw.UpdateTime { | |
| 60 | + // needUpdate = true | |
| 61 | + // } | |
| 62 | + //} else { | |
| 63 | + // needUpdate = true | |
| 64 | + //} | |
| 65 | + //// 更新数据 | |
| 66 | + //if needUpdate { | |
| 67 | + // confNew := &CardActivityConfigRaw{} | |
| 68 | + // hasConfNew, err := svdto.First(confNew, gameId) | |
| 69 | + // if err != nil { | |
| 70 | + // return | |
| 71 | + // } | |
| 72 | + // if !hasConfNew { | |
| 73 | + // return | |
| 74 | + // } | |
| 75 | + // ConfigDecode(gameId, confNew) | |
| 76 | + //} | |
| 80 | 77 | } | ... | ... |
| ... | ... | @@ -0,0 +1,91 @@ |
| 1 | +package cardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/common/svconst" | |
| 5 | + "apigame/common/svdto" | |
| 6 | + "apigame/service/constd" | |
| 7 | + "apigame/util/utdto" | |
| 8 | + "apigame/util/util-lx/lxalilog" | |
| 9 | + "apigame/util/util-lx/lxtime" | |
| 10 | + "encoding/json" | |
| 11 | + "fmt" | |
| 12 | +) | |
| 13 | + | |
| 14 | +// CardHolderData 卡牌活动持久数据 | |
| 15 | +type CardHolderData struct { | |
| 16 | + Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` | |
| 17 | + ActivityId int64 `gorm:"comment:活动ID"` | |
| 18 | + Details *CardHolderDataDetails `gorm:"-"` // 活动详情 | |
| 19 | + DetailsText string `gorm:"comment:活动详情封装"` | |
| 20 | + CreateTime int64 `gorm:"comment:创建时间戳"` | |
| 21 | + UpdateTime int64 `gorm:"comment:修改时间戳"` | |
| 22 | +} | |
| 23 | + | |
| 24 | +func (c *CardHolderData) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } | |
| 25 | + | |
| 26 | +func (d *CardHolderData) GetRule(gameId string) *svdto.DtoRule { | |
| 27 | + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_DATA | |
| 28 | + return &svdto.DtoRule{ | |
| 29 | + DbMysql: svconst.DbCommon, | |
| 30 | + TableName: tableName + gameId, | |
| 31 | + CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 32 | + CacheTime: 300, | |
| 33 | + } | |
| 34 | +} | |
| 35 | + | |
| 36 | +// CardHolderDataDetails 卡牌活动详情 | |
| 37 | +type CardHolderDataDetails struct { | |
| 38 | + Cards map[int]int // 每张卡集了多少张 k=卡牌ID v=数量 | |
| 39 | + Album map[int]int // 卡组奖励领取 k=卡组ID v=数量 | |
| 40 | + StarSequenceScales map[string]int // 星级序列刻度 k=ID_用户序列_用户分组 v=刻度 | |
| 41 | + CardSequenceScales map[string]int // 卡牌序列刻度 k=ID_用户序列_用户分组 v=刻度 | |
| 42 | + Round int // 卡册当前轮次 | |
| 43 | + StarCount int // 星星点数 | |
| 44 | + LastStarCount int // 上期活动剩余星星点数 | |
| 45 | + AutoExchangeHolder []int // 活动切换时自动兑换的卡包列表 | |
| 46 | +} | |
| 47 | + | |
| 48 | +func NewCardHolderData(uid int64) *CardHolderData { | |
| 49 | + d := &CardHolderData{ | |
| 50 | + Uid: uid, | |
| 51 | + Details: NewCardHolderDataDetails(), | |
| 52 | + } | |
| 53 | + d.Encode() | |
| 54 | + return d | |
| 55 | +} | |
| 56 | + | |
| 57 | +func NewCardHolderDataDetails() *CardHolderDataDetails { | |
| 58 | + return &CardHolderDataDetails{ | |
| 59 | + Cards: make(map[int]int), | |
| 60 | + Album: make(map[int]int), | |
| 61 | + StarSequenceScales: make(map[string]int), | |
| 62 | + CardSequenceScales: make(map[string]int), | |
| 63 | + Round: 1, | |
| 64 | + StarCount: 0, | |
| 65 | + AutoExchangeHolder: make([]int, 0), | |
| 66 | + } | |
| 67 | +} | |
| 68 | + | |
| 69 | +func (d *CardHolderData) Init(uid int64) { | |
| 70 | + d.Uid = uid | |
| 71 | + d.CreateTime = lxtime.NowUninx() | |
| 72 | +} | |
| 73 | + | |
| 74 | +// Encode 打包数据 | |
| 75 | +func (d *CardHolderData) Encode() { | |
| 76 | + details, err := json.Marshal(d.Details) | |
| 77 | + if err != nil { | |
| 78 | + lxalilog.Errors(err, "CardHolderData Encode Error", d.Uid, d.ActivityId) | |
| 79 | + return | |
| 80 | + } | |
| 81 | + d.DetailsText = string(details) | |
| 82 | +} | |
| 83 | + | |
| 84 | +// Decode 分包数据 | |
| 85 | +func (d *CardHolderData) Decode() { | |
| 86 | + err := json.Unmarshal([]byte(d.DetailsText), d.Details) | |
| 87 | + if err != nil { | |
| 88 | + lxalilog.Errors(err, "CardHolderData Decode Error", d.Uid, d.ActivityId) | |
| 89 | + return | |
| 90 | + } | |
| 91 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,119 @@ |
| 1 | +package cardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/common/svconst" | |
| 5 | + "apigame/common/svdto" | |
| 6 | + "apigame/service/constd" | |
| 7 | + "apigame/util/utdto" | |
| 8 | + "apigame/util/util-lx/lxtime" | |
| 9 | + "fmt" | |
| 10 | +) | |
| 11 | + | |
| 12 | +// CardHolderRecordBase 开卡包活动日志公共 | |
| 13 | +type CardHolderRecordBase struct { | |
| 14 | + Id int64 `gorm:"primaryKey;comment:日志ID"` | |
| 15 | + Uid int64 `gorm:"comment:玩家唯一ID"` | |
| 16 | + SequenceId string `gorm:"type:varchar(255);comment:用户序列组ID"` | |
| 17 | + Cohort string `gorm:"type:varchar(255);comment:用户分组ID"` | |
| 18 | + ActivityId int64 `gorm:"comment:当前活动ID"` | |
| 19 | + Round int `gorm:"comment:当前轮次"` | |
| 20 | + CreateTime int64 `gorm:"comment:创建时间戳"` | |
| 21 | + UpdateTime int64 `gorm:"comment:修改时间戳"` | |
| 22 | +} | |
| 23 | + | |
| 24 | +func NewCardHolderRecordBase(uid int64, sequenceId string, cohort string, activityId int64, round int) CardHolderRecordBase { | |
| 25 | + secNow := lxtime.NowUninx() | |
| 26 | + return CardHolderRecordBase{ | |
| 27 | + CreateTime: secNow, | |
| 28 | + UpdateTime: secNow, | |
| 29 | + Uid: uid, | |
| 30 | + SequenceId: sequenceId, | |
| 31 | + Cohort: cohort, | |
| 32 | + ActivityId: activityId, | |
| 33 | + Round: round, | |
| 34 | + } | |
| 35 | +} | |
| 36 | + | |
| 37 | +// CardHolderRecordOpen 开卡包活动日志开卡包 | |
| 38 | +type CardHolderRecordOpen struct { | |
| 39 | + CardHolderRecordBase | |
| 40 | + OpenMode int `gorm:"comment:开包类型0客户端驱动1星星商店购买2剩余星星兑换"` | |
| 41 | + CardholderId int `gorm:"comment:卡包ID"` | |
| 42 | + CardList string `gorm:"type:varchar(255);comment:开卡内容"` | |
| 43 | +} | |
| 44 | + | |
| 45 | +func (c *CardHolderRecordOpen) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } | |
| 46 | + | |
| 47 | +func (d *CardHolderRecordOpen) GetRule(gameId string) *svdto.DtoRule { | |
| 48 | + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN | |
| 49 | + return &svdto.DtoRule{ | |
| 50 | + DbMysql: svconst.DbCommon, | |
| 51 | + TableName: tableName + gameId, | |
| 52 | + CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 53 | + CacheTime: 300, | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | |
| 57 | +func NewCardHolderRecordOpen(recordBase CardHolderRecordBase, | |
| 58 | + openMode int, cardholderId int, cardList string) *CardHolderRecordOpen { | |
| 59 | + return &CardHolderRecordOpen{ | |
| 60 | + CardHolderRecordBase: recordBase, | |
| 61 | + OpenMode: openMode, | |
| 62 | + CardholderId: cardholderId, | |
| 63 | + CardList: cardList, | |
| 64 | + } | |
| 65 | +} | |
| 66 | + | |
| 67 | +// CardHolderRecordRewardAlbum 开卡包活动日志领取卡组奖励 | |
| 68 | +type CardHolderRecordRewardAlbum struct { | |
| 69 | + CardHolderRecordBase | |
| 70 | + AlbumId int `gorm:"comment:卡组ID"` | |
| 71 | + Award string `gorm:"type:varchar(255);comment:奖励内容"` | |
| 72 | +} | |
| 73 | + | |
| 74 | +func (c *CardHolderRecordRewardAlbum) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } | |
| 75 | + | |
| 76 | +func (d *CardHolderRecordRewardAlbum) GetRule(gameId string) *svdto.DtoRule { | |
| 77 | + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM | |
| 78 | + return &svdto.DtoRule{ | |
| 79 | + DbMysql: svconst.DbCommon, | |
| 80 | + TableName: tableName + gameId, | |
| 81 | + CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 82 | + CacheTime: 300, | |
| 83 | + } | |
| 84 | +} | |
| 85 | + | |
| 86 | +func NewCardHolderRecordRewardAlbum(recordBase CardHolderRecordBase, | |
| 87 | + albumId int, award string) *CardHolderRecordRewardAlbum { | |
| 88 | + return &CardHolderRecordRewardAlbum{ | |
| 89 | + CardHolderRecordBase: recordBase, | |
| 90 | + AlbumId: albumId, | |
| 91 | + Award: award, | |
| 92 | + } | |
| 93 | +} | |
| 94 | + | |
| 95 | +// CardHolderRecordRewardRound 开卡包活动日志领取轮次奖励 | |
| 96 | +type CardHolderRecordRewardRound struct { | |
| 97 | + CardHolderRecordBase | |
| 98 | + Award string `gorm:"type:varchar(255);comment:奖励内容"` | |
| 99 | +} | |
| 100 | + | |
| 101 | +func (c *CardHolderRecordRewardRound) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } | |
| 102 | + | |
| 103 | +func (d *CardHolderRecordRewardRound) GetRule(gameId string) *svdto.DtoRule { | |
| 104 | + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND | |
| 105 | + return &svdto.DtoRule{ | |
| 106 | + DbMysql: svconst.DbCommon, | |
| 107 | + TableName: tableName + gameId, | |
| 108 | + CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), | |
| 109 | + CacheTime: 300, | |
| 110 | + } | |
| 111 | +} | |
| 112 | + | |
| 113 | +func NewCardHolderRecordRewardRound(recordBase CardHolderRecordBase, | |
| 114 | + award string) *CardHolderRecordRewardRound { | |
| 115 | + return &CardHolderRecordRewardRound{ | |
| 116 | + CardHolderRecordBase: recordBase, | |
| 117 | + Award: award, | |
| 118 | + } | |
| 119 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +package cardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/common/svconst" | |
| 5 | + "apigame/common/svdto" | |
| 6 | +) | |
| 7 | + | |
| 8 | +func Init() { | |
| 9 | + | |
| 10 | + // create table | |
| 11 | + // 卡牌卡包 | |
| 12 | + for _, gameId := range svconst.GameListCardHolder { | |
| 13 | + svdto.InitTable(new(CardHolderData), gameId) | |
| 14 | + svdto.InitTable(new(CardHolderRecordOpen), gameId) | |
| 15 | + svdto.InitTable(new(CardHolderRecordRewardAlbum), gameId) | |
| 16 | + svdto.InitTable(new(CardHolderRecordRewardRound), gameId) | |
| 17 | + } | |
| 18 | + | |
| 19 | +} | ... | ... |
service/cardholder/logic.go
| 1 | 1 | package cardholder |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | - "apigame/common/svconst" | |
| 5 | 4 | "apigame/common/svdto" |
| 6 | - "apigame/dto" | |
| 7 | 5 | "apigame/models" |
| 8 | 6 | "apigame/service/constd" |
| 9 | 7 | "apigame/util/util-lx/lxalilog" |
| ... | ... | @@ -17,16 +15,16 @@ import ( |
| 17 | 15 | ) |
| 18 | 16 | |
| 19 | 17 | // SaveData 存储数据 |
| 20 | -func SaveData(gameId string, d *dto.CardHolderData) { | |
| 18 | +func SaveData(gameId string, d *CardHolderData) { | |
| 21 | 19 | d.UpdateTime = lxtime.NowUninx() |
| 22 | 20 | d.Encode() |
| 23 | 21 | |
| 24 | - svdto.Save(svconst.DbCommon, d, gameId) | |
| 22 | + svdto.Save(d, gameId) | |
| 25 | 23 | } |
| 26 | 24 | |
| 27 | -func _LoadData(gameId string, uid int64) (d *dto.CardHolderData) { | |
| 28 | - d = dto.NewCardHolderData(uid) | |
| 29 | - has, err := svdto.First(svconst.DbCommon, d, gameId) | |
| 25 | +func _LoadData(gameId string, uid int64) (d *CardHolderData) { | |
| 26 | + d = NewCardHolderData(uid) | |
| 27 | + has, err := svdto.First(d, gameId) | |
| 30 | 28 | if err != nil { |
| 31 | 29 | return |
| 32 | 30 | } |
| ... | ... | @@ -34,13 +32,13 @@ func _LoadData(gameId string, uid int64) (d *dto.CardHolderData) { |
| 34 | 32 | d.Decode() |
| 35 | 33 | } else { |
| 36 | 34 | d.Init(uid) |
| 37 | - svdto.Insert(svconst.DbCommon, d, gameId) | |
| 35 | + svdto.Insert(d, gameId) | |
| 38 | 36 | } |
| 39 | 37 | return |
| 40 | 38 | } |
| 41 | 39 | |
| 42 | 40 | // LoadData 获取数据 外部接口 |
| 43 | -func LoadData(gameId string, uid int64, config *CardActivityConfig) (d *dto.CardHolderData) { | |
| 41 | +func LoadData(gameId string, uid int64, config *CardActivityConfig) (d *CardHolderData) { | |
| 44 | 42 | configId := config.Id |
| 45 | 43 | d = _LoadData(gameId, uid) |
| 46 | 44 | // 如果当前有上线活动(活动ID不为0),且活动ID和玩家数据不同,说明活动已切换 需更新 |
| ... | ... | @@ -51,7 +49,7 @@ func LoadData(gameId string, uid int64, config *CardActivityConfig) (d *dto.Card |
| 51 | 49 | starCount := d.Details.StarCount |
| 52 | 50 | |
| 53 | 51 | d.ActivityId = configId |
| 54 | - d.Details = dto.NewCardHolderDataDetails() | |
| 52 | + d.Details = NewCardHolderDataDetails() | |
| 55 | 53 | |
| 56 | 54 | // 使用剩余的星星数来自动兑换卡包 |
| 57 | 55 | d.Details.LastStarCount = starCount |
| ... | ... | @@ -78,7 +76,7 @@ func CheckStatus(conf *CardActivityConfig) string { |
| 78 | 76 | } |
| 79 | 77 | |
| 80 | 78 | // CheckGameData 检查游戏数据 轮次等 |
| 81 | -func CheckGameData(d *dto.CardHolderData, conf *CardActivityConfig) string { | |
| 79 | +func CheckGameData(d *CardHolderData, conf *CardActivityConfig) string { | |
| 82 | 80 | if d.Details.Round > conf.Raw.Round { |
| 83 | 81 | return constd.RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR |
| 84 | 82 | } |
| ... | ... | @@ -121,7 +119,7 @@ func GetListFromArray(array []string, scale, count int) []string { |
| 121 | 119 | } |
| 122 | 120 | |
| 123 | 121 | // GetNewCard 按顺序查找数目最少的一张卡抽取 |
| 124 | -func GetNewCard(gameData *dto.CardHolderData, conf *CardActivityConfig) int { | |
| 122 | +func GetNewCard(gameData *CardHolderData, conf *CardActivityConfig) int { | |
| 125 | 123 | if len(conf.CardConfig) < 1 { |
| 126 | 124 | return 0 |
| 127 | 125 | } |
| ... | ... | @@ -138,7 +136,7 @@ func GetNewCard(gameData *dto.CardHolderData, conf *CardActivityConfig) int { |
| 138 | 136 | } |
| 139 | 137 | |
| 140 | 138 | // CheckAlbumFinish 判断卡组是否已集齐 |
| 141 | -func CheckAlbumFinish(albumId int, gameData *dto.CardHolderData, config *CardActivityConfig) bool { | |
| 139 | +func CheckAlbumFinish(albumId int, gameData *CardHolderData, config *CardActivityConfig) bool { | |
| 142 | 140 | for _, conf := range config.CardConfig { |
| 143 | 141 | if conf.SetId == albumId { |
| 144 | 142 | count := gameData.Details.Cards[conf.Id] |
| ... | ... | @@ -151,7 +149,7 @@ func CheckAlbumFinish(albumId int, gameData *dto.CardHolderData, config *CardAct |
| 151 | 149 | } |
| 152 | 150 | |
| 153 | 151 | // CheckRoundFinish 判断轮次是否已集齐(所有卡组集齐) |
| 154 | -func CheckRoundFinish(gameData *dto.CardHolderData, config *CardActivityConfig) bool { | |
| 152 | +func CheckRoundFinish(gameData *CardHolderData, config *CardActivityConfig) bool { | |
| 155 | 153 | for _, conf := range config.AlbumConfig { |
| 156 | 154 | count := gameData.Details.Album[conf.SetId] |
| 157 | 155 | if count < 1 { |
| ... | ... | @@ -162,14 +160,14 @@ func CheckRoundFinish(gameData *dto.CardHolderData, config *CardActivityConfig) |
| 162 | 160 | } |
| 163 | 161 | |
| 164 | 162 | // HandleNextRound 处理轮次完成 星级序列刻度 卡牌序列刻度 |
| 165 | -func HandleNextRound(gameData *dto.CardHolderData) { | |
| 163 | +func HandleNextRound(gameData *CardHolderData) { | |
| 166 | 164 | gameData.Details.Round += 1 |
| 167 | 165 | gameData.Details.Cards = make(map[int]int) |
| 168 | 166 | gameData.Details.Album = make(map[int]int) |
| 169 | 167 | } |
| 170 | 168 | |
| 171 | 169 | // GetInfo 玩家卡牌活动信息 |
| 172 | -func GetInfo(gameData *dto.CardHolderData, conf *CardActivityConfig) models.CardHolderInfo { | |
| 170 | +func GetInfo(gameData *CardHolderData, conf *CardActivityConfig) models.CardHolderInfo { | |
| 173 | 171 | info := models.CardHolderInfo{ |
| 174 | 172 | Cards: make(map[int]int), |
| 175 | 173 | Album: make(map[int]int), |
| ... | ... | @@ -189,7 +187,7 @@ func GetInfo(gameData *dto.CardHolderData, conf *CardActivityConfig) models.Card |
| 189 | 187 | // DoOpen 封装的抽卡逻辑 |
| 190 | 188 | // openMode:开包类型0客户端驱动1星星商店购买2剩余星星兑换 |
| 191 | 189 | func DoOpen(gameId string, |
| 192 | - gameData *dto.CardHolderData, | |
| 190 | + gameData *CardHolderData, | |
| 193 | 191 | config *CardActivityConfig, |
| 194 | 192 | confCardholder OpenCardholderConfig, |
| 195 | 193 | sequenceId, cohort string, |
| ... | ... | @@ -242,8 +240,8 @@ func DoOpen(gameId string, |
| 242 | 240 | } |
| 243 | 241 | // 记录开卡包日志 |
| 244 | 242 | { |
| 245 | - recordBase := dto.NewCardHolderRecordBase(gameData.Uid, sequenceId, cohort, config.Id, gameData.Details.Round) | |
| 246 | - svdto.SaveRecord(gameId, dto.NewCardHolderRecordOpen(recordBase, | |
| 243 | + recordBase := NewCardHolderRecordBase(gameData.Uid, sequenceId, cohort, config.Id, gameData.Details.Round) | |
| 244 | + svdto.SaveRecord(gameId, NewCardHolderRecordOpen(recordBase, | |
| 247 | 245 | openMode, utstring.StringToInt(confCardholder.Id), utjson.JsonString(newCards))) |
| 248 | 246 | } |
| 249 | 247 | |
| ... | ... | @@ -252,7 +250,7 @@ func DoOpen(gameId string, |
| 252 | 250 | |
| 253 | 251 | // DoOpenCheckAward 封装的新卡判断是否出发卡组和轮次奖励的逻辑 |
| 254 | 252 | func DoOpenCheckAward(gameId string, |
| 255 | - gameData *dto.CardHolderData, | |
| 253 | + gameData *CardHolderData, | |
| 256 | 254 | config *CardActivityConfig, |
| 257 | 255 | sequenceId, cohort string, |
| 258 | 256 | newCards []int, |
| ... | ... | @@ -290,8 +288,8 @@ func DoOpenCheckAward(gameId string, |
| 290 | 288 | awardAlbum[albumId] = award |
| 291 | 289 | { |
| 292 | 290 | // 记录日志 |
| 293 | - recordBase := dto.NewCardHolderRecordBase(gameData.Uid, sequenceId, cohort, config.Id, gameData.Details.Round) | |
| 294 | - svdto.SaveRecord(gameId, dto.NewCardHolderRecordRewardAlbum(recordBase, | |
| 291 | + recordBase := NewCardHolderRecordBase(gameData.Uid, sequenceId, cohort, config.Id, gameData.Details.Round) | |
| 292 | + svdto.SaveRecord(gameId, NewCardHolderRecordRewardAlbum(recordBase, | |
| 295 | 293 | albumId, award)) |
| 296 | 294 | } |
| 297 | 295 | } |
| ... | ... | @@ -301,8 +299,8 @@ func DoOpenCheckAward(gameId string, |
| 301 | 299 | awardRound = config.Awards[utstring.IntToString(gameData.Details.Round)] |
| 302 | 300 | |
| 303 | 301 | // 记录日志 |
| 304 | - recordBase := dto.NewCardHolderRecordBase(gameData.Uid, sequenceId, cohort, config.Id, gameData.Details.Round) | |
| 305 | - svdto.SaveRecord(gameId, dto.NewCardHolderRecordRewardRound(recordBase, | |
| 302 | + recordBase := NewCardHolderRecordBase(gameData.Uid, sequenceId, cohort, config.Id, gameData.Details.Round) | |
| 303 | + svdto.SaveRecord(gameId, NewCardHolderRecordRewardRound(recordBase, | |
| 306 | 304 | awardRound)) |
| 307 | 305 | |
| 308 | 306 | // 处理轮次完成 |
| ... | ... | @@ -314,7 +312,7 @@ func DoOpenCheckAward(gameId string, |
| 314 | 312 | } |
| 315 | 313 | |
| 316 | 314 | // CalculateStarCount 计算星星点数 |
| 317 | -func CalculateStarCount(gameData *dto.CardHolderData, config *CardActivityConfig) { | |
| 315 | +func CalculateStarCount(gameData *CardHolderData, config *CardActivityConfig) { | |
| 318 | 316 | starCount := 0 |
| 319 | 317 | for cardId, cardCount := range gameData.Details.Cards { |
| 320 | 318 | if cardCount <= 1 { |
| ... | ... | @@ -336,7 +334,7 @@ func CalculateStarCount(gameData *dto.CardHolderData, config *CardActivityConfig |
| 336 | 334 | } |
| 337 | 335 | |
| 338 | 336 | // GetStarCardList 按照规则扣除星星数找到需要扣除的卡牌列表 |
| 339 | -func GetStarCardList(gameData *dto.CardHolderData, config *CardActivityConfig, needStar int) (enough bool, cardList map[int]int) { | |
| 337 | +func GetStarCardList(gameData *CardHolderData, config *CardActivityConfig, needStar int) (enough bool, cardList map[int]int) { | |
| 340 | 338 | enough = false |
| 341 | 339 | cardList = make(map[int]int) |
| 342 | 340 | starAmount := 0 |
| ... | ... | @@ -405,7 +403,7 @@ func GetStarCardList(gameData *dto.CardHolderData, config *CardActivityConfig, n |
| 405 | 403 | } |
| 406 | 404 | |
| 407 | 405 | // NextActivityAutoExchange 活动切换时自动兑换卡包 |
| 408 | -func NextActivityAutoExchange(gameId string, gameData *dto.CardHolderData, config *CardActivityConfig) { | |
| 406 | +func NextActivityAutoExchange(gameId string, gameData *CardHolderData, config *CardActivityConfig) { | |
| 409 | 407 | starCount := gameData.Details.LastStarCount |
| 410 | 408 | // 把星星的配置按照需要的星星数降序排列 |
| 411 | 409 | list := lo.Values[int, StarShopConfig](config.StarShopConfig) | ... | ... |
service/constd/games.go
util/zredis/kv.go
| ... | ... | @@ -24,6 +24,11 @@ func Set(conn redis.Conn, key, value string) (err error) { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | func Get(conn redis.Conn, key string) (value string, err error) { |
| 27 | - value, err = redis.String(conn.Do("Get", "name")) | |
| 27 | + value, err = redis.String(conn.Do("Get", key)) | |
| 28 | + return | |
| 29 | +} | |
| 30 | + | |
| 31 | +func SetEx(conn redis.Conn, key, value string, exTime int) (err error) { | |
| 32 | + _, err = conn.Do("Set", key, value, "EX", exTime) | |
| 28 | 33 | return |
| 29 | 34 | } | ... | ... |