diff --git a/internal/logic/orderservice/create_order_logic.go b/internal/logic/orderservice/create_order_logic.go index 151fbe4..ccc8046 100644 --- a/internal/logic/orderservice/create_order_logic.go +++ b/internal/logic/orderservice/create_order_logic.go @@ -140,6 +140,7 @@ func (l *CreateOrderLogic) CreateOrder(in *tweeting.CreateOrderReq) (*tweeting.O return &tweeting.OKResp{}, nil } +//nolint:gocyclo,gocognit func buildCreateOrderReq(in *tweeting.CreateOrderReq) (*createOrderReq, error) { createOrderReq := &createOrderReq{ BusinessID: in.BusinessId, diff --git a/internal/logic/orderservice/delete_order_logic.go b/internal/logic/orderservice/delete_order_logic.go index fccce01..89c0fa0 100644 --- a/internal/logic/orderservice/delete_order_logic.go +++ b/internal/logic/orderservice/delete_order_logic.go @@ -1,9 +1,10 @@ package orderservicelogic import ( - ers "code.30cm.net/digimon/library-go/errs" "context" + ers "code.30cm.net/digimon/library-go/errs" + "app-cloudep-order-server/gen_result/pb/tweeting" "app-cloudep-order-server/internal/svc" diff --git a/internal/logic/orderservice/get_order_logic.go b/internal/logic/orderservice/get_order_logic.go index f236f28..58e823f 100644 --- a/internal/logic/orderservice/get_order_logic.go +++ b/internal/logic/orderservice/get_order_logic.go @@ -1,8 +1,9 @@ package orderservicelogic import ( - ers "code.30cm.net/digimon/library-go/errs" "context" + + ers "code.30cm.net/digimon/library-go/errs" "github.com/shopspring/decimal" "app-cloudep-order-server/gen_result/pb/tweeting" @@ -88,5 +89,6 @@ func (l *GetOrderLogic) GetOrder(in *tweeting.GetOrderReq) (*tweeting.GetOrderRe func decimalToString(amount decimal.Decimal) *string { a := amount.String() + return &a } diff --git a/internal/logic/orderservice/list_order_logic.go b/internal/logic/orderservice/list_order_logic.go index dc55359..dd418a7 100644 --- a/internal/logic/orderservice/list_order_logic.go +++ b/internal/logic/orderservice/list_order_logic.go @@ -2,9 +2,10 @@ package orderservicelogic import ( model "app-cloudep-order-server/internal/model/mongo" - ers "code.30cm.net/digimon/library-go/errs" "context" - "fmt" + + ers "code.30cm.net/digimon/library-go/errs" + "github.com/shopspring/decimal" "app-cloudep-order-server/gen_result/pb/tweeting" "app-cloudep-order-server/internal/svc" @@ -67,6 +68,95 @@ func (l *ListOrderLogic) ListOrder(in *tweeting.ListOrderReq) (*tweeting.ListOrd return nil, err } - fmt.Println(orders, total) - return &tweeting.ListOrderResp{}, nil + res := make([]*tweeting.GetOrderResp, 0, len(orders)) + for _, item := range orders { + res = append(res, ConvertOrderToGetOrderResp(item)) + } + + return &tweeting.ListOrderResp{ + Data: res, + Page: &tweeting.Pager{ + Total: total, + Index: in.GetPageIndex(), + Size: in.GetPageSize(), + }, + }, nil +} + +// ConvertOrderToGetOrderResp 將 Order 結構轉換為 GetOrderResp +func ConvertOrderToGetOrderResp(order model.Order) *tweeting.GetOrderResp { + return &tweeting.GetOrderResp{ + 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: optionalString(order.ReferenceBrand), + ReferenceUid: optionalString(order.ReferenceUID), + WalletStatus: optionalInt64(order.WalletStatus), + ThreePartyStatus: optionalInt64(order.ThreePartyStatus), + DirectionType: optionalInt64(order.DirectionType), + CryptoType: optionalString(order.CryptoType), + ThirdPartyFee: optionalDecimalToString(order.ThirdPartyFee), + CryptoToUsdtRate: optionalDecimalToString(order.CryptoToUSDTRate), + FiatToUsdRate: optionalDecimalToString(order.FiatToUSDRate), + FeeCryptoToUsdtRate: optionalDecimalToString(order.FeeCryptoToUSDTRate), + UsdtToCryptoTypeRate: optionalDecimalToString(order.USDTToCryptoTypeRate), + PaymentFiat: optionalString(order.PaymentFiat), + PaymentUnitPrice: optionalDecimalToString(order.PaymentUnitPrice), + PaymentTemplateId: optionalString(order.PaymentTemplateID), + OrderArrivalTime: optionalInt64(order.OrderArrivalTime), + OrderPaymentTime: optionalInt64(order.OrderPaymentTime), + UnpaidTimeoutSecond: optionalInt64(order.UnpaidTimeoutSecond), + ChainType: optionalString(order.ChainType), + TxHash: optionalString(order.TxHash), + FromAddress: optionalString(order.FromAddress), + ToAddress: optionalString(order.ToAddress), + ChainFee: optionalDecimalToString(order.ChainFee), + ChainFeeCrypto: optionalString(order.ChainFeeCrypto), + Memo: optionalString(order.Memo), + OrderNote: optionalString(order.OrderNote), + CreateTime: order.CreateTime, + UpdateTime: order.UpdateTime, + } +} + +// Helper functions for optional fields +func optionalString(s *string) *string { + if s != nil { + return s + } + + return nil +} + +func optionalInt64(i *int64) *int64 { + if i != nil { + return i + } + + return nil +} + +func optionalDecimalToString(d *decimal.Decimal) *string { + if d != nil { + s := d.String() + + return &s + } + + return nil +} + +func ConvertOrdersToGetOrderResp(orders []model.Order) []*tweeting.GetOrderResp { + res := make([]*tweeting.GetOrderResp, 0, len(orders)) + for _, order := range orders { + res = append(res, ConvertOrderToGetOrderResp(order)) + } + + return res } diff --git a/internal/logic/orderservice/order_status_timeout_logic.go b/internal/logic/orderservice/order_status_timeout_logic.go index 4a3096c..ca4359c 100644 --- a/internal/logic/orderservice/order_status_timeout_logic.go +++ b/internal/logic/orderservice/order_status_timeout_logic.go @@ -27,7 +27,7 @@ func NewOrderStatusTimeoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) } // OrderStatusTimeout 訂單超時任務/cron/order-status/timeout -func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(in *tweeting.OrderStatusTimeoutReq) (*tweeting.OKResp, error) { +func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(_ *tweeting.OrderStatusTimeoutReq) (*tweeting.OKResp, error) { now := time.Now().UTC().UnixNano() _, err := l.svcCtx.OrderModel.UpdateTimeoutOrder(l.ctx, model.UpdateTimeoutReq{ CreateTimeBefore: now, diff --git a/internal/model/mongo/order_model.go b/internal/model/mongo/order_model.go index 47f5b25..d931bbc 100644 --- a/internal/model/mongo/order_model.go +++ b/internal/model/mongo/order_model.go @@ -4,9 +4,10 @@ import ( "app-cloudep-order-server/internal/domain" "context" "errors" - "go.mongodb.org/mongo-driver/mongo/options" "time" + "go.mongodb.org/mongo-driver/mongo/options" + "github.com/zeromicro/go-zero/core/stores/mon" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -156,7 +157,9 @@ func (m *defaultOrderModel) FindOneBusinessID(ctx context.Context, id string) (* func (m *customOrderModel) ListOrder(ctx context.Context, req GetOrderListReq) ([]Order, int64, error) { // 定義查詢過濾器 - filter := bson.M{} + filter := bson.M{ + "delete_time": bson.M{"$in": []any{0, nil}}, + } // 添加查詢條件 if req.ReferenceID != "" { diff --git a/internal/server/orderservice/order_service_server.go b/internal/server/orderservice/order_service_server.go index 0438b47..bae682a 100644 --- a/internal/server/orderservice/order_service_server.go +++ b/internal/server/orderservice/order_service_server.go @@ -7,7 +7,7 @@ import ( "context" "app-cloudep-order-server/gen_result/pb/tweeting" - "app-cloudep-order-server/internal/logic/orderservice" + orderservicelogic "app-cloudep-order-server/internal/logic/orderservice" "app-cloudep-order-server/internal/svc" ) diff --git a/order.go b/order.go index 0876820..c5aeb4f 100644 --- a/order.go +++ b/order.go @@ -34,6 +34,7 @@ func main() { }) defer s.Stop() + //nolint:forbidigo fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) s.Start() }