Compare commits

...

2 Commits

Author SHA1 Message Date
win
8d8f660e34 Merge remote-tracking branch 'origin/zuncle' 2026-03-17 18:36:24 +08:00
c7cd3c21e5 feat(shipping): 发货订单超过48小时不允许撤销
- 在cancel_shipping.go中添加48小时限制检查
- 在shipping_groups.go中返回created_at字段供前端判断
- 超过48小时的订单撤销时提示'需要撤销发货请联系客服'
2026-03-17 18:11:00 +08:00
2 changed files with 27 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package user
import (
"context"
"fmt"
"time"
"bindbox-game/internal/repository/mysql/dao"
)
@ -22,13 +23,15 @@ func (s *service) CancelShipping(ctx context.Context, userID int64, inventoryID
InventoryID int64
// 记录 shipping_record 中存储的实际 user_id用于后续恢复 inventory
RecordUserID int64
// 记录创建时间用于48小时限制检查
CreatedAt time.Time
}
// 根据参数查询待取消的发货记录
if batchNo != "" {
// 按批次号查询:仅允许取消属于自己的发货记录
rows, err := tx.ShippingRecords.WithContext(ctx).
Select(tx.ShippingRecords.ID, tx.ShippingRecords.InventoryID, tx.ShippingRecords.UserID).
Select(tx.ShippingRecords.ID, tx.ShippingRecords.InventoryID, tx.ShippingRecords.UserID, tx.ShippingRecords.CreatedAt).
Where(tx.ShippingRecords.BatchNo.Eq(batchNo)).
Where(tx.ShippingRecords.UserID.Eq(userID)).
Where(tx.ShippingRecords.Status.Eq(1)). // 待发货状态
@ -41,7 +44,8 @@ func (s *service) CancelShipping(ctx context.Context, userID int64, inventoryID
ID int64
InventoryID int64
RecordUserID int64
}{ID: r.ID, InventoryID: r.InventoryID, RecordUserID: r.UserID})
CreatedAt time.Time
}{ID: r.ID, InventoryID: r.InventoryID, RecordUserID: r.UserID, CreatedAt: r.CreatedAt})
}
} else if inventoryID > 0 {
// 按单个资产ID查询先不过滤 user_id取到记录后比对归属
@ -61,13 +65,23 @@ func (s *service) CancelShipping(ctx context.Context, userID int64, inventoryID
ID int64
InventoryID int64
RecordUserID int64
}{ID: sr.ID, InventoryID: sr.InventoryID, RecordUserID: sr.UserID})
CreatedAt time.Time
}{ID: sr.ID, InventoryID: sr.InventoryID, RecordUserID: sr.UserID, CreatedAt: sr.CreatedAt})
}
if len(records) == 0 {
return fmt.Errorf("no pending shipping records found")
}
// 检查48小时限制发货申请超过48小时不允许撤销
const cancelWindow = 48 * time.Hour
now := time.Now()
for _, rec := range records {
if now.Sub(rec.CreatedAt) > cancelWindow {
return fmt.Errorf("发货申请超过48小时不允许撤销需要撤销发货请联系客服")
}
}
// 批量处理每条记录
for _, rec := range records {
// 1. 更新发货记录状态为已取消 (status=5)

View File

@ -22,6 +22,7 @@ type ShipmentGroup struct {
Count int64 `json:"count"`
ShippedAt *time.Time `json:"shipped_at,omitempty"`
ReceivedAt *time.Time `json:"received_at,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"` // 发货申请创建时间用于前端判断48小时撤销限制
InventoryIDs []int64 `json:"inventory_ids"`
ProductIDs []int64 `json:"product_ids"`
Products []ProductInfo `json:"products"`
@ -53,6 +54,7 @@ func (s *service) ListUserShipmentGroups(ctx context.Context, userID int64, page
status int32
shippedAt *time.Time
receivedAt *time.Time
createdAt *time.Time // 最早的创建时间
inv []int64
pid []int64
}
@ -90,6 +92,13 @@ func (s *service) ListUserShipmentGroups(ctx context.Context, userID int64, page
t := r.ReceivedAt
a.receivedAt = &t
}
// 记录最早的创建时间
if !r.CreatedAt.IsZero() {
if a.createdAt == nil || r.CreatedAt.Before(*a.createdAt) {
t := r.CreatedAt
a.createdAt = &t
}
}
a.inv = append(a.inv, r.InventoryID)
if r.ProductID > 0 {
a.pid = append(a.pid, r.ProductID)
@ -126,6 +135,7 @@ func (s *service) ListUserShipmentGroups(ctx context.Context, userID int64, page
Count: c,
ShippedAt: a.shippedAt,
ReceivedAt: a.receivedAt,
CreatedAt: a.createdAt,
InventoryIDs: a.inv,
ProductIDs: a.pid,
Products: products,