feat: user get mobile
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 1s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 1s
CI / task (push) Successful in 0s
CI / user (push) Successful in 28s
CI / water (push) Successful in 1s
CI / wecom (push) Successful in 0s
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 1s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 1s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / support (push) Successful in 1s
CI / task (push) Successful in 0s
CI / user (push) Successful in 28s
CI / water (push) Successful in 1s
CI / wecom (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package analysislogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type InternalSetRegisteredLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewInternalSetRegisteredLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InternalSetRegisteredLogic {
|
||||
return &InternalSetRegisteredLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *InternalSetRegisteredLogic) InternalSetRegistered(in *analysis.InternalSetRegisteredReq) (*analysis.InternalSetRegisteredData, error) {
|
||||
if in == nil || in.Id < utils.NumberOne {
|
||||
return nil, status.Error(codes.InvalidArgument, "用户ID不能为空")
|
||||
}
|
||||
|
||||
row, err := common.LoadAnalysisUser(in.Id)
|
||||
if err != nil {
|
||||
l.Errorf("internal set registered get: %v", err)
|
||||
return nil, status.Error(codes.Internal, utils.Fail.Msg)
|
||||
}
|
||||
if row == nil {
|
||||
return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg)
|
||||
}
|
||||
if row.IsRegistered == uint8(utils.StatusOk) {
|
||||
return &analysis.InternalSetRegisteredData{Ok: true}, nil
|
||||
}
|
||||
|
||||
_, err = model.UserModel{}.Init().Edit(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)},
|
||||
}, map[string]interface{}{
|
||||
"is_registered": uint8(utils.StatusOk),
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("internal set registered edit: %v", err)
|
||||
return nil, status.Error(codes.Internal, utils.Fail.Msg)
|
||||
}
|
||||
|
||||
return &analysis.InternalSetRegisteredData{Ok: true}, nil
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package analysisuserlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
analysis "lone-services/rpc/analysis/pb"
|
||||
userpb "lone-services/rpc/user/pb"
|
||||
analysisconfig "lone-services/services/analysis/internal/config"
|
||||
"lone-services/services/analysis/internal/logic/common"
|
||||
"lone-services/services/analysis/internal/model"
|
||||
"lone-services/services/analysis/internal/svc"
|
||||
"lone-services/services/analysis/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserRegisterLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRegisterLogic {
|
||||
return &UserRegisterLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserRegisterLogic) UserRegister(in *analysis.UserRegisterReq) (*analysis.Response, error) {
|
||||
var req validator.UserRegisterValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return common.OutResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
bizId, loginUser, fail := common.RequireBizUserId(l.ctx)
|
||||
if fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
row, err := common.LoadAnalysisUser(bizId)
|
||||
if err != nil {
|
||||
l.Errorf("register load user: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if row == nil {
|
||||
return common.FailResponse(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
wxCfg, cfgErr := analysisconfig.LoadWechatConfig()
|
||||
if cfgErr != nil {
|
||||
l.Errorf("register wechat config: %v", cfgErr)
|
||||
return common.OutResponse(utils.Fail, "微信配置缺失"), nil
|
||||
}
|
||||
|
||||
token, tokenErr := wxCfg.NewAuthClient().AccessToken(l.ctx)
|
||||
if tokenErr != nil {
|
||||
l.Errorf("register access token: %v", tokenErr)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
phone, phoneErr := wxCfg.NewAuthClient().GetPhoneNumber(token.AccessToken, req.Code)
|
||||
if phoneErr != nil {
|
||||
l.Errorf("register get phone: %v", phoneErr)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
mobile := phone.PhoneNumber
|
||||
if mobile == utils.StringEmpty {
|
||||
mobile = phone.PurePhoneNumber
|
||||
}
|
||||
if mobile == utils.StringEmpty {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
if l.svcCtx.UserSvcName == utils.StringEmpty {
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
|
||||
if err != nil {
|
||||
l.Errorf("register get user rpc: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
if _, err = userpb.NewUserClient(cli.Conn()).InternalUpdateMobile(l.ctx, &userpb.InternalUpdateMobileReq{
|
||||
UserId: loginUser.ID,
|
||||
Mobile: mobile,
|
||||
}); err != nil {
|
||||
l.Errorf("register update mobile: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
_, err = model.UserModel{}.Init().Edit(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(bizId, utils.NumberTen)},
|
||||
}, map[string]interface{}{
|
||||
"is_registered": uint8(utils.StatusOk),
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("register update flag: %v", err)
|
||||
return common.FailResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return common.OkResponse(nil), nil
|
||||
}
|
||||
Reference in New Issue
Block a user