Compare commits

..

No commits in common. "8d8f660e343ac996e26f6f0d8cf177205a28f81e" and "a450a92673ec8bec74e7a4692902e9fccd01d38f" have entirely different histories.

2 changed files with 3 additions and 27 deletions

View File

@ -3,7 +3,6 @@ package user
import (
"context"
"fmt"
"time"
"bindbox-game/internal/repository/mysql/dao"
)
@ -23,15 +22,13 @@ 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, tx.ShippingRecords.CreatedAt).
Select(tx.ShippingRecords.ID, tx.ShippingRecords.InventoryID, tx.ShippingRecords.UserID).
Where(tx.ShippingRecords.BatchNo.Eq(batchNo)).
Where(tx.ShippingRecords.UserID.Eq(userID)).
Where(tx.ShippingRecords.Status.Eq(1)). // 待发货状态
@ -44,8 +41,7 @@ func (s *service) CancelShipping(ctx context.Context, userID int64, inventoryID
ID int64
InventoryID int64
RecordUserID int64
CreatedAt time.Time
}{ID: r.ID, InventoryID: r.InventoryID, RecordUserID: r.UserID, CreatedAt: r.CreatedAt})
}{ID: r.ID, InventoryID: r.InventoryID, RecordUserID: r.UserID})
}
} else if inventoryID > 0 {
// 按单个资产ID查询先不过滤 user_id取到记录后比对归属
@ -65,23 +61,13 @@ func (s *service) CancelShipping(ctx context.Context, userID int64, inventoryID
ID int64
InventoryID int64
RecordUserID int64
CreatedAt time.Time
}{ID: sr.ID, InventoryID: sr.InventoryID, RecordUserID: sr.UserID, CreatedAt: sr.CreatedAt})
}{ID: sr.ID, InventoryID: sr.InventoryID, RecordUserID: sr.UserID})
}
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,7 +22,6 @@ 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"`
@ -54,7 +53,6 @@ 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
}
@ -92,13 +90,6 @@ 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)
@ -135,7 +126,6 @@ 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,