cygx_yanxuan_special.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. }
  91. type Doc struct {
  92. DocName string
  93. DocSuffix string
  94. DocUrl string
  95. DocIcon string
  96. }
  97. func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialCenterResp, err error) {
  98. o := orm.NewOrm()
  99. sql := ``
  100. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,
  101. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  102. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  103. FROM cygx_yanxuan_special AS a
  104. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  105. WHERE 1=1 `
  106. if condition != "" {
  107. sql += condition
  108. }
  109. sql += `ORDER BY a.publish_time DESC `
  110. _, err = o.Raw(sql, userId, pars).QueryRows(&items)
  111. return
  112. }
  113. type EnableCygxYanxuanSpecialReq struct {
  114. Id int // 文章id
  115. Status int // 1通过2驳回
  116. Reason string //理由
  117. }
  118. func EnableYanxuanSpecial(id, status int, reason string) (err error) {
  119. o := orm.NewOrm()
  120. sql := ``
  121. sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  122. _, err = o.Raw(sql, status, reason, id).Exec()
  123. return
  124. }
  125. type SpecialListResp struct {
  126. List []*CygxYanxuanSpecialCenterResp
  127. IsAuthor bool
  128. }
  129. func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
  130. o := orm.NewOrm()
  131. sql := ``
  132. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  133. b.nick_name,b.real_name,b.special_name,
  134. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  135. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  136. FROM cygx_yanxuan_special AS a
  137. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  138. WHERE a.id=? `
  139. err = o.Raw(sql, userId, specialId).QueryRow(&item)
  140. return
  141. }
  142. type CygxYanxuanSpecialReq struct {
  143. Id int `orm:"column(id);pk"`
  144. Content string // 内容
  145. Tags string // 标签
  146. DoType int // 1保存 2发布
  147. ImgUrl string // 图片链接
  148. DocUrl string // 文档链接
  149. Title string // 标题
  150. Type int // 类型1:笔记,2:观点
  151. IndustryTags string // 行业标签
  152. CompanyTags string // 公司标签
  153. }
  154. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  155. o := orm.NewOrm()
  156. lastId, err = o.Insert(item)
  157. return
  158. }
  159. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  160. o := orm.NewOrm()
  161. sql := ``
  162. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,company_tags=?,industry_tags=?,img_url=?,doc_url=?,type=?,status=?,
  163. modify_time=NOW(),publish_time=NOW() WHERE id = ? `
  164. _, err = o.Raw(sql, item.Title, item.Content, item.CompanyTags, item.IndustryTags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.Id).Exec()
  165. return
  166. }
  167. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  168. o := orm.NewOrm()
  169. sql := ``
  170. if keyword == "" {
  171. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  172. } else {
  173. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  174. }
  175. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  176. return
  177. }
  178. type CancelPublishCygxYanxuanSpecialReq struct {
  179. Id int // 文章id
  180. }
  181. func CancelPublishYanxuanSpecial(id int) (err error) {
  182. o := orm.NewOrm()
  183. sql := ``
  184. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  185. _, err = o.Raw(sql, id).Exec()
  186. return
  187. }
  188. type DelCygxYanxuanSpecialReq struct {
  189. Id int // 文章id
  190. }
  191. func DelYanxuanSpecial(id int) (err error) {
  192. o := orm.NewOrm()
  193. sql := ``
  194. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  195. _, err = o.Raw(sql, id).Exec()
  196. return
  197. }
  198. type CygxYanxuanSpecialCheckReq struct {
  199. Content string // 内容
  200. ImgUrl []string // 图片
  201. }
  202. func GetYanxuanSpecialFollowUserById(specialId int) (items []int, err error) {
  203. o := orm.NewOrm()
  204. sql := ``
  205. sql = `SELECT b.user_id
  206. FROM cygx_yanxuan_special AS a
  207. JOIN cygx_yanxuan_special_follow AS b ON a.user_id = b.follow_user_id
  208. WHERE a.id=? `
  209. _, err = o.Raw(sql, specialId).QueryRows(&items)
  210. return
  211. }
  212. func GetYanxuanSpecialItemById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  213. o := orm.NewOrm()
  214. sql := ``
  215. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  216. b.nick_name,b.real_name,b.special_name
  217. FROM cygx_yanxuan_special AS a
  218. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  219. WHERE a.id=? `
  220. err = o.Raw(sql, specialId).QueryRow(&item)
  221. return
  222. }
  223. // 获取数量
  224. func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
  225. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special WHERE 1= 1 `
  226. if condition != "" {
  227. sqlCount += condition
  228. }
  229. o := orm.NewOrm()
  230. err = o.Raw(sqlCount, pars).QueryRow(&count)
  231. return
  232. }