This commit is contained in:
aozhiwei 2024-11-20 15:35:23 +08:00
parent 00d105d68d
commit 032e403760
2 changed files with 22 additions and 1 deletions

View File

@ -27,7 +27,7 @@ func (this *Bag) Create() error {
return nil
}
func (this *Bag) Find(accountId string, nowTime int64, itemId int32) (error, bool) {
func (this *Bag) Find(accountId string, itemId int32) (error, bool) {
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Table(this.TableName()).Take(
this, "account_id = ? and item_id = ?", accountId, itemId); result.Error != nil &&
!errors.Is(result.Error, gorm.ErrRecordNotFound) {
@ -36,3 +36,13 @@ func (this *Bag) Find(accountId string, nowTime int64, itemId int32) (error, boo
return nil, result.RowsAffected > 0
}
}
func (this *Bag) AddItemNum(itemNum int32, nowTime int32) error {
this.ItemNum += itemNum
this.ModifyTime = nowTime
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Model(this).Select(
"item_num", "modifytime").Updates(this); result.Error != nil {
return result.Error
}
return nil
}

View File

@ -1,7 +1,9 @@
package service
import (
"f5"
"main/vo"
"main/model"
)
type award struct {
@ -14,4 +16,13 @@ func (this *award) unInit() {
}
func (this *award) AddItem(accountId string, itemId int32, itemNum int32, baseVo *vo.BaseVo) {
nowTime := int32(f5.GetApp().GetRealSeconds())
bagItem := new(model.Bag)
if err, found := bagItem.Find(accountId, itemId); err == nil {
if found {
bagItem.AddItemNum(itemNum, nowTime)
} else {
}
}
}