This commit is contained in:
aozhiwei 2024-11-11 14:12:14 +08:00
parent 133548133d
commit ee316fccea
3 changed files with 10 additions and 7 deletions

View File

@ -21,10 +21,10 @@ func (this *ActivityApi) RollDice(c *gin.Context) {
user := new(model.User) user := new(model.User)
nowTime := f5.GetApp().GetRealSeconds() nowTime := f5.GetApp().GetRealSeconds()
if err, found := user.Find(s.GetAccountId(), nowTime); err != nil { if err, found := user.Find(s.GetAccountId(), nowTime); err != nil {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error1")
return return
} else if !found { } else if !found {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error2")
return return
} }
if user.Dice <= 0 { if user.Dice <= 0 {
@ -33,16 +33,16 @@ func (this *ActivityApi) RollDice(c *gin.Context) {
} }
rewardMeta := mt.Table.Reward.RandElement() rewardMeta := mt.Table.Reward.RandElement()
if rewardMeta == nil { if rewardMeta == nil {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error3")
return return
} }
score := rewardMeta.RandScore() score := rewardMeta.RandScore()
if score <= 0 { if score <= 0 {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error4")
return return
} }
if err := user.DecDice(1); err != nil { if err := user.DecDice(1); err != nil {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error5")
return return
} }
rspObj := struct { rspObj := struct {

View File

@ -53,7 +53,7 @@ func (this *User) Create() error {
} }
func (this *User) DecDice(num int32) error { func (this *User) DecDice(num int32) error {
if this.Score < int64(num) { if this.Dice < num {
return errors.New("") return errors.New("")
} }
oldDice := this.Dice oldDice := this.Dice

View File

@ -2,6 +2,7 @@ package activity
import ( import (
"f5" "f5"
"main/middleware"
"main/api/v1" "main/api/v1"
) )
@ -9,5 +10,7 @@ type ActivityRouter struct{}
func (this *ActivityRouter) InitRouter() { func (this *ActivityRouter) InitRouter() {
api := v1.ApiGroupApp.ActivityApiGroup api := v1.ApiGroupApp.ActivityApiGroup
f5.GetApp().GetGinEngine().POST("/api/v1/activity/roll_dice", api.ActivityApi.RollDice) f5.GetApp().GetGinEngine().POST("/api/v1/activity/roll_dice",
middleware.JwtAuth,
api.ActivityApi.RollDice)
} }