github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/routers/root/RReadReply.go (about) 1 package root 2 3 import ( 4 "fmt" 5 "github.com/insionng/makross" 6 7 "strconv" 8 "github.com/insionng/yougam/helper" 9 "github.com/insionng/yougam/models" 10 ) 11 12 func GetRReadReplyHandler(self *makross.Context) error { 13 14 15 TplNames := "root/update_reply" 16 self.Set("catpage", "RReadReplyHandler") 17 18 switch cmid := self.Param("cmid").MustInt64(); { 19 //单独模式 20 case cmid > 0: 21 { 22 if rp, err := models.GetReply(cmid); rp != nil && err == nil { 23 self.Set("reply", *rp) 24 25 } else { 26 self.Flash.Error(err.Error()) 27 return self.Render(TplNames) 28 29 } 30 } 31 32 //列表模式 33 case cmid <= 0: 34 { 35 TplNames = "root/reply_table" 36 offset := self.Args("offset").MustInt64() 37 limit := self.Args("limit").MustInt64() 38 field := self.FormValue("field") 39 ctype := self.Args("ctype").MustInt64() 40 pid := self.Args("pid").MustInt64() 41 42 if limit == 0 { 43 limit = 1000 //默认限制显示最近1000条,需要显示全部请在提交请求的时候设置limit字段为-1 44 } 45 46 if field == "" { 47 field = "id" 48 } 49 50 if rps := models.GetReplysByPid(pid, ctype, int(offset), int(limit), field); rps != nil { 51 self.Set("replys", rps) 52 return self.Render(TplNames) 53 54 } 55 } 56 } 57 58 return self.Render(TplNames) 59 } 60 61 func PostRReadReplyHandler(self *makross.Context) error { 62 63 64 delrowids := self.FormValue("delrowids") 65 iserr := false 66 //删除评论 67 if delrowids != "" { 68 69 delids := helper.Split(delrowids, ",") 70 for _, delid := range delids { 71 rid, _ := strconv.ParseInt(delid, 10, 0) 72 73 if rid > 0 { 74 if rp, err := models.GetReply(rid); rp != nil && err == nil { 75 76 if rp.Tid > 0 { 77 78 if rps := models.GetReplysByTid(rp.Tid, 0, 0, 0, "id"); rps != nil { 79 for _, g := range *rps { 80 models.DelReply(g.Id) 81 } 82 83 self.Flash.Success("删除 Reply id:" + delrowids + "成功!") 84 85 } 86 87 } 88 } else { 89 90 if e := models.DelReply(rid); e != nil { 91 iserr = true 92 self.Flash.Error("删除 Reply id:" + strconv.FormatInt(rid, 10) + "出现错误 " + fmt.Sprintf("%s", e) + "!") 93 94 } else { 95 self.Flash.Success("删除 Reply id:" + strconv.FormatInt(rid, 10) + "成功!") 96 97 } 98 } 99 } 100 } 101 102 if iserr == false { 103 self.Flash.Success("删除 Reply id:" + delrowids + "成功!") 104 } 105 } else { 106 self.Flash.Error("非法 Reply id!") 107 108 } 109 110 return self.Redirect("/root/read/reply/") 111 112 }