Commit 10969d16d81742efef734760ebb35157dd5e04a3
1 parent
ffc151b5
Exists in
master
and in
1 other branch
feat:公共库整理,开卡包(新卡,保底卡)
Showing
13 changed files
with
396 additions
and
186 deletions
Show diff stats
api-util/json.go
api-util/umysql/index.go
| ... | ... | @@ -1,55 +0,0 @@ |
| 1 | -package umysql | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "github.com/astaxie/beego/orm" | |
| 5 | - "strings" | |
| 6 | -) | |
| 7 | - | |
| 8 | -// FindSql 查询数据 根据sql | |
| 9 | -func FindSql(dbName string, sql string, result any) (err error) { | |
| 10 | - orm := orm.NewOrm() | |
| 11 | - orm.Using(dbName) | |
| 12 | - | |
| 13 | - if _, err = orm.Raw(sql).QueryRows(result); err != nil { | |
| 14 | - if strings.Contains(err.Error(), "doesn't exist") { | |
| 15 | - err = nil | |
| 16 | - return | |
| 17 | - } | |
| 18 | - return | |
| 19 | - } | |
| 20 | - return | |
| 21 | -} | |
| 22 | - | |
| 23 | -// FindOneSql 查询一条数据 根据sql | |
| 24 | -func FindOneSql(dbName string, sql string, result any) (err error) { | |
| 25 | - orm := orm.NewOrm() | |
| 26 | - orm.Using(dbName) | |
| 27 | - | |
| 28 | - if err = orm.Raw(sql).QueryRow(result); err != nil { | |
| 29 | - if strings.Contains(err.Error(), "doesn't exist") { | |
| 30 | - err = nil | |
| 31 | - return | |
| 32 | - } | |
| 33 | - return | |
| 34 | - } | |
| 35 | - return | |
| 36 | -} | |
| 37 | - | |
| 38 | -// | |
| 39 | -//// Find 查询数据 | |
| 40 | -//func Find(dbName string, tableName string, result any) (err error) { | |
| 41 | -// o := orm.NewOrm() | |
| 42 | -// o.Using(dbName) | |
| 43 | -// | |
| 44 | -// // 也可以直接使用对象作为表名 | |
| 45 | -// qs := o.QueryTable(tableName) | |
| 46 | -// | |
| 47 | -// if _, err = qs.All(result); err != nil { | |
| 48 | -// if strings.Contains(err.Error(), "doesn't exist") { | |
| 49 | -// err = nil | |
| 50 | -// return | |
| 51 | -// } | |
| 52 | -// return | |
| 53 | -// } | |
| 54 | -// return | |
| 55 | -//} |
models/ht-cardholder.go
| ... | ... | @@ -8,12 +8,21 @@ import ( |
| 8 | 8 | "github.com/astaxie/beego/orm" |
| 9 | 9 | ) |
| 10 | 10 | |
| 11 | +func InitHtCardholder() { | |
| 12 | + | |
| 13 | + // register model | |
| 14 | + orm.RegisterModel(new(HtCardHolderData)) | |
| 15 | + | |
| 16 | + // create table | |
| 17 | + orm.RunSyncdb("default", false, true) | |
| 18 | +} | |
| 19 | + | |
| 11 | 20 | // HtCardHolderData 卡牌活动持久数据 |
| 12 | 21 | type HtCardHolderData struct { |
| 13 | 22 | Uid int64 `orm:"pk"` // 玩家唯一ID |
| 14 | 23 | ActivityId int64 // 活动ID |
| 15 | - DetailsData *HtCardHolderDataDetails `orm:"-"` // 活动详情 | |
| 16 | - Details string `orm:"type(text)"` // 活动详情封装 | |
| 24 | + Details *HtCardHolderDataDetails `orm:"-"` // 活动详情 | |
| 25 | + DetailsText string `orm:"type(text)"` // 活动详情封装 | |
| 17 | 26 | CreateTime int64 // 创建时间戳 |
| 18 | 27 | UpdateTime int64 // 修改时间戳 |
| 19 | 28 | } |
| ... | ... | @@ -30,8 +39,8 @@ type HtCardHolderDataDetails struct { |
| 30 | 39 | |
| 31 | 40 | func NewHtCardHolderData(uid int64) *HtCardHolderData { |
| 32 | 41 | return &HtCardHolderData{ |
| 33 | - Uid: uid, | |
| 34 | - DetailsData: NewHtCardHolderDataDetails(), | |
| 42 | + Uid: uid, | |
| 43 | + Details: NewHtCardHolderDataDetails(), | |
| 35 | 44 | } |
| 36 | 45 | } |
| 37 | 46 | |
| ... | ... | @@ -52,17 +61,17 @@ func (d *HtCardHolderData) TableName() string { |
| 52 | 61 | |
| 53 | 62 | // Encode 打包数据 |
| 54 | 63 | func (d *HtCardHolderData) Encode() { |
| 55 | - details, err := json.Marshal(d.DetailsData) | |
| 64 | + details, err := json.Marshal(d.Details) | |
| 56 | 65 | if err != nil { |
| 57 | 66 | lxalilog.Errors(err, "HtCardHolderData Encode Error", d.Uid, d.ActivityId) |
| 58 | 67 | return |
| 59 | 68 | } |
| 60 | - d.Details = string(details) | |
| 69 | + d.DetailsText = string(details) | |
| 61 | 70 | } |
| 62 | 71 | |
| 63 | 72 | // Decode 分包数据 |
| 64 | 73 | func (d *HtCardHolderData) Decode() { |
| 65 | - err := json.Unmarshal([]byte(d.Details), d.DetailsData) | |
| 74 | + err := json.Unmarshal([]byte(d.DetailsText), d.Details) | |
| 66 | 75 | if err != nil { |
| 67 | 76 | lxalilog.Errors(err, "HtCardHolderData Decode Error", d.Uid, d.ActivityId) |
| 68 | 77 | return |
| ... | ... | @@ -77,24 +86,15 @@ func (d *HtCardHolderData) GetInfo() dto.HtCardHolderInfo { |
| 77 | 86 | Album: make(map[string]int), |
| 78 | 87 | Round: 0, |
| 79 | 88 | } |
| 80 | - for i, i2 := range d.DetailsData.Cardholder { | |
| 89 | + for i, i2 := range d.Details.Cardholder { | |
| 81 | 90 | info.Cardholder[i] = i2 |
| 82 | 91 | } |
| 83 | - for i, i2 := range d.DetailsData.Cards { | |
| 92 | + for i, i2 := range d.Details.Cards { | |
| 84 | 93 | info.Cards[i] = i2 |
| 85 | 94 | } |
| 86 | - for i, i2 := range d.DetailsData.Album { | |
| 95 | + for i, i2 := range d.Details.Album { | |
| 87 | 96 | info.Album[i] = i2 |
| 88 | 97 | } |
| 89 | - info.Round = d.DetailsData.Round | |
| 98 | + info.Round = d.Details.Round | |
| 90 | 99 | return info |
| 91 | 100 | } |
| 92 | - | |
| 93 | -func InitHtCardholder() { | |
| 94 | - | |
| 95 | - // register model | |
| 96 | - orm.RegisterModel(new(HtCardHolderData)) | |
| 97 | - | |
| 98 | - // create table | |
| 99 | - orm.RunSyncdb("default", false, true) | |
| 100 | -} | ... | ... |
service/ht-cardholder/config-registry.go
| ... | ... | @@ -6,6 +6,7 @@ import ( |
| 6 | 6 | "encoding/json" |
| 7 | 7 | "errors" |
| 8 | 8 | "fmt" |
| 9 | + "strings" | |
| 9 | 10 | ) |
| 10 | 11 | |
| 11 | 12 | var ( |
| ... | ... | @@ -83,6 +84,7 @@ func ConfigDecode() { |
| 83 | 84 | return |
| 84 | 85 | } |
| 85 | 86 | for _, i2 := range configs { |
| 87 | + i2.NormalCardSequenceIds = strings.Split(i2.NormalCardSequenceId, ",") | |
| 86 | 88 | combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) |
| 87 | 89 | Config.NormalCardStarSequence[combineId] = i2 |
| 88 | 90 | } |
| ... | ... | @@ -96,6 +98,7 @@ func ConfigDecode() { |
| 96 | 98 | return |
| 97 | 99 | } |
| 98 | 100 | for _, i2 := range configs { |
| 101 | + i2.CardIdLists = strings.Split(i2.CardIdList, ",") | |
| 99 | 102 | combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) |
| 100 | 103 | Config.CardSequenceConfig[combineId] = i2 |
| 101 | 104 | } | ... | ... |
service/ht-cardholder/config.go
| ... | ... | @@ -64,24 +64,26 @@ type CardConfig struct { |
| 64 | 64 | type CardholderConfig struct { |
| 65 | 65 | Id string `json:"id"` // ID |
| 66 | 66 | GuaranteedStar string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID |
| 67 | - IsGoldCardholder int `json:"isgoldcardholder"` // 是否是金卡包 | |
| 68 | - IsNew int `json:"isnew"` // 是否是新卡包 | |
| 67 | + IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 | |
| 68 | + IsNew int `json:"is_new"` // 是否是新卡包 | |
| 69 | 69 | NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 |
| 70 | 70 | MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // NormalCardStarSequence 非保底卡星级ID |
| 74 | 74 | type NormalCardStarSequence struct { |
| 75 | - Id string `json:"id"` // ID | |
| 76 | - SequenceId string `json:"user_sequence_id"` // 用户序列组ID | |
| 77 | - Cohort string `json:"cohort"` // 用户分组 | |
| 78 | - NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列 | |
| 75 | + Id string `json:"id"` // ID | |
| 76 | + SequenceId string `json:"user_sequence_id"` // 用户序列组ID | |
| 77 | + Cohort string `json:"cohort"` // 用户分组 | |
| 78 | + NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列 | |
| 79 | + NormalCardSequenceIds []string `json:"-"` // 非保底星级序列 | |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | // CardSequenceConfig 星级ID对应的卡片 |
| 82 | 83 | type CardSequenceConfig struct { |
| 83 | - Id string `json:"id"` // SequenceId 用户序列组ID | |
| 84 | - SequenceId string `json:"user_sequence_id"` // 用户序列组ID | |
| 85 | - Cohort string `json:"cohort"` // 用户分组 | |
| 86 | - CardIdList string `json:"card_id_list"` // 卡牌抽取序列 | |
| 84 | + Id string `json:"id"` // SequenceId 用户序列组ID | |
| 85 | + SequenceId string `json:"user_sequence_id"` // 用户序列组ID | |
| 86 | + Cohort string `json:"cohort"` // 用户分组 | |
| 87 | + CardIdList string `json:"card_id_list"` // 卡牌抽取序列 | |
| 88 | + CardIdLists []string `json:"-"` // 卡牌抽取序列 | |
| 87 | 89 | } | ... | ... |
service/ht-cardholder/configs.go
| 1 | 1 | package ht_cardholder |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | - "apigame/api-util/umysql" | |
| 5 | 4 | "apigame/lx-util/lxalilog" |
| 6 | 5 | "apigame/service/constd" |
| 6 | + "apigame/util/utmysql" | |
| 7 | 7 | "fmt" |
| 8 | 8 | "github.com/astaxie/beego/logs" |
| 9 | 9 | ) |
| ... | ... | @@ -31,7 +31,7 @@ func LoadConfigs() { |
| 31 | 31 | { |
| 32 | 32 | conf := make([]CardActivityUpdateConfig, 0) |
| 33 | 33 | sql := fmt.Sprintf("select id,status,update_time from %s", configTableName) |
| 34 | - err := umysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf) | |
| 34 | + err := utmysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf) | |
| 35 | 35 | if err != nil { |
| 36 | 36 | lxalilog.Errors(err, sql, constd.GAME_ID_HT) |
| 37 | 37 | return |
| ... | ... | @@ -53,7 +53,7 @@ func LoadConfigs() { |
| 53 | 53 | logs.Debug("__________________尝试更新活动条目ID:", configOpen.Id) |
| 54 | 54 | confNew := CardActivityConfigRaw{} |
| 55 | 55 | sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTableName, configOpen.Id) |
| 56 | - err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew) | |
| 56 | + err := utmysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew) | |
| 57 | 57 | if err != nil { |
| 58 | 58 | lxalilog.Errors(err, sql, constd.GAME_ID_HT, configOpen.Id) |
| 59 | 59 | return | ... | ... |
service/ht-cardholder/handle.go
| ... | ... | @@ -2,11 +2,8 @@ package ht_cardholder |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 4 | "apigame/dto" |
| 5 | - "apigame/lx-util/lxalilog" | |
| 6 | - "apigame/lx-util/lxtime" | |
| 7 | - "apigame/models" | |
| 8 | 5 | "apigame/service/constd" |
| 9 | - "github.com/astaxie/beego/orm" | |
| 6 | + "apigame/util/uttype" | |
| 10 | 7 | "strconv" |
| 11 | 8 | ) |
| 12 | 9 | |
| ... | ... | @@ -54,9 +51,10 @@ func HandleGetNew(req *dto.ReqHtCardHolderGetNew) (code string, rsp dto.RspHtCar |
| 54 | 51 | // 读取游戏数据 |
| 55 | 52 | gameData := LoadData(req.UID) |
| 56 | 53 | |
| 57 | - gameData.DetailsData.Cardholder[req.Id] += req.Count | |
| 54 | + gameData.Details.Cardholder[req.Id] += req.Count | |
| 58 | 55 | SaveData(gameData) |
| 59 | 56 | |
| 57 | + // 返回信息 | |
| 60 | 58 | rsp.HtCardHolderInfo = gameData.GetInfo() |
| 61 | 59 | |
| 62 | 60 | return |
| ... | ... | @@ -75,100 +73,59 @@ func HandleOpen(req *dto.ReqHtCardHolderOpen) (code string, rsp dto.RspHtCardHol |
| 75 | 73 | if code != constd.RECODE_OK { |
| 76 | 74 | return |
| 77 | 75 | } |
| 78 | - //// 检查卡包ID | |
| 79 | - //confCardholder, okCardholderConfig := Registry.Config.CardholderConfig[strconv.Itoa(req.Id)] | |
| 80 | - //if !okCardholderConfig { | |
| 81 | - // code = constd.RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR | |
| 82 | - // return | |
| 83 | - //} | |
| 84 | - // | |
| 85 | - //// 读取游戏数据 | |
| 86 | - //gameData := LoadData(req.UID) | |
| 87 | - // | |
| 88 | - //// 判断卡包数目 | |
| 89 | - //countOld, _ := gameData.DetailsData.Cardholder[req.Id] | |
| 90 | - //if countOld < 1 { | |
| 91 | - // code = constd.RECODE_MERGE_CARDHOLDER_CARDHOLDER_NOTENOUGH_ERROR | |
| 92 | - // return | |
| 93 | - //} | |
| 94 | - // | |
| 95 | - //// 开始处理抽卡 | |
| 96 | - //sequenceId, cohort := GetUserSequenceIdAndCohort(req.UID) | |
| 97 | - //// 先抽保底卡 | |
| 98 | - //if confCardholder.GuaranteedStar != "0" { | |
| 99 | - // confGuaranteed, hasGuaranteed := FindCardSequenceConfig(confCardholder.GuaranteedStar, sequenceId, cohort) | |
| 100 | - // if hasGuaranteed { | |
| 101 | - // | |
| 102 | - // } | |
| 103 | - //} | |
| 76 | + // 检查卡包ID | |
| 77 | + confCardholder, okCardholderConfig := Config.CardholderConfig[strconv.Itoa(req.Id)] | |
| 78 | + if !okCardholderConfig { | |
| 79 | + code = constd.RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR | |
| 80 | + return | |
| 81 | + } | |
| 104 | 82 | |
| 105 | - return | |
| 106 | -} | |
| 83 | + // 读取游戏数据 | |
| 84 | + gameData := LoadData(req.UID) | |
| 107 | 85 | |
| 108 | -// SaveData 存储数据 | |
| 109 | -func SaveData(d *models.HtCardHolderData) { | |
| 110 | - d.UpdateTime = lxtime.NowUninx() | |
| 111 | - d.Encode() | |
| 112 | - o := orm.NewOrm() | |
| 113 | - o.Using(constd.MYSQL_DEFAULT) | |
| 114 | - if _, err := o.InsertOrUpdate(d); err != nil { | |
| 115 | - lxalilog.Errors(err, "ht_cardholder SaveData Error", d.Uid) | |
| 86 | + // 判断卡包数目 | |
| 87 | + countOld, _ := gameData.Details.Cardholder[req.Id] | |
| 88 | + if countOld < 1 { | |
| 89 | + code = constd.RECODE_MERGE_CARDHOLDER_CARDHOLDER_NOTENOUGH_ERROR | |
| 90 | + return | |
| 116 | 91 | } |
| 117 | -} | |
| 118 | 92 | |
| 119 | -func _LoadData(uid int64) (d *models.HtCardHolderData) { | |
| 120 | - d = models.NewHtCardHolderData(uid) | |
| 121 | - o := orm.NewOrm() | |
| 122 | - o.Using(constd.MYSQL_DEFAULT) | |
| 123 | - qs := o.QueryTable(d) | |
| 124 | - qs = qs.Filter("uid", uid) | |
| 125 | - count, err := qs.Count() | |
| 126 | - if count == 0 { | |
| 127 | - d.CreateTime = lxtime.NowUninx() | |
| 93 | + // 开始处理抽卡 | |
| 94 | + sequenceId, cohort := GetUserSequenceIdAndCohort(req.UID) | |
| 95 | + if confCardholder.IsNew != 0 { | |
| 96 | + // 如果是新卡包 按顺序查找数目最少的一张卡抽取 | |
| 97 | + cardId := GetNewCard(gameData) | |
| 98 | + // 增加卡牌 | |
| 99 | + gameData.Details.Cards[cardId] += 1 | |
| 100 | + rsp.NewCards = append(rsp.NewCards, cardId) | |
| 128 | 101 | } else { |
| 129 | - err = qs.One(d) | |
| 130 | - if err != nil { | |
| 131 | - lxalilog.Errors(err, "ht_cardholder LoadData Error", uid) | |
| 132 | - } else { | |
| 133 | - d.DetailsData = models.NewHtCardHolderDataDetails() | |
| 134 | - d.Decode() | |
| 102 | + // 正常抽卡 | |
| 103 | + // 先抽保底卡 | |
| 104 | + if confCardholder.GuaranteedStar != "0" { | |
| 105 | + confGuaranteed, hasGuaranteed := FindCardSequenceConfig(confCardholder.GuaranteedStar, sequenceId, cohort) | |
| 106 | + if hasGuaranteed { | |
| 107 | + combineId := CombineIdSequenceIdCohort(confCardholder.GuaranteedStar, sequenceId, cohort) | |
| 108 | + scale := gameData.Details.CardSequenceScales[combineId] | |
| 109 | + cardId := GetOneFromArray(confGuaranteed.CardIdLists, scale) | |
| 110 | + cardIdInt := uttype.StringToInt(cardId) | |
| 111 | + // 增加刻度 | |
| 112 | + gameData.Details.CardSequenceScales[combineId] = scale + 1 | |
| 113 | + // 增加卡牌 | |
| 114 | + gameData.Details.Cards[cardIdInt] += 1 | |
| 115 | + rsp.NewCards = append(rsp.NewCards, cardIdInt) | |
| 116 | + } | |
| 135 | 117 | } |
| 136 | - } | |
| 137 | - return | |
| 138 | -} | |
| 139 | 118 | |
| 140 | -// LoadData 获取数据 外部接口 | |
| 141 | -func LoadData(uid int64) (d *models.HtCardHolderData) { | |
| 142 | - d = _LoadData(uid) | |
| 143 | - // 如果当前有上线活动(活动ID不为0),且活动ID和玩家数据不同,说明活动已切换 需更新 | |
| 144 | - if Config.Id != 0 && | |
| 145 | - Config.Id != d.ActivityId { | |
| 146 | - d.ActivityId = Config.Id | |
| 147 | - d.DetailsData = models.NewHtCardHolderDataDetails() | |
| 148 | - SaveData(d) | |
| 149 | 119 | } |
| 150 | - return | |
| 151 | -} | |
| 152 | 120 | |
| 153 | -// CheckStatus 判断活动是否开启 | |
| 154 | -func CheckStatus() string { | |
| 155 | - sec := lxtime.NowUninx() | |
| 156 | - if Config.Id == 0 { | |
| 157 | - return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR | |
| 158 | - } | |
| 159 | - if sec < Config.Raw.StartTime { | |
| 160 | - return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR | |
| 161 | - } | |
| 162 | - if sec > Config.Raw.EndTime { | |
| 163 | - return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR | |
| 164 | - } | |
| 165 | - return constd.RECODE_OK | |
| 166 | -} | |
| 121 | + // 删除一个卡包 | |
| 122 | + gameData.Details.Cardholder[req.Id] = countOld - 1 | |
| 123 | + | |
| 124 | + // 存档 | |
| 125 | + SaveData(gameData) | |
| 126 | + | |
| 127 | + // 返回信息 | |
| 128 | + rsp.HtCardHolderInfo = gameData.GetInfo() | |
| 167 | 129 | |
| 168 | -// GetUserSequenceIdAndCohort 获取 用户序列组ID(sequenceId) 用户分组(cohort) | |
| 169 | -func GetUserSequenceIdAndCohort(uid int64) (sequenceId, cohort string) { | |
| 170 | - // todo 这里后续要对接 | |
| 171 | - sequenceId = "1" | |
| 172 | - cohort = "1" | |
| 173 | 130 | return |
| 174 | 131 | } | ... | ... |
| ... | ... | @@ -0,0 +1,122 @@ |
| 1 | +package ht_cardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/lx-util/lxalilog" | |
| 5 | + "apigame/lx-util/lxtime" | |
| 6 | + "apigame/models" | |
| 7 | + "apigame/service/constd" | |
| 8 | + "apigame/util/uttype" | |
| 9 | + "github.com/astaxie/beego/orm" | |
| 10 | +) | |
| 11 | + | |
| 12 | +// SaveData 存储数据 | |
| 13 | +func SaveData(d *models.HtCardHolderData) { | |
| 14 | + d.UpdateTime = lxtime.NowUninx() | |
| 15 | + d.Encode() | |
| 16 | + o := orm.NewOrm() | |
| 17 | + o.Using(constd.MYSQL_DEFAULT) | |
| 18 | + if _, err := o.InsertOrUpdate(d); err != nil { | |
| 19 | + lxalilog.Errors(err, "ht_cardholder SaveData Error", d.Uid) | |
| 20 | + } | |
| 21 | +} | |
| 22 | + | |
| 23 | +func _LoadData(uid int64) (d *models.HtCardHolderData) { | |
| 24 | + d = models.NewHtCardHolderData(uid) | |
| 25 | + o := orm.NewOrm() | |
| 26 | + o.Using(constd.MYSQL_DEFAULT) | |
| 27 | + qs := o.QueryTable(d) | |
| 28 | + qs = qs.Filter("uid", uid) | |
| 29 | + count, err := qs.Count() | |
| 30 | + if count == 0 { | |
| 31 | + d.CreateTime = lxtime.NowUninx() | |
| 32 | + } else { | |
| 33 | + err = qs.One(d) | |
| 34 | + if err != nil { | |
| 35 | + lxalilog.Errors(err, "ht_cardholder LoadData Error", uid) | |
| 36 | + } else { | |
| 37 | + d.Details = models.NewHtCardHolderDataDetails() | |
| 38 | + d.Decode() | |
| 39 | + } | |
| 40 | + } | |
| 41 | + return | |
| 42 | +} | |
| 43 | + | |
| 44 | +// LoadData 获取数据 外部接口 | |
| 45 | +func LoadData(uid int64) (d *models.HtCardHolderData) { | |
| 46 | + d = _LoadData(uid) | |
| 47 | + // 如果当前有上线活动(活动ID不为0),且活动ID和玩家数据不同,说明活动已切换 需更新 | |
| 48 | + if Config.Id != 0 && | |
| 49 | + Config.Id != d.ActivityId { | |
| 50 | + d.ActivityId = Config.Id | |
| 51 | + d.Details = models.NewHtCardHolderDataDetails() | |
| 52 | + SaveData(d) | |
| 53 | + } | |
| 54 | + return | |
| 55 | +} | |
| 56 | + | |
| 57 | +// CheckStatus 判断活动是否开启 | |
| 58 | +func CheckStatus() string { | |
| 59 | + sec := lxtime.NowUninx() | |
| 60 | + if Config.Id == 0 { | |
| 61 | + return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR | |
| 62 | + } | |
| 63 | + if sec < Config.Raw.StartTime { | |
| 64 | + return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR | |
| 65 | + } | |
| 66 | + if sec > Config.Raw.EndTime { | |
| 67 | + return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR | |
| 68 | + } | |
| 69 | + return constd.RECODE_OK | |
| 70 | +} | |
| 71 | + | |
| 72 | +// GetUserSequenceIdAndCohort 获取 用户序列组ID(sequenceId) 用户分组(cohort) | |
| 73 | +func GetUserSequenceIdAndCohort(uid int64) (sequenceId, cohort string) { | |
| 74 | + // todo 这里后续要对接 | |
| 75 | + sequenceId = "1" | |
| 76 | + cohort = "1" | |
| 77 | + return | |
| 78 | +} | |
| 79 | + | |
| 80 | +// GetOneFromArray 从配置的数组里获取一个值 scale=之前刻度 | |
| 81 | +func GetOneFromArray(array []string, scale int) string { | |
| 82 | + length := len(array) | |
| 83 | + if length < 1 { | |
| 84 | + return "" | |
| 85 | + } | |
| 86 | + if length == 1 { | |
| 87 | + return array[0] | |
| 88 | + } | |
| 89 | + return array[scale%length] | |
| 90 | +} | |
| 91 | + | |
| 92 | +// GetListFromArray 从配置的数组里获取一组值 scale=之前刻度 count=数目 | |
| 93 | +func GetListFromArray(array []string, scale, count int) []string { | |
| 94 | + list := make([]string, 0) | |
| 95 | + if count < 0 { | |
| 96 | + return list | |
| 97 | + } | |
| 98 | + s := scale | |
| 99 | + for i := 0; i < count; i++ { | |
| 100 | + one := GetOneFromArray(array, s) | |
| 101 | + list = append(list, one) | |
| 102 | + s++ | |
| 103 | + } | |
| 104 | + return list | |
| 105 | +} | |
| 106 | + | |
| 107 | +// GetNewCard 按顺序查找数目最少的一张卡抽取 | |
| 108 | +func GetNewCard(gameData *models.HtCardHolderData) int { | |
| 109 | + if len(Config.CardConfig) < 1 { | |
| 110 | + return 0 | |
| 111 | + } | |
| 112 | + rate := int64(100000000) | |
| 113 | + list := make([]int64, 0) | |
| 114 | + for id, _ := range Config.CardConfig { | |
| 115 | + count, _ := gameData.Details.Cards[id] | |
| 116 | + index := int64(count)*rate + int64(id) | |
| 117 | + list = append(list, index) | |
| 118 | + } | |
| 119 | + | |
| 120 | + indexMin := uttype.Min(list...) | |
| 121 | + return int(indexMin % rate) | |
| 122 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | +package utmysql | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "github.com/astaxie/beego/orm" | |
| 5 | + "strings" | |
| 6 | +) | |
| 7 | + | |
| 8 | +// FindSql 查询数据 根据sql | |
| 9 | +func FindSql(dbName string, sql string, result any) (err error) { | |
| 10 | + orm := orm.NewOrm() | |
| 11 | + orm.Using(dbName) | |
| 12 | + | |
| 13 | + if _, err = orm.Raw(sql).QueryRows(result); err != nil { | |
| 14 | + if strings.Contains(err.Error(), "doesn't exist") { | |
| 15 | + err = nil | |
| 16 | + return | |
| 17 | + } | |
| 18 | + return | |
| 19 | + } | |
| 20 | + return | |
| 21 | +} | |
| 22 | + | |
| 23 | +// FindOneSql 查询一条数据 根据sql | |
| 24 | +func FindOneSql(dbName string, sql string, result any) (err error) { | |
| 25 | + orm := orm.NewOrm() | |
| 26 | + orm.Using(dbName) | |
| 27 | + | |
| 28 | + if err = orm.Raw(sql).QueryRow(result); err != nil { | |
| 29 | + if strings.Contains(err.Error(), "doesn't exist") { | |
| 30 | + err = nil | |
| 31 | + return | |
| 32 | + } | |
| 33 | + return | |
| 34 | + } | |
| 35 | + return | |
| 36 | +} | |
| 37 | + | |
| 38 | +// | |
| 39 | +//// Find 查询数据 | |
| 40 | +//func Find(dbName string, tableName string, result any) (err error) { | |
| 41 | +// o := orm.NewOrm() | |
| 42 | +// o.Using(dbName) | |
| 43 | +// | |
| 44 | +// // 也可以直接使用对象作为表名 | |
| 45 | +// qs := o.QueryTable(tableName) | |
| 46 | +// | |
| 47 | +// if _, err = qs.All(result); err != nil { | |
| 48 | +// if strings.Contains(err.Error(), "doesn't exist") { | |
| 49 | +// err = nil | |
| 50 | +// return | |
| 51 | +// } | |
| 52 | +// return | |
| 53 | +// } | |
| 54 | +// return | |
| 55 | +//} | ... | ... |
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +package uttype | |
| 2 | + | |
| 3 | +// Int 整型 | |
| 4 | +type Int interface { | |
| 5 | + int | int8 | int16 | int32 | int64 | float32 | float64 | |
| 6 | +} | |
| 7 | + | |
| 8 | +// Uint 无符号整型 | |
| 9 | +type Uint interface { | |
| 10 | + uint | uint8 | uint16 | uint32 | |
| 11 | +} | |
| 12 | + | |
| 13 | +// Float 浮点 | |
| 14 | +type Float interface { | |
| 15 | + float32 | float64 | |
| 16 | +} | |
| 17 | + | |
| 18 | +// Number 数字 | |
| 19 | +type Number interface { | |
| 20 | + Int | Uint | Float | |
| 21 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +package uttype | |
| 2 | + | |
| 3 | +func Min[T Number](values ...T) T { | |
| 4 | + result := values[0] | |
| 5 | + for _, v := range values[1:] { | |
| 6 | + if v < result { | |
| 7 | + result = v | |
| 8 | + } | |
| 9 | + } | |
| 10 | + return result | |
| 11 | +} | |
| 12 | + | |
| 13 | +func Max[T Number](values ...T) T { | |
| 14 | + result := values[0] | |
| 15 | + for _, v := range values[1:] { | |
| 16 | + if v > result { | |
| 17 | + result = v | |
| 18 | + } | |
| 19 | + } | |
| 20 | + return result | |
| 21 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,84 @@ |
| 1 | +package uttype | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "strconv" | |
| 5 | + "strings" | |
| 6 | +) | |
| 7 | + | |
| 8 | +const ( | |
| 9 | + StrSpe1 = "|" | |
| 10 | + StrSpe2 = "_" | |
| 11 | +) | |
| 12 | + | |
| 13 | +func StringToInt(str string) int { | |
| 14 | + if value, err := strconv.Atoi(str); err == nil { | |
| 15 | + return value | |
| 16 | + } | |
| 17 | + return 0 | |
| 18 | +} | |
| 19 | +func StringToInt32(str string) int32 { | |
| 20 | + return int32(StringToInt(str)) | |
| 21 | +} | |
| 22 | +func StringToInt64(str string) int64 { | |
| 23 | + if value, err := strconv.ParseInt(str, 10, 64); err == nil { | |
| 24 | + return value | |
| 25 | + } | |
| 26 | + return 0 | |
| 27 | +} | |
| 28 | +func IntToString(value int) string { | |
| 29 | + return strconv.Itoa(value) | |
| 30 | +} | |
| 31 | +func Int32ToString(value int32) string { | |
| 32 | + return IntToString(int(value)) | |
| 33 | +} | |
| 34 | +func Int64ToString(value int64) string { | |
| 35 | + return strconv.FormatInt(value, 10) | |
| 36 | +} | |
| 37 | + | |
| 38 | +func ListStringToListInt(list []string) []int { | |
| 39 | + result := make([]int, 0) | |
| 40 | + for _, v := range list { | |
| 41 | + result = append(result, StringToInt(v)) | |
| 42 | + } | |
| 43 | + return result | |
| 44 | +} | |
| 45 | +func ListStringToListInt64(list []string) []int64 { | |
| 46 | + result := make([]int64, 0) | |
| 47 | + for _, v := range list { | |
| 48 | + result = append(result, StringToInt64(v)) | |
| 49 | + } | |
| 50 | + return result | |
| 51 | +} | |
| 52 | +func StringToListString(str string) []string { | |
| 53 | + return strings.Split(str, StrSpe1) | |
| 54 | +} | |
| 55 | +func StringToListInt(str string) []int { | |
| 56 | + return ListStringToListInt(strings.Split(str, StrSpe1)) | |
| 57 | +} | |
| 58 | +func StringToListListString(str string) [][]string { | |
| 59 | + result := make([][]string, 0) | |
| 60 | + list1 := strings.Split(str, StrSpe1) | |
| 61 | + for _, v := range list1 { | |
| 62 | + list2 := strings.Split(v, StrSpe2) | |
| 63 | + result = append(result, list2) | |
| 64 | + } | |
| 65 | + return result | |
| 66 | +} | |
| 67 | +func StringToListListInt(str string) [][]int { | |
| 68 | + result := make([][]int, 0) | |
| 69 | + list1 := strings.Split(str, StrSpe1) | |
| 70 | + for _, v := range list1 { | |
| 71 | + list2 := strings.Split(v, StrSpe2) | |
| 72 | + result = append(result, ListStringToListInt(list2)) | |
| 73 | + } | |
| 74 | + return result | |
| 75 | +} | |
| 76 | +func StringToListListInt64(str string) [][]int64 { | |
| 77 | + result := make([][]int64, 0) | |
| 78 | + list1 := strings.Split(str, StrSpe1) | |
| 79 | + for _, v := range list1 { | |
| 80 | + list2 := strings.Split(v, StrSpe2) | |
| 81 | + result = append(result, ListStringToListInt64(list2)) | |
| 82 | + } | |
| 83 | + return result | |
| 84 | +} | ... | ... |