feat: implement coupon management and receive flow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
auth_dto "quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/requests"
|
||||
@@ -319,3 +320,40 @@ func (u *User) MyCoupons(ctx fiber.Ctx, user *models.User, status string) ([]dto
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Coupon.ListUserCoupons(ctx, tenantID, user.ID, status)
|
||||
}
|
||||
|
||||
// List available coupons for order amount
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/me/coupons/available [get]
|
||||
// @Summary List available coupons
|
||||
// @Description List coupons available for the given order amount
|
||||
// @Tags UserCenter
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param amount query int64 true "Order amount (cents)"
|
||||
// @Success 200 {array} dto.UserCouponItem
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind amount query
|
||||
func (u *User) AvailableCoupons(ctx fiber.Ctx, user *models.User, amount int64) ([]dto.UserCouponItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Coupon.ListAvailable(ctx, tenantID, user.ID, amount)
|
||||
}
|
||||
|
||||
// Receive coupon
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/me/coupons/receive [post]
|
||||
// @Summary Receive coupon
|
||||
// @Description Receive a coupon by coupon_id
|
||||
// @Tags UserCenter
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param form body dto.CouponReceiveForm true "Receive form"
|
||||
// @Success 200 {object} dto.UserCouponItem
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind form body
|
||||
func (u *User) ReceiveCoupon(ctx fiber.Ctx, user *models.User, form *dto.CouponReceiveForm) (*dto.UserCouponItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter.WithMsg("参数无效")
|
||||
}
|
||||
return services.Coupon.Receive(ctx, tenantID, user.ID, form.CouponID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user