Files
huangguo_server/web/api/goldcfgctrl/goldcfg.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

164 lines
5.9 KiB
Go

package goldcfgctrl
import (
"encoding/json"
"fmt"
"strings"
"91porn-server/common"
"91porn-server/common/constant"
"91porn-server/common/stderr"
"91porn-server/models/l/operatorlgmod"
"91porn-server/models/v/goldcfgmod"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 支付优惠配置 doc
// @Summary 支付优惠配置新增
// @Description 支付优惠新增
// @Tags 支付-配置
// @Accept mpfd,json
// @Produce json,html
// @Param amount formData integer true "基础货币额度"
// @Param incrAmount formData integer false "增加的优惠额度 incrAmount与incTax 不可同时为空"
// @Param incTax formData number false "按比率增加额外优惠额"
// @Param type formData string true "充值方式"
// @Param typeName formData string true "类型名称:支付宝,微信,代充"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /gold/cfg/add [post]
func Add(c *gin.Context) {
manager, err := common.GetAdminAct(c)
if err != nil {
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
return
}
incr := goldcfgmod.Incr{}
if err := c.ShouldBind(&incr); err != nil {
common.ServeJSON(c, stderr.ErrParamError, err)
return
}
if incr.IncTax > 1 || incr.IncTax < 0 {
common.ServeJSON(c, stderr.ErrParamError, err)
return
}
if err = goldcfgmod.InsertOne(&incr); err != nil {
common.ServeJSON(c, stderr.ErrDbInsertError, err)
return
}
log, _ := json.Marshal(&incr)
_ = operatorlgmod.RecordOperation(manager, constant.GoldConfig, constant.Add, string(log), c.Request.URL.RequestURI())
common.ServeJSON(c, stderr.Success, nil)
}
// 支付优惠配置 doc
// @Summary 支付优惠配置
// @Description 支付优惠编辑
// @Tags 支付-配置
// @Accept mpfd,json
// @Produce json,html
// @Param id formData string true "id"
// @Param amount formData integer false "基础货币额度"
// @Param incrAmount formData integer false "增加的优惠额度"
// @Param incTax formData number false "按比率增加额外优惠额"
// @Param type formData string false "充值方式"
// @Param typeName formData string false "类型名称:支付宝,微信,代充"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /gold/cfg/edit [post]
func Edit(c *gin.Context) {
manager, err := common.GetAdminAct(c)
if err != nil {
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
return
}
var arg struct {
ID primitive.ObjectID `json:"id" bson:"id" binding:"required"` //基础货币额度
goldcfgmod.EditDoc
}
if err := c.ShouldBind(&arg); err != nil {
common.ServeJSON(c, stderr.ErrParamError, err)
return
}
if arg.IncTax != nil {
if *arg.IncTax > 1 || *arg.IncTax < 0 {
common.ServeJSON(c, stderr.ErrParamError, err)
return
}
}
if _, err = goldcfgmod.Update(arg.ID, arg.EditDoc); err != nil {
//判断是否有重复插入
if strings.Contains(err.Error(), "E11000 duplicate key error") {
common.ServeJSON(c, stderr.ErrDbUpdateError, err)
return
}
common.ServeJSON(c, stderr.Failure, fmt.Errorf("goldcfgmod updateOne error: %+v", err))
return
}
log, _ := json.Marshal(&arg)
_ = operatorlgmod.RecordOperation(manager, constant.GoldConfig, constant.Modify, string(log), c.Request.URL.RequestURI())
common.ServeJSON(c, stderr.Success, nil)
}
// 支付优惠配置 doc
// @Summary 支付优惠配置列表
// @Description 支付优惠列表
// @Tags 支付-配置
// @Accept mpfd,json
// @Produce json,html
// @Param amount formData integer true "基础货币额度"
// @Param type formData string true "充值方式"
// @Param typeName formData string true "类型名称:支付宝,微信,代充"
// @Param pageNumber query integer true "当前页" mininum(1)
// @Param pageSize query integer true "每页条数" mininum(1)
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /gold/cfg/list [get]
func List(ctx *gin.Context) {
param := goldcfgmod.ListParam{}
if err := ctx.ShouldBind(&param); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, "web gold config list arg error "+err.Error())
return
}
result, err := goldcfgmod.List(param)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
return
}
common.ServeJSON(ctx, stderr.Success, result)
}
// 支付优惠配置 doc
// @Summary 支付优惠配置删除
// @Description 支付删除
// @Tags 支付-配置
// @Accept mpfd,json
// @Produce json,html
// @Param ids formData array true "ID数组"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /gold/cfg/del [delete]
func Del(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
var param struct {
IDs []primitive.ObjectID `form:"ids" json:"ids" binding:"required"`
}
if err = ctx.ShouldBind(&param); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
if _, err = goldcfgmod.Delete(param.IDs); err != nil {
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
return
}
log, _ := json.Marshal(&param)
_ = operatorlgmod.RecordOperation(manager, constant.GoldConfig, constant.Delete, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, nil)
}