cygx_yanxuan_special.go 8.1 KB

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