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

75 lines
1.9 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,
Contact: info.Contact,
UserMobile: info.UserMobile,
IdCard: info.IdCard,
BusinessLicense: info.BusinessLicense,
Images: info.Images,
Content: info.Content,
OpenTime: info.OpenTime,
Address: info.Address,
City: info.City,
County: info.County,
DistrictIds: info.District,
Area: info.Area,
BankInfo: info.BankInfo,
BuyAmount: info.BuyAmount,
ResidualNumber: info.ResidualNumber,
}, nil
}