This commit is contained in:
yangduo 2024-12-06 19:38:34 +08:00
parent adf2337fde
commit c03212df1c
3 changed files with 42 additions and 37 deletions

View File

@ -117,7 +117,8 @@ func (this *ActivityApi) RollDice(c *gin.Context) {
awardgridids := mt.Table.MapGrid.GetAwardGridIdList()
if len(*items) > 0 {
gridawarded := false
for _, id := range user.AwardGridsList {
userAwardgrids := user.GetAwardGrids()
for _, id := range userAwardgrids {
if id == user.CurrGrid {
gridawarded = true
break
@ -129,7 +130,7 @@ func (this *ActivityApi) RollDice(c *gin.Context) {
rspObj.GetOrCreateAward().AddItem(item.ItemId, item.ItemNum)
}
if len(awardgridids) > len(user.AwardGridsList) + 1 {
if len(awardgridids) > len(userAwardgrids) + 1 {
user.AddAwardGrid(user.CurrGrid)
} else {
user.ClearAwardGrid()

View File

@ -11,27 +11,26 @@ import (
)
type User struct {
Idx int64 `gorm:"column:idx;AUTO_INCREMENT"`
AccountId string `gorm:"column:account_id;primaryKey"`
Uid string `gorm:"column:uid"`
Gid string `gorm:"column:gid"`
OpenId string `gorm:"column:openid"`
Version int32 `gorm:"column:version"`
Avatar string `gorm:"column:avatar"`
NickName string `gorm:"column:nickname"`
Invited string `gorm:"column:invited"`
Ext string `gorm:"column:ext"`
Plat int32 `gorm:"column:plat"`
PlatVip int32 `gorm:"column:plat_vip"`
Score int64 `gorm:"column:score"`
Dice int32 `gorm:"column:dice"`
SpecDice int32 `gorm:"column:spec_dice"`
LastPresentDiceTime int32 `gorm:"column:last_present_dice_time"`
CurrGrid int32 `gorm:"column:curr_grid"`
AwardGrids string `gorm:"column:award_grids"`
AwardGridsList []int32 `gorm:"-`
CreateTime int32 `gorm:"column:createtime;<-:create"`
ModifyTime int32 `gorm:"column:modifytime"`
Idx int64 `gorm:"column:idx;AUTO_INCREMENT"`
AccountId string `gorm:"column:account_id;primaryKey"`
Uid string `gorm:"column:uid"`
Gid string `gorm:"column:gid"`
OpenId string `gorm:"column:openid"`
Version int32 `gorm:"column:version"`
Avatar string `gorm:"column:avatar"`
NickName string `gorm:"column:nickname"`
Invited string `gorm:"column:invited"`
Ext string `gorm:"column:ext"`
Plat int32 `gorm:"column:plat"`
PlatVip int32 `gorm:"column:plat_vip"`
Score int64 `gorm:"column:score"`
Dice int32 `gorm:"column:dice"`
SpecDice int32 `gorm:"column:spec_dice"`
LastPresentDiceTime int32 `gorm:"column:last_present_dice_time"`
CurrGrid int32 `gorm:"column:curr_grid"`
awardGrids string `gorm:"column:award_grids"`
CreateTime int32 `gorm:"column:createtime;<-:create"`
ModifyTime int32 `gorm:"column:modifytime"`
}
func (this *User) TableName() string {
@ -67,13 +66,6 @@ func (this *User) Find(accountId string, nowTime int64) (error, bool) {
return err, false
}
}
gridstr := strings.Split(this.AwardGrids, ",")
this.AwardGridsList = []int32{}
for _, item := range gridstr {
if item != "" {
this.AwardGridsList = append(this.AwardGridsList, q5.SafeToInt32(item))
}
}
}
return nil, result.RowsAffected > 0
}
@ -170,12 +162,12 @@ func (this *User) UpdateName() error {
}
func (this *User) AddAwardGrid(gridid int32) error {
this.AwardGridsList = append(this.AwardGridsList, gridid)
if len(this.AwardGridsList) > 1 {
this.AwardGrids += ","
awardGridsList := this.GetAwardGrids()
if len(awardGridsList) > 1 {
this.awardGrids += ","
}
this.AwardGrids += q5.SafeToString(gridid)
this.awardGrids += q5.SafeToString(gridid)
if err := this.UpdateFields([]string{"award_grids"}); err != nil {
return err
}
@ -183,10 +175,22 @@ func (this *User) AddAwardGrid(gridid int32) error {
}
func (this *User) ClearAwardGrid() error {
this.AwardGridsList = []int32{}
this.AwardGrids = ""
this.awardGrids = ""
if err := this.UpdateFields([]string{"award_grids"}); err != nil {
return err
}
return nil
}
func (this *User) GetAwardGrids() []int32 {
gridstr := strings.Split(this.awardGrids, ",")
awardGridsList := []int32{}
for _, item := range gridstr {
if item != "" {
awardGridsList = append(awardGridsList, q5.SafeToInt32(item))
}
}
return awardGridsList
}

View File

@ -27,5 +27,5 @@ func (this *User) FromModel(m *model.User) {
this.SpecDice = m.SpecDice
this.CurrGrid = m.CurrGrid
this.LastPresentDiceTime = m.LastPresentDiceTime
this.AwardGrids = m.AwardGridsList
this.AwardGrids = m.GetAwardGrids()
}