fix
This commit is contained in:
parent
727765e853
commit
9baddab371
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -163,5 +163,7 @@ func (this *MissionApi) ClaimTaskAward(c *gin.Context) {
|
||||
q5.AppendSlice(&rspObj.Data, missionVo)
|
||||
}
|
||||
|
||||
user.UpdateUserFields()
|
||||
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
@ -101,5 +101,6 @@ func (this *ShopApi) Buy(c *gin.Context) {
|
||||
q5.AppendSlice(&rspObj.BaseVo.GetOrCreateSideEffect().Effects, "task")
|
||||
}
|
||||
|
||||
user.UpdateUserFields()
|
||||
c.JSON(200, rspObj)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user