// 实时数据 package controllers import ( "box-gm/models" "box-gm/utils" "encoding/json" "log" "github.com/astaxie/beego" ) type ExchangeCodeController struct { beego.Controller } func (c *ExchangeCodeController) Get() { userinfo := c.GetSession("user") if userinfo == nil { c.Ctx.Redirect(302, "/accountlogin") return } c.Data["username"] = userinfo.(*LoginInfo).Username c.Data["token"] = models.GetToken() userPermission := models.GetPermission(userinfo.(*LoginInfo).Username) if (userPermission & (1 << uint(models.ModelSystem))) == 0 { c.Ctx.Redirect(302, "/accountlogin") return } c.Data["ItemList"] = models.GetItemInfoList() c.Data["infoList"] = models.GetExchangeCodeInfo() c.TplName = "exchangecode.tpl" } func (c *ExchangeCodeController) Post() { userinfo := c.GetSession("user") log.Printf("ExchangeCodeController Post userinfo[%v]", userinfo) if userinfo == nil { c.Ctx.Redirect(302, "/accountlogin") return } pcode := c.GetString("pcode") log.Printf("ExchangeCodeController Post pcode[%s]", pcode) hf := models.GetExchangeCodeInfoByCode(pcode) if hf != nil { c.Data["json"] = &map[string]interface{}{"status": false, "info": "新增失败:渠道已配置"} c.ServeJSON() return } awardTimes, _ := c.GetInt64("awardTimes") expireTime := c.GetString("expireTime") items := c.GetString("items") u := new(models.ExchangeCodeInfo) u.Pcode = pcode u.AwardTimes = awardTimes u.ExpireTime = utils.GetTime64(expireTime) var eItems []*models.ExchangeItemsInfo err := json.Unmarshal([]byte(items), &eItems) if err != nil { log.Printf("ExchangeCodeController items[%s] err[%v]", items, err) c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()} c.ServeJSON() return } u.Items = eItems err = models.AddExchangeCodeInfo(u) if err != nil { c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()} c.ServeJSON() return } c.Data["json"] = &map[string]interface{}{"status": true, "info": "新增兑换码成功"} c.ServeJSON() } func (c *ExchangeCodeController) Put() { userinfo := c.GetSession("user") if userinfo == nil { c.Ctx.Redirect(302, "/accountlogin") return } u := new(models.HotfixInfo) u.Id, _ = c.GetInt64("id") u.Channel, _ = c.GetInt64("channel") u.Version = c.GetString("version") u.DowloadAddr = c.GetString("addr") u.FileSize = c.GetString("filesize") _, err := models.UpdateHotfixInfo(u) if err != nil { c.Data["json"] = &map[string]interface{}{"status": false, "info": err} c.ServeJSON() return } c.Data["json"] = &map[string]interface{}{"status": true, "info": "更新热更新参数成功"} c.ServeJSON() } func (c *ExchangeCodeController) Delete() { userinfo := c.GetSession("user") if userinfo == nil { c.Ctx.Redirect(302, "/accountlogin") return } id, _ := c.GetInt64("id") cp := models.GetHotfixInfoById(id) if cp == nil { c.Data["json"] = &map[string]interface{}{"status": false, "info": "参数不存在"} c.ServeJSON() return } models.DelHotfixInfoById(id) c.Data["json"] = &map[string]interface{}{"status": true, "info": "删除热更新参成功"} c.ServeJSON() }