2024-10-06 07:02:30 +00:00
|
|
|
package orderservicelogic
|
|
|
|
|
|
|
|
import (
|
2024-10-12 09:49:58 +00:00
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
2024-10-06 07:02:30 +00:00
|
|
|
"context"
|
2024-10-12 09:49:58 +00:00
|
|
|
"github.com/shopspring/decimal"
|
2024-10-06 07:02:30 +00:00
|
|
|
|
|
|
|
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
|
|
"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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-12 09:49:58 +00:00
|
|
|
// 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 *tweeting.GetOrderReq) (*tweeting.GetOrderResp, error) {
|
2024-10-12 09:49:58 +00:00
|
|
|
// 驗證資料
|
|
|
|
if err := l.svcCtx.Validate.ValidateAll(&GetOrderQuery{
|
|
|
|
BusinessID: in.GetBusinessId(),
|
|
|
|
}); err != nil {
|
|
|
|
// 錯誤代碼 06-011-00
|
|
|
|
return nil, ers.InvalidFormat(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
order, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &tweeting.GetOrderResp{
|
|
|
|
UpdateTime: order.UpdateTime,
|
|
|
|
CreateTime: order.CreateTime,
|
|
|
|
BusinessId: order.BusinessID,
|
|
|
|
OrderType: int32(order.OrderType),
|
|
|
|
OrderStatus: int32(order.OrderStatus),
|
|
|
|
Brand: order.Brand,
|
|
|
|
OrderUid: order.OrderUID,
|
|
|
|
ReferenceId: order.ReferenceID,
|
|
|
|
Count: order.Count.String(),
|
|
|
|
OrderFee: order.OrderFee.String(),
|
|
|
|
Amount: order.Amount.String(),
|
|
|
|
// 下面的是未來擴充用,加密貨幣用,或者幣別轉換用,普通訂單用不到
|
|
|
|
ReferenceBrand: order.ReferenceBrand,
|
|
|
|
ReferenceUid: order.ReferenceUID,
|
|
|
|
WalletStatus: order.WalletStatus,
|
|
|
|
ThreePartyStatus: order.ThreePartyStatus,
|
|
|
|
DirectionType: order.DirectionType,
|
|
|
|
CryptoType: order.CryptoType,
|
|
|
|
ThirdPartyFee: decimalToString(*order.ThirdPartyFee),
|
|
|
|
CryptoToUsdtRate: decimalToString(*order.CryptoToUSDTRate),
|
|
|
|
FiatToUsdRate: decimalToString(*order.FiatToUSDRate),
|
|
|
|
FeeCryptoToUsdtRate: decimalToString(*order.FeeCryptoToUSDTRate),
|
|
|
|
UsdtToCryptoTypeRate: decimalToString(*order.USDTToCryptoTypeRate),
|
|
|
|
PaymentFiat: order.PaymentFiat,
|
|
|
|
PaymentUnitPrice: decimalToString(*order.PaymentUnitPrice),
|
|
|
|
PaymentTemplateId: order.PaymentTemplateID,
|
|
|
|
OrderArrivalTime: order.OrderArrivalTime,
|
|
|
|
OrderPaymentTime: order.OrderPaymentTime,
|
|
|
|
UnpaidTimeoutSecond: order.UnpaidTimeoutSecond,
|
|
|
|
ChainType: order.ChainType,
|
|
|
|
TxHash: order.TxHash,
|
|
|
|
FromAddress: order.FromAddress,
|
|
|
|
ToAddress: order.ToAddress,
|
|
|
|
ChainFee: decimalToString(*order.ChainFee),
|
|
|
|
ChainFeeCrypto: order.ChainFeeCrypto,
|
|
|
|
Memo: order.Memo,
|
|
|
|
OrderNote: order.OrderNote,
|
|
|
|
}, nil
|
|
|
|
}
|
2024-10-06 07:02:30 +00:00
|
|
|
|
2024-10-12 09:49:58 +00:00
|
|
|
func decimalToString(amount decimal.Decimal) *string {
|
|
|
|
a := amount.String()
|
|
|
|
return &a
|
2024-10-06 07:02:30 +00:00
|
|
|
}
|