// 会员在线
package controllers

import (
	"box-gm/events"
	"box-gm/models"

	"github.com/astaxie/beego"
)

type RtPayLoginController struct {
	beego.Controller
}

// 主界面
// 通过c.Data[key]返回数据
// ace模板文件通过{{.key}}获取数据
func (c *RtPayLoginController) 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.ModelRealTime))) == 0 {
		c.Ctx.Redirect(302, "/accountlogin")
		return
	}
	serverId := c.GetString("server_id")
	if serverId == "" {
		serverId = "1001"
	}
	minutes, _ := c.GetInt("minutes")
	if minutes == 0 {
		minutes = 5
	}
	days, _ := c.GetInt("days")
	if days == 0 {
		days = 7
	}
	series, categories := events.PayLogin_get_range_day_time_count(days, minutes, serverId)
	filename := events.Save_rtpaylogin_records(series, minutes, userinfo.(*LoginInfo).Username)
	c.Data["Series"], c.Data["Categories"] = series, categories
	c.Data["Server_id"] = serverId
	c.Data["Minutes"] = minutes
	c.Data["file"] = filename
	c.Data["Days"] = days
	if c.GetString("querydata") == "rtpaylogin" {
		c.Ctx.Output.Download(filename)
	} else {
		//界面模板文件
		c.TplName = "rt_paylogin.tpl"
	}
}
