From c7cd3c21e573a7d2bbe1c70bb91416d429d4778e Mon Sep 17 00:00:00 2001 From: Zuncle <34310384@qq.com> Date: Tue, 17 Mar 2026 18:11:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(shipping):=20=E5=8F=91=E8=B4=A7=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=B6=85=E8=BF=8748=E5=B0=8F=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=92=A4=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在cancel_shipping.go中添加48小时限制检查 - 在shipping_groups.go中返回created_at字段供前端判断 - 超过48小时的订单撤销时提示'需要撤销发货请联系客服' --- internal/service/user/cancel_shipping.go | 20 +++++++++++++++++--- internal/service/user/shipping_groups.go | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/service/user/cancel_shipping.go b/internal/service/user/cancel_shipping.go index 477f9ee..62563ce 100755 --- a/internal/service/user/cancel_shipping.go +++ b/internal/service/user/cancel_shipping.go @@ -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) diff --git a/internal/service/user/shipping_groups.go b/internal/service/user/shipping_groups.go index 6c452ba..d2c875f 100755 --- a/internal/service/user/shipping_groups.go +++ b/internal/service/user/shipping_groups.go @@ -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,