增加提取castile到游戏的逻辑。
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user