feat: implement coupon management and receive flow

This commit is contained in:
2026-01-13 18:19:29 +08:00
parent 9b06f768ab
commit 4f315cc2db
18 changed files with 1787 additions and 246 deletions

View File

@@ -1,6 +1,7 @@
package v1
import (
"quyun/v2/app/errorx"
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
@@ -359,3 +360,103 @@ func (c *Creator) Withdraw(ctx fiber.Ctx, user *models.User, form *dto.WithdrawF
tenantID := getTenantID(ctx)
return services.Creator.Withdraw(ctx, tenantID, user.ID, form)
}
// Create coupon
//
// @Router /t/:tenantCode/v1/creator/coupons [post]
// @Summary Create coupon
// @Description Create coupon template
// @Tags CreatorCenter
// @Accept json
// @Produce json
// @Param form body dto.CouponCreateForm true "Coupon form"
// @Success 200 {object} dto.CouponItem
// @Bind user local key(__ctx_user)
// @Bind form body
func (c *Creator) CreateCoupon(ctx fiber.Ctx, user *models.User, form *dto.CouponCreateForm) (*dto.CouponItem, error) {
tenantID := getTenantID(ctx)
return services.Coupon.Create(ctx, tenantID, user.ID, form)
}
// List coupons
//
// @Router /t/:tenantCode/v1/creator/coupons [get]
// @Summary List coupons
// @Description List coupon templates
// @Tags CreatorCenter
// @Accept json
// @Produce json
// @Param page query int false "Page"
// @Param limit query int false "Limit"
// @Param type query string false "Type (fix_amount/discount)"
// @Param status query string false "Status (active/expired)"
// @Param keyword query string false "Keyword"
// @Success 200 {object} requests.Pager
// @Bind user local key(__ctx_user)
// @Bind filter query
func (c *Creator) ListCoupons(ctx fiber.Ctx, user *models.User, filter *dto.CouponListFilter) (*requests.Pager, error) {
tenantID := getTenantID(ctx)
return services.Coupon.List(ctx, tenantID, filter)
}
// Get coupon
//
// @Router /t/:tenantCode/v1/creator/coupons/:id<int> [get]
// @Summary Get coupon
// @Description Get coupon template detail
// @Tags CreatorCenter
// @Accept json
// @Produce json
// @Param id path int64 true "Coupon ID"
// @Success 200 {object} dto.CouponItem
// @Bind user local key(__ctx_user)
// @Bind id path
func (c *Creator) GetCoupon(ctx fiber.Ctx, user *models.User, id int64) (*dto.CouponItem, error) {
tenantID := getTenantID(ctx)
return services.Coupon.Get(ctx, tenantID, id)
}
// Update coupon
//
// @Router /t/:tenantCode/v1/creator/coupons/:id<int> [put]
// @Summary Update coupon
// @Description Update coupon template
// @Tags CreatorCenter
// @Accept json
// @Produce json
// @Param id path int64 true "Coupon ID"
// @Param form body dto.CouponUpdateForm true "Coupon form"
// @Success 200 {object} dto.CouponItem
// @Bind user local key(__ctx_user)
// @Bind id path
// @Bind form body
func (c *Creator) UpdateCoupon(ctx fiber.Ctx, user *models.User, id int64, form *dto.CouponUpdateForm) (*dto.CouponItem, error) {
tenantID := getTenantID(ctx)
return services.Coupon.Update(ctx, tenantID, user.ID, id, form)
}
// Grant coupon
//
// @Router /t/:tenantCode/v1/creator/coupons/:id<int>/grant [post]
// @Summary Grant coupon
// @Description Grant coupon to users
// @Tags CreatorCenter
// @Accept json
// @Produce json
// @Param id path int64 true "Coupon ID"
// @Param form body dto.CouponGrantForm true "Grant form"
// @Success 200 {string} string "Granted"
// @Bind user local key(__ctx_user)
// @Bind id path
// @Bind form body
func (c *Creator) GrantCoupon(ctx fiber.Ctx, user *models.User, id int64, form *dto.CouponGrantForm) (string, error) {
tenantID := getTenantID(ctx)
if form == nil {
return "", errorx.ErrInvalidParameter.WithMsg("参数无效")
}
_, err := services.Coupon.Grant(ctx, tenantID, id, form.UserIDs)
if err != nil {
return "", err
}
return "Granted", nil
}