cygx_yanxuan_special.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. func GetYanxuanSpecialBySpecialId(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  145. o := orm.NewOrm()
  146. sql := ``
  147. sql = `SELECT a.*
  148. FROM cygx_yanxuan_special AS a
  149. WHERE a.id=? `
  150. err = o.Raw(sql, specialId).QueryRow(&item)
  151. return
  152. }
  153. type CygxYanxuanSpecialReq struct {
  154. Id int `orm:"column(id);pk"`
  155. Content string // 内容
  156. Tags string // 标签
  157. DoType int // 1保存 2发布
  158. ImgUrl string // 图片链接
  159. DocUrl string // 文档链接
  160. Title string // 标题
  161. Type int // 类型1:笔记,2:观点
  162. IndustryTags string // 行业标签
  163. CompanyTags string // 公司标签
  164. }
  165. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  166. o := orm.NewOrm()
  167. lastId, err = o.Insert(item)
  168. return
  169. }
  170. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  171. o := orm.NewOrm()
  172. sql := ``
  173. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,company_tags=?,industry_tags=?,img_url=?,doc_url=?,type=?,status=?,
  174. modify_time=NOW(),publish_time=NOW() WHERE id = ? `
  175. _, err = o.Raw(sql, item.Title, item.Content, item.CompanyTags, item.IndustryTags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.Id).Exec()
  176. return
  177. }
  178. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  179. o := orm.NewOrm()
  180. sql := ``
  181. if keyword == "" {
  182. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  183. } else {
  184. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  185. }
  186. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  187. return
  188. }
  189. type CancelPublishCygxYanxuanSpecialReq struct {
  190. Id int // 文章id
  191. }
  192. func CancelPublishYanxuanSpecial(id int) (err error) {
  193. o := orm.NewOrm()
  194. sql := ``
  195. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  196. _, err = o.Raw(sql, id).Exec()
  197. return
  198. }
  199. type DelCygxYanxuanSpecialReq struct {
  200. Id int // 文章id
  201. }
  202. func DelYanxuanSpecial(id int) (err error) {
  203. o := orm.NewOrm()
  204. sql := ``
  205. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  206. _, err = o.Raw(sql, id).Exec()
  207. return
  208. }
  209. type CygxYanxuanSpecialCheckReq struct {
  210. Content string // 内容
  211. ImgUrl []string // 图片
  212. }
  213. func GetYanxuanSpecialFollowUserById(specialId int) (items []int, err error) {
  214. o := orm.NewOrm()
  215. sql := ``
  216. sql = `SELECT b.user_id
  217. FROM cygx_yanxuan_special AS a
  218. JOIN cygx_yanxuan_special_follow AS b ON a.user_id = b.follow_user_id
  219. WHERE a.id=? `
  220. _, err = o.Raw(sql, specialId).QueryRows(&items)
  221. return
  222. }
  223. func GetYanxuanSpecialItemById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  224. o := orm.NewOrm()
  225. sql := ``
  226. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  227. b.nick_name,b.real_name,b.special_name
  228. FROM cygx_yanxuan_special AS a
  229. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  230. WHERE a.id=? `
  231. err = o.Raw(sql, specialId).QueryRow(&item)
  232. return
  233. }
  234. // 获取数量
  235. func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
  236. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special WHERE 1= 1 `
  237. if condition != "" {
  238. sqlCount += condition
  239. }
  240. o := orm.NewOrm()
  241. err = o.Raw(sqlCount, pars).QueryRow(&count)
  242. return
  243. }