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

199 lines
6.3 KiB
Go

package withdrawctrl
import (
"encoding/json"
"fmt"
"time"
"91porn-server/common"
"91porn-server/common/constant"
"91porn-server/common/constant/redisconst"
"91porn-server/common/log"
"91porn-server/common/stderr"
"91porn-server/models/l/operatorlgmod"
"91porn-server/models/v/wdchannmod"
"91porn-server/models/v/wdtaxmod"
"91porn-server/web/service/withdrawser"
"91porn-server/web/webg"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// GetChannel doc
// @Summary 获取提现渠道
// @Description 获取提现渠道
// @Tags withdraw
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/withdraw/channel/list [get]
func GetChannel(ctx *gin.Context) {
infos, err := withdrawser.WithdrawType()
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
return
}
common.ServeJSON(ctx, stderr.Success, infos)
}
// ChannelInsert doc
// @Summary 新增
// @Description 新增
// @Tags withdraw
// @Accept mpfd,json
// @Produce json,html
// @Param reachargeDetails formData wdchannmod.ChannelReq ture "product卡"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/withdraw/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 := wdchannmod.ChannelReq{}
if err = ctx.ShouldBind(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
pc := wdchannmod.WithdrawChannel{
ChannelName: req.ChannelName,
CID: req.CID,
PayType: req.PayType,
MinMoney: req.MinMoney,
QpMinMoney: req.QpMinMoney,
MaxMoney: req.MaxMoney,
Weight: req.Weight,
UpdatedAt: time.Now(),
CreatedAt: time.Now(),
}
if err = wdchannmod.InsertWithdrawChannel(&pc); err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
return
}
common.Go(func() {
_, _ = webg.Redis.Del(redisconst.WithdrawCfgCacheKey())
})
log, _ := json.Marshal(req)
_ = operatorlgmod.RecordOperation(manager, constant.TradeManageWithdrawType, constant.Add, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, nil)
}
// ChannelUpdate doc
// @Summary 编辑提现渠道
// @Description 编辑提现渠道
// @Tags withdraw
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/withdraw/channel/update [post]
func ChannelUpdate(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
var arg struct {
ID string `json:"id"`
wdchannmod.WithdrawChannelSelector
}
if err = ctx.ShouldBind(&arg); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
cnt, err := wdchannmod.UpdateWithdrawChannel(arg.ID, &arg.WithdrawChannelSelector)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
return
}
common.Go(func() {
_, _ = webg.Redis.Del(redisconst.WithdrawCfgCacheKey())
})
log, _ := json.Marshal(arg)
_ = operatorlgmod.RecordOperation(manager, constant.TradeManageWithdrawType, constant.Modify, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, wdchannmod.OpeResp{Count: cnt})
}
// ChannelDelete doc
// @Summary 删除
// @Description 删除
// @Tags withdraw
// @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/withdraw/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 := wdchannmod.DelReq{}
if err = ctx.ShouldBind(&req); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
oids := make([]primitive.ObjectID, 0, len(req.IDs))
for _, id := range req.IDs {
oid, err := primitive.ObjectIDFromHex(id)
if err != nil {
log.Error(fmt.Sprintf("exchange string(%s) to objectID error.", id))
continue
}
oids = append(oids, oid)
}
cond := bson.M{"_id": bson.M{"$in": oids}}
cnt, err := wdchannmod.DeleteWithdrawChannel(cond)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
return
}
common.Go(func() {
_, _ = webg.Redis.Del(redisconst.WithdrawCfgCacheKey())
})
log, _ := json.Marshal(req)
_ = operatorlgmod.RecordOperation(manager, constant.TradeManageWithdrawType, constant.Delete, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, wdchannmod.OpeResp{Count: cnt})
}
// ChannelBatch doc
// @Summary 编辑提现税率
// @Description 编辑提现税率
// @Tags withdraw
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /api/web/withdraw/channel/batch [post]
func ChannelBatch(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
set := wdtaxmod.WithdrawTariffSelector{}
if err = ctx.ShouldBind(&set); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
cnt, err := wdtaxmod.UpdateWithDrawTariff(set)
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
return
}
common.Go(func() {
_, _ = webg.Redis.Del(redisconst.WithdrawTariffCacheKey())
})
log, _ := json.Marshal(set)
_ = operatorlgmod.RecordOperation(manager, constant.TradeManageWithdrawType, constant.Modify, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, wdchannmod.OpeResp{Count: cnt})
}