cygx_yanxuan_special.go 12 KB

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