From c03212df1c3db71008ef5b90bd514d11c2e22df7 Mon Sep 17 00:00:00 2001 From: yangduo Date: Fri, 6 Dec 2024 19:38:34 +0800 Subject: [PATCH] adjust --- .../wheelserver/api/v1/activity/activity.go | 5 +- server/wheelserver/model/user.go | 72 ++++++++++--------- server/wheelserver/vo/user.go | 2 +- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/server/wheelserver/api/v1/activity/activity.go b/server/wheelserver/api/v1/activity/activity.go index 4d8d76b1..ac388bd7 100644 --- a/server/wheelserver/api/v1/activity/activity.go +++ b/server/wheelserver/api/v1/activity/activity.go @@ -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() diff --git a/server/wheelserver/model/user.go b/server/wheelserver/model/user.go index 229a5034..ecb38256 100644 --- a/server/wheelserver/model/user.go +++ b/server/wheelserver/model/user.go @@ -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 +} diff --git a/server/wheelserver/vo/user.go b/server/wheelserver/vo/user.go index a6c90767..077866b2 100644 --- a/server/wheelserver/vo/user.go +++ b/server/wheelserver/vo/user.go @@ -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() }