diff --git a/README.md b/README.md index 5968e42..9f01532 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ ## TODO +异常展示全部信息,只返回 bizerr 的内容,控制台打印全部 err 内容 + +ip 提取频率限制,在 ensure 函数加逻辑,通过 redis 或者 pg 计算分钟内提取次数,只允许每分钟提取 30 次 + proxy 的删除和更新,锁粒度应该有问题 交易信息持久化 diff --git a/scripts/sql/fill.sql b/scripts/sql/fill.sql index bb1181c..1ac333e 100644 --- a/scripts/sql/fill.sql +++ b/scripts/sql/fill.sql @@ -259,6 +259,10 @@ insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values ((select id from permission where name = 'balance_activity:read' and deleted_at is null), 'balance_activity:read:of_user', '读取指定用户的余额变动列表', 1); +-- coupon:write 子权限 +insert into permission (parent_id, name, description, sort) values + ((select id from permission where name = 'coupon:write' and deleted_at is null), 'coupon:write:assign', '发放优惠券', 1); + -- -------------------------- -- level 4 -- -------------------------- diff --git a/web/core/scopes.go b/web/core/scopes.go index 2e7ef43..2b1c909 100644 --- a/web/core/scopes.go +++ b/web/core/scopes.go @@ -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") // 读取批次列表 diff --git a/web/handlers/coupon.go b/web/handlers/coupon.go index fbfb007..8861062 100644 --- a/web/handlers/coupon.go +++ b/web/handlers/coupon.go @@ -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"` +} diff --git a/web/routes.go b/web/routes.go index eb15579..09a9c9f 100644 --- a/web/routes.go +++ b/web/routes.go @@ -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) } diff --git a/web/services/channel_baiyin.go b/web/services/channel_baiyin.go index 92fecd9..3bdec4c 100644 --- a/web/services/channel_baiyin.go +++ b/web/services/channel_baiyin.go @@ -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 {