diff --git a/server/wheelserver/api/v1/activity/activity.go b/server/wheelserver/api/v1/activity/activity.go index f9cbc4be..44285667 100644 --- a/server/wheelserver/api/v1/activity/activity.go +++ b/server/wheelserver/api/v1/activity/activity.go @@ -103,13 +103,14 @@ func (this *ActivityApi) RollDice(c *gin.Context) { } user.CurrGrid += rspObj.Point } - user.UpdateFields([]string{"curr_grid"}) + // user.UpdateFields([]string{"curr_grid"}) + user.AddFields("curr_grid") items := gridMeta.GetRewardItems() if items == nil { f5.RspErr(c, 500, "server internal error7") return } - + fullgrid := false if len(*items) > 0 { gridawarded := false @@ -156,6 +157,7 @@ func (this *ActivityApi) RollDice(c *gin.Context) { } rspObj.GetOrCreateSideEffect().GetOrCreateUser().FromModel(user) + user.UpdateUserFields() c.JSON(200, rspObj) } @@ -197,8 +199,9 @@ func (this *ActivityApi) Claim(c *gin.Context) { } user.CurrGrid = 1 - user.AwardGrids = "" - user.UpdateFields([]string{"curr_grid", "award_grids"}) + user.ClearAwardGrid() + // user.UpdateFields([]string{"curr_grid", "award_grids"}) + user.AddFields("curr_grid") for _, item := range *items { rspObj.GetOrCreateAward().AddItem(item.ItemId, item.ItemNum) @@ -214,5 +217,6 @@ func (this *ActivityApi) Claim(c *gin.Context) { } rspObj.GetOrCreateSideEffect().GetOrCreateUser().FromModel(user) + user.UpdateUserFields() c.JSON(200, rspObj) } diff --git a/server/wheelserver/api/v1/inapp_shop/inapp_shop.go b/server/wheelserver/api/v1/inapp_shop/inapp_shop.go index be156711..fb83130d 100644 --- a/server/wheelserver/api/v1/inapp_shop/inapp_shop.go +++ b/server/wheelserver/api/v1/inapp_shop/inapp_shop.go @@ -198,5 +198,6 @@ func (this *InAppShopApi) Callback(c *gin.Context) { service.Award.AddItem(orderModel.AccountId, itemcfg.GetId(), ordergoods.GetAmount(), nil) } - service.Task.UpdateTaskProgress(orderModel.AccountId, itemcfg.GetItemType(), ordergoods.GetAmount(), nil) + service.Task.UpdateTaskProgress(orderModel.AccountId, itemcfg.GetItemType(), ordergoods.GetAmount(), nil) + user.UpdateUserFields() } diff --git a/server/wheelserver/api/v1/mission/mission.go b/server/wheelserver/api/v1/mission/mission.go index 22cc459a..db5f86fd 100644 --- a/server/wheelserver/api/v1/mission/mission.go +++ b/server/wheelserver/api/v1/mission/mission.go @@ -163,5 +163,7 @@ func (this *MissionApi) ClaimTaskAward(c *gin.Context) { q5.AppendSlice(&rspObj.Data, missionVo) } + user.UpdateUserFields() + c.JSON(200, rspObj) } diff --git a/server/wheelserver/api/v1/shop/shop.go b/server/wheelserver/api/v1/shop/shop.go index 95968152..162b408d 100644 --- a/server/wheelserver/api/v1/shop/shop.go +++ b/server/wheelserver/api/v1/shop/shop.go @@ -101,5 +101,6 @@ func (this *ShopApi) Buy(c *gin.Context) { q5.AppendSlice(&rspObj.BaseVo.GetOrCreateSideEffect().Effects, "task") } + user.UpdateUserFields() c.JSON(200, rspObj) } diff --git a/server/wheelserver/api/v1/user/user.go b/server/wheelserver/api/v1/user/user.go index 80840161..e7a05100 100644 --- a/server/wheelserver/api/v1/user/user.go +++ b/server/wheelserver/api/v1/user/user.go @@ -63,13 +63,14 @@ func (this *UserApi) Login(c *gin.Context) { } if user.NickName != s.GetNickName() { - user.UpdateName() + user.UpdateName(s.GetNickName()) } f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user}) rspObj.UserInfo.FromModel(user) if found { rspObj.UserInfo.HourlyEarnings = service.Chip.GetHourEarning(user.AccountId) } + user.UpdateUserFields() c.JSON(200, rspObj) } diff --git a/server/wheelserver/model/user.go b/server/wheelserver/model/user.go index c665bf52..8c7b8f02 100644 --- a/server/wheelserver/model/user.go +++ b/server/wheelserver/model/user.go @@ -11,26 +11,27 @@ 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"` - 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"` + updatefields map[string]int `gorm:"-"` } func (this *User) TableName() string { @@ -45,6 +46,30 @@ func (this *User) UpdateFields(fields []string) error { return nil } +func (this *User) UpdateUserFields() error { + if len(this.updatefields) == 0 { + return nil + } + + fields := []string{} + for item := range this.updatefields { + fields = append(fields, item) + } + + for k := range this.updatefields { + delete(this.updatefields, k) + } + + return this.UpdateFields(fields) +} + +func (this *User) AddFields(f string) { + if this.updatefields == nil { + this.updatefields = map[string]int{} + } + this.updatefields[f] = 1 +} + func (this *User) Find(accountId string, nowTime int64) (error, bool) { if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take( this, "account_id = ?", accountId); result.Error != nil && @@ -98,23 +123,26 @@ func (this *User) DecDice(num int32) error { updatepresentTime = true } - updatefileds := []string{"dice"} + // updatefileds := []string{"dice"} + this.AddFields("dice") if updatepresentTime { - updatefileds = append(updatefileds, "last_present_dice_time") + // updatefileds = append(updatefileds, "last_present_dice_time") + this.AddFields("last_present_dice_time") } - if err := this.UpdateFields(updatefileds); err != nil { - this.Dice = oldDice - return err - } + // if err := this.UpdateFields(updatefileds); err != nil { + // this.Dice = oldDice + // return err + // } return nil } func (this *User) AddSpecDice(num int32) error { this.SpecDice += num - if err := this.UpdateFields([]string{"spec_dice"}); err != nil { - return err - } + // if err := this.UpdateFields([]string{"spec_dice"}); err != nil { + // return err + // } + this.AddFields("spec_dice") return nil } @@ -122,12 +150,13 @@ func (this *User) DecSpecDice(num int32) error { if this.SpecDice < num { return errors.New("") } - oldSpecDice := this.SpecDice + // oldSpecDice := this.SpecDice this.SpecDice -= num - if err := this.UpdateFields([]string{"spec_dice"}); err != nil { - this.SpecDice = oldSpecDice - return err - } + // if err := this.UpdateFields([]string{"spec_dice"}); err != nil { + // this.SpecDice = oldSpecDice + // return err + // } + this.AddFields("spec_dice") return nil } @@ -135,12 +164,13 @@ func (this *User) DecScore(num int32) error { if this.Score < int64(num) { return errors.New("") } - oldScore := this.Score + // oldScore := this.Score this.Score -= int64(num) - if err := this.UpdateFields([]string{"score"}); err != nil { - this.Score = oldScore - return err - } + // if err := this.UpdateFields([]string{"score"}); err != nil { + // this.Score = oldScore + // return err + // } + this.AddFields("score") return nil } @@ -148,17 +178,21 @@ func (this *User) AddScore(score int32) error { if score <= 0 { return nil } - oldScore := this.Score + // oldScore := this.Score this.Score += int64(score) - if err := this.UpdateFields([]string{"score"}); err != nil { - this.Score = oldScore - return err - } + // if err := this.UpdateFields([]string{"score"}); err != nil { + // this.Score = oldScore + // return err + // } + this.AddFields("score") return nil } -func (this *User) UpdateName() error { - return this.UpdateFields([]string{"nickname"}) +func (this *User) UpdateName(name string) error { + this.NickName = name + // return this.UpdateFields([]string{"nickname"}) + this.AddFields("nickname") + return nil } func (this *User) AddAwardGrid(gridid int32) error { @@ -168,12 +202,16 @@ func (this *User) AddAwardGrid(gridid int32) error { } this.AwardGrids += q5.SafeToString(gridid) - return this.UpdateFields([]string{"award_grids"}) + // return this.UpdateFields([]string{"award_grids"}) + this.AddFields("award_grids") + return nil } func (this *User) ClearAwardGrid() error { this.AwardGrids = "" - return this.UpdateFields([]string{"award_grids"}) + // return this.UpdateFields([]string{"award_grids"}) + this.AddFields("award_grids") + return nil } func (this *User) GetAwardGrids() []int32 { diff --git a/server/wheelserver/service/award.go b/server/wheelserver/service/award.go index 2e5bbfbe..52be99d1 100644 --- a/server/wheelserver/service/award.go +++ b/server/wheelserver/service/award.go @@ -32,6 +32,7 @@ func (this *award) AddItem(accountId string, itemId int32, itemNum int32, baseVo baseVo.GetOrCreateSideEffect().User.FromModel(user) baseVo.GetOrCreateSideEffect().User.HourlyEarnings = Chip.GetHourEarning(user.AccountId) } + user.UpdateUserFields() } return } diff --git a/server/wheelserver/service/buff.go b/server/wheelserver/service/buff.go index a18964b3..a7f05bae 100644 --- a/server/wheelserver/service/buff.go +++ b/server/wheelserver/service/buff.go @@ -2,13 +2,12 @@ package service import ( "f5" - "main/model" "main/constant" + "main/model" "main/mt" ) type buff struct { - } func (this *buff) init() { @@ -18,15 +17,16 @@ func (this *buff) unInit() { } func (this *buff) List(accountId string) (error, []*model.Buff) { + nowTime := f5.GetApp().GetRealSeconds() buffs := []*model.Buff{} result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(new(model.Buff).TableName()).Where( - "account_id = ?", accountId).Find(&buffs) + "account_id = ? AND expiretime > ?", accountId, nowTime).Find(&buffs) return result.Error, buffs } func (this *buff) Add(accountId string, buffList []int32) { nowTime := int32(f5.GetApp().GetRealSeconds()) - for _, buffId := range(buffList) { + for _, buffId := range buffList { buffMeta := mt.Table.Buff.GetById(int64(buffId)) if buffMeta != nil { buffModel := new(model.Buff) @@ -60,7 +60,7 @@ func (this *buff) Add(accountId string, buffList []int32) { func (this *buff) HasBuffEffect(accountId string, buffEffect int32) (error, bool) { if err, buffs := this.List(accountId); err == nil { - for _, v := range(buffs) { + for _, v := range buffs { buffMeta := mt.Table.Buff.GetById(int64(v.BuffId)) if buffMeta != nil && buffMeta.GetBuffEffect() == buffEffect { return nil, true diff --git a/server/wheelserver/service/chip.go b/server/wheelserver/service/chip.go index b74828d3..213a7029 100644 --- a/server/wheelserver/service/chip.go +++ b/server/wheelserver/service/chip.go @@ -98,6 +98,7 @@ func (this *chip) checkEarningLoop() { userearning := this.CalcScore(accountId) user.AddScore(userearning) Task.UpdateTaskProgress(accountId, constant.ITEM_TYPE_SCORE, userearning, nil) + user.UpdateUserFields() } } else { deletelist[accountId] = 0 diff --git a/server/wheelserver/service/task.go b/server/wheelserver/service/task.go index 6aac5b55..d17a465a 100644 --- a/server/wheelserver/service/task.go +++ b/server/wheelserver/service/task.go @@ -114,8 +114,12 @@ func (this *task) List(accountId string, data *[]*vo.Mission) (errcode int32, ms for _, taskitem := range tasks { missionVo := new(vo.Mission) missionVo.FromModel(taskitem) - q5.AppendSlice(data, missionVo) + q5.AppendSlice(data, missionVo) } + + q5.Sort(*data, func(t *vo.Mission, m *vo.Mission) bool { + return t.MissionId < m.MissionId + }) } if tasksupdate {