cygx_yanxuan_special.go 9.7 KB

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