feat(backend): 购买单取消透传 pay v2 cancel
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,27 @@ func (h *PayHandler) PurchaseStatus(c *gin.Context) {
|
||||
util.RespondSuccess(c, st)
|
||||
}
|
||||
|
||||
// Cancel POST /api/v1/license/purchase/:out_trade_no/cancel — 取消本店一笔购买单
|
||||
// (防 pending 单堆积挤占 reconcile 每轮 50 条限额)。仅管理员可用(handler 内判权,同 Purchase)。
|
||||
func (h *PayHandler) Cancel(c *gin.Context) {
|
||||
role := middleware.GetRole(c)
|
||||
if role != "admin" && role != "superadmin" {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "仅管理员可取消购买单"})
|
||||
return
|
||||
}
|
||||
canceled, err := h.svc.CancelPurchase(middleware.GetShopID(c), c.Param("out_trade_no"))
|
||||
if err != nil {
|
||||
if errors.Is(err, service.ErrPurchaseNotFound) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Printf("[pay] cancel failed shop=%d out_trade_no=%s: %v", middleware.GetShopID(c), c.Param("out_trade_no"), err)
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": "取消失败,请稍后重试"})
|
||||
return
|
||||
}
|
||||
util.RespondSuccess(c, gin.H{"canceled": canceled})
|
||||
}
|
||||
|
||||
// PromoStatus GET /api/v1/license/promo-status — 本店首月特惠是否已享用(前端据此置灰特惠档)。
|
||||
func (h *PayHandler) PromoStatus(c *gin.Context) {
|
||||
used, err := h.svc.PromoUsed(middleware.GetShopID(c))
|
||||
|
||||
Reference in New Issue
Block a user