168 lines
5.3 KiB
Go
168 lines
5.3 KiB
Go
package rechargectrl
|
|
|
|
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/rchgamtmod"
|
|
"91porn-server/web/vidhelp"
|
|
"91porn-server/web/webg"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// GetGoldList 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/gold/list [get]
|
|
func GetGoldList(ctx *gin.Context) {
|
|
infos, err := rchgamtmod.GetGoldList()
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
|
|
return
|
|
}
|
|
common.ServeJSON(ctx, stderr.Success, infos)
|
|
}
|
|
|
|
// GoldInsert doc
|
|
// @Summary 新增
|
|
// @Description 新增
|
|
// @Tags recharge
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param reachargeDetails formData rchgamtmod.GoldReq true "product卡"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /api/web/recharge/gold/add [post]
|
|
func GoldInsert(ctx *gin.Context) {
|
|
manager, err := common.GetAdminAct(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
req := rchgamtmod.GoldReq{}
|
|
if err = ctx.ShouldBind(&req); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
gd := rchgamtmod.Gold{
|
|
Name: req.Name,
|
|
Coins: req.Coins,
|
|
Price: req.Price,
|
|
Active: req.Active,
|
|
UpdatedAt: time.Now(),
|
|
CreatedAt: time.Now(),
|
|
}
|
|
if err = rchgamtmod.InsertGold(&gd); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
|
|
return
|
|
}
|
|
redisKey := redisconst.DataCachKey(rchgamtmod.RedisKey, "GetPayChannel")
|
|
_, _ = webg.Redis.Del(redisKey)
|
|
log, _ := json.Marshal(req)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.ProductManageCoin, constant.Add, string(log), ctx.Request.URL.RequestURI())
|
|
common.ServeJSON(ctx, stderr.Success, nil)
|
|
}
|
|
|
|
// GoldUpdate 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/gold/update [post]
|
|
func GoldUpdate(ctx *gin.Context) {
|
|
manager, err := common.GetAdminAct(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
req := rchgamtmod.EditGoldReq{}
|
|
if err = ctx.ShouldBind(&req); err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
|
return
|
|
}
|
|
oid, err := primitive.ObjectIDFromHex(req.ID)
|
|
if err != nil {
|
|
log.Warn(fmt.Sprintf("exchange string(%s) to objectID error.", req.ID))
|
|
return
|
|
}
|
|
req.UpdatedAt = time.Now()
|
|
m := vidhelp.Struct2Map(req.GoldReq)
|
|
cond := bson.M{"_id": oid}
|
|
updt := bson.M(m)
|
|
cnt, err := rchgamtmod.UpdateGold(cond, updt)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
|
|
return
|
|
}
|
|
redisKey := redisconst.DataCachKey(rchgamtmod.RedisKey, "GetPayChannel")
|
|
_, _ = webg.Redis.Del(redisKey)
|
|
log, _ := json.Marshal(req)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.ProductManageCoin, constant.Modify, string(log), ctx.Request.URL.RequestURI())
|
|
common.ServeJSON(ctx, stderr.Success, rchgamtmod.OpeResp{Count: cnt})
|
|
}
|
|
|
|
// GoldDelete 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/gold/delete [delete]
|
|
func GoldDelete(ctx *gin.Context) {
|
|
manager, err := common.GetAdminAct(ctx)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
req := rchgamtmod.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.Warn(fmt.Sprintf("exchange string(%s) to objectID error.", id))
|
|
continue
|
|
}
|
|
oids = append(oids, oid)
|
|
}
|
|
if oids == nil {
|
|
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
|
return
|
|
}
|
|
cond := bson.M{"_id": bson.M{"$in": oids}}
|
|
cnt, err := rchgamtmod.DeleteGold(cond)
|
|
if err != nil {
|
|
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
|
|
return
|
|
}
|
|
redisKey := redisconst.DataCachKey(rchgamtmod.RedisKey, "GetPayChannel")
|
|
_, _ = webg.Redis.Del(redisKey)
|
|
log, _ := json.Marshal(req)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.ProductManageCoin, constant.Delete, string(log), ctx.Request.URL.RequestURI())
|
|
common.ServeJSON(ctx, stderr.Success, rchgamtmod.OpeResp{Count: cnt})
|
|
}
|