feature/order_base #1
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 != "" {
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue