Exemple #1
0
func (this *ConfigController) Prepare() {
	banner1_url := beego.AppConfig.String("banner1.url")
	banner1_id, _ := beego.AppConfig.Int("banner1.id")
	art := models.Article{Id: banner1_id}
	err := models.GetByProperty(&art)
	if err != nil {
		beego.Error(err)
	}
	this.Data["banner1_url"] = banner1_url
	this.Data["banner1_art"] = art

	banner2_url := beego.AppConfig.String("banner2.url")
	banner2_id, _ := beego.AppConfig.Int("banner2.id")
	art2 := models.Article{Id: banner2_id}
	err2 := models.GetByProperty(&art2)
	if err2 != nil {
		beego.Error(err)
	}
	this.Data["banner2_url"] = banner2_url
	this.Data["banner2_art"] = art2

	banner3_url := beego.AppConfig.String("banner3.url")
	banner3_id, _ := beego.AppConfig.Int("banner3.id")
	art3 := models.Article{Id: banner3_id}
	err3 := models.GetByProperty(&art3)
	if err3 != nil {
		beego.Error(err)
	}
	this.Data["banner3_url"] = banner3_url
	this.Data["banner3_art"] = art3
}
Exemple #2
0
func addClickNum(id int) {
	idstr := strconv.Itoa(id)
	click_num_obj := cache.Redis.Get("article:" + idstr + ":click_num")
	var click_num int
	var err error
	//没有数据获取数据库中的
	if click_num_obj == nil {
		art2 := models.Article{Id: id}
		err = models.GetByProperty(&art2)
		if err != nil {
			beego.Error(err)
		}
		click_num = art2.ClickNum
	} else {
		click_num, _ = redis.Int(click_num_obj, err)
	}
	click_num++
	if click_num%10 == 0 {
		if _, err = models.AddClickNum(id, click_num); err != nil {
			cache.Redis.Delete("article:" + idstr + ":click_num")
		}
	} else {
		cache.Redis.Put("article:"+idstr+":click_num", click_num, 99999)
	}
}
Exemple #3
0
func (this *AticleController) ShowModify() {
	id, err := this.GetInt("id")
	if err != nil {
		this.ToJsonFails("请输入正确的id")
		return
	}
	types := models.GetAllType()
	art := &models.Article{Id: id}
	models.GetByProperty(art)
	this.Data["types"] = types
	this.Data["art"] = art
	this.Data["op"] = "modify"
	this.GetLayout("admin/edit.tpl")
}
Exemple #4
0
func (this *AticleController) Modify() {
	art := models.Article{}
	if err := this.ParseForm(&art); err != nil {
		beego.Error(err)

		return
	}
	beego.Info(art)
	if _, err := utils.NewOrm().Update(&art, "Title", "Content", "TypeId", "ModifyTime"); err != nil {
		types := models.GetAllType()
		models.GetByProperty(&art)
		this.Data["types"] = types
		this.Data["art"] = art
		this.Data["op"] = "modify"
		this.GetLayout("admin/edit.tpl")
		return
	}
	this.Manage()
}
Exemple #5
0
func getArticle(id int) (art models.Article) {
	idstr := strconv.Itoa(id)
	art_obj := cache.Redis.Get("article:" + idstr + ":view")
	var err error
	beego.Error(art_obj)
	if art_obj == nil {
		art = models.Article{Id: id}
		err = models.GetByProperty(&art)
		if err != nil {
			beego.Error(err)
		}
		bytes, _ := json.Marshal(art)
		cache.Redis.Put("article:"+idstr+":view", bytes, 60*10)
		return art
	}
	bytes, err := redis.Bytes(art_obj, err)
	err = json.Unmarshal(bytes, &art)
	if err != nil {
		beego.Error(err)
	}

	return art
}