|
|
@@ -71,18 +71,17 @@ func AddGidConfig(c *gin.Context) {
|
|
|
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,
|
|
|
+ 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},
|
|
|
}
|
|
|
|
|
|
err := global.App.DB.Table("game").Create(&gameNew).Error
|
|
|
@@ -93,18 +92,17 @@ func AddGidConfig(c *gin.Context) {
|
|
|
} 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},
|
|
|
+ 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},
|
|
|
}).Error
|
|
|
if err != nil {
|
|
|
response.Fail(c, 1001, err.Error())
|
|
|
@@ -122,7 +120,6 @@ 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 {
|
|
|
@@ -135,6 +132,177 @@ func AddGidConfig(c *gin.Context) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+// 新增游戏gid
|
|
|
+func AddPid(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Pid string `form:"pid" json:"pid" binding:"required"`
|
|
|
+ PidName string `form:"pidName" json:"pidName" binding:"required"`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ //查重
|
|
|
+ var gid model.Game
|
|
|
+ global.App.DB.Table("game_pid").
|
|
|
+ Where("pid", form.Pid).
|
|
|
+ Or("pidName = ? ", form.PidName).
|
|
|
+ First(&gid)
|
|
|
+
|
|
|
+ if gid.Gid != "" {
|
|
|
+ response.Fail(c, 1001, "gid 已存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err := global.App.DB.Table("game_pid").Create(&model.GamePid{
|
|
|
+ Pid: form.Pid,
|
|
|
+ PidName: form.PidName,
|
|
|
+ }).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, "创建pid失败"+err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{})
|
|
|
+}
|
|
|
+
|
|
|
+func DelPid(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Pid string `form:"pid" json:"pid" binding:"required"`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ //有没有在使用
|
|
|
+ var count int64
|
|
|
+ global.App.DB.Table("game").Where("pid", form.Pid).Count(&count)
|
|
|
+
|
|
|
+ if count > 0 {
|
|
|
+ response.Fail(c, 1001, "gid已经使用,无法删除")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err := global.App.DB.Table("game_pid").Where("pid", form.Pid).Delete(&model.GamePid{}).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, "删除失败"+err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{})
|
|
|
+}
|
|
|
+
|
|
|
+func PidList(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Search string `form:"search" json:"search" binding:""`
|
|
|
+ Offset int `form:"offset" json:"offset" binding:""`
|
|
|
+ Limit int `form:"limit" json:"limit" binding:""`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ query := global.App.DB.Table("game_pid")
|
|
|
+ if form.Search != "" {
|
|
|
+ query = query.Where("pid", "like", "%"+form.Search+"%").
|
|
|
+ Or("pidName LIKE ?", "%"+form.Search+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ var count int64
|
|
|
+ var res []model.GamePid
|
|
|
+
|
|
|
+ err := query.Count(&count).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, "查询总数失败"+err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ err = query.Offset(form.Offset).Limit(form.Limit).Scan(&res).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1002, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": res,
|
|
|
+ "count": count,
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func PidToGidList(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Search string `form:"search" binding:""`
|
|
|
+ Active bool `form:"active" binding:"" `
|
|
|
+ }{})
|
|
|
+
|
|
|
+ type game struct {
|
|
|
+ Id int `json:"id" gorm:"primary_key"`
|
|
|
+ Pid string `json:"pid" gorm:"column:pid; "`
|
|
|
+ Gid string `json:"gid" gorm:"column:gid; "`
|
|
|
+ GameName string `json:"gameName" gorm:"column:gameName; "`
|
|
|
+ PidName string `json:"pidName" gorm:"column:pidName; "`
|
|
|
+ }
|
|
|
+
|
|
|
+ var gameList []game
|
|
|
+ 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+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证gid权限
|
|
|
+ permission := c.GetString("permission")
|
|
|
+ var PermissionSlice []string
|
|
|
+ json.Unmarshal([]byte(permission), &PermissionSlice)
|
|
|
+
|
|
|
+ if !utils.InArray("all", PermissionSlice) {
|
|
|
+ fmt.Println(PermissionSlice)
|
|
|
+ //需要验证gid权限
|
|
|
+ query = query.WhereIn("gid", PermissionSlice)
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.Active == true {
|
|
|
+ //获取近七天有数据的gid
|
|
|
+ ActiveGid := service.GetActiveGid()
|
|
|
+ query = query.WhereIn("gid", ActiveGid)
|
|
|
+ }
|
|
|
+
|
|
|
+ err := query.
|
|
|
+ LeftJoin("game_pid", "game_pid.pid = game.pid").
|
|
|
+ Select("game.id", "game.gid", "game.gameName", "game.pid", "pidName").Where("id", ">", 0).Scan(&gameList).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1002, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ type res struct {
|
|
|
+ PidName string `json:"pidName" gorm:"column:pidName; "`
|
|
|
+ Pid string `json:"pid" gorm:"column:pid; "`
|
|
|
+ GidList []game `json:"gidList" gorm:"-"`
|
|
|
+ }
|
|
|
+
|
|
|
+ var Res []res
|
|
|
+
|
|
|
+ var pidList []string
|
|
|
+
|
|
|
+ for _, game := range gameList {
|
|
|
+ if !utils.InArray(game.Pid, pidList) {
|
|
|
+ pidList = append(pidList, game.Pid)
|
|
|
+
|
|
|
+ Res = append(Res, res{
|
|
|
+ PidName: game.PidName,
|
|
|
+ Pid: game.Pid,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, game1 := range gameList {
|
|
|
+ for k, value := range Res {
|
|
|
+ if value.Pid == game1.Pid {
|
|
|
+ Res[k].GidList = append(Res[k].GidList, game1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": Res,
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/* 获取配置 */
|
|
|
func GetGidConfig(c *gin.Context) {
|
|
|
form := request.Check(c, &struct {
|