cygx_yanxuan_special.go 13 KB

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