diff --git a/server/adminserver/api/v1/system/gameswitch.go b/server/adminserver/api/v1/system/gameswitch.go index c35b1794..877b19c6 100644 --- a/server/adminserver/api/v1/system/gameswitch.go +++ b/server/adminserver/api/v1/system/gameswitch.go @@ -1,6 +1,7 @@ package system import ( + "encoding/json" "f5" "fmt" "main/constant" @@ -54,7 +55,8 @@ func (this *GameSwitchApi) List(c *gin.Context) { page := c.DefaultQuery("page", "") result := []struct { system.GameSwitch - Remark string `json:"remark"` + Servers []int32 `json:"serverList"` + Remark string `json:"remark"` }{} f5.GetGoStyleDb().PageQuery( constant.CONF_DB, @@ -82,6 +84,8 @@ func (this *GameSwitchApi) List(c *gin.Context) { if exist { p.Remark = desc } + p.Servers = make([]int32, 0) + json.Unmarshal([]byte(pg.Rows.GetByName("server_list")), &p.Servers) p.AuditOpen = q5.SafeToInt32(pg.Rows.GetByName("audit_is_open")) p.CreateTime = q5.SafeToInt32(pg.Rows.GetByName("createtime")) p.ModifyTime = q5.SafeToInt32(pg.Rows.GetByName("modifytime")) @@ -139,10 +143,11 @@ func (this *GameSwitchApi) Add(c *gin.Context) { func (this *GameSwitchApi) Edit(c *gin.Context) { req := struct { - Name string `binding:"required" json:"switch_name"` - Open *int32 `binding:"required" json:"is_open"` - AuditOpen *int32 `binding:"required" json:"audit_is_open"` - Remark string `json:"remark"` + Name string `binding:"required" json:"switch_name"` + Open *int32 `binding:"required" json:"is_open"` + Servers []int32 `json:"serverList"` + AuditOpen *int32 `binding:"required" json:"audit_is_open"` + Remark string `json:"remark"` }{} if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -151,7 +156,10 @@ func (this *GameSwitchApi) Edit(c *gin.Context) { }) return } - gswitch := new(system.GameSwitch) + gswitch := new(struct { + system.GameSwitch + Servers string `gorm:"column:server_list" json:"serverList"` + }) db := f5.GetApp().GetOrmDb(constant.CONF_DB) if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil { if !f5.IsOrmErrRecordNotFound(err) { @@ -171,6 +179,8 @@ func (this *GameSwitchApi) Edit(c *gin.Context) { nowDaySeconds := int32(f5.GetApp().GetRealSeconds()) gswitch.Opened = *req.Open + serverbytes,_ := json.Marshal(req.Servers) + gswitch.Servers = string(serverbytes) gswitch.AuditOpen = *req.AuditOpen gswitch.ModifyTime = nowDaySeconds if err := db.Where("switch_name = ?", req.Name).Save(gswitch).Error; err != nil { @@ -246,7 +256,7 @@ func (this *GameSwitchApi) Refresh(c *gin.Context) { if q5.DecodeJson(rsp.GetRawData(), &rspJson) != nil { f5.RspErr2(c, 500, "server internal error") return - } + } f5.RspErr2(c, rspJson.ErrCode, rspJson.ErrMsg) }) }