cygx_yanxuan_special.go 8.1 KB

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