123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- // 实时数据
- package controllers
- import (
- "box-gm/models"
- "encoding/json"
- "fmt"
- "log"
- "github.com/astaxie/beego"
- )
- type RollAwardController struct {
- beego.Controller
- }
- func (c *RollAwardController) 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.GetRollAwardInfo()
- c.TplName = "rollaward.tpl"
- }
- func (c *RollAwardController) Post() {
- userinfo := c.GetSession("user")
- log.Printf("RollAwardController Post userinfo[%v]", userinfo)
- if userinfo == nil {
- c.Ctx.Redirect(302, "/accountlogin")
- return
- }
- items := c.GetString("items")
- var eItems []int
- err := json.Unmarshal([]byte(items), &eItems)
- if err != nil {
- log.Printf("RollAwardController items[%s] err[%v]", items, err)
- c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()}
- c.ServeJSON()
- return
- }
- u := new(models.RollAwardInfo)
- u.Id = models.CreateRollAwardId()
- u.ItemIdList = eItems
- err = models.AddRollAwardInfo(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": "新增roll房奖池方案成功"}
- c.ServeJSON()
- }
- func (c *RollAwardController) Put() {
- userinfo := c.GetSession("user")
- if userinfo == nil {
- c.Ctx.Redirect(302, "/accountlogin")
- return
- }
- id, _ := c.GetInt("id")
- log.Printf("RollAwardController Put id[%d]", id)
- hf := models.GetRollAwardInfoById(id)
- if hf == nil {
- c.Data["json"] = &map[string]interface{}{"status": false, "info": "修改失败:奖池方案不存在"}
- c.ServeJSON()
- return
- }
- items := c.GetString("items")
- var eItems []int
- err := json.Unmarshal([]byte(items), &eItems)
- if err != nil {
- log.Printf("RollAwardController items[%s] err[%v]", items, err)
- c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()}
- c.ServeJSON()
- return
- }
- hf.ItemIdList = eItems
- err = models.UpdateRollAwardInfo(hf)
- 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": fmt.Sprintf("修改奖池方案[%d]成功", id)}
- c.ServeJSON()
- }
- func (c *RollAwardController) Delete() {
- userinfo := c.GetSession("user")
- if userinfo == nil {
- c.Ctx.Redirect(302, "/accountlogin")
- return
- }
- id, _ := c.GetInt("id")
- log.Printf("RollAwardController Post Delete id[%d]", id)
- hf := models.GetRollAwardInfoById(id)
- if hf == nil {
- c.Data["json"] = &map[string]interface{}{"status": false, "info": "修改失败:兑换码配置不存在"}
- c.ServeJSON()
- return
- }
- models.DelRollAwardInfoById(id)
- c.Data["json"] = &map[string]interface{}{"status": true, "info": "删除兑换码成功"}
- c.ServeJSON()
- }
|