2025-04-09 14:46:53 +00:00
|
|
|
package productitemservicelogic
|
2025-04-09 09:29:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-04-10 07:59:30 +00:00
|
|
|
|
|
|
|
"code.30cm.net/digimon/app-cloudep-product-service/internal/utils"
|
2025-04-09 09:29:56 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2025-04-09 14:46:53 +00:00
|
|
|
type GetLogic struct {
|
2025-04-09 09:29:56 +00:00
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
logx.Logger
|
|
|
|
}
|
|
|
|
|
2025-04-09 14:46:53 +00:00
|
|
|
func NewGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogic {
|
|
|
|
return &GetLogic{
|
2025-04-09 09:29:56 +00:00
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-09 14:46:53 +00:00
|
|
|
// Get 取得 ProductItem
|
|
|
|
func (l *GetLogic) Get(in *product.GetProductItemRequest) (*product.ProductItem, error) {
|
2025-04-09 09:29:56 +00:00
|
|
|
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(),
|
2025-04-09 14:46:53 +00:00
|
|
|
UpdatedAt: &item.UpdatedAt,
|
|
|
|
CreatedAt: &item.CreatedAt,
|
2025-04-09 09:29:56 +00:00
|
|
|
}
|
|
|
|
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 {
|
2025-04-10 07:47:07 +00:00
|
|
|
c = append(c, &product.CustomField{
|
2025-04-09 09:29:56 +00:00
|
|
|
Key: fItem.Key,
|
|
|
|
Value: fItem.Value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
result.CustomFields = c
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|