app-cloudep-order-server/internal/logic/orderservice/get_order_logic.go

92 lines
3.1 KiB
Go
Raw Normal View History

2024-10-06 07:02:30 +00:00
package orderservicelogic
import (
"app-cloudep-order-server/gen_result/pb/order"
"app-cloudep-order-server/internal/domain"
2024-10-06 07:02:30 +00:00
"app-cloudep-order-server/internal/svc"
ers "code.30cm.net/digimon/library-go/errs"
"context"
"errors"
"github.com/zeromicro/go-zero/core/stores/mon"
2024-10-06 07:02:30 +00:00
"github.com/zeromicro/go-zero/core/logx"
)
type GetOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderLogic {
return &GetOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetOrderQuery 取得訂單
type GetOrderQuery struct {
BusinessID string `json:"business_id" validate:"required"`
}
2024-10-06 07:02:30 +00:00
// GetOrder 取得訂單詳情
func (l *GetOrderLogic) GetOrder(in *order.GetOrderReq) (*order.GetOrderResp, error) {
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&GetOrderQuery{
BusinessID: in.GetBusinessId(),
}); err != nil {
// 錯誤代碼 06-011-00
return nil, ers.InvalidFormat(err.Error())
}
o, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId())
if err != nil {
if errors.As(err, &mon.ErrNotFound) {
return nil, domain.NotFoundError(domain.DataNotFoundErrorCode, "failed to get this order id:", in.GetBusinessId())
}
return nil, err
}
2024-10-06 07:02:30 +00:00
return &order.GetOrderResp{
UpdateTime: o.UpdateTime,
CreateTime: o.CreateTime,
BusinessId: o.BusinessID,
OrderType: int32(o.OrderType),
OrderStatus: int32(o.OrderStatus),
Brand: o.Brand,
OrderUid: o.OrderUID,
ReferenceId: o.ReferenceID,
Count: o.Count.String(),
OrderFee: o.OrderFee.String(),
Amount: o.Amount.String(),
// 下面的為未來擴充用的欄位
ReferenceBrand: nilString(o.ReferenceBrand),
ReferenceUid: nilString(o.ReferenceUID),
WalletStatus: nilInt64(o.WalletStatus),
ThreePartyStatus: nilInt64(o.ThreePartyStatus),
DirectionType: nilInt64(o.DirectionType),
CryptoType: nilString(o.CryptoType),
ThirdPartyFee: convertDecimal128ToString(o.ThirdPartyFee),
CryptoToUsdtRate: convertDecimal128ToString(o.CryptoToUSDTRate),
FiatToUsdRate: convertDecimal128ToString(o.FiatToUSDRate),
FeeCryptoToUsdtRate: convertDecimal128ToString(o.FeeCryptoToUSDTRate),
UsdtToCryptoTypeRate: convertDecimal128ToString(o.USDTToCryptoTypeRate),
PaymentFiat: nilString(o.PaymentFiat),
PaymentUnitPrice: convertDecimal128ToString(o.PaymentUnitPrice),
PaymentTemplateId: nilString(o.PaymentTemplateID),
OrderArrivalTime: nilInt64(o.OrderArrivalTime),
OrderPaymentTime: nilInt64(o.OrderPaymentTime),
UnpaidTimeoutSecond: nilInt64(o.UnpaidTimeoutSecond),
ChainType: nilString(o.ChainType),
TxHash: nilString(o.TxHash),
FromAddress: nilString(o.FromAddress),
ToAddress: nilString(o.ToAddress),
ChainFee: convertDecimal128ToString(o.ChainFee),
ChainFeeCrypto: nilString(o.ChainFeeCrypto),
Memo: nilString(o.Memo),
OrderNote: nilString(o.OrderNote),
}, nil
2024-10-06 07:02:30 +00:00
}