github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/models/Issue.go (about) 1 package models 2 3 import ( 4 "fmt" 5 ) 6 7 type IssueMark struct { 8 Id int64 9 Uid int64 `xorm:"index"` //举报人 10 Rid int64 `xorm:"index"` //被举报项id 11 Ctype int64 `xorm:"index"` // 1为topic类型 -1是comment类型 12 Title string `xorm:"index"` //举报标题 13 Content string `xorm:"text"` //举报内容 14 } 15 16 //SetIssueMark 设置举报标记 17 func SetIssueMark(uid int64, rid int64, ctype int64, content string) (int64, error) { 18 rptm := &IssueMark{Uid: uid, Rid: rid, Ctype: ctype, Content: content} 19 rows, err := Engine.Insert(rptm) 20 return rows, err 21 } 22 23 func IsIssueMark(uid int64, rid int64, ctype int64) bool { 24 25 rptm := &IssueMark{} 26 27 if has, err := Engine.Where("uid=? and rid=? and ctype=?", uid, rid, ctype).Get(rptm); err != nil { 28 fmt.Println(err) 29 return false 30 } else { 31 if has { 32 if rptm.Uid == uid { 33 return true 34 } else { 35 return false 36 } 37 38 } else { 39 return false 40 } 41 } 42 43 } 44 45 func GetIssue(rid int64) (*IssueMark, error) { 46 47 rm := &IssueMark{} 48 49 has, err := Engine.Id(rid).Get(rm) 50 if has { 51 return rm, err 52 } else { 53 54 return nil, err 55 } 56 } 57 58 func GetIssues(offset int, limit int, field string, ctype int64) (*[]*IssueMark, error) { 59 60 rms := new([]*IssueMark) 61 62 if ctype == 0 { //同时查询两种类型举报项 63 err := Engine.Limit(limit, offset).Desc(field).Find(rms) 64 return rms, err 65 66 } else if (ctype == 1) || (ctype == -1) { //1为topic类型 -1是comment类型 按指定类型查询举报项目 67 68 err := Engine.Where("ctype=?", ctype).Limit(limit, offset).Desc(field).Find(rms) 69 return rms, err 70 } else { 71 72 return nil, nil 73 } 74 }