92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
sale "lone-services/rpc/sale/pb"
|
|
"lone-services/services/sale/internal/dao"
|
|
"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 InfoInternalLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewInfoInternalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoInternalLogic {
|
|
return &InfoInternalLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *InfoInternalLogic) InfoInternal(in *sale.InfoReq) (*sale.InfoData, error) {
|
|
var req validator.InfoValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return nil, status.Error(codes.InvalidArgument, msg)
|
|
}
|
|
|
|
info, err := querySaleInfo(req.Id)
|
|
if err != nil {
|
|
l.Errorf("sale InfoInternal: %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
|
|
}
|
|
|
|
func toSaleInfoData(info *dao.SaleInfo) *sale.InfoData {
|
|
data := &sale.InfoData{
|
|
Id: info.Id,
|
|
SaleId: info.SaleId,
|
|
Mobile: info.Mobile,
|
|
OriginMobile: info.OriginMobile,
|
|
Name: info.Name,
|
|
IdCardFront: info.IdCardFront,
|
|
IdCardBack: info.IdCardBack,
|
|
BusinessLicense: info.BusinessLicense,
|
|
Region: &sale.Region{
|
|
Province: info.Region.Province,
|
|
City: info.Region.City,
|
|
District: info.Region.District,
|
|
},
|
|
ProvinceId: info.ProvinceId,
|
|
CityId: info.CityId,
|
|
DistrictId: info.DistrictId,
|
|
TerritoryId: info.TerritoryId,
|
|
TerritoryName: info.TerritoryName,
|
|
GroupId: info.GroupId,
|
|
Address: info.Address,
|
|
Status: uint32(info.Status),
|
|
Avatar: info.Avatar,
|
|
Account: info.Account,
|
|
Type: uint32(info.Type),
|
|
Sex: uint32(info.Sex),
|
|
BirthDate: info.BirthDate,
|
|
Reason: info.Reason,
|
|
AdminId: info.AdminId,
|
|
AdminName: info.AdminName,
|
|
CreateTime: info.CreateTime.String(),
|
|
UpdateTime: info.UpdateTime.String(),
|
|
}
|
|
if info.Group != nil {
|
|
data.Group = &sale.GroupItem{
|
|
Id: info.Group.Id,
|
|
Name: info.Group.Name,
|
|
}
|
|
}
|
|
return data
|
|
}
|