cygx_yanxuan_special.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxYanxuanSpecial struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int // 用户ID
  9. CreateTime time.Time // 创建时间
  10. ModifyTime time.Time // 修改时间
  11. PublishTime time.Time // 提审过审或驳回时间
  12. Content string // 内容
  13. Tags string // 标签
  14. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  15. ImgUrl string // 图片链接
  16. DocUrl string // 文档链接
  17. Reason string // 理由
  18. Title string // 标题
  19. Type int // 类型1:笔记,2:观点
  20. }
  21. type CygxYanxuanSpecialItem struct {
  22. Id int `orm:"column(id);pk"`
  23. UserId int // 用户ID
  24. CreateTime string // 创建时间
  25. ModifyTime string // 修改时间
  26. PublishTime string // 提审过审或驳回时间
  27. Content string // 内容
  28. Tags string // 标签
  29. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  30. ImgUrl string // 图片链接
  31. DocUrl string // 文档链接
  32. SpecialName string // 专栏名称
  33. Introduction string // 介绍
  34. Label string // 标签
  35. NickName string // 昵称
  36. RealName string // 姓名
  37. Mobile string // 手机号
  38. HeadImg string // 头像
  39. BgImg string // 背景图
  40. Reason string // 理由
  41. Title string // 标题
  42. Type int // 类型1:笔记,2:观点
  43. CollectNum int
  44. MyCollectNum int
  45. IsCollect int
  46. ContentHasImg int //正文是否包含图片 1包含 0不包含
  47. Docs []Doc
  48. }
  49. type CygxYanxuanSpecialResp struct {
  50. CygxYanxuanSpecialItem
  51. Docs []Doc
  52. }
  53. type Doc struct {
  54. DocName string
  55. DocSuffix string
  56. DocUrl string
  57. DocIcon string
  58. }
  59. func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
  60. o := orm.NewOrm()
  61. sql := ``
  62. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,
  63. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  64. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  65. FROM cygx_yanxuan_special AS a
  66. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  67. WHERE 1=1 `
  68. if condition != "" {
  69. sql += condition
  70. }
  71. sql += `ORDER BY a.publish_time DESC `
  72. _, err = o.Raw(sql, userId, pars).QueryRows(&items)
  73. return
  74. }
  75. type EnableCygxYanxuanSpecialReq struct {
  76. Id int // 文章id
  77. Status int // 1通过2驳回
  78. Reason string //理由
  79. }
  80. func EnableYanxuanSpecial(id, status int, reason string) (err error) {
  81. o := orm.NewOrm()
  82. sql := ``
  83. sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,publish_time=NOW() WHERE id = ? `
  84. _, err = o.Raw(sql, status, reason, id).Exec()
  85. return
  86. }
  87. type SpecialListResp struct {
  88. List []*CygxYanxuanSpecialItem
  89. IsAuthor bool
  90. }
  91. func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
  92. o := orm.NewOrm()
  93. sql := ``
  94. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  95. b.nick_name,b.real_name,b.special_name,
  96. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  97. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  98. FROM cygx_yanxuan_special AS a
  99. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  100. WHERE a.id=? `
  101. err = o.Raw(sql, userId, specialId).QueryRow(&item)
  102. return
  103. }
  104. type CygxYanxuanSpecialReq struct {
  105. Id int `orm:"column(id);pk"`
  106. Content string // 内容
  107. Tags string // 标签
  108. DoType int // 1保存 2发布
  109. ImgUrl string // 图片链接
  110. DocUrl string // 文档链接
  111. Title string // 标题
  112. Type int // 类型1:笔记,2:观点
  113. }
  114. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  115. o := orm.NewOrm()
  116. lastId, err = o.Insert(item)
  117. return
  118. }
  119. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  120. o := orm.NewOrm()
  121. sql := ``
  122. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,tags=?,img_url=?,doc_url=?,type=?,status=?,
  123. modify_time=NOW(),publish_time=NOW() WHERE id = ? `
  124. _, err = o.Raw(sql, item.Title, item.Content, item.Tags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.Id).Exec()
  125. return
  126. }
  127. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  128. o := orm.NewOrm()
  129. sql := ``
  130. if keyword == "" {
  131. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  132. } else {
  133. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  134. }
  135. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  136. return
  137. }
  138. type CancelPublishCygxYanxuanSpecialReq struct {
  139. Id int // 文章id
  140. }
  141. func CancelPublishYanxuanSpecial(id int) (err error) {
  142. o := orm.NewOrm()
  143. sql := ``
  144. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW() WHERE id = ? `
  145. _, err = o.Raw(sql, id).Exec()
  146. return
  147. }
  148. type DelCygxYanxuanSpecialReq struct {
  149. Id int // 文章id
  150. }
  151. func DelYanxuanSpecial(id int) (err error) {
  152. o := orm.NewOrm()
  153. sql := ``
  154. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  155. _, err = o.Raw(sql, id).Exec()
  156. return
  157. }