Esempio n. 1
0
//批量操作
func (this *TagController) batch() {
	ids := this.GetStrings("ids[]")
	op := this.GetString("op")

	idarr := make([]int64, 0)
	for _, v := range ids {
		if id, _ := strconv.Atoi(v); id > 0 {
			idarr = append(idarr, int64(id))
		}
	}

	switch op {
	case "upcount": //更新统计
		for _, id := range idarr {
			obj := models.Tag{Id: id}
			if obj.Read() == nil {
				obj.UpCount()
			}
		}
	case "merge": //合并到
		toname := strings.TrimSpace(this.GetString("toname"))
		if toname != "" && len(idarr) > 0 {
			tag := new(models.Tag)
			tag.Name = toname
			if tag.Read("name") != nil {
				tag.Count = 0
				tag.Insert()
			}
			for _, id := range idarr {
				obj := models.Tag{Id: id}
				if obj.Read() == nil {
					obj.MergeTo(tag)
					obj.Delete()
				}
			}
			tag.UpCount()
		}
	case "delete": //批量删除
		for _, id := range idarr {
			obj := models.Tag{Id: id}
			if obj.Read() == nil {
				obj.Delete()
			}
		}
	}

	this.Redirect("/admin/tag", 302)
}