gomod引用

This commit is contained in:
2025-12-12 18:16:28 +08:00
parent a4ba4dd715
commit 465c138f21
11 changed files with 340 additions and 403 deletions

View File

@@ -54,7 +54,7 @@ func (d *order) CreatePendingOrder(ctx context.Context, order *entity.OrderPendi
}
// GetOrderByNo 根据订单号查询订单(自动识别状态)
func (d *order) GetOrderByNo(ctx context.Context, tenantID, orderNo string) (interface{}, consts.OrderStatus, error) {
func (d *order) GetOrderByNo(ctx context.Context, orderNo string) (interface{}, consts.OrderStatus, error) {
// 按状态优先级搜索(从最新状态开始)
statuses := []consts.OrderStatus{
consts.OrderStatusCompleted,
@@ -72,22 +72,22 @@ func (d *order) GetOrderByNo(ctx context.Context, tenantID, orderNo string) (int
switch status {
case consts.OrderStatusPending:
var order entity.OrderPending
if err := d.findOrderByNo(collection, ctx, tenantID, orderNo, &order); err == nil {
if err := d.findOrderByNo(collection, ctx, orderNo, &order); err == nil {
return &order, status, nil
}
case consts.OrderStatusPaid:
var order entity.OrderPaid
if err := d.findOrderByNo(collection, ctx, tenantID, orderNo, &order); err == nil {
if err := d.findOrderByNo(collection, ctx, orderNo, &order); err == nil {
return &order, status, nil
}
case consts.OrderStatusShipped:
var order entity.OrderShipped
if err := d.findOrderByNo(collection, ctx, tenantID, orderNo, &order); err == nil {
if err := d.findOrderByNo(collection, ctx, orderNo, &order); err == nil {
return &order, status, nil
}
case consts.OrderStatusCompleted:
var order entity.OrderCompleted
if err := d.findOrderByNo(collection, ctx, tenantID, orderNo, &order); err == nil {
if err := d.findOrderByNo(collection, ctx, orderNo, &order); err == nil {
return &order, status, nil
}
}
@@ -97,10 +97,9 @@ func (d *order) GetOrderByNo(ctx context.Context, tenantID, orderNo string) (int
}
// findOrderByNo 通用订单查询方法
func (d *order) findOrderByNo(collection string, ctx context.Context, tenantID, orderNo string, result interface{}) error {
func (d *order) findOrderByNo(collection string, ctx context.Context, orderNo string, result interface{}) error {
filter := bson.M{
"tenant_id": tenantID,
"order_no": orderNo,
"order_no": orderNo,
}
err := mongo.FindOne(ctx, filter, result, collection)
@@ -111,7 +110,7 @@ func (d *order) findOrderByNo(collection string, ctx context.Context, tenantID,
}
// MoveOrderToStatus 将订单从一个状态移动到另一个状态
func (d *order) MoveOrderToStatus(ctx context.Context, fromStatus, toStatus consts.OrderStatus, tenantID, orderNo string, updateData bson.M) error {
func (d *order) MoveOrderToStatus(ctx context.Context, fromStatus, toStatus consts.OrderStatus, orderNo string, updateData bson.M) error {
// 获取源集合
srcCollection, err := d.getCollection(fromStatus)
if err != nil {
@@ -127,8 +126,7 @@ func (d *order) MoveOrderToStatus(ctx context.Context, fromStatus, toStatus cons
// 查找源订单
var orderData bson.M
filter := bson.M{
"tenant_id": tenantID,
"order_no": orderNo,
"order_no": orderNo,
}
err = mongo.FindOne(ctx, filter, &orderData, srcCollection)
@@ -154,7 +152,7 @@ func (d *order) MoveOrderToStatus(ctx context.Context, fromStatus, toStatus cons
}
// UpdatePendingOrder 更新待支付订单
func (d *order) UpdatePendingOrder(ctx context.Context, tenantID, orderNo string, update bson.M) error {
func (d *order) UpdatePendingOrder(ctx context.Context, orderNo string, update bson.M) error {
collection, err := d.getCollection(consts.OrderStatusPending)
if err != nil {
return err
@@ -163,8 +161,7 @@ func (d *order) UpdatePendingOrder(ctx context.Context, tenantID, orderNo string
update["updated_at"] = time.Now()
filter := bson.M{
"tenant_id": tenantID,
"order_no": orderNo,
"order_no": orderNo,
}
_, err = mongo.Update(ctx, filter, bson.M{"$set": update}, collection)
@@ -172,14 +169,14 @@ func (d *order) UpdatePendingOrder(ctx context.Context, tenantID, orderNo string
}
// ListOrdersByStatus 根据状态查询订单列表
func (d *order) ListOrdersByStatus(ctx context.Context, status consts.OrderStatus, tenantID, userID string, page, pageSize int) (interface{}, int64, error) {
func (d *order) ListOrdersByStatus(ctx context.Context, status consts.OrderStatus, userID string, page, pageSize int) (interface{}, int64, error) {
collection, err := d.getCollection(status)
if err != nil {
return nil, 0, err
}
// 构建查询条件
filter := bson.M{"tenant_id": tenantID}
filter := bson.M{}
if userID != "" {
filter["user_id"] = userID
}
@@ -225,14 +222,13 @@ func (d *order) ListOrdersByStatus(ctx context.Context, status consts.OrderStatu
}
// GetExpiredPendingOrders 获取过期的待支付订单
func (d *order) GetExpiredPendingOrders(ctx context.Context, tenantID string) ([]entity.OrderPending, error) {
func (d *order) GetExpiredPendingOrders(ctx context.Context) ([]entity.OrderPending, error) {
collection, err := d.getCollection(consts.OrderStatusPending)
if err != nil {
return nil, err
}
filter := bson.M{
"tenant_id": tenantID,
"expired_at": bson.M{"$lte": time.Now()},
}
@@ -245,15 +241,14 @@ func (d *order) GetExpiredPendingOrders(ctx context.Context, tenantID string) ([
}
// UpdatePayInfo 更新支付信息(待支付订单)
func (d *order) UpdatePayInfo(ctx context.Context, tenantID, orderNo string, payInfo entity.PayInfo) error {
func (d *order) UpdatePayInfo(ctx context.Context, orderNo string, payInfo entity.PayInfo) error {
collection, err := d.getCollection(consts.OrderStatusPending)
if err != nil {
return err
}
filter := bson.M{
"tenant_id": tenantID,
"order_no": orderNo,
"order_no": orderNo,
}
update := bson.M{
"pay_info": payInfo,