feat: openid login
This commit is contained in:
@@ -101,13 +101,17 @@ func maskSaleMobile(info *dao.SaleInfo) {
|
||||
info.Mobile = utils.DecryptPhoneReplace(mobile)
|
||||
}
|
||||
|
||||
// querySaleInfo 查询销售详情并附带分组;mobile 脱敏,origin_mobile 为加密串。
|
||||
// 未找到时返回 (nil, nil)。
|
||||
func querySaleInfo(id int64) (*dao.SaleInfo, error) {
|
||||
return querySaleInfoByEq(map[string]string{"id": strconv.FormatInt(id, 10)})
|
||||
}
|
||||
|
||||
func querySaleInfoByUserId(userId int64) (*dao.SaleInfo, error) {
|
||||
return querySaleInfoByEq(map[string]string{"user_id": strconv.FormatInt(userId, 10)})
|
||||
}
|
||||
|
||||
func querySaleInfoByEq(eq map[string]string) (*dao.SaleInfo, error) {
|
||||
var info dao.SaleInfo
|
||||
if err := (model.SaleModel{}.Init().GetOne(modelbase.Params{
|
||||
Eq: map[string]string{"id": strconv.FormatInt(id, 10)},
|
||||
}, &info)); err != nil {
|
||||
if err := (model.SaleModel{}.Init().GetOne(modelbase.Params{Eq: eq}, &info)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
sale "lone-services/rpc/sale/pb"
|
||||
"lone-services/services/sale/internal/svc"
|
||||
"lone-services/services/sale/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type InfoByUserIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewInfoByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoByUserIdLogic {
|
||||
return &InfoByUserIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *InfoByUserIdLogic) InfoByUserId(in *sale.InfoByUserIdReq) (*sale.InfoData, error) {
|
||||
var req validator.InfoByUserIdValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return nil, status.Error(codes.InvalidArgument, msg)
|
||||
}
|
||||
|
||||
info, err := querySaleInfoByUserId(req.UserId)
|
||||
if err != nil {
|
||||
l.Errorf("sale InfoByUserId: %v", err)
|
||||
return nil, status.Error(codes.Internal, utils.Fail.Msg)
|
||||
}
|
||||
if info == nil {
|
||||
return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg)
|
||||
}
|
||||
|
||||
return toSaleInfoData(info), nil
|
||||
}
|
||||
@@ -50,6 +50,7 @@ func (l *InfoInternalLogic) InfoInternal(in *sale.InfoReq) (*sale.InfoData, erro
|
||||
func toSaleInfoData(info *dao.SaleInfo) *sale.InfoData {
|
||||
data := &sale.InfoData{
|
||||
Id: info.Id,
|
||||
UserId: info.UserId,
|
||||
SaleId: info.SaleId,
|
||||
Mobile: info.Mobile,
|
||||
OriginMobile: info.OriginMobile,
|
||||
|
||||
@@ -86,7 +86,13 @@ func (s *SaleServer) InfoInternal(ctx context.Context, in *sale.InfoReq) (*sale.
|
||||
return l.InfoInternal(in)
|
||||
}
|
||||
|
||||
// 按 id 批量查销售 id+name(内部)
|
||||
// 按 user_id 查销售详情(内部)
|
||||
func (s *SaleServer) InfoByUserId(ctx context.Context, in *sale.InfoByUserIdReq) (*sale.InfoData, error) {
|
||||
l := logic.NewInfoByUserIdLogic(ctx, s.svcCtx)
|
||||
return l.InfoByUserId(in)
|
||||
}
|
||||
|
||||
// ids 批量查销售
|
||||
func (s *SaleServer) NamesByIds(ctx context.Context, in *sale.NamesByIdsReq) (*sale.NamesByIdsData, error) {
|
||||
l := logic.NewNamesByIdsLogic(ctx, s.svcCtx)
|
||||
return l.NamesByIds(in)
|
||||
|
||||
@@ -14,24 +14,25 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
CreateReq = sale.CreateReq
|
||||
EditReq = sale.EditReq
|
||||
GroupCreateReq = sale.GroupCreateReq
|
||||
GroupEmptyReq = sale.GroupEmptyReq
|
||||
GroupItem = sale.GroupItem
|
||||
GroupItemsReq = sale.GroupItemsReq
|
||||
InfoData = sale.InfoData
|
||||
InfoReq = sale.InfoReq
|
||||
ItemsReq = sale.ItemsReq
|
||||
NameItem = sale.NameItem
|
||||
NamesByIdsData = sale.NamesByIdsData
|
||||
NamesByIdsItem = sale.NamesByIdsItem
|
||||
NamesByIdsReq = sale.NamesByIdsReq
|
||||
NamesData = sale.NamesData
|
||||
NamesReq = sale.NamesReq
|
||||
Region = sale.Region
|
||||
Response = sale.Response
|
||||
StatusReq = sale.StatusReq
|
||||
CreateReq = sale.CreateReq
|
||||
EditReq = sale.EditReq
|
||||
GroupCreateReq = sale.GroupCreateReq
|
||||
GroupEmptyReq = sale.GroupEmptyReq
|
||||
GroupItem = sale.GroupItem
|
||||
GroupItemsReq = sale.GroupItemsReq
|
||||
InfoByUserIdReq = sale.InfoByUserIdReq
|
||||
InfoData = sale.InfoData
|
||||
InfoReq = sale.InfoReq
|
||||
ItemsReq = sale.ItemsReq
|
||||
NameItem = sale.NameItem
|
||||
NamesByIdsData = sale.NamesByIdsData
|
||||
NamesByIdsItem = sale.NamesByIdsItem
|
||||
NamesByIdsReq = sale.NamesByIdsReq
|
||||
NamesData = sale.NamesData
|
||||
NamesReq = sale.NamesReq
|
||||
Region = sale.Region
|
||||
Response = sale.Response
|
||||
StatusReq = sale.StatusReq
|
||||
|
||||
Sale interface {
|
||||
// 销售分组
|
||||
@@ -49,7 +50,9 @@ type (
|
||||
Status(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error)
|
||||
// 销售详情
|
||||
InfoInternal(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoData, error)
|
||||
// 按 id 批量查销售 id+name(内部)
|
||||
// 按 user_id 查销售详情(内部)
|
||||
InfoByUserId(ctx context.Context, in *InfoByUserIdReq, opts ...grpc.CallOption) (*InfoData, error)
|
||||
// ids 批量查销售
|
||||
NamesByIds(ctx context.Context, in *NamesByIdsReq, opts ...grpc.CallOption) (*NamesByIdsData, error)
|
||||
}
|
||||
|
||||
@@ -127,7 +130,13 @@ func (m *defaultSale) InfoInternal(ctx context.Context, in *InfoReq, opts ...grp
|
||||
return client.InfoInternal(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 按 id 批量查销售 id+name(内部)
|
||||
// 按 user_id 查销售详情(内部)
|
||||
func (m *defaultSale) InfoByUserId(ctx context.Context, in *InfoByUserIdReq, opts ...grpc.CallOption) (*InfoData, error) {
|
||||
client := sale.NewSaleClient(m.cli.Conn())
|
||||
return client.InfoByUserId(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// ids 批量查销售
|
||||
func (m *defaultSale) NamesByIds(ctx context.Context, in *NamesByIdsReq, opts ...grpc.CallOption) (*NamesByIdsData, error) {
|
||||
client := sale.NewSaleClient(m.cli.Conn())
|
||||
return client.NamesByIds(ctx, in, opts...)
|
||||
|
||||
@@ -147,6 +147,17 @@ func (p InfoValidator) GetMessage() validate.ValidatorMessages {
|
||||
}
|
||||
}
|
||||
|
||||
type InfoByUserIdValidator struct {
|
||||
UserId int64 `validate:"required,gt=0"`
|
||||
}
|
||||
|
||||
func (p InfoByUserIdValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"UserId.required": "用户ID不能为空",
|
||||
"UserId.gt": "用户ID必须大于0",
|
||||
}
|
||||
}
|
||||
|
||||
type ItemsValidator struct {
|
||||
Name string `validate:"omitempty,max=256"`
|
||||
Page uint32 `validate:"omitempty,min=1"`
|
||||
|
||||
Reference in New Issue
Block a user