Files
lone-services/services/store/internal/logic/getInfoByIdLogic.go
T
2026-10-19 17:30:45 +08:00

89 lines
2.4 KiB
Go

package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/services/store/internal/dao"
"lone-services/services/store/internal/model"
"strconv"
store "lone-services/rpc/store/pb"
"lone-services/services/store/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type GetInfoByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetInfoByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInfoByIdLogic {
return &GetInfoByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetInfoByIdLogic) GetInfoById(in *store.IdRequest) (*store.InfoResponse, error) {
var info dao.StoreInfo
modelObj := model.StoreModel{}.Init()
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}}
err := modelObj.GetOne(w, &info)
if err != nil {
l.Logger.Error(err)
return nil, status.Error(codes.Internal, utils.Fail.Msg)
}
if info.Id < utils.NumberOne {
return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg)
}
if info.Id > utils.NumberZero {
mobile, dErr := utils.DecryptPhone(info.UserMobile)
if dErr != nil {
return nil, status.Error(codes.Internal, utils.ErrorEncryptAesError.Msg)
}
info.UserMobile = mobile
}
return &store.InfoResponse{
Id: info.Id,
Name: info.Name,
UserName: info.UserName,
Contact: info.Contact,
UserMobile: info.UserMobile,
IdCard: info.IdCard,
BusinessLicense: info.BusinessLicense,
Images: info.Images,
StoreImages: info.StoreImages,
Content: info.Content,
OpenTime: info.OpenTime,
Address: info.Address,
Province: info.Province,
ProvinceName: info.ProvinceName,
City: info.City,
CityName: info.CityName,
County: info.County,
CountyName: info.CountyName,
DistrictIds: info.District,
Area: info.Area,
BankInfo: info.BankInfo,
Type: info.Type,
SaleId: info.SaleId,
LongitudeWgs84: info.LongitudeWgs84,
LatitudeWgs84: info.LatitudeWgs84,
LongitudeGcj02: info.LongitudeGcj02,
LatitudeGcj02: info.LatitudeGcj02,
BuyAmount: info.BuyAmount,
ResidualNumber: info.ResidualNumber,
Status: info.Status,
CreateTime: info.CreateTime.String(),
}, nil
}