@@ -0,0 +1,58 @@
|
||||
package goldextractrl
|
||||
|
||||
import (
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/goldextramod"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func UserGoldExtra(ctx *gin.Context) {
|
||||
uid, err := common.GetUID(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
||||
return
|
||||
}
|
||||
var goldExtraReq struct {
|
||||
Type uint `form:"type" json:"type"`
|
||||
commod.Page
|
||||
}
|
||||
if err := ctx.ShouldBind(&goldExtraReq); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
skip := goldExtraReq.Skip()
|
||||
limit := goldExtraReq.Limit()
|
||||
var userExtras []goldextramod.GoldExtra
|
||||
switch goldExtraReq.Type {
|
||||
case 0: // 返回所有
|
||||
userExtras, err = goldextramod.GetUserGoldExtra(nil, uid, skip, limit+1)
|
||||
case 1: // 只返回有效
|
||||
userExtras, err = goldextramod.GetUserGoldExtraValid(nil, uid, skip, limit+1)
|
||||
case 2: // 已过期
|
||||
userExtras, err = goldextramod.GetUserGoldExtraExpired(nil, uid, skip, limit+1)
|
||||
case 3: // 已使用
|
||||
userExtras, err = goldextramod.GetUserGoldExtraUsed(nil, uid, skip, limit+1)
|
||||
default:
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "无效的type值")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, "")
|
||||
return
|
||||
}
|
||||
hasNext := false
|
||||
if uint64(len(userExtras)) > limit {
|
||||
userExtras = userExtras[:limit]
|
||||
hasNext = true
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, struct {
|
||||
List []goldextramod.GoldExtra `json:"list"`
|
||||
HasNext bool `json:"hasNext"`
|
||||
}{
|
||||
List: userExtras,
|
||||
HasNext: hasNext,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user