2024-10-06 07:02:30 +00:00
|
|
|
package orderservicelogic
|
|
|
|
|
|
|
|
import (
|
2024-10-12 13:56:59 +00:00
|
|
|
"app-cloudep-order-server/gen_result/pb/order"
|
2024-10-06 07:02:30 +00:00
|
|
|
"context"
|
2024-10-22 09:12:05 +00:00
|
|
|
"fmt"
|
2024-10-12 13:04:06 +00:00
|
|
|
|
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
2024-10-12 09:49:58 +00:00
|
|
|
"github.com/shopspring/decimal"
|
2024-10-06 07:02:30 +00:00
|
|
|
|
|
|
|
"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 取得訂單詳情
|
2024-10-12 13:56:59 +00:00
|
|
|
func (l *GetOrderLogic) GetOrder(in *order.GetOrderReq) (*order.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())
|
|
|
|
}
|
|
|
|
|
2024-10-12 13:56:59 +00:00
|
|
|
o, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId())
|
2024-10-12 09:49:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-22 09:12:05 +00:00
|
|
|
fmt.Println(o)
|
2024-10-12 09:49:58 +00:00
|
|
|
|
2024-10-12 13:56:59 +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(),
|
2024-10-22 09:12:05 +00:00
|
|
|
// 下面的為未來擴充用的欄位
|
|
|
|
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: decimalToString(o.ThirdPartyFee),
|
|
|
|
CryptoToUsdtRate: decimalToString(o.CryptoToUSDTRate),
|
|
|
|
FiatToUsdRate: decimalToString(o.FiatToUSDRate),
|
|
|
|
FeeCryptoToUsdtRate: decimalToString(o.FeeCryptoToUSDTRate),
|
|
|
|
UsdtToCryptoTypeRate: decimalToString(o.USDTToCryptoTypeRate),
|
|
|
|
PaymentFiat: nilString(o.PaymentFiat),
|
|
|
|
PaymentUnitPrice: decimalToString(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: decimalToString(o.ChainFee),
|
|
|
|
ChainFeeCrypto: nilString(o.ChainFeeCrypto),
|
|
|
|
Memo: nilString(o.Memo),
|
|
|
|
OrderNote: nilString(o.OrderNote),
|
2024-10-12 09:49:58 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2024-10-06 07:02:30 +00:00
|
|
|
|
2024-10-22 09:12:05 +00:00
|
|
|
func decimalToString(amount *decimal.Decimal) *string {
|
|
|
|
if amount == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-10-12 09:49:58 +00:00
|
|
|
a := amount.String()
|
2024-10-12 13:04:06 +00:00
|
|
|
|
2024-10-12 09:49:58 +00:00
|
|
|
return &a
|
2024-10-06 07:02:30 +00:00
|
|
|
}
|
2024-10-22 09:12:05 +00:00
|
|
|
|
|
|
|
func nilString(s *string) *string {
|
|
|
|
if s == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func nilInt64(i *int64) *int64 {
|
|
|
|
if i == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return i
|
|
|
|
}
|