84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
package productlogic
|
|
|
|
import (
|
|
"code.30cm.net/digimon/app-cloudep-product-service/internal/utils"
|
|
"context"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"code.30cm.net/digimon/app-cloudep-product-service/gen_result/pb/product"
|
|
"code.30cm.net/digimon/app-cloudep-product-service/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetProductItemLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetProductItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductItemLogic {
|
|
return &GetProductItemLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// GetProductItem 取得 ProductItem
|
|
func (l *GetProductItemLogic) GetProductItem(in *product.GetProductItemRequest) (*product.ProductItem, error) {
|
|
item, err := l.svcCtx.ProductItemUseCase.Get(l.ctx, in.GetId())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
result := &product.ProductItem{
|
|
Id: proto.String(item.ID),
|
|
ReferenceId: item.ReferenceID,
|
|
Name: item.Name,
|
|
Description: utils.DecodeToBase64Snappy(item.Description),
|
|
ShortDescription: utils.DecodeToBase64Snappy(item.ShortDescription),
|
|
IsUnLimit: item.IsUnLimit,
|
|
IsFree: item.IsFree,
|
|
Stock: item.Stock,
|
|
Price: item.Price,
|
|
Sku: item.SKU,
|
|
TimeSeries: item.TimeSeries.ToString(),
|
|
SalesCount: item.SalesCount,
|
|
Status: item.Status.ToString(),
|
|
UpdatedAt: proto.String(item.UpdatedAt),
|
|
CreatedAt: proto.String(item.CreatedAt),
|
|
}
|
|
media := make([]*product.Media, 0, len(item.Media))
|
|
for _, pi := range item.Media {
|
|
media = append(media, &product.Media{
|
|
Sort: proto.Uint64(pi.Sort),
|
|
Url: pi.URL,
|
|
Type: pi.Type,
|
|
})
|
|
}
|
|
result.Media = media
|
|
|
|
// 運費
|
|
f := make([]*product.CustomField, 0, len(item.Freight))
|
|
for _, fItem := range item.Freight {
|
|
f = append(f, &product.CustomField{
|
|
Key: fItem.Key,
|
|
Value: fItem.Value,
|
|
})
|
|
}
|
|
result.Freight = f
|
|
|
|
// 運費
|
|
c := make([]*product.CustomField, 0, len(item.CustomFields))
|
|
for _, fItem := range item.CustomFields {
|
|
f = append(f, &product.CustomField{
|
|
Key: fItem.Key,
|
|
Value: fItem.Value,
|
|
})
|
|
}
|
|
result.CustomFields = c
|
|
|
|
return result, nil
|
|
}
|