cygx_yanxuan_special.go 9.5 KB

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