cygx_yanxuan_special.go 11 KB

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