Beispiel #1
0
/**
查看排名
*/
func (c *PollController) PollHomeRanking() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("PollHomeRanking Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("PollHomeRanking Post")
	}
	pollsid := c.Input().Get("pollsid")
	beego.Debug("pollsid:", pollsid)
	c.Data["PollsId"] = pollsid
	if len(pollsid) != 0 {
		objs, err := models.GetAllPollState(pollsid, 1)
		if err != nil {
			beego.Debug(err)
		}
		for i := 0; i < len(objs); i++ {
			num, err := models.GetVoteNum(pollsid, objs[i].Id)
			if err != nil {
				beego.Error(err)
			}
			objs[i].VoteNum = num
		}
		for i := 0; i < len(objs); i++ {
			for j := 0; j < len(objs)-i-1; j++ {
				if objs[j].VoteNum < objs[j+1].VoteNum {
					objs[j], objs[j+1] = objs[j+1], objs[j]
				}
			}
		}
		for i := 0; i < len(objs); i++ {
			objs[i].Ranking = int32(i)
		}
		beego.Debug("objs :", objs)
		c.Data["Objs"] = objs
	}
	c.TplName = "pollhomeranking.html"
}
Beispiel #2
0
/**
投票主页
*/
func (c *PollController) PollHome() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("PollHome Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("PollHome Post")
	}
	pollsid := c.Input().Get("pollsid")
	beego.Debug("pollsid :", pollsid)
	state := c.Input().Get("state")
	code := c.Input().Get("code")
	beego.Debug("/poll/pollhem state :", state)
	beego.Debug("/poll/pollhem code :", code)
	share_url := "http://www.baoguangguang.cn/poll/pollhome"
	if len(code) != 0 && len(state) != 0 {
		pollsid = state
		_, err := getPollWxOpenId(c, pollsid, code)
		if err != nil {
			beego.Error(err)
		}
		share_url = fmt.Sprintf("http://www.baoguangguang.cn/poll/pollhome?code=%s&state=%s", code, state)
	}
	beego.Debug("/poll/pollhem pollsid :", pollsid)
	openid := getPollCookie(c)
	//测试openid
	isdebug := "false"
	iniconf, err := config.NewConfig("json", "conf/myconfig.json")
	if err != nil {
		beego.Debug(err)
	} else {
		isdebug = iniconf.String("qax580::isdebug")
	}
	if isdebug == "true" {
		openid = "o3AhEuB_wdTELvlErL4F1Em4Nck4"
		c.Data["OpenId"] = openid
	}

	op := c.Input().Get("op")
	beego.Debug("op :", op)
	switch op {
	case "vote":
		id := c.Input().Get("id")
		err := models.AddVote(openid, pollsid, id)
		if err != nil {
			beego.Error(err)
		}
		url := fmt.Sprintf("/poll/pollhome?pollsid=%s", pollsid)
		c.Redirect(url, 302)
		return
	}
	c.Data["Time"] = int64(0)
	if len(pollsid) != 0 {
		err := models.AddPollsPv(pollsid)
		if err != nil {
			beego.Error(err)
		}
		polls, err := models.GetOnePolls(pollsid)
		if err != nil {
			beego.Error(err)
		}
		beego.Debug("polls", polls)
		c.Data["Time"] = polls.EndTimeLong
		c.Data["Polls"] = polls
		pv, err := models.GetPollsPv(pollsid)
		c.Data["PV"] = pv
		pollnum, err := models.GetPollAllNum(pollsid)
		c.Data["PollNum"] = pollnum
		votenum, err := models.GetVoteAllNum(pollsid)
		c.Data["VoteNum"] = votenum

		endtime := polls.EndTimeLong
		curtime := time.Now().Unix()
		timestr := "活动已过期"
		if endtime-curtime > 0 {
			t := time.Unix(endtime, 0)

			_, mon, day := t.Date()
			_, cmon, cday := time.Now().Date()
			hour, min, _ := t.Clock()
			chour, cmin, _ := time.Now().Clock()
			timestr = fmt.Sprintf("%d月%d天%02d小时%02d分", mon-cmon, day-cday, hour-chour, min-cmin)
			// beego.Debug(timestr)
		}
		c.Data["TimeStr"] = timestr

		objs, err := models.GetAllPollState(pollsid, 1)
		if err != nil {
			beego.Debug(err)
		}
		for i := 0; i < len(objs); i++ {
			num, err := models.GetVoteNum(pollsid, objs[i].Id)
			if err != nil {
				beego.Error(err)
			}
			objs[i].VoteNum = num
		}
		// beego.Debug("objs :", objs)
		c.Data["Objs"] = objs
		wxShareCon := models.WxShareCon{}
		wxShareCon.Title = polls.Title
		wxShareCon.Link = fmt.Sprintf("http://www.baoguangguang.cn/poll/pollwx?id=%s", pollsid)
		wxShareCon.ImgUrl = fmt.Sprintf("http://182.92.167.29:8080/imagehosting/%s", polls.Image)
		getPollShare(polls.Appid, polls.Secret, share_url, wxShareCon, c)
	}
	c.Data["PollsId"] = pollsid
	c.TplName = "pollhome.html"
}