cygx_yanxuan_special.go 11 KB

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