|
|
@@ -2,15 +2,41 @@ package router
|
|
|
|
|
|
import (
|
|
|
"ARKItems/entity"
|
|
|
+ "ARKItems/entity/ark"
|
|
|
"ARKItems/util"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "github.com/spf13/cast"
|
|
|
+ "net/http"
|
|
|
)
|
|
|
|
|
|
func ARKConfigRouter(api *gin.RouterGroup) {
|
|
|
api.GET("/messages", GetMessages)
|
|
|
+
|
|
|
api.GET("/timedPointsReward", GetTimedPointsReward)
|
|
|
+
|
|
|
api.POST("/timedPointsReward/group", SaveGroup)
|
|
|
+ api.PUT("/timedPointsReward/group", UpdateGroup)
|
|
|
+ api.DELETE("/timedPointsReward/group", DeleteGroup)
|
|
|
+
|
|
|
+ api.GET("/general", GetGeneral)
|
|
|
+ api.PUT("/general", UpdateGeneral)
|
|
|
+
|
|
|
+ api.GET("/kit", GetKits)
|
|
|
+ api.POST("/kit", SaveKit)
|
|
|
+ api.PUT("/kit", UpdateKit)
|
|
|
+ api.DELETE("/kit", DeleteKit)
|
|
|
+
|
|
|
+ api.GET("/shopItem", GetShopItem)
|
|
|
+ api.POST("/shopItem", SaveShopItem)
|
|
|
+ api.PUT("/shopItem", UpdateShopItem)
|
|
|
+ api.DELETE("/shopItem", DeleteShopItem)
|
|
|
+
|
|
|
+ api.GET("/sellItem", GetSellItem)
|
|
|
+ api.POST("/sellItem", SaveSellItem)
|
|
|
+ api.PUT("/sellItem", UpdateSellItem)
|
|
|
+ api.DELETE("/sellItem", DeleteSellItem)
|
|
|
}
|
|
|
|
|
|
func GetMessages(c *gin.Context) {
|
|
|
@@ -19,6 +45,61 @@ func GetMessages(c *gin.Context) {
|
|
|
func GetTimedPointsReward(c *gin.Context) {
|
|
|
c.JSON(200, CreateResultData(ARKConfig.General.TimedPointsReward))
|
|
|
}
|
|
|
+func GetGeneral(c *gin.Context) {
|
|
|
+ marshal, err := json.Marshal(ARKConfig.General)
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m := make(map[string]interface{})
|
|
|
+ json.Unmarshal(marshal, &m)
|
|
|
+ delete(m, "Groups")
|
|
|
+ c.JSON(200, CreateResultData(m))
|
|
|
+}
|
|
|
+
|
|
|
+func UpdateGeneral(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("group")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var General = ark.General{}
|
|
|
+ err = util.DataToObject(g, &General)
|
|
|
+ if ARKConfig.General.UseOriginalTradeCommandWithUI != General.UseOriginalTradeCommandWithUI {
|
|
|
+ ARKConfig.General.UseOriginalTradeCommandWithUI = General.UseOriginalTradeCommandWithUI
|
|
|
+ }
|
|
|
+ if ARKConfig.General.CryoLimitedTime != General.CryoLimitedTime {
|
|
|
+ ARKConfig.General.CryoLimitedTime = General.CryoLimitedTime
|
|
|
+ }
|
|
|
+ if ARKConfig.General.GiveDinosInCryopods != General.GiveDinosInCryopods {
|
|
|
+ ARKConfig.General.GiveDinosInCryopods = General.GiveDinosInCryopods
|
|
|
+ }
|
|
|
+ if ARKConfig.General.UseSoulTraps != General.UseSoulTraps {
|
|
|
+ ARKConfig.General.UseSoulTraps = General.UseSoulTraps
|
|
|
+ }
|
|
|
+ if ARKConfig.General.ItemsPerPage != General.ItemsPerPage {
|
|
|
+ ARKConfig.General.ItemsPerPage = General.ItemsPerPage
|
|
|
+ }
|
|
|
+ if ARKConfig.General.ShopDisplayTime != General.ShopDisplayTime {
|
|
|
+ ARKConfig.General.ShopDisplayTime = General.ShopDisplayTime
|
|
|
+ }
|
|
|
+ if ARKConfig.General.ShopTextSize != General.ShopTextSize {
|
|
|
+ ARKConfig.General.ShopTextSize = General.ShopTextSize
|
|
|
+ }
|
|
|
+ if ARKConfig.General.DefaultKit != General.DefaultKit {
|
|
|
+ ARKConfig.General.DefaultKit = General.DefaultKit
|
|
|
+ }
|
|
|
+ if ARKConfig.General.ShopDisplayTime != General.ShopDisplayTime {
|
|
|
+ ARKConfig.General.ShopDisplayTime = General.ShopDisplayTime
|
|
|
+ }
|
|
|
+ if ARKConfig.General.DbPathOverride != General.DbPathOverride {
|
|
|
+ ARKConfig.General.DbPathOverride = General.DbPathOverride
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+}
|
|
|
+
|
|
|
+//-----------------组修改----------------------
|
|
|
|
|
|
// SaveGroup 添加VIP
|
|
|
func SaveGroup(c *gin.Context) {
|
|
|
@@ -31,10 +112,267 @@ func SaveGroup(c *gin.Context) {
|
|
|
var Group = entity.Group{}
|
|
|
err = util.DataToObject(g, &Group)
|
|
|
fmt.Println(g, Group)
|
|
|
+ ARKConfig.General.TimedPointsReward.Groups[Group.Name] = ark.Group{Amount: Group.Amount}
|
|
|
c.JSON(200, CreateResult())
|
|
|
}
|
|
|
|
|
|
// UpdateGroup 修改VIP
|
|
|
func UpdateGroup(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("group")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var Group = entity.Group{}
|
|
|
+ err = util.DataToObject(g, &Group)
|
|
|
+ if Group.Name == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "VIP名称不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.General.TimedPointsReward.Groups[Group.Name]
|
|
|
+ if ok {
|
|
|
+ ARKConfig.General.TimedPointsReward.Groups[Group.Name] = ark.Group{Amount: Group.Amount}
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResultError(400, "VIP组名不存在"))
|
|
|
+}
|
|
|
+
|
|
|
+// DeleteGroup 修改VIP
|
|
|
+func DeleteGroup(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ name, err := param("groupName")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if cast.ToString(name) == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "VIP名称不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.General.TimedPointsReward.Groups[cast.ToString(name)]
|
|
|
+ if ok {
|
|
|
+ //删除一个元素
|
|
|
+ delete(ARKConfig.General.TimedPointsReward.Groups, cast.ToString(name))
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResultError(400, "VIP组名不存在"))
|
|
|
+}
|
|
|
+
|
|
|
+//==================礼包==========================
|
|
|
+
|
|
|
+func GetKits(c *gin.Context) {
|
|
|
+ c.JSON(200, CreateResultData(ARKConfig.Kits))
|
|
|
+}
|
|
|
+func SaveKit(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("kit")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var Kit = ark.Kit{}
|
|
|
+ err = util.DataToObject(g, &Kit)
|
|
|
+ if Kit.Description == "" || Kit.Price == 0 || Kit.DefaultAmount == 0 {
|
|
|
+ c.JSON(200, CreateResultError(400, "礼包描述不能为空,价格,数量不能为0"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ARKConfig.Kits[Kit.Description] = Kit
|
|
|
+}
|
|
|
+func UpdateKit(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("kit")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var Kit = ark.Kit{}
|
|
|
+ err = util.DataToObject(g, &Kit)
|
|
|
+ if Kit.Description == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "礼包描述不能为空"))
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.Kits[Kit.Description]
|
|
|
+ if ok {
|
|
|
+ if Kit.Price == 0 || Kit.DefaultAmount == 0 {
|
|
|
+ c.JSON(200, CreateResultError(400, "价格,数量不能为0"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ARKConfig.Kits[Kit.Description] = Kit
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResultError(400, "礼包不存在"))
|
|
|
+}
|
|
|
+func DeleteKit(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ name, err := param("kitName")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if cast.ToString(name) == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "礼包名称不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.Kits[cast.ToString(name)]
|
|
|
+ if ok {
|
|
|
+ //删除一个元素
|
|
|
+ delete(ARKConfig.Kits, cast.ToString(name))
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResultError(400, "礼包不存在"))
|
|
|
+}
|
|
|
|
|
|
+//====================商店==========================
|
|
|
+
|
|
|
+func GetShopItem(c *gin.Context) {
|
|
|
+ c.JSON(200, CreateResultData(ARKConfig.ShopItems))
|
|
|
+}
|
|
|
+
|
|
|
+func SaveShopItem(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("shopItem")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ShopItem = ark.ShopItem{}
|
|
|
+ err = util.DataToObject(g, &ShopItem)
|
|
|
+ if ShopItem.Description == "" || ShopItem.Price == 0 || ShopItem.Type == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "商店描述,价格,类型不能为空,为0"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.ShopItems[ShopItem.Description]
|
|
|
+ if ok {
|
|
|
+ c.JSON(200, CreateResultError(400, "商品名已存在"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ARKConfig.ShopItems[ShopItem.Description] = ShopItem
|
|
|
+}
|
|
|
+
|
|
|
+func UpdateShopItem(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("shopItem")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ShopItem = ark.ShopItem{}
|
|
|
+ err = util.DataToObject(g, &ShopItem)
|
|
|
+ if ShopItem.Description == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "商店名不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.ShopItems[ShopItem.Description]
|
|
|
+ if ok {
|
|
|
+ if ShopItem.Price == 0 || ShopItem.Type == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "价格,类型不能为空,为0"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ARKConfig.ShopItems[ShopItem.Description] = ShopItem
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResultError(400, "商品名不存在"))
|
|
|
+}
|
|
|
+
|
|
|
+func DeleteShopItem(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ name, err := param("shopItemName")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(200, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if cast.ToString(name) == "" {
|
|
|
+ c.JSON(200, CreateResultError(400, "商店名不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.ShopItems[cast.ToString(name)]
|
|
|
+ if ok {
|
|
|
+ //删除一个元素
|
|
|
+ delete(ARKConfig.ShopItems, cast.ToString(name))
|
|
|
+ c.JSON(200, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, CreateResultError(400, "商店名不存在"))
|
|
|
+}
|
|
|
+
|
|
|
+//========================回收==========================
|
|
|
+
|
|
|
+func GetSellItem(c *gin.Context) {
|
|
|
+ c.JSON(http.StatusOK, CreateResultData(ARKConfig.SellItems))
|
|
|
+}
|
|
|
+
|
|
|
+func SaveSellItem(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("sellItem")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var sellItem ark.SellItem
|
|
|
+ err = util.DataToObject(g, &sellItem)
|
|
|
+ if sellItem.Description == "" || sellItem.Price == 0 || sellItem.Type == "" {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "描述、价格、类型不能为空或为0"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.SellItems[sellItem.Description]
|
|
|
+ if ok {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "商品名已存在"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ARKConfig.SellItems[sellItem.Description] = sellItem
|
|
|
+ c.JSON(http.StatusOK, CreateResult())
|
|
|
+}
|
|
|
+
|
|
|
+func UpdateSellItem(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ g, err := param("sellItem")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var sellItem ark.SellItem
|
|
|
+ err = util.DataToObject(g, &sellItem)
|
|
|
+ if sellItem.Description == "" {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "商品描述不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.SellItems[sellItem.Description]
|
|
|
+ if ok {
|
|
|
+ if sellItem.Price == 0 || sellItem.Type == "" {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "价格、类型不能为空或为0"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ARKConfig.SellItems[sellItem.Description] = sellItem
|
|
|
+ c.JSON(http.StatusOK, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "商品名不存在"))
|
|
|
+}
|
|
|
+
|
|
|
+func DeleteSellItem(c *gin.Context) {
|
|
|
+ param := util.GetJsonAnyParam(c)
|
|
|
+ name, err := param("sellItemName")
|
|
|
+ if err != nil {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "参数错误"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if cast.ToString(name) == "" {
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "商品描述不能为空"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, ok := ARKConfig.SellItems[cast.ToString(name)]
|
|
|
+ if ok {
|
|
|
+ // 删除一个元素
|
|
|
+ delete(ARKConfig.SellItems, cast.ToString(name))
|
|
|
+ c.JSON(http.StatusOK, CreateResult())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(http.StatusBadRequest, CreateResultError(400, "商品名不存在"))
|
|
|
}
|