|
@@ -8,12 +8,46 @@ import (
|
|
|
"designs/global"
|
|
|
"designs/model"
|
|
|
"designs/utils"
|
|
|
+ "encoding/json"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+func InitGidConfig(c *gin.Context) {
|
|
|
+ gidKey := config.Get("app.gid") + "*"
|
|
|
+ keys, _ := global.App.Redis.Keys(context.Background(), gidKey).Result()
|
|
|
+ var gameData = []interface{}{}
|
|
|
+ for _, val := range keys {
|
|
|
+ res, _ := global.App.Redis.HGetAll(context.Background(), val).Result()
|
|
|
+ gameData = append(gameData, res)
|
|
|
+ }
|
|
|
+
|
|
|
+ now := model.XTime{
|
|
|
+ Time: time.Now(),
|
|
|
+ }
|
|
|
+ for _, v := range gameData {
|
|
|
+ var game model.Game
|
|
|
+ data, _ := json.Marshal(v)
|
|
|
+ json.Unmarshal(data, &game)
|
|
|
+
|
|
|
+ game.CreatedAt = now
|
|
|
+ game.UpdatedAt = now
|
|
|
+
|
|
|
+ err := global.App.DB.Table("game").Create(&game).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 111, "数据插入错误"+err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "res": "gid写入数据库完成",
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/* 添加游戏配置 */
|
|
|
//http://127.0.0.1:8787/v1/user/AddGidConfig
|
|
|
func AddGidConfig(c *gin.Context) {
|
|
@@ -26,6 +60,57 @@ func AddGidConfig(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ now := time.Now()
|
|
|
+
|
|
|
+ //更新数据库
|
|
|
+ var game model.Game
|
|
|
+ global.App.DB.Table("game").Where("gid", form.Gid).First(&game)
|
|
|
+
|
|
|
+ if game.Gid == "" {
|
|
|
+ //新增
|
|
|
+ gameNew := model.Game{
|
|
|
+ Gid: form.Gid,
|
|
|
+ Pid: form.Pid,
|
|
|
+ GameName: form.GameName,
|
|
|
+ WxAppid: form.WxAppid,
|
|
|
+ WxSecret: form.WxSecret,
|
|
|
+ TtAppid: form.TtAppid,
|
|
|
+ TtSecret: form.TtSecret,
|
|
|
+ TtTplId: form.TtTplId,
|
|
|
+ WxTplId: form.WxTplId,
|
|
|
+ CreatedAt: model.XTime{Time: now},
|
|
|
+ UpdatedAt: model.XTime{Time: now},
|
|
|
+ ConfigPath: form.ConfigPath,
|
|
|
+ }
|
|
|
+
|
|
|
+ err := global.App.DB.Table("game").Create(&gameNew).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //更新
|
|
|
+ err := global.App.DB.Table("game").Where("gid", form.Gid).Updates(&model.Game{
|
|
|
+ Gid: form.Gid,
|
|
|
+ Pid: form.Pid,
|
|
|
+ GameName: form.GameName,
|
|
|
+ WxAppid: form.WxAppid,
|
|
|
+ WxSecret: form.WxSecret,
|
|
|
+ TtAppid: form.TtAppid,
|
|
|
+ TtSecret: form.TtSecret,
|
|
|
+ TtTplId: form.TtTplId,
|
|
|
+ WxTplId: form.WxTplId,
|
|
|
+ ConfigPath: form.ConfigPath,
|
|
|
+ CreatedAt: model.XTime{Time: now},
|
|
|
+ UpdatedAt: model.XTime{Time: now},
|
|
|
+ }).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新redis
|
|
|
gameConfigData := make(map[string]interface{})
|
|
|
gameConfigData["gid"] = form.Gid
|
|
|
gameConfigData["gameName"] = form.GameName
|
|
@@ -35,6 +120,7 @@ func AddGidConfig(c *gin.Context) {
|
|
|
gameConfigData["ttSecret"] = form.TtSecret
|
|
|
gameConfigData["ttTplId"] = form.TtTplId
|
|
|
gameConfigData["wxTplId"] = form.WxTplId
|
|
|
+ gameConfigData["configPath"] = form.ConfigPath
|
|
|
gidKey := config.Get("app.gid") + form.Gid
|
|
|
err := global.App.Redis.HMSet(context.Background(), gidKey, gameConfigData).Err()
|
|
|
if err != nil {
|
|
@@ -49,22 +135,48 @@ func AddGidConfig(c *gin.Context) {
|
|
|
|
|
|
/* 获取配置 */
|
|
|
func GetGidConfig(c *gin.Context) {
|
|
|
- var data GetGameCfg
|
|
|
- form := request.Check(c, &data)
|
|
|
- if form.AppSecret != config.Get("app.app_secret") {
|
|
|
- response.Fail(c, 1003, "密钥不对")
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Offset int `form:"offset" binding:"" json:"offset"`
|
|
|
+ Limit int `form:"limit" binding:"" json:"limit"`
|
|
|
+ Search string `form:"search" binding:"" json:"search"`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ var gameList []model.Game
|
|
|
+ var count int64
|
|
|
+ query := global.App.DB.Table("game")
|
|
|
+
|
|
|
+ if form.Search != "" {
|
|
|
+ query = query.Where("gid", "like", "%"+form.Search+"%").
|
|
|
+ Or("pid LIKE ?", "%"+form.Search+"%").
|
|
|
+ Or("gameName LIKE ?", "%"+form.Search+"%")
|
|
|
}
|
|
|
|
|
|
- gidKey := config.Get("app.gid") + "*"
|
|
|
- keys, _ := global.App.Redis.Keys(context.Background(), gidKey).Result()
|
|
|
- var gameData = []interface{}{}
|
|
|
- for _, val := range keys {
|
|
|
- res, _ := global.App.Redis.HGetAll(context.Background(), val).Result()
|
|
|
- gameData = append(gameData, res)
|
|
|
+ err := query.Count(&count).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
+ if form.Limit != 0 {
|
|
|
+ query = query.Limit(form.Limit)
|
|
|
+ }
|
|
|
+ err = query.Offset(form.Offset).Scan(&gameList).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1002, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //gidKey := config.Get("app.gid") + "*"
|
|
|
+ //keys, _ := global.App.Redis.Keys(context.Background(), gidKey).Result()
|
|
|
+ //var gameData = []interface{}{}
|
|
|
+ //for _, val := range keys {
|
|
|
+ // res, _ := global.App.Redis.HGetAll(context.Background(), val).Result()
|
|
|
+ // gameData = append(gameData, res)
|
|
|
+ //}
|
|
|
+
|
|
|
response.Success(c, gin.H{
|
|
|
- "data": gameData,
|
|
|
+ "data": gameList,
|
|
|
+ "count": count,
|
|
|
})
|
|
|
}
|
|
|
|