Files
lone-services/services/user/internal/logic/qrcodeScanLogic.go
T
2026-10-15 09:23:07 +08:00

47 lines
1.2 KiB
Go

package logic
import (
"context"
"lone-services/pkg/utils"
"lone-services/pkg/validate"
pkgws "lone-services/pkg/ws"
user "lone-services/rpc/user/pb"
"lone-services/services/user/internal/svc"
"lone-services/services/user/validator"
"github.com/zeromicro/go-zero/core/logx"
)
type QrcodeScanLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewQrcodeScanLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QrcodeScanLogic {
return &QrcodeScanLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *QrcodeScanLogic) QrcodeScan(in *user.QrcodeScanReq) (*user.Response, error) {
var req validator.QrcodeScanValidator
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
return outResponse(utils.ErrorParams, msg), nil
}
if _, err := pkgws.GetSession(l.ctx, req.SessionId); err != nil {
l.Errorf("qrcode scan session: %v", err)
return failResponse(utils.ErrorQRcodeExp), nil
}
data := map[string]int{"ws_type": pkgws.WsTypeScan}
if err := pkgws.Publish(l.ctx, req.SessionId, pkgws.Success(data)); err != nil {
l.Errorf("qrcode scan publish: %v", err)
}
return okResponse(nil), nil
}