add order service logic
This commit is contained in:
parent
008f40a898
commit
8596d56fc7
|
@ -119,6 +119,11 @@ issues:
|
|||
|
||||
exclude-dirs:
|
||||
- internal/model
|
||||
- internal/logic/couponservice
|
||||
- internal/logic/inventoryservice
|
||||
- internal/logic/productservice
|
||||
- internal/logic/subscriptionservice
|
||||
- internal/logic/walletservice
|
||||
|
||||
exclude-files:
|
||||
- .*_test.go
|
||||
|
|
|
@ -52,17 +52,17 @@ type GetOrderQuery struct {
|
|||
}
|
||||
|
||||
type GetOrderResp struct {
|
||||
BusinessId string // 訂單業務流水號
|
||||
BusinessID string // 訂單業務流水號
|
||||
OrderType domain.OrderType `json:"order_type"` // 訂單類型
|
||||
OrderStatus domain.OrderStatus `json:"order_status"` // 訂單狀態
|
||||
Brand string `json:"brand"` // 下單平台
|
||||
OrderUid string `json:"order_uid"` // 下單用戶 UID
|
||||
ReferenceId string `json:"reference_id"` // 訂單來源
|
||||
OrderUID string `json:"order_uid"` // 下單用戶 UID
|
||||
ReferenceID string `json:"reference_id"` // 訂單來源
|
||||
Count string `json:"count"` // 訂單數量 (decimal to string)
|
||||
OrderFee string `json:"order_fee"` // 訂單手續費 (decimal to string)
|
||||
Amount string `json:"amount"` // 單價 (decimal to string)
|
||||
ReferenceBrand *string `json:"reference_brand,omitempty"` // 訂單來源平台
|
||||
ReferenceUid *string `json:"reference_uid,omitempty"` // 訂單來源用戶 UID
|
||||
ReferenceUID *string `json:"reference_uid,omitempty"` // 訂單來源用戶 UID
|
||||
WalletStatus *int64 `json:"wallet_status,omitempty"` // 交易金額狀態
|
||||
ThreePartyStatus *int64 `json:"three_party_status,omitempty"` // 三方請求狀態
|
||||
DirectionType *int64 `json:"direction_type,omitempty"` // 交易方向
|
||||
|
@ -74,7 +74,7 @@ type GetOrderResp struct {
|
|||
UsdtToCryptoTypeRate *string `json:"usdt_to_crypto_type_rate,omitempty"` // USDT 對交易幣種匯率 (decimal to string)
|
||||
PaymentFiat *string `json:"payment_fiat,omitempty"` // 支付法幣
|
||||
PaymentUnitPrice *string `json:"payment_unit_price,omitempty"` // crypto 單價 (decimal to string)
|
||||
PaymentTemplateId *string `json:"payment_template_id,omitempty"` // 支付方式配置 ID
|
||||
PaymentTemplateID *string `json:"payment_template_id,omitempty"` // 支付方式配置 ID
|
||||
OrderArrivalTime *int64 `json:"order_arrival_time,omitempty"` // 訂單到帳時間
|
||||
OrderPaymentTime *int64 `json:"order_payment_time,omitempty"` // 訂單付款時間
|
||||
UnpaidTimeoutSecond *int64 `json:"unpaid_timeout_second,omitempty"` // 支付期限秒數
|
||||
|
|
|
@ -3,9 +3,10 @@ package orderservicelogic
|
|||
import (
|
||||
"app-cloudep-trade-service/internal/domain"
|
||||
"app-cloudep-trade-service/internal/domain/usecase"
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"context"
|
||||
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
|
||||
"app-cloudep-trade-service/gen_result/pb/trade"
|
||||
"app-cloudep-trade-service/internal/svc"
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@ package orderservicelogic
|
|||
import (
|
||||
"app-cloudep-trade-service/internal/domain"
|
||||
"app-cloudep-trade-service/internal/domain/usecase"
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"context"
|
||||
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"app-cloudep-trade-service/gen_result/pb/trade"
|
||||
|
|
|
@ -2,9 +2,10 @@ package orderservicelogic
|
|||
|
||||
import (
|
||||
"app-cloudep-trade-service/internal/domain/usecase"
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"context"
|
||||
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
|
||||
"app-cloudep-trade-service/gen_result/pb/trade"
|
||||
"app-cloudep-trade-service/internal/svc"
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@ package orderservicelogic
|
|||
|
||||
import (
|
||||
"app-cloudep-trade-service/internal/domain/usecase"
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"context"
|
||||
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
|
||||
"app-cloudep-trade-service/gen_result/pb/trade"
|
||||
"app-cloudep-trade-service/internal/svc"
|
||||
|
||||
|
@ -49,18 +50,18 @@ func (l *GetOrderLogic) GetOrder(in *trade.GetOrderReq) (*trade.GetOrderResp, er
|
|||
return &trade.GetOrderResp{
|
||||
UpdateTime: o.UpdateTime,
|
||||
CreateTime: o.CreateTime,
|
||||
BusinessId: o.BusinessId,
|
||||
BusinessId: o.BusinessID,
|
||||
OrderType: int32(o.OrderType),
|
||||
OrderStatus: int32(o.OrderStatus),
|
||||
Brand: o.Brand,
|
||||
OrderUid: o.OrderUid,
|
||||
ReferenceId: o.ReferenceId,
|
||||
OrderUid: o.OrderUID,
|
||||
ReferenceId: o.ReferenceID,
|
||||
Count: o.Count,
|
||||
OrderFee: o.OrderFee,
|
||||
Amount: o.Amount,
|
||||
// 下面的為未來擴充用的欄位
|
||||
ReferenceBrand: o.ReferenceBrand,
|
||||
ReferenceUid: o.ReferenceUid,
|
||||
ReferenceUid: o.ReferenceUID,
|
||||
WalletStatus: o.WalletStatus,
|
||||
ThreePartyStatus: o.ThreePartyStatus,
|
||||
DirectionType: o.DirectionType,
|
||||
|
@ -72,7 +73,7 @@ func (l *GetOrderLogic) GetOrder(in *trade.GetOrderReq) (*trade.GetOrderResp, er
|
|||
UsdtToCryptoTypeRate: o.UsdtToCryptoTypeRate,
|
||||
PaymentFiat: o.PaymentFiat,
|
||||
PaymentUnitPrice: o.PaymentUnitPrice,
|
||||
PaymentTemplateId: o.PaymentTemplateId,
|
||||
PaymentTemplateId: o.PaymentTemplateID,
|
||||
OrderArrivalTime: o.OrderArrivalTime,
|
||||
OrderPaymentTime: o.OrderPaymentTime,
|
||||
UnpaidTimeoutSecond: o.UnpaidTimeoutSecond,
|
||||
|
|
|
@ -3,9 +3,10 @@ package orderservicelogic
|
|||
import (
|
||||
"app-cloudep-trade-service/internal/domain"
|
||||
"app-cloudep-trade-service/internal/domain/usecase"
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"context"
|
||||
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
|
||||
"app-cloudep-trade-service/gen_result/pb/trade"
|
||||
"app-cloudep-trade-service/internal/svc"
|
||||
|
||||
|
@ -107,17 +108,17 @@ func (l *ListOrderLogic) ListOrder(in *trade.ListOrderReq) (*trade.ListOrderResp
|
|||
data := make([]*trade.GetOrderResp, 0, len(order.Data))
|
||||
for _, item := range order.Data {
|
||||
data = append(data, &trade.GetOrderResp{
|
||||
BusinessId: item.BusinessId,
|
||||
BusinessId: item.BusinessID,
|
||||
OrderType: int32(item.OrderType),
|
||||
OrderStatus: int32(item.OrderStatus),
|
||||
Brand: item.Brand,
|
||||
OrderUid: item.OrderUid,
|
||||
ReferenceId: item.ReferenceId,
|
||||
OrderUid: item.OrderUID,
|
||||
ReferenceId: item.ReferenceID,
|
||||
Count: item.Count,
|
||||
OrderFee: item.OrderFee,
|
||||
Amount: item.Amount,
|
||||
ReferenceBrand: item.ReferenceBrand,
|
||||
ReferenceUid: item.ReferenceUid,
|
||||
ReferenceUid: item.ReferenceUID,
|
||||
WalletStatus: item.WalletStatus,
|
||||
ThreePartyStatus: item.ThreePartyStatus,
|
||||
DirectionType: item.DirectionType,
|
||||
|
@ -129,7 +130,7 @@ func (l *ListOrderLogic) ListOrder(in *trade.ListOrderReq) (*trade.ListOrderResp
|
|||
UsdtToCryptoTypeRate: item.UsdtToCryptoTypeRate,
|
||||
PaymentFiat: item.PaymentFiat,
|
||||
PaymentUnitPrice: item.PaymentUnitPrice,
|
||||
PaymentTemplateId: item.PaymentTemplateId,
|
||||
PaymentTemplateId: item.PaymentTemplateID,
|
||||
OrderArrivalTime: item.OrderArrivalTime,
|
||||
OrderPaymentTime: item.OrderPaymentTime,
|
||||
UnpaidTimeoutSecond: item.UnpaidTimeoutSecond,
|
||||
|
|
|
@ -2,9 +2,10 @@ package orderservicelogic
|
|||
|
||||
import (
|
||||
"app-cloudep-trade-service/internal/domain/usecase"
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
"context"
|
||||
|
||||
ers "code.30cm.net/digimon/library-go/errs"
|
||||
|
||||
"app-cloudep-trade-service/gen_result/pb/trade"
|
||||
"app-cloudep-trade-service/internal/svc"
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ func NewOrderStatusTimeoutLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
|
||||
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
|
||||
func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(in *trade.OrderStatusTimeoutReq) (*trade.OKResp, error) {
|
||||
func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(_ *trade.OrderStatusTimeoutReq) (*trade.OKResp, error) {
|
||||
err := l.svcCtx.OrderUseCase.OrderStatusTimeout(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -126,23 +126,24 @@ func (o *OrderUseCase) GetOrder(ctx context.Context, param usecase.GetOrderQuery
|
|||
if errors.Is(mon.ErrNotFound, err) {
|
||||
return nil, domain.NotFoundError(domain.DataNotFoundErrorCode, "failed to get this order id:", param.BusinessID)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &usecase.GetOrderResp{
|
||||
UpdateTime: order.UpdateTime,
|
||||
CreateTime: order.CreateTime,
|
||||
BusinessId: order.BusinessID,
|
||||
BusinessID: order.BusinessID,
|
||||
OrderType: order.OrderType,
|
||||
OrderStatus: order.OrderStatus,
|
||||
Brand: order.Brand,
|
||||
OrderUid: order.OrderUID,
|
||||
ReferenceId: order.ReferenceID,
|
||||
OrderUID: order.OrderUID,
|
||||
ReferenceID: order.ReferenceID,
|
||||
Count: order.Count.String(),
|
||||
OrderFee: order.OrderFee.String(),
|
||||
Amount: order.Amount.String(),
|
||||
ReferenceBrand: order.ReferenceBrand,
|
||||
ReferenceUid: order.ReferenceUID,
|
||||
ReferenceUID: order.ReferenceUID,
|
||||
WalletStatus: Int64Ptr(order.WalletStatus),
|
||||
ThreePartyStatus: order.ThreePartyStatus,
|
||||
DirectionType: Int64Ptr(order.DirectionType),
|
||||
|
@ -154,7 +155,7 @@ func (o *OrderUseCase) GetOrder(ctx context.Context, param usecase.GetOrderQuery
|
|||
UsdtToCryptoTypeRate: DecimalToStringPtr(order.USDTToCryptoTypeRate),
|
||||
PaymentFiat: order.PaymentFiat,
|
||||
PaymentUnitPrice: DecimalToStringPtr(order.PaymentUnitPrice),
|
||||
PaymentTemplateId: order.PaymentTemplateID,
|
||||
PaymentTemplateID: order.PaymentTemplateID,
|
||||
OrderArrivalTime: order.OrderArrivalTime,
|
||||
OrderPaymentTime: order.OrderPaymentTime,
|
||||
UnpaidTimeoutSecond: order.UnpaidTimeoutSecond,
|
||||
|
@ -266,17 +267,17 @@ func (o *OrderUseCase) convertOrdersToResponses(orders []model.Order) []*usecase
|
|||
resp := &usecase.GetOrderResp{
|
||||
UpdateTime: order.UpdateTime,
|
||||
CreateTime: order.CreateTime,
|
||||
BusinessId: order.BusinessID,
|
||||
BusinessID: order.BusinessID,
|
||||
OrderType: order.OrderType,
|
||||
OrderStatus: order.OrderStatus,
|
||||
Brand: order.Brand,
|
||||
OrderUid: order.OrderUID,
|
||||
ReferenceId: order.ReferenceID,
|
||||
OrderUID: order.OrderUID,
|
||||
ReferenceID: order.ReferenceID,
|
||||
Count: order.Count.String(),
|
||||
OrderFee: order.OrderFee.String(),
|
||||
Amount: order.Amount.String(),
|
||||
ReferenceBrand: order.ReferenceBrand,
|
||||
ReferenceUid: order.ReferenceUID,
|
||||
ReferenceUID: order.ReferenceUID,
|
||||
WalletStatus: Int64Ptr(order.WalletStatus),
|
||||
ThreePartyStatus: order.ThreePartyStatus,
|
||||
DirectionType: Int64Ptr(order.DirectionType),
|
||||
|
@ -288,7 +289,7 @@ func (o *OrderUseCase) convertOrdersToResponses(orders []model.Order) []*usecase
|
|||
UsdtToCryptoTypeRate: DecimalToStringPtr(order.USDTToCryptoTypeRate),
|
||||
PaymentFiat: order.PaymentFiat,
|
||||
PaymentUnitPrice: DecimalToStringPtr(order.PaymentUnitPrice),
|
||||
PaymentTemplateId: order.PaymentTemplateID,
|
||||
PaymentTemplateID: order.PaymentTemplateID,
|
||||
OrderArrivalTime: order.OrderArrivalTime,
|
||||
OrderPaymentTime: order.OrderPaymentTime,
|
||||
UnpaidTimeoutSecond: order.UnpaidTimeoutSecond,
|
||||
|
@ -303,5 +304,6 @@ func (o *OrderUseCase) convertOrdersToResponses(orders []model.Order) []*usecase
|
|||
}
|
||||
res = append(res, resp)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@ import (
|
|||
model "app-cloudep-trade-service/internal/model/mongo"
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/assert/v2"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/stores/mon"
|
||||
"go.uber.org/mock/gomock"
|
||||
"time"
|
||||
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -266,23 +267,23 @@ func TestOrderUseCase_GetOrder(t *testing.T) {
|
|||
wantResp: &usecase.GetOrderResp{ // 构建预期响应
|
||||
UpdateTime: mockOrder.UpdateTime,
|
||||
CreateTime: mockOrder.CreateTime,
|
||||
BusinessId: mockOrder.BusinessID,
|
||||
BusinessID: mockOrder.BusinessID,
|
||||
OrderType: mockOrder.OrderType,
|
||||
OrderStatus: mockOrder.OrderStatus,
|
||||
Brand: mockOrder.Brand,
|
||||
OrderUid: mockOrder.OrderUID,
|
||||
ReferenceId: mockOrder.ReferenceID,
|
||||
OrderUID: mockOrder.OrderUID,
|
||||
ReferenceID: mockOrder.ReferenceID,
|
||||
Count: mockOrder.Count.String(),
|
||||
OrderFee: mockOrder.OrderFee.String(),
|
||||
Amount: mockOrder.Amount.String(),
|
||||
ReferenceBrand: mockOrder.ReferenceBrand,
|
||||
ReferenceUid: mockOrder.ReferenceUID,
|
||||
ReferenceUID: mockOrder.ReferenceUID,
|
||||
WalletStatus: Int64Ptr(mockOrder.WalletStatus),
|
||||
ThreePartyStatus: mockOrder.ThreePartyStatus,
|
||||
DirectionType: Int64Ptr(mockOrder.DirectionType),
|
||||
CryptoType: mockOrder.CryptoType,
|
||||
PaymentFiat: mockOrder.PaymentFiat,
|
||||
PaymentTemplateId: mockOrder.PaymentTemplateID,
|
||||
PaymentTemplateID: mockOrder.PaymentTemplateID,
|
||||
OrderArrivalTime: mockOrder.OrderArrivalTime,
|
||||
OrderPaymentTime: mockOrder.OrderPaymentTime,
|
||||
UnpaidTimeoutSecond: mockOrder.UnpaidTimeoutSecond,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package usecase
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-playground/assert/v2"
|
||||
"github.com/shopspring/decimal"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// 測試 Int64Ptr 函數
|
||||
|
|
Loading…
Reference in New Issue