cygx_yanxuan_special.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxYanxuanSpecial struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int // 用户ID
  9. CreateTime time.Time // 创建时间
  10. ModifyTime time.Time // 修改时间
  11. PublishTime time.Time // 提审过审或驳回时间
  12. Content string // 内容
  13. Tags string // 标签
  14. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  15. ImgUrl string // 图片链接
  16. DocUrl string // 文档链接
  17. Reason string // 理由
  18. Title string // 标题
  19. Type int // 类型1:笔记,2:观点
  20. }
  21. type CygxYanxuanSpecialItem struct {
  22. Id int `orm:"column(id);pk"`
  23. UserId int // 用户ID
  24. CreateTime string // 创建时间
  25. ModifyTime string // 修改时间
  26. PublishTime string // 提审过审或驳回时间
  27. Content string // 内容
  28. Tags string // 标签
  29. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  30. ImgUrl string // 图片链接
  31. DocUrl string // 文档链接
  32. SpecialName string // 专栏名称
  33. Introduction string // 介绍
  34. Label string // 标签
  35. NickName string // 昵称
  36. RealName string // 姓名
  37. Mobile string // 手机号
  38. HeadImg string // 头像
  39. BgImg string // 背景图
  40. Reason string // 理由
  41. Title string // 标题
  42. Type string // 类型1:笔记,2:观点
  43. }
  44. func GetYanxuanSpecialList(condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
  45. o := orm.NewOrm()
  46. sql := ``
  47. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name
  48. FROM cygx_yanxuan_special AS a
  49. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  50. WHERE 1=1 `
  51. if condition != "" {
  52. sql += condition
  53. }
  54. sql += `ORDER BY a.publish_time DESC `
  55. _, err = o.Raw(sql, pars).QueryRows(&items)
  56. return
  57. }
  58. type EnableCygxYanxuanSpecialReq struct {
  59. Id int // 文章id
  60. Status int // 1通过2驳回
  61. Reason string //理由
  62. }
  63. func EnableYanxuanSpecial(id, status int, reason string) (err error) {
  64. o := orm.NewOrm()
  65. sql := ``
  66. sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,publish_time=NOW() WHERE id = ? `
  67. _, err = o.Raw(sql, status, reason, id).Exec()
  68. return
  69. }
  70. type SpecialListResp struct {
  71. List []*CygxYanxuanSpecialItem
  72. IsAuthor bool
  73. }
  74. func GetYanxuanSpecialById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  75. o := orm.NewOrm()
  76. sql := ``
  77. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name
  78. FROM cygx_yanxuan_special AS a
  79. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  80. WHERE a.id=? `
  81. err = o.Raw(sql, specialId).QueryRow(&item)
  82. return
  83. }
  84. type CygxYanxuanSpecialReq struct {
  85. Id int `orm:"column(id);pk"`
  86. UserId int // 用户ID
  87. Content string // 内容
  88. Tags string // 标签
  89. DoType int // 1保存 2发布
  90. ImgUrl string // 图片链接
  91. DocUrl string // 文档链接
  92. Title string // 标题
  93. Type int // 类型1:笔记,2:观点
  94. }
  95. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  96. o := orm.NewOrm()
  97. lastId, err = o.Insert(item)
  98. return
  99. }
  100. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  101. o := orm.NewOrm()
  102. sql := ``
  103. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,tags=?,img_url=?,doc_url=?,type=?,status=?,
  104. modify_time=NOW(),publish_time=NOW() WHERE id = ? `
  105. _, err = o.Raw(sql, item.Title, item.Content,item.Tags,item.ImgUrl,item.DocUrl,item.Type,item.Status).Exec()
  106. return
  107. }
  108. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  109. o := orm.NewOrm()
  110. sql := ``
  111. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%`+keyword+`%' `
  112. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  113. return
  114. }