feat: 实现每日签到功能并优化战斗和道具逻辑

This commit is contained in:
xinian
2026-04-06 02:06:11 +08:00
committed by cnb
parent f433a26a6d
commit 5b37d9493b
17 changed files with 1066 additions and 86 deletions

View File

@@ -0,0 +1,20 @@
package admin
import (
"blazing/cool"
"blazing/modules/player/service"
)
type SignRecordController struct {
*cool.Controller
}
func init() {
cool.RegisterController(&SignRecordController{
&cool.Controller{
Prefix: "/admin/game/signrecord",
Api: []string{"Delete", "Update", "Info", "List", "Page"},
Service: service.NewSignService(0),
},
})
}

View File

@@ -0,0 +1,106 @@
package app
import (
"blazing/cool"
configservice "blazing/modules/config/service"
playerservice "blazing/modules/player/service"
"context"
"fmt"
"strings"
"github.com/deatil/go-cryptobin/cryptobin/crypto"
"github.com/gogf/gf/v2/frame/g"
)
type SignController struct {
*cool.Controller
}
func init() {
controller := &SignController{
&cool.Controller{
Prefix: "/seer/game/sign",
Api: []string{},
Service: configservice.NewSignInService(),
},
}
cool.RegisterController(controller)
}
type SignStateReq struct {
g.Meta `path:"/state" method:"GET"`
UserID uint32 `json:"user_id" v:"required|min:1#用户ID不能为空|用户ID非法"`
Session string `json:"session" v:"required#session不能为空"`
SignInID uint32 `json:"sign_in_id" d:"1" v:"min:1#签到活动ID非法"`
}
type SignClaimReq struct {
g.Meta `path:"/claim" method:"POST"`
UserID uint32 `json:"user_id" v:"required|min:1#用户ID不能为空|用户ID非法"`
Session string `json:"session" v:"required#session不能为空"`
SignInID uint32 `json:"sign_in_id" d:"1" v:"min:1#签到活动ID非法"`
}
func (c *SignController) State(ctx context.Context, req *SignStateReq) (res *cool.BaseRes, err error) {
if err = g.Validator().Data(req).Run(ctx); err != nil {
return cool.Fail(err.Error()), nil
}
if err = validateGameSession(req.UserID, req.Session); err != nil {
return cool.Fail(err.Error()), nil
}
state, err := playerservice.NewSignService(req.UserID).GetState(req.SignInID)
if err != nil {
return cool.Fail(err.Error()), nil
}
return cool.Ok(state), nil
}
func (c *SignController) Claim(ctx context.Context, req *SignClaimReq) (res *cool.BaseRes, err error) {
if err = g.Validator().Data(req).Run(ctx); err != nil {
return cool.Fail(err.Error()), nil
}
if err = validateGameSession(req.UserID, req.Session); err != nil {
return cool.Fail(err.Error()), nil
}
result, err := playerservice.NewSignService(req.UserID).Claim(req.SignInID)
if err != nil {
return cool.Fail(err.Error()), nil
}
return cool.Ok(result), nil
}
func validateGameSession(userID uint32, session string) error {
if userID == 0 {
return fmt.Errorf("user_id不能为空")
}
session = strings.TrimSpace(session)
if session == "" {
return fmt.Errorf("session不能为空")
}
cached, err := cool.CacheManager.Get(context.Background(), fmt.Sprintf("session:%d", userID))
if err != nil || cached.IsEmpty() {
return fmt.Errorf("session已过期请重新登录")
}
rawSession := session
decrypted := crypto.
FromBase64String(session).
SetKey("gfertf12dfertf12").
SetIv("gfertf12dfertf12").
Aes().
CBC().
PKCS7Padding().
Decrypt().
ToString()
if decrypted != "" {
rawSession = decrypted
}
if rawSession != cached.String() {
return fmt.Errorf("session无效请重新登录")
}
return nil
}