cygx_yanxuan_special.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. CompanyTags string // 标签
  14. IndustryTags string // 标签
  15. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  16. ImgUrl string // 图片链接
  17. DocUrl string // 文档链接
  18. Reason string // 理由
  19. Title string // 标题
  20. Type int // 类型1:笔记,2:观点
  21. }
  22. type CygxYanxuanSpecialItem struct {
  23. Id int `orm:"column(id);pk"`
  24. UserId int // 用户ID
  25. SpecialColumnId int // 专栏栏目ID
  26. CreateTime string // 创建时间
  27. ModifyTime string // 修改时间
  28. PublishTime string // 提审过审或驳回时间
  29. Content string // 内容
  30. Tags string // 标签
  31. TagList []string // 标签
  32. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  33. ImgUrl string // 图片链接
  34. ImgUrlList []string // 图片链接
  35. DocUrl string // 文档链接
  36. SpecialName string // 专栏名称
  37. Introduction string // 介绍
  38. Label string // 标签
  39. NickName string // 昵称
  40. RealName string // 姓名
  41. Mobile string // 手机号
  42. HeadImg string // 头像
  43. BgImg string // 背景图
  44. Reason string // 理由
  45. Title string // 标题
  46. AuthorStatus int // 作者状态
  47. Type int // 类型1:笔记,2:观点
  48. CollectNum int
  49. MyCollectNum int
  50. IsCollect int
  51. ContentHasImg int //正文是否包含图片 1包含 0不包含
  52. CompanyTags string
  53. IndustryTags string
  54. Docs []Doc
  55. Annotation string `description:"核心观点"`
  56. }
  57. type CygxYanxuanSpecialResp struct {
  58. CygxYanxuanSpecialItem
  59. Docs []Doc
  60. CompanyTags []string
  61. IndustryTags []string
  62. }
  63. type Doc struct {
  64. DocName string
  65. DocSuffix string
  66. DocUrl string
  67. DocIcon string
  68. }
  69. type DocReq struct {
  70. DocName string
  71. DocSuffix string
  72. DocUrl string
  73. }
  74. func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
  75. o := orm.NewOrm()
  76. sql := ``
  77. sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,b.status AS author_status,
  78. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  79. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  80. FROM cygx_yanxuan_special AS a
  81. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  82. WHERE 1=1 `
  83. if condition != "" {
  84. sql += condition
  85. }
  86. sql += `ORDER BY a.publish_time DESC `
  87. _, err = o.Raw(sql, userId, pars).QueryRows(&items)
  88. return
  89. }
  90. type EnableCygxYanxuanSpecialReq struct {
  91. Id int // 文章id
  92. Status int // 1通过2驳回
  93. Reason string //理由
  94. }
  95. func EnableYanxuanSpecial(id, status int, reason string) (err error) {
  96. o := orm.NewOrm()
  97. sql := ``
  98. sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,publish_time=NOW() WHERE id = ? `
  99. _, err = o.Raw(sql, status, reason, id).Exec()
  100. return
  101. }
  102. type SpecialListResp struct {
  103. List []*CygxYanxuanSpecialItem
  104. IsAuthor bool
  105. }
  106. func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
  107. o := orm.NewOrm()
  108. sql := ``
  109. sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  110. b.nick_name,b.real_name,b.special_name,
  111. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  112. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  113. FROM cygx_yanxuan_special AS a
  114. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  115. WHERE a.id=? `
  116. err = o.Raw(sql, userId, specialId).QueryRow(&item)
  117. return
  118. }
  119. type CygxYanxuanSpecialReq struct {
  120. Id int `orm:"column(id);pk"`
  121. Content string // 内容
  122. IndustryTags []string // 行业标签
  123. CompanyTags []string // 公司标签
  124. DoType int // 1保存 2发布
  125. ImgUrl []string // 图片链接
  126. Docs []Doc // 文档链接
  127. Title string // 标题
  128. Type int // 类型1:笔记,2:观点
  129. }
  130. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  131. o := orm.NewOrm()
  132. lastId, err = o.Insert(item)
  133. return
  134. }
  135. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  136. o := orm.NewOrm()
  137. sql := ``
  138. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,company_tags=?,industry_tags=?,img_url=?,doc_url=?,type=?,status=?,
  139. modify_time=NOW(),publish_time=NOW() WHERE id = ? `
  140. _, err = o.Raw(sql, item.Title, item.Content, item.CompanyTags, item.IndustryTags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.Id).Exec()
  141. return
  142. }
  143. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  144. o := orm.NewOrm()
  145. sql := ``
  146. if keyword == "" {
  147. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  148. } else {
  149. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  150. }
  151. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  152. return
  153. }
  154. type CancelPublishCygxYanxuanSpecialReq struct {
  155. Id int // 文章id
  156. }
  157. func CancelPublishYanxuanSpecial(id int) (err error) {
  158. o := orm.NewOrm()
  159. sql := ``
  160. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  161. _, err = o.Raw(sql, id).Exec()
  162. return
  163. }
  164. type DelCygxYanxuanSpecialReq struct {
  165. Id int // 文章id
  166. }
  167. func DelYanxuanSpecial(id int) (err error) {
  168. o := orm.NewOrm()
  169. sql := ``
  170. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  171. _, err = o.Raw(sql, id).Exec()
  172. return
  173. }
  174. type CygxYanxuanSpecialCheckReq struct {
  175. Content string // 内容
  176. ImgUrl []string // 图片
  177. }
  178. func GetYanxuanSpecialFollowUserById(specialId int) (items []int, err error) {
  179. o := orm.NewOrm()
  180. sql := ``
  181. sql = `SELECT b.user_id
  182. FROM cygx_yanxuan_special AS a
  183. JOIN cygx_yanxuan_special_follow AS b ON a.user_id = b.follow_user_id
  184. WHERE a.id=? `
  185. _, err = o.Raw(sql, specialId).QueryRows(&items)
  186. return
  187. }
  188. func GetYanxuanSpecialItemById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  189. o := orm.NewOrm()
  190. sql := ``
  191. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  192. b.nick_name,b.real_name,b.special_name
  193. FROM cygx_yanxuan_special AS a
  194. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  195. WHERE a.id=? `
  196. err = o.Raw(sql, specialId).QueryRow(&item)
  197. return
  198. }
  199. // 获取数量
  200. func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
  201. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special WHERE 1= 1 `
  202. if condition != "" {
  203. sqlCount += condition
  204. }
  205. o := orm.NewOrm()
  206. err = o.Raw(sqlCount, pars).QueryRow(&count)
  207. return
  208. }