cygx_yanxuan_special.go 10 KB

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