This commit is contained in:
aozhiwei 2024-11-20 16:36:32 +08:00
parent 3f5dee6f82
commit c3d4fdc784
2 changed files with 29 additions and 26 deletions

View File

@ -7,7 +7,7 @@ import (
"main/common"
"main/model"
"main/vo"
"main/mt"
"main/service"
"github.com/gin-gonic/gin"
)
@ -19,35 +19,20 @@ func (this *BagApi) List(c *gin.Context) {
if s == nil {
return
}
user := new(model.User)
rspObj := struct {
vo.BaseVo
UserInfo vo.User `json:"user_info"`
}{}
nowTime := f5.GetApp().GetRealSeconds()
if err, found := user.Find(s.GetAccountId(), nowTime); err != nil {
err, items := service.Bag.List(s.GetAccountId())
if err != nil {
f5.RspErr(c, 500, "server internal error")
return
} else if !found {
user.AccountId = s.GetAccountId()
user.Avatar = ""
user.NickName = s.GetNickName()
user.Score = 0
user.Dice = mt.Table.Global.GetDailyDiceNum()
user.LastPresentDiceTime = q5.ToInt32(nowTime)
user.CreateTime = q5.ToInt32(nowTime)
user.ModifyTime = q5.ToInt32(nowTime)
if user.Create() != nil {
f5.RspErr(c, 500, "server internal error")
return
}
f5.GetMsgQueue().FireEvent(constant.MSG_CREATE_USER, q5.Args{user})
}
if user.NickName != s.GetNickName() {
user.UpdateName()
rspObj := struct {
vo.BaseVo
Data []*vo.BagItem `json:"data"`
}{}
for _, m := range items {
v := new(vo.BagItem)
v.FromModel(m)
q5.AppendSlice(&rspObj.Data, v)
}
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}

View File

@ -0,0 +1,18 @@
package vo
import (
"q5"
"main/model"
)
type BagItem struct {
ItemUniId string `json:"item_uniid"`
ItemId int32 `json:"item_id"`
ItemNum int32 `json:"item_num"`
}
func (this *BagItem) FromModel(m *model.Bag) {
this.ItemUniId = q5.ToString(m.Idx)
this.ItemId = m.ItemId
this.ItemNum = m.ItemNum
}