feature/order_base #1

Merged
daniel.w merged 7 commits from feature/order_base into main 2024-10-23 09:50:13 +00:00
8 changed files with 108 additions and 10 deletions
Showing only changes of commit 07e5ce0eca - Show all commits

View File

@ -140,6 +140,7 @@ func (l *CreateOrderLogic) CreateOrder(in *tweeting.CreateOrderReq) (*tweeting.O
return &tweeting.OKResp{}, nil return &tweeting.OKResp{}, nil
} }
//nolint:gocyclo,gocognit
func buildCreateOrderReq(in *tweeting.CreateOrderReq) (*createOrderReq, error) { func buildCreateOrderReq(in *tweeting.CreateOrderReq) (*createOrderReq, error) {
createOrderReq := &createOrderReq{ createOrderReq := &createOrderReq{
BusinessID: in.BusinessId, BusinessID: in.BusinessId,

View File

@ -1,9 +1,10 @@
package orderservicelogic package orderservicelogic
import ( import (
ers "code.30cm.net/digimon/library-go/errs"
"context" "context"
ers "code.30cm.net/digimon/library-go/errs"
"app-cloudep-order-server/gen_result/pb/tweeting" "app-cloudep-order-server/gen_result/pb/tweeting"
"app-cloudep-order-server/internal/svc" "app-cloudep-order-server/internal/svc"

View File

@ -1,8 +1,9 @@
package orderservicelogic package orderservicelogic
import ( import (
ers "code.30cm.net/digimon/library-go/errs"
"context" "context"
ers "code.30cm.net/digimon/library-go/errs"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
"app-cloudep-order-server/gen_result/pb/tweeting" "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 { func decimalToString(amount decimal.Decimal) *string {
a := amount.String() a := amount.String()
return &a return &a
} }

View File

@ -2,9 +2,10 @@ package orderservicelogic
import ( import (
model "app-cloudep-order-server/internal/model/mongo" model "app-cloudep-order-server/internal/model/mongo"
ers "code.30cm.net/digimon/library-go/errs"
"context" "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/gen_result/pb/tweeting"
"app-cloudep-order-server/internal/svc" "app-cloudep-order-server/internal/svc"
@ -67,6 +68,95 @@ func (l *ListOrderLogic) ListOrder(in *tweeting.ListOrderReq) (*tweeting.ListOrd
return nil, err return nil, err
} }
fmt.Println(orders, total) res := make([]*tweeting.GetOrderResp, 0, len(orders))
return &tweeting.ListOrderResp{}, nil 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
} }

View File

@ -27,7 +27,7 @@ func NewOrderStatusTimeoutLogic(ctx context.Context, svcCtx *svc.ServiceContext)
} }
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout // 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() now := time.Now().UTC().UnixNano()
_, err := l.svcCtx.OrderModel.UpdateTimeoutOrder(l.ctx, model.UpdateTimeoutReq{ _, err := l.svcCtx.OrderModel.UpdateTimeoutOrder(l.ctx, model.UpdateTimeoutReq{
CreateTimeBefore: now, CreateTimeBefore: now,

View File

@ -4,9 +4,10 @@ import (
"app-cloudep-order-server/internal/domain" "app-cloudep-order-server/internal/domain"
"context" "context"
"errors" "errors"
"go.mongodb.org/mongo-driver/mongo/options"
"time" "time"
"go.mongodb.org/mongo-driver/mongo/options"
"github.com/zeromicro/go-zero/core/stores/mon" "github.com/zeromicro/go-zero/core/stores/mon"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo" "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) { 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 != "" { if req.ReferenceID != "" {

View File

@ -7,7 +7,7 @@ import (
"context" "context"
"app-cloudep-order-server/gen_result/pb/tweeting" "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" "app-cloudep-order-server/internal/svc"
) )

View File

@ -34,6 +34,7 @@ func main() {
}) })
defer s.Stop() defer s.Stop()
//nolint:forbidigo
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start() s.Start()
} }