cygx_yanxuan_special.go 12 KB

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