Пример #1
0
/**
投票详情
*/
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"
}
Пример #2
0
/**
投票搜索详情
*/
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"
}
Пример #3
0
func getPollWxOpenId(c *PollController, pollsid string, code string) (string, error) {
	polls, err := models.GetOnePolls(pollsid)
	if err != nil {
		beego.Error(err)
	} else {
		tokenobj, err := getWxAutoToken(polls.Appid, polls.Secret, code)
		if err != nil {
			beego.Error(err)
		} else {
			maxAge := 1<<31 - 1
			c.Ctx.SetCookie(COOKIE_WX_OPENID, tokenobj.OpenID, maxAge, "/")
			return tokenobj.OpenID, nil
		}
	}
	return "", err
}
Пример #4
0
func (c *PollController) PollWx() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("PollWx Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("PollWx Post")
	}
	id := c.Input().Get("id")
	if len(id) != 0 {
		polls, err := models.GetOnePolls(id)
		if err != nil {
			beego.Error(err)
		} else {
			appid := polls.Appid
			secret := polls.Secret
			if len(appid) != 0 && len(secret) != 0 {
				isdebug := "true"
				iniconf, err := config.NewConfig("json", "conf/myconfig.json")
				if err != nil {
					beego.Debug(err)
				} else {
					isdebug = iniconf.String("qax580::isdebug")
				}
				wx_url := "[REALM]?appid=[APPID]&redirect_uri=[REDIRECT_URI]&response_type=code&scope=snsapi_base&state=[STATE]#wechat_redirect"
				realm_name := ""
				if isdebug == "true" {
					realm_name = "http://localhost:9095"
				} else {
					realm_name = "https://open.weixin.qq.com/connect/oauth2/authorize"
				}
				redirect_uri := "http%3a%2f%2fwww.baoguangguang.cn%2fpoll%2fpollhome"
				state := id
				wx_url = strings.Replace(wx_url, "[REALM]", realm_name, -1)
				wx_url = strings.Replace(wx_url, "[APPID]", appid, -1)
				wx_url = strings.Replace(wx_url, "[REDIRECT_URI]", redirect_uri, -1)
				wx_url = strings.Replace(wx_url, "[STATE]", state, -1)
				beego.Debug("/poll/pollwx autho url :", wx_url)
				c.Redirect(wx_url, 302)
				return
			}
		}
	}
	c.TplName = "pollwx.html"
}
Пример #5
0
func (c *PollController) AdminUppollsInfo() {
	bool, username := chackAccount(c.Ctx)
	if bool {
		c.Data["isUser"] = bool
		c.Data["User"] = username
	} else {
		c.Redirect("/admin", 302)
		return
	}
	// beego.Debug("c.Input() :", c.Input())
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminUppollsInfo Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminUppollsInfo Post")
		id := c.Input().Get("id")
		title := c.Input().Get("title")
		info := c.Input().Get("info")
		more := c.Input().Get("more")
		endtime := c.Input().Get("endtime")
		appid := c.Input().Get("appid")
		secret := c.Input().Get("secret")
		prize := c.Input().Get("prize")
		ext := c.Input().Get("ext")
		// test := []byte("http://mp.weixin.qq.com/s?__biz=MzA5MTQ2NjQ2MA==&mid=401382373&idx=1&sn=f585506b1c883712bc3a2b47ae6f09b7#rd")
		// beego.Debug("AdminUppollsInfo Post test:", test)
		// beego.Debug("AdminUppollsInfo Post more:", more)
		// if len(more) != 0 {
		// 	more = string(fmt.Sprintf("[%s]", more))
		// }
		// beego.Debug("AdminUppollsInfo Post test str:", string(test))
		// beego.Debug("AdminUppollsInfo Post more str:", more)
		// beego.Debug("more byte", strings.Split(more, ","))
		// strs := strings.Split(more, ",")
		// slice2 := []byte{}
		// for i := 0; i < len(strs); i++ {
		// 	is, err := strconv.Atoi(strs[i])
		// 	if err != nil {
		// 		beego.Error(err)
		// 	}
		// 	slice2 = append(slice2, byte(is))
		// }
		// more = string(slice2)
		more = jsTostr(more)
		beego.Debug("AdminUppollsInfo Post more ", more)
		// beego.Debug("AdminUppollsInfo Post test str:", string(strings.Split(more, ",")))
		if len(title) != 0 && len(info) != 0 && len(more) != 0 && len(appid) != 0 && len(secret) != 0 {
			beego.Debug("endtime", endtime)
			//获取本地location
			toBeCharge := endtime                                           //待转化为时间戳的字符串 注意 这里的小时和分钟还要秒必须写 因为是跟着模板走的 修改模板的话也可以不写
			timeLayout := "2006-01-02 15:04"                                //转化所需模板
			loc, _ := time.LoadLocation("Local")                            //重要:获取时区
			theTime, _ := time.ParseInLocation(timeLayout, toBeCharge, loc) //使用模板在对应时区转化为time.time类型
			endtimelong := theTime.Unix()                                   //转化为时间戳 类型是int64
			beego.Debug("theTime", theTime)                                 //打印输出theTime 2015-01-01 15:15:00 +0800 CST
			beego.Debug("endtimelong ", endtimelong)                        //打印输出时间戳 1420041600
			t := time.Now().Unix()
			beego.Debug("local time", t)
			if endtimelong < t {
				beego.Error("select end time error")
			} else {
				err := models.UpPollsInfo(id, title, info, more, endtimelong, appid, secret, prize, ext)
				if err != nil {
					beego.Error(err)
				}
			}
			url := "/poll/adminpolls"
			c.Redirect(url, 302)
			return
		}
	}

	id := c.Input().Get("id")
	obj, err := models.GetOnePolls(id)
	if err != nil {
		beego.Error(err)
	}
	beego.Debug("id :", id)
	beego.Debug("obj :", obj)
	c.Data["Id"] = id
	c.Data["Obj"] = obj
	c.TplName = "adminuppollsinfo.html"
}
Пример #6
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"
}
Пример #7
0
func (c *PollController) AdminUppollsImg() {
	bool, username := chackAccount(c.Ctx)
	if bool {
		c.Data["isUser"] = bool
		c.Data["User"] = username
	} else {
		c.Redirect("/admin", 302)
		return
	}
	c.Data["isUser"] = bool
	c.Data["User"] = username
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminUppollsImg Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminUppollsImg Post")

		id := c.Input().Get("id")
		originalimg := c.Input().Get("originalimg")
		image_name := originalimg
		if len(id) != 0 {
			// 获取附件
			_, fh, err := c.GetFile("image")
			// beego.Debug("上传图片:", fh)
			if err != nil {
				beego.Error(err)
			}
			var attachment string
			if fh != nil {
				// 保存附件
				attachment = fh.Filename
				t := time.Now().Unix()
				str2 := fmt.Sprintf("%d", t)
				s := []string{attachment, str2}
				h := md5.New()
				h.Write([]byte(strings.Join(s, ""))) // 需要加密的字符串
				image_name = hex.EncodeToString(h.Sum(nil))
				beego.Info(image_name) // 输出加密结果
				err = c.SaveToFile("image", path.Join("imagehosting", image_name))
				if err != nil {
					beego.Error(err)
					image_name = originalimg
				}
			}

			beego.Debug("上传前图片", originalimg, "上传后图片", image_name)
			if len(image_name) != 0 {
				err := models.UpPollsImg(id, image_name)
				if err != nil {
					beego.Error(err)
				} else {
					c.Redirect("/poll/adminpolls", 302)
					return
				}
			}
		}
	}
	id := c.Input().Get("id")
	obj, err := models.GetOnePolls(id)
	if err != nil {
		beego.Error(err)
	}
	c.Data["Obj"] = obj
	c.TplName = "adminuppollsimg.html"
}