@@ -0,0 +1,108 @@
|
||||
package paymentguidectrl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/l/operatorlgmod"
|
||||
"91porn-server/models/v/paymentguidemod"
|
||||
"91porn-server/web/service/paymentguideser"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func List(ctx *gin.Context) {
|
||||
req := paymentguideser.ListReq{}
|
||||
if err := ctx.ShouldBindQuery(&req); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
resp, err := req.List()
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, resp)
|
||||
}
|
||||
|
||||
func Add(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
req := paymentguideser.AddReq{}
|
||||
if err = ctx.ShouldBindJSON(&req); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if req.IsBatch() {
|
||||
if req.Config == nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "config is required")
|
||||
return
|
||||
}
|
||||
configs, batchErr := (paymentguideser.BatchAddReq{Scenes: req.Scenes, Config: *req.Config}).Configs()
|
||||
if batchErr != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, batchErr.Error())
|
||||
return
|
||||
}
|
||||
resp, batchErr := paymentguideser.BatchAdd(ctx.Request.Context(), configs)
|
||||
if batchErr != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbInsertManyError, batchErr.Error())
|
||||
return
|
||||
}
|
||||
body, _ := json.Marshal(configs)
|
||||
_ = operatorlgmod.RecordOperation(manager, "付费引导配置", "批量创建", string(body), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, resp)
|
||||
return
|
||||
}
|
||||
config := req.PaymentGuide
|
||||
if err = paymentguideser.Add(&config); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := json.Marshal(config)
|
||||
_ = operatorlgmod.RecordOperation(manager, "付费引导配置", "创建", string(body), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, config.ID)
|
||||
}
|
||||
|
||||
func Edit(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
config := paymentguidemod.PaymentGuide{}
|
||||
if err = ctx.ShouldBindJSON(&config); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if err = paymentguideser.Edit(&config); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
|
||||
return
|
||||
}
|
||||
body, _ := json.Marshal(config)
|
||||
_ = operatorlgmod.RecordOperation(manager, "付费引导配置", "修改", string(body), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
|
||||
func Delete(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
id, err := primitive.ObjectIDFromHex(ctx.Query("id"))
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "invalid id")
|
||||
return
|
||||
}
|
||||
if err = paymentguideser.Delete(id); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
|
||||
return
|
||||
}
|
||||
_ = operatorlgmod.RecordOperation(manager, "付费引导配置", "删除", id.Hex(), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
Reference in New Issue
Block a user