Пример #1
0
func (c *RecommendController) Post() {
	op := c.Input().Get("op")
	switch op {
	case "rec":
		index, err := models.GetQueryIndex("123456")
		if err != nil {
			beego.Error(err)
		}
		posts, err := models.QueryPagePost(index, 5)
		if err != nil {
			beego.Error(err)
		}
		if len(posts) != 0 {

		} else {
			beego.Debug("no info")
		}
		c.Data["Posts"] = posts
		beego.Debug(posts)
	}
	c.TplName = "recommend.html"
}
Пример #2
0
//根据类型解析消息
func responseTypeMsg(body []byte, msgType string) string {
	response_xml := ""
	switch msgType {
	//文字
	case "text":
		requestBody := &TextRequestBody{}
		err := xml.Unmarshal(body, requestBody)
		if err != nil {
			beego.Debug(err.Error())
			response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
		} else {
			requestBody := &TextRequestBody{}
			err := xml.Unmarshal(body, requestBody)
			if err != nil {
				response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
			} else if requestBody.Content == "你好" || requestBody.Content == "您好" {
				response_xml = responseTextMsg(requestBody.FromUserName, jieshao_info, qax580_name)
			} else if strings.Index(requestBody.Content, "发布") >= 0 {
				response_xml = responseTextMsg(requestBody.FromUserName, function_info, qax580_name)
			} else {
				//是否存在关键字
				key_count := int32(0)
				count, err := models.GetKeywordsCount(requestBody.Content)
				if err != nil {
					beego.Error(err)
				} else {
					key_count = count
				}
				if key_count > 0 {
					obj, err := models.GetOneKeywords(requestBody.Content)
					if err != nil {
						beego.Error(err)
					} else {
						objs, err := models.QueryFuzzyLimitKeyobj(obj.Id, 5)
						if err != nil {
							beego.Error(err)
						}
						if len(objs) > 0 {
							response_xml = responseKeyXML(requestBody.FromUserName, requestBody.Content, objs, qax580_name)
						} else {
							response_xml = responseCustomerService(requestBody.FromUserName, requestBody.ToUserName)
						}
					}
				} else {
					//信息查询
					beego.Debug(requestBody.Content)
					posts, err := models.QueryFuzzyLimitPost(requestBody.Content, 5)
					if err != nil {
						beego.Error(err)
					}
					// beego.Debug(requestBody.FromUserName)
					// beego.Debug(requestBody.ToUserName)
					if len(posts) > 0 {
						response_xml = responseImageTextXML(requestBody.FromUserName, requestBody.Content, posts, qax580_name)
					} else {
						response_xml = responseCustomerService(requestBody.FromUserName, requestBody.ToUserName)
					}
				}
			}
		}
		//音频
	case "voice":
		requestBody := &VoiceRequestBody{}
		err := xml.Unmarshal(body, requestBody)
		if err != nil {
			response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
		} else {
			beego.Debug(requestBody.Recognition)
			posts, err := models.QueryFuzzyLimitPost(requestBody.Recognition, 5)
			if err != nil {
				beego.Error(err)
			}
			response_xml = responseImageTextXML(requestBody.FromUserName, requestBody.Recognition, posts, qax580_name)

		}
		//点击
	case "event":
		requestBody := &EventResponseBody{}
		err := xml.Unmarshal(body, requestBody)
		if err != nil {
			beego.Debug(err.Error())
			response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
		} else {
			beego.Debug("qax 580 Event:", requestBody.Event, "EventKey", requestBody.EventKey)
			//自定义点击事件
			if requestBody.Event == "CLICK" {
				//推荐
				if requestBody.EventKey == "recommend" {
					// posts, err := models.QueryLimitPost(5)
					// if err != nil {
					// 	beego.Error(err)
					// }
					// response_xml = responseImageTextXML(requestBody.FromUserName, "", posts)
					index, err := models.GetQueryIndex(requestBody.FromUserName)
					if err != nil {
						beego.Error(err)
					}
					posts, err := models.QueryPagePost(index, 5)
					if err != nil {
						beego.Error(err)
					}
					beego.Debug("recommend count :", len(posts))
					if len(posts) != 0 {
						response_xml = responseImageTextXML(requestBody.FromUserName, "", posts, qax580_name)
					} else {
						response_xml = responseTextMsg(requestBody.FromUserName, "今日已无更多推荐信息", qax580_name)
					}
					//关于
				} else if requestBody.EventKey == "about" {
					response_xml = responseAbout(requestBody.FromUserName, qax580_name, about_info)
				} else if requestBody.EventKey == "today" { //今日580
					response_xml = responseToday(requestBody.FromUserName, qax580_name)
				} else {

				}
				//关注
			} else if requestBody.Event == "subscribe" {

				response_xml = responseTextMsg(requestBody.FromUserName, subscribe_info, qax580_name)
				beego.Debug("subscribe qax580")
				eventSubscribe(requestBody, qa_appid, qa_secret)
			} else {
				//其他类型
				response_xml = responseTextMsg(requestBody.FromUserName, error_info, qax580_name)
			}

		}

	default:
		beego.Debug(msgType)
	}
	beego.Debug(response_xml)
	return response_xml
}
Пример #3
0
func (c *HomeController) Get() {
	openid := getCookie(c)
	c.Data["FromType"] = getHomeFromType(c)
	setUrl(c)
	city := getSelectCity(c)
	CurrentPage := int32(1)
	count, err := models.GetPostCount()
	if strings.Contains(city, CITY_ALL) {
	} else {
		count, err = models.GetCityPostCount(city)
	}
	NumberofPages := int32(10)
	temp := count / NumberofPages
	if (count % NumberofPages) != 0 {
		temp = temp + 1
	}
	CotalPages := temp
	pagetype := c.Input().Get("type")
	page := c.Input().Get("page")
	// beego.Debug("pagetype:", pagetype)

	guanggaos, err := models.GetAllGuanggaosState1()
	if err != nil {
		beego.Error(err)
	}
	c.Data["City"] = city
	c.Data["Guanggaos"] = guanggaos

	if len(pagetype) != 0 && len(page) != 0 {
		switch pagetype {
		case "first": //首页
			CurrentPage = 1
		case "prev": //上一页
			pageint, error := strconv.Atoi(page)
			if error != nil {
				beego.Error(error)
			}
			CurrentPage = int32(pageint)
		case "next": //下一页
			pageint, error := strconv.Atoi(page)
			if error != nil {
				beego.Error(error)
			}
			CurrentPage = int32(pageint)
		case "last": //尾页
			CurrentPage = CotalPages
		case "page": //页码
			pageint, error := strconv.Atoi(page)
			if error != nil {
				beego.Error(error)
			}
			CurrentPage = int32(pageint)
		}
	}
	c.Data["CurrentPage"] = CurrentPage
	c.Data["CotalPages"] = CotalPages
	c.Data["NumberofPages"] = NumberofPages
	if strings.Contains(city, CITY_ALL) {
		posts, err := models.QueryPagePost(CurrentPage-1, NumberofPages)
		if err != nil {
			beego.Error(err)
		}
		c.Data["Posts"] = posts
	} else {
		posts, err := models.QueryCityPagePost(CurrentPage-1, NumberofPages, city)
		if err != nil {
			beego.Error(err)
		}
		c.Data["Posts"] = posts
	}

	// beego.Debug(posts)
	c.TplName = "home.html"

	isdebug := "true"
	iscanting := "false"
	iniconf, err := config.NewConfig("json", "conf/myconfig.json")
	if err != nil {
		beego.Error(err)
	} else {
		isdebug = iniconf.String("qax580::isdebug")
		iscanting = iniconf.String("qax580::iscanting")
	}
	// beego.Debug(isdebug)
	beego.Debug("IsCanting", iscanting)
	c.Data["IsDebug"] = isdebug
	c.Data["IsCanting"] = iscanting
	notice_num, err := models.GetUserNoticeNum(openid)
	if err != nil {
		beego.Error(err)
	}
	beego.Debug("notice_num :", notice_num)
	c.Data["NoticeNum"] = notice_num
	op := c.Input().Get("op")
	switch op {
	case "del":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}
		id = c.Input().Get("id")
		err := models.DeletePost(id)
		if err != nil {
			beego.Error(err)
		}
		// beego.Debug("is del " + id)
		c.Redirect("/", 302)
		return
	}
}