95 lines
2.8 KiB
Go
95 lines
2.8 KiB
Go
package orderservicelogic
|
|
|
|
import (
|
|
"app-cloudep-order-server/gen_result/pb/order"
|
|
"context"
|
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
"github.com/shopspring/decimal"
|
|
|
|
"app-cloudep-order-server/internal/svc"
|
|
|
|
"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"`
|
|
}
|
|
|
|
// 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 {
|
|
return nil, err
|
|
}
|
|
|
|
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: o.ReferenceBrand,
|
|
ReferenceUid: o.ReferenceUID,
|
|
WalletStatus: o.WalletStatus,
|
|
ThreePartyStatus: o.ThreePartyStatus,
|
|
DirectionType: o.DirectionType,
|
|
CryptoType: o.CryptoType,
|
|
ThirdPartyFee: decimalToString(*o.ThirdPartyFee),
|
|
CryptoToUsdtRate: decimalToString(*o.CryptoToUSDTRate),
|
|
FiatToUsdRate: decimalToString(*o.FiatToUSDRate),
|
|
FeeCryptoToUsdtRate: decimalToString(*o.FeeCryptoToUSDTRate),
|
|
UsdtToCryptoTypeRate: decimalToString(*o.USDTToCryptoTypeRate),
|
|
PaymentFiat: o.PaymentFiat,
|
|
PaymentUnitPrice: decimalToString(*o.PaymentUnitPrice),
|
|
PaymentTemplateId: o.PaymentTemplateID,
|
|
OrderArrivalTime: o.OrderArrivalTime,
|
|
OrderPaymentTime: o.OrderPaymentTime,
|
|
UnpaidTimeoutSecond: o.UnpaidTimeoutSecond,
|
|
ChainType: o.ChainType,
|
|
TxHash: o.TxHash,
|
|
FromAddress: o.FromAddress,
|
|
ToAddress: o.ToAddress,
|
|
ChainFee: decimalToString(*o.ChainFee),
|
|
ChainFeeCrypto: o.ChainFeeCrypto,
|
|
Memo: o.Memo,
|
|
OrderNote: o.OrderNote,
|
|
}, nil
|
|
}
|
|
|
|
func decimalToString(amount decimal.Decimal) *string {
|
|
a := amount.String()
|
|
|
|
return &a
|
|
}
|