Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

140 lines
4.4 KiB
Go

package rechargectrl
import (
"encoding/json"
"time"
"91porn-server/common"
"91porn-server/common/constant"
"91porn-server/common/stderr"
"91porn-server/models/l/operatorlgmod"
"91porn-server/models/v/rchgchanmod"
"github.com/gin-gonic/gin"
)
// GetChannel doc
// @Summary 获取支付渠道
// @Description 获取支付渠道
// @Tags recharge
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/recharge/channel/list [get]
func GetChannel(ctx *gin.Context) {
infos, err := rchgchanmod.GetPayChannels()
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
return
}
common.ServeJSON(ctx, stderr.Success, infos)
}
// ChannelInsert doc
// @Summary 新增
// @Description 新增
// @Tags recharge
// @Accept mpfd,json
// @Produce json,html
// @Param reachargeDetails formData rchgchanmod.ChannelReq ture "product卡"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/recharge/channel/add [post]
func ChannelInsert(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
req := rchgchanmod.ChannelReq{}
if err := ctx.ShouldBind(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
pc := rchgchanmod.PayChannel{
ChannelName: req.ChannelName,
CID: req.CID,
PayType: req.PayType,
MinMoney: req.MinMoney,
MaxMoney: req.MaxMoney,
Weight: req.Weight,
Active: req.Active,
Rate: req.Rate,
Category: req.Category,
ActivePeriod: req.ActivePeriod,
AmountTypes: req.AmountTypes,
UpdatedAt: time.Now(),
CreatedAt: time.Now(),
}
if err := rchgchanmod.InsertPayChannel(&pc); err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
return
}
log, _ := json.Marshal(req)
_ = operatorlgmod.RecordOperation(manager, constant.ProductManagePayType, constant.Add, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, nil)
}
// ChannelUpdate doc
// @Summary 编辑充值渠道
// @Description 编辑充值渠道
// @Tags recharge
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/recharge/channel/update [post]
func ChannelUpdate(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
req := rchgchanmod.EditReq{}
if err = ctx.ShouldBind(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
cnt, err := rchgchanmod.UpdatePayChannel(req.ID, req.EditInfo)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
return
}
log, _ := json.Marshal(req)
_ = operatorlgmod.RecordOperation(manager, constant.ProductManagePayType, constant.Modify, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, rchgchanmod.OpeResp{Count: cnt})
}
// ChannelDelete doc
// @Summary 删除
// @Description 删除
// @Tags recharge
// @Accept mpfd,json
// @Produce json,html
// @Param id formData int true "product等级""
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/recharge/channel/delete [delete]
func ChannelDelete(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
req := rchgchanmod.DelReq{}
if err = ctx.ShouldBind(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
cnt, err := rchgchanmod.DeletePayChannel(req.IDs)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
return
}
log, _ := json.Marshal(req)
_ = operatorlgmod.RecordOperation(manager, constant.ProductManagePayType, constant.Delete, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, rchgchanmod.OpeResp{Count: cnt})
}