cygx_yanxuan_special.go 10 KB

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