feat(quality-owner): 增加优质号主自助取消与权益校验
This commit is contained in:
@@ -2,6 +2,7 @@ package qualityowner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -48,6 +49,24 @@ func (h *Handler) Activate(c *gin.Context) {
|
||||
response.OK(c, item)
|
||||
}
|
||||
|
||||
func (h *Handler) Cancel(c *gin.Context) {
|
||||
userID, ok := currentUserID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少用户上下文")
|
||||
return
|
||||
}
|
||||
item, err := h.service.Cancel(c.Request.Context(), userID, AuditMeta{
|
||||
IP: c.ClientIP(),
|
||||
UserAgent: c.GetHeader("User-Agent"),
|
||||
RequestID: middleware.GetRequestID(c),
|
||||
})
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, item)
|
||||
}
|
||||
|
||||
func (h *Handler) AdminSet(c *gin.Context) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
@@ -109,6 +128,15 @@ func writeError(c *gin.Context, err error) {
|
||||
response.Error(c, http.StatusConflict, "quality_owner_payment_pending", "已有待完成的保证金支付,请先完成支付或稍后重试")
|
||||
case errors.Is(err, ErrInactive):
|
||||
response.Error(c, http.StatusConflict, "quality_owner_inactive", "当前不是优质号主")
|
||||
case errors.Is(err, ErrActivePremiumListings):
|
||||
var activeErr ActivePremiumListingsError
|
||||
errors.As(err, &activeErr)
|
||||
response.Error(
|
||||
c,
|
||||
http.StatusConflict,
|
||||
"quality_owner_active_premium_listings",
|
||||
fmt.Sprintf("极品专区还有 %d 个进行中账号,请先下架或完成订单后再取消", activeErr.Count),
|
||||
)
|
||||
case errors.Is(err, ErrInvalidReason):
|
||||
response.BadRequest(c, "请填写 2-200 字的操作原因")
|
||||
case errors.Is(err, gorm.ErrRecordNotFound):
|
||||
|
||||
Reference in New Issue
Block a user