cygx_yanxuan_special_user.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxYanxuanSpecialAuthor struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int // 用户ID
  9. SpecialName string // 专栏名称
  10. Introduction string // 介绍
  11. Label string // 标签
  12. NickName string // 昵称
  13. RealName string // 姓名
  14. Mobile string // 手机号
  15. CreateTime time.Time // 创建时间
  16. ModifyTime time.Time // 修改时间
  17. HeadImg string // 头像
  18. BgImg string // 背景图
  19. Status int // 1启用2禁用
  20. }
  21. type CygxYanxuanSpecialAuthorItem struct {
  22. Id int `orm:"column(id);pk"`
  23. UserId int // 用户ID
  24. SpecialName string // 专栏名称
  25. Introduction string // 介绍
  26. Label string // 标签
  27. NickName string // 昵称
  28. RealName string // 姓名
  29. CompanyName string // 公司名
  30. Mobile string // 手机号
  31. CreateTime string // 创建时间
  32. ModifyTime time.Time // 修改时间
  33. HeadImg string // 头像
  34. BgImg string // 背景图
  35. BgImgPc string // 背景图
  36. Status int // 1启用2禁用
  37. CollectNum int // 被收藏数
  38. FollowNum int // 被关注数
  39. SpecialArticleNum int // 文章数
  40. LatestPublishTime time.Time // 最近更新时间
  41. LatestPublishDate string // 最近更新时间
  42. IsFollow int // 是否已关注 1已关注 0 未关注
  43. }
  44. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  45. o := orm.NewOrm()
  46. lastId, err = o.Insert(item)
  47. return
  48. }
  49. type EnableCygxYanxuanSpecialAuthorReq struct {
  50. UserId int // 用户ID
  51. Status int // 1启用2禁用
  52. }
  53. // 启用禁用作者
  54. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  55. o := orm.NewOrm()
  56. sql := ``
  57. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  58. _, err = o.Raw(sql, status, userId).Exec()
  59. return
  60. }
  61. func GetYanxuanSpecialAuthor(reqUserId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  62. o := orm.NewOrm()
  63. sql := ``
  64. sql = `SELECT
  65. a.*,
  66. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac INNER JOIN cygx_yanxuan_special as cs ON ac.yanxuan_special_id = cs.id WHERE cs.user_id = a.user_id ) AS collect_num,
  67. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  68. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  69. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id =? AND cf.user_id = ? ) AS is_follow
  70. FROM
  71. cygx_yanxuan_special_author as a WHERE a.user_id=? `
  72. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  73. return
  74. }
  75. func GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  76. o := orm.NewOrm()
  77. sql := ``
  78. sql = `SELECT
  79. a.*,
  80. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac INNER JOIN cygx_yanxuan_special as cs ON ac.yanxuan_special_id = cs.id WHERE cs.user_id = a.user_id ) AS collect_num,
  81. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  82. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  83. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf INNER JOIN cygx_yanxuan_special_author AS ca ON cf.follow_user_id=ca.user_id
  84. WHERE cf.user_id = ? AND ca.id = ? ) AS is_follow
  85. FROM
  86. cygx_yanxuan_special_author as a
  87. WHERE a.id=? `
  88. err = o.Raw(sql, sysUserId, specialColumnId, specialColumnId).QueryRow(&item)
  89. return
  90. }
  91. type SaveCygxYanxuanSpecialAuthorReq struct {
  92. SpecialColumnId int // 专栏栏目ID
  93. SpecialName string // 专栏名称
  94. Introduction string // 介绍
  95. Label string // 标签
  96. NickName string // 昵称
  97. BgImg string // 背景图
  98. }
  99. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  100. o := orm.NewOrm()
  101. sql := ``
  102. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  103. ,modify_time=NOW() WHERE id = ? `
  104. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.Id).Exec()
  105. return
  106. }
  107. func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
  108. o := orm.NewOrm()
  109. sql := ``
  110. sql = `SELECT
  111. a.*,
  112. IFNULL(( SELECT publish_time FROM cygx_yanxuan_special WHERE user_id = a.user_id AND STATUS = 3 ORDER BY publish_time DESC LIMIT 1 ), a.modify_time) AS latest_publish_time
  113. FROM
  114. cygx_yanxuan_special_author AS a
  115. WHERE
  116. a.nick_name <> ''
  117. ORDER BY
  118. latest_publish_time DESC `
  119. _, err = o.Raw(sql).QueryRows(&items)
  120. return
  121. }
  122. type SpecialAuthorListResp struct {
  123. List []*CygxYanxuanSpecialAuthorItem
  124. IsAuthor bool
  125. }
  126. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  127. SpecialColumnId int // 专栏栏目ID
  128. HeadImg string // 头像
  129. }
  130. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  131. o := orm.NewOrm()
  132. sql := ``
  133. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW() WHERE id = ? `
  134. _, err = o.Raw(sql, item.HeadImg, item.Id).Exec()
  135. return
  136. }
  137. func GetYanxuanSpecialAuthorById(specialColumnId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  138. o := orm.NewOrm()
  139. sql := ``
  140. sql = `SELECT * FROM cygx_yanxuan_special_author WHERE id = ? `
  141. err = o.Raw(sql, specialColumnId).QueryRow(&item)
  142. return
  143. }