增加提取castile到游戏的逻辑。

This commit is contained in:
yuming88
2025-04-28 19:26:17 +08:00
parent e50137a90e
commit d40cdda6ae
11 changed files with 205 additions and 73 deletions

View File

@@ -1,7 +1,11 @@
package transfercastile
import (
"errors"
"fmt"
"net/http"
"nova_task/internal/pkg/utils"
"time"
"github.com/zeromicro/go-zero/rest/httpx"
"nova_task/internal/logic/transfercastile"
@@ -18,8 +22,22 @@ func TransferCastileToGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
uid := utils.GetUidUint(r.Context())
redisKey := fmt.Sprintf("transferCastile:uid:%d", uid)
//加锁
lock, err := svcCtx.Redis.SetnxEx(redisKey, time.Now().String(), 120)
if !lock || err != nil {
httpx.ErrorCtx(r.Context(), w, errors.New("operation frequently"))
return
}
l := transfercastile.NewTransferCastileToGameLogic(r.Context(), svcCtx)
resp, err := l.TransferCastileToGame(&req)
//删除redis KEY
_, _ = svcCtx.Redis.Del(redisKey)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {