/** 投票详情 */ func (c *PollController) PollHomeCon() { if c.Ctx.Input.IsGet() { beego.Debug("PollHome Get") } if c.Ctx.Input.IsPost() { beego.Debug("PollHome Post") } openid := getPollCookie(c) pollsid := c.Input().Get("pollsid") pollid := c.Input().Get("pollid") beego.Debug("pollsid:", pollsid) beego.Debug("pollid:", pollid) c.Data["PollsId"] = pollsid c.Data["PollId"] = pollid op := c.Input().Get("op") beego.Debug("op:", op) switch op { case "vote": err := models.AddVote(openid, pollsid, pollid) if err != nil { beego.Debug(err) } url := fmt.Sprintf("/poll/pollhomecon?pollsid=%s&pollid=%s", pollsid, pollid) beego.Debug("url:", url) c.Redirect(url, 302) return } obj, err := models.GetOnePoll(pollsid, pollid) if err != nil { beego.Error(err) } num, err := models.GetVoteNum1(pollsid, pollid) if err != nil { beego.Error(err) } polls, err := models.GetOnePolls(pollsid) if err != nil { beego.Error(err) } wxShareCon := models.WxShareCon{} wxShareCon.Title = obj.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", obj.Image) shaer_url := fmt.Sprintf("http://www.baoguangguang.cn/poll/pollhomecon?pollsid=%s&pollid=%s", pollsid, pollid) getPollShare(polls.Appid, polls.Secret, shaer_url, wxShareCon, c) beego.Debug("VoteNum", num) obj.VoteNum = num c.Data["Time"] = polls.EndTimeLong c.Data["Polls"] = polls c.Data["Obj"] = obj c.TplName = "pollhomecon.html" }
/** 投票搜索详情 */ func (c *PollController) PollHomeSearch() { if c.Ctx.Input.IsGet() { beego.Debug("PollHomeSearch Get") } if c.Ctx.Input.IsPost() { beego.Debug("PollHomeSearch Post") } openid := getPollCookie(c) pollsid := c.Input().Get("pollsid") search := c.Input().Get("search") beego.Debug("pollsid:", pollsid) beego.Debug("search:", search) c.Data["PollsId"] = pollsid c.Data["Search"] = search op := c.Input().Get("op") beego.Debug("op:", op) switch op { case "vote": pollid := c.Input().Get("pollid") err := models.AddVote(openid, pollsid, pollid) if err != nil { beego.Debug(err) } url := fmt.Sprintf("/poll/pollhomesearch?pollsid=%s&search=%s", pollsid, search) beego.Debug("url:", url) c.Redirect(url, 302) return } objs, err := models.GetAllPollOr(search) 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 } polls, err := models.GetOnePolls(pollsid) if err != nil { beego.Error(err) } c.Data["Time"] = polls.EndTimeLong c.Data["Polls"] = polls c.Data["Objs"] = objs c.TplName = "pollhomesearch.html" }
/** 投票主页 */ 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" }