This commit is contained in:
aozhiwei 2024-11-20 12:54:31 +08:00
parent ce71769b2d
commit d62d5a7ee9
13 changed files with 265 additions and 0 deletions

View File

@ -0,0 +1,74 @@
package bag
import (
"q5"
"f5"
"main/constant"
"main/common"
"main/model"
"main/vo"
"main/mt"
"github.com/gin-gonic/gin"
)
type BagApi struct {
}
func (this *BagApi) List(c *gin.Context) {
s := c.MustGet(constant.SESSION_KEY).(common.Session)
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 {
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()
}
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}
func (this *BagApi) UseItem(c *gin.Context) {
s := c.MustGet(constant.SESSION_KEY).(common.Session)
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 {
f5.RspErr(c, 500, "server internal error")
return
} else if !found {
f5.RspErr(c, 1, "server internal error")
return
}
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}

View File

@ -0,0 +1,5 @@
package bag
type ApiGroup struct {
BagApi
}

View File

@ -0,0 +1,52 @@
package buff
import (
"q5"
"f5"
"main/constant"
"main/common"
"main/model"
"main/vo"
"main/mt"
"github.com/gin-gonic/gin"
)
type BuffApi struct {
}
func (this *BuffApi) List(c *gin.Context) {
s := c.MustGet(constant.SESSION_KEY).(common.Session)
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 {
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()
}
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}

View File

@ -0,0 +1,5 @@
package buff
type ApiGroup struct {
BuffApi
}

View File

@ -8,6 +8,9 @@ import (
"main/api/v1/mission" "main/api/v1/mission"
"main/api/v1/shop" "main/api/v1/shop"
"main/api/v1/user" "main/api/v1/user"
"main/api/v1/buff"
"main/api/v1/bag"
"main/api/v1/gm"
) )
type ApiGroup struct { type ApiGroup struct {
@ -18,6 +21,9 @@ type ApiGroup struct {
MissionApiGroup mission.ApiGroup MissionApiGroup mission.ApiGroup
ShopApiGroup shop.ApiGroup ShopApiGroup shop.ApiGroup
UserApiGroup user.ApiGroup UserApiGroup user.ApiGroup
BuffApiGroup buff.ApiGroup
BagApiGroup bag.ApiGroup
GmApiGroup gm.ApiGroup
} }
var ApiGroupApp = new(ApiGroup) var ApiGroupApp = new(ApiGroup)

View File

@ -0,0 +1,5 @@
package gm
type ApiGroup struct {
GmApi
}

View File

@ -0,0 +1,52 @@
package gm
import (
"q5"
"f5"
"main/constant"
"main/common"
"main/model"
"main/vo"
"main/mt"
"github.com/gin-gonic/gin"
)
type GmApi struct {
}
func (this *GmApi) ExecCmd(c *gin.Context) {
s := c.MustGet(constant.SESSION_KEY).(common.Session)
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 {
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()
}
f5.GetMsgQueue().FireEvent(constant.MSG_LOGIN, q5.Args{user})
rspObj.UserInfo.FromModel(user)
c.JSON(200, rspObj)
}

View File

@ -0,0 +1,19 @@
package bag
import (
"f5"
"main/middleware"
"main/api/v1"
)
type BagRouter struct{}
func (this *BagRouter) InitRouter() {
api := v1.ApiGroupApp.BagApiGroup
f5.GetApp().GetGinEngine().GET("/api/v1/bag/list",
middleware.JwtAuth,
api.BagApi.List)
f5.GetApp().GetGinEngine().POST("/api/v1/bag/use_item",
middleware.JwtAuth,
api.BagApi.UserItem)
}

View File

@ -0,0 +1,5 @@
package bag
type RouterGroup struct {
BagRouter
}

View File

@ -0,0 +1,16 @@
package buff
import (
"f5"
"main/middleware"
"main/api/v1"
)
type BuffRouter struct{}
func (this *BuffRouter) InitRouter() {
api := v1.ApiGroupApp.BuffApiGroup
f5.GetApp().GetGinEngine().GET("/api/v1/buff/list",
middleware.JwtAuth,
api.BuffApi.List)
}

View File

@ -0,0 +1,5 @@
package buff
type RouterGroup struct {
BuffRouter
}

View File

@ -0,0 +1,5 @@
package gm
type RouterGroup struct {
GmRouter
}

View File

@ -0,0 +1,16 @@
package user
import (
"f5"
"main/middleware"
"main/api/v1"
)
type BagRouter struct{}
func (this *BagRouter) InitRouter() {
api := v1.ApiGroupApp.BagApiGroup
f5.GetApp().GetGinEngine().POST("/api/v1/gm/exec_cmd",
middleware.JwtAuth,
api.BagApi.ExecCmd)
}