137 lines
4.0 KiB
Go
137 lines
4.0 KiB
Go
package couponctl
|
|
|
|
import (
|
|
"91porn-server/app/service/couponser"
|
|
"91porn-server/common"
|
|
"91porn-server/common/log"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/v/coupon_record_mod"
|
|
"91porn-server/models/v/prize_record_mod"
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// List doc
|
|
// @Summary 获取优惠券
|
|
// @Description 获取优惠券
|
|
// @Tags
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param type query integer true "优惠券类型"
|
|
// @Param pageNumber query integer true "查询页码"
|
|
// @Param pageSize query integer true "页码大小"
|
|
// @Success 200 {object} coupon_record_mod.QueryAllRes
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/app/coupon/list [get]
|
|
func List(c *gin.Context) {
|
|
uid, err := common.GetUID(c)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrNoToken, nil)
|
|
return
|
|
}
|
|
var req coupon_record_mod.AppListReq
|
|
err = c.ShouldBindQuery(&req)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
data, err := couponser.List(uid, &req)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.Failure, nil)
|
|
return
|
|
}
|
|
common.ServeJSON(c, stderr.Success, data)
|
|
}
|
|
|
|
// Gain doc
|
|
// @Summary 上传用户信息
|
|
// @Description 上传用户信息
|
|
// @Tags
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param type query integer true "优惠券类型"
|
|
// @Param pageNumber query integer true "查询页码"
|
|
// @Param pageSize query integer true "页码大小"
|
|
// @Success 200 {object} coupon_record_mod.QueryAllRes
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/app/luckyDraw/gain [get]
|
|
func Gain(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
|
return
|
|
}
|
|
|
|
data, err := couponser.Gain(ctx, uid)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.Failure, nil)
|
|
return
|
|
}
|
|
common.ServeToJSON(ctx, stderr.Success, data)
|
|
}
|
|
|
|
// Upload doc
|
|
// @Summary 上传用户优惠券
|
|
// @Description 上传用户优惠券
|
|
// @Tags
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param type query integer true "优惠券类型"
|
|
// @Param pageNumber query integer true "查询页码"
|
|
// @Param pageSize query integer true "页码大小"
|
|
// @Success 200 {object} coupon_record_mod.QueryAllRes
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/app/coupon/Upload [post]
|
|
func Upload(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
|
return
|
|
}
|
|
var req prize_record_mod.AppUploadReq
|
|
if err = ctx.ShouldBind(&req); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
|
|
if err = couponser.Upload(uid, &req); err != nil {
|
|
log.Error(fmt.Sprintf("App couponser Upload err:%v", err))
|
|
common.ServeJSON(ctx, stderr.Failure, err.Error())
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, stderr.Success.Msg())
|
|
}
|
|
|
|
// Delete doc
|
|
// @Summary 删除用户优惠券
|
|
// @Description 删除用户优惠券
|
|
// @Tags
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param type query integer true "优惠券类型"
|
|
// @Param pageNumber query integer true "查询页码"
|
|
// @Param pageSize query integer true "页码大小"
|
|
// @Success 200 {object} coupon_record_mod.QueryAllRes
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/app/coupon [delete]
|
|
func Delete(ctx *gin.Context) {
|
|
uid, err := common.GetUID(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
|
return
|
|
}
|
|
var req prize_record_mod.AppDeleteReq
|
|
if err = ctx.ShouldBind(&req); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
|
|
if err = couponser.Delete(uid, &req); err != nil {
|
|
log.Error(fmt.Sprintf("App couponser Upload err:%v", err))
|
|
common.ServeJSON(ctx, stderr.Failure, nil)
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, nil)
|
|
}
|