发放优惠券

This commit is contained in:
2026-04-27 14:05:35 +08:00
parent d59f4ca37f
commit e70f2337cb
6 changed files with 38 additions and 3 deletions

View File

@@ -48,9 +48,10 @@ const (
ScopeUserWriteBalanceDec = string("user:write:balance:dec") // 减少用户余额
ScopeUserWriteBind = string("user:write:bind") // 用户认领
ScopeCoupon = string("coupon") // 优惠券
ScopeCouponRead = string("coupon:read") // 读取优惠券列表
ScopeCouponWrite = string("coupon:write") // 写入优惠券
ScopeCoupon = string("coupon") // 优惠券
ScopeCouponRead = string("coupon:read") // 读取优惠券列表
ScopeCouponWrite = string("coupon:write") // 写入优惠券
ScopeCouponWriteAssign = string("coupon:write:assign") // 发放优惠券
ScopeBatch = string("batch") // 批次
ScopeBatchRead = string("batch:read") // 读取批次列表

View File

@@ -103,3 +103,27 @@ func DeleteCoupon(c *fiber.Ctx) error {
return nil
}
func AssignCoupon(c *fiber.Ctx) error {
_, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeCouponWriteAssign)
if err != nil {
return err
}
var req AssignCouponReq
if err := g.Validator.ParseBody(c, &req); err != nil {
return err
}
err = s.Coupon.Assign(req.CouponID, req.UserID)
if err != nil {
return err
}
return nil
}
type AssignCouponReq struct {
CouponID int32 `json:"coupon_id" validate:"required"`
UserID int32 `json:"user_id" validate:"required"`
}

View File

@@ -253,4 +253,5 @@ func adminRouter(api fiber.Router) {
coupon.Post("/create", handlers.CreateCoupon)
coupon.Post("/update", handlers.UpdateCoupon)
coupon.Post("/remove", handlers.DeleteCoupon)
coupon.Post("/update/assign", handlers.AssignCoupon)
}

View File

@@ -99,6 +99,7 @@ func (s *channelBaiyinProvider) CreateChannels(source netip.Addr, resourceId int
Sort: u.P("ip_unchanged_time_asc"),
})
if err != nil {
fmt.Printf("获取可用节点失败: %v\n", err)
return nil, core.NewBizErr("获取可用节点失败", err)
}
if edgesResp.Total != count && len(edgesResp.Edges) != count {