cygx_yanxuan_special.go 12 KB

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