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/rchgamegoldmod" "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" ) // GetGameGoldList 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/gameGold/list [get] func GetGameGoldList(ctx *gin.Context) { infos, err := rchgamegoldmod.GetGoldList() if err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } common.ServeJSON(ctx, stderr.Success, infos) } // GameGoldInsert doc // @Summary 新增 // @Description 新增 // @Tags recharge // @Accept mpfd,json // @Produce json,html // @Param reachargeDetails formData rchgamegoldmod.GoldReq true "product卡" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /api/web/recharge/gameGold/add [post] func GameGoldInsert(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } req := rchgamegoldmod.GoldReq{} if err := ctx.ShouldBind(&req); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if req.Coins*100 != req.Price { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } gd := rchgamegoldmod.Gold{ Name: req.Name, Coins: req.Coins, Price: req.Price, CouponDesc: req.CouponDesc, GiveVipDays: req.GiveVipDays, LouFengUnlockTimes: req.LouFengUnlockTimes, GiveGameCoin: req.GiveGameCoin, NotFirst: req.NotFirst, Active: req.Active, UpdatedAt: time.Now(), CreatedAt: time.Now(), } if err := rchgamegoldmod.InsertGold(&gd); err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } redisKey := redisconst.DataCachKey(rchgamegoldmod.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) } // GameGoldUpdate 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/gameGold/update [post] func GameGoldUpdate(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } req := rchgamegoldmod.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 := rchgamegoldmod.UpdateGold(cond, updt) if err != nil { common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error()) return } redisKey := redisconst.DataCachKey(rchgamegoldmod.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, rchgamegoldmod.OpeResp{Count: cnt}) } // GameGoldDelete 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/gameGold/delete [delete] func GameGoldDelete(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } req := rchgamegoldmod.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 := rchgamegoldmod.DeleteGold(cond) if err != nil { common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error()) return } redisKey := redisconst.DataCachKey(rchgamegoldmod.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, rchgamegoldmod.OpeResp{Count: cnt}) }