调整微信扫码登录相关接口,拆分门店奖励:奖励类型、奖励详情

This commit is contained in:
2025-06-03 11:06:00 +08:00
parent ea87bc829e
commit fdc9cc3463
37 changed files with 698 additions and 189 deletions

View File

@ -2,14 +2,54 @@ package wx
import (
"context"
"encoding/json"
"fmt"
v1 "server/api/wx/v1"
"server/internal/model"
"server/utility/ecode"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"server/api/auth/v1"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/glog"
)
func (c *ControllerV1) WeChatPolling(ctx context.Context, req *v1.WeChatPollingReq) (res *v1.WeChatPollingRes, err error) {
// 收到请求根据 uuid 查询缓存中的数据,看看是否生成了 token
return nil, gerror.NewCode(gcode.CodeNotImplemented)
loginCacheKey := fmt.Sprintf("wx:login:cache:%s", req.SceneId)
glog.Infof(ctx, "开始处理微信长轮询请求SceneID: %s", req.SceneId)
var loginCache model.LoginCache
data, err := g.Redis().Get(ctx, loginCacheKey)
if err != nil {
glog.Errorf(ctx, "从 Redis 获取登录缓存失败SceneID: %s错误: %v", req.SceneId, err)
return nil, ecode.Fail.Sub("获取登录状态失败")
}
if data.IsEmpty() {
glog.Warningf(ctx, "用户尚未扫码登录SceneID: %s", req.SceneId)
return nil, ecode.InvalidOperation.Sub("请先调用获取二维码登录")
}
if err = json.Unmarshal(data.Bytes(), &loginCache); err != nil {
glog.Errorf(ctx, "解析登录状态失败SceneID: %s错误: %v", req.SceneId, err)
return nil, ecode.Fail.Sub("解析登录状态失败")
}
switch loginCache.Status {
case 0:
glog.Infof(ctx, "用户尚未扫码登录SceneID: %s", req.SceneId)
return &v1.WeChatPollingRes{
Status: "waiting",
Token: "",
}, nil
case 1:
// 直接返回缓存的token
glog.Infof(ctx, "用户扫码登录成功SceneID: %s返回缓存Token", req.SceneId)
return &v1.WeChatPollingRes{
Status: "success",
Token: loginCache.Token,
}, nil
default:
glog.Warningf(ctx, "未知登录状态 %dSceneID: %s", loginCache.Status, req.SceneId)
return nil, ecode.InvalidOperation.Sub("未知登录状态")
}
}