This commit is contained in:
daniel.w 2024-10-23 17:38:00 +08:00
parent 0a62d892ce
commit ac0b2eab13
6 changed files with 50 additions and 10 deletions

View File

@ -23,6 +23,11 @@ const (
TimeoutOrderErrorCode
)
const (
_ ErrorCode = 10 + iota
DataNotFoundErrorCode
)
func CommentError(ec ErrorCode, s ...string) *ers.LibError {
return ers.NewError(code.CloudEPOrder, code.DBError, ec.ToUint32(), strings.Join(s, " "))
}
@ -34,3 +39,7 @@ func CommentErrorL(ec ErrorCode,
return e
}
func NotFoundError(ec ErrorCode, s ...string) *ers.LibError {
return ers.NewError(code.CloudEPOrder, code.ResourceNotFound, ec.ToUint32(), strings.Join(s, " "))
}

View File

@ -47,7 +47,7 @@ func convertDecimalToDecimal128(d decimal.Decimal) primitive.Decimal128 {
// 將 primitive.Decimal128 轉換為字符串
func convertDecimal128ToString(d128 *primitive.Decimal128) *string {
if d128 != nil {
if d128 == nil {
return nil
}
result := d128.String()

View File

@ -2,9 +2,12 @@ package orderservicelogic
import (
"app-cloudep-order-server/gen_result/pb/order"
"app-cloudep-order-server/internal/domain"
"app-cloudep-order-server/internal/svc"
ers "code.30cm.net/digimon/library-go/errs"
"context"
"errors"
"github.com/zeromicro/go-zero/core/stores/mon"
"github.com/zeromicro/go-zero/core/logx"
)
@ -40,6 +43,9 @@ func (l *GetOrderLogic) GetOrder(in *order.GetOrderReq) (*order.GetOrderResp, er
o, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId())
if err != nil {
if errors.As(err, &mon.ErrNotFound) {
return nil, domain.NotFoundError(domain.DataNotFoundErrorCode, "failed to get this order id:", in.GetBusinessId())
}
return nil, err
}

View File

@ -52,7 +52,7 @@ type GetOrderListReq struct {
// ListOrder 取得訂單列表
func (l *ListOrderLogic) ListOrder(in *order.ListOrderReq) (*order.ListOrderResp, error) {
// 驗證資料,目前只有 Page 必帶,其他要驗證在驗證
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&GetOrderListReq{
PageIndex: in.GetPageIndex(),
PageSize: in.GetPageSize(),
@ -61,14 +61,39 @@ func (l *ListOrderLogic) ListOrder(in *order.ListOrderReq) (*order.ListOrderResp
return nil, ers.InvalidFormat(err.Error())
}
orders, total, err := l.svcCtx.OrderModel.ListOrder(l.ctx, model.GetOrderListReq{})
// 構建查詢條件
req := model.GetOrderListReq{
PageIndex: in.GetPageIndex(),
PageSize: in.GetPageSize(),
ReferenceID: in.ReferenceId,
ReferenceUID: in.ReferenceUid,
BusinessID: in.BusinessId,
UID: in.Uid,
OrderType: int(in.OrderType),
DirectionType: in.DirectionType,
OrderStatus: in.OrderStatus,
StartCreateTime: in.StartCreateTime,
EndCreateTime: in.EndCreateTime,
StartUpdateTime: in.StartUpdateTime,
EndUpdateTime: in.EndUpdateTime,
StartOrderArrivalTime: in.StartOrderArrivalTime,
EndOrderArrivalTime: in.EndOrderArrivalTime,
StartOrderPaymentTime: in.StartOrderPaymentTime,
EndOrderPaymentTime: in.EndOrderPaymentTime,
CryptoType: in.CryptoType,
TxHash: in.TxHash,
}
// 查詢訂單
orders, total, err := l.svcCtx.OrderModel.ListOrder(l.ctx, req)
if err != nil {
return nil, err
}
// 構建返回結果
res := make([]*order.GetOrderResp, 0, len(orders))
for _, item := range orders {
res = append(res, ConvertOrderToGetOrderResp(item))
res = append(res, convertOrderToGetOrderResp(item))
}
return &order.ListOrderResp{
@ -82,7 +107,7 @@ func (l *ListOrderLogic) ListOrder(in *order.ListOrderReq) (*order.ListOrderResp
}
// ConvertOrderToGetOrderResp 將 Order 結構轉換為 GetOrderResp
func ConvertOrderToGetOrderResp(o model.Order) *order.GetOrderResp {
func convertOrderToGetOrderResp(o model.Order) *order.GetOrderResp {
return &order.GetOrderResp{
BusinessId: o.BusinessID,
OrderType: int32(o.OrderType),

View File

@ -4,9 +4,8 @@ import (
"app-cloudep-order-server/gen_result/pb/order"
"app-cloudep-order-server/internal/domain"
model "app-cloudep-order-server/internal/model/mongo"
"context"
ers "code.30cm.net/digimon/library-go/errs"
"context"
"app-cloudep-order-server/internal/svc"

View File

@ -49,8 +49,8 @@ type (
BusinessID string `json:"business_id"`
UID string `json:"uid"`
OrderType int `json:"order_type"`
DirectionType []int64 `json:"direction_type"`
OrderStatus []int64 `json:"order_status"`
DirectionType []int32 `json:"direction_type"`
OrderStatus []int32 `json:"order_status"`
StartCreateTime int64 `json:"start_create_time"`
EndCreateTime int64 `json:"end_create_time"`
@ -80,7 +80,7 @@ func (m *customOrderModel) UpdateStatus(ctx context.Context, data UpdateStatusRe
// 更新 update_time 和 status
updates["update_time"] = time.Now().UTC().UnixNano()
updates["status"] = data.Status
updates["order_status"] = data.Status
// 使用 updates map 作為 $set 的內容
res, err := m.conn.UpdateOne(ctx,
@ -93,6 +93,7 @@ func (m *customOrderModel) UpdateStatus(ctx context.Context, data UpdateStatusRe
},
bson.M{"$set": updates}, // 使用 updates 而不是整個 data
)
return res, err
}