cygx_yanxuan_special_user.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. BgImgDown string // 背景图下部分
  20. Status int // 1启用2禁用
  21. }
  22. type CygxYanxuanSpecialAuthorItem struct {
  23. Id int `orm:"column(id);pk"`
  24. UserId int // 用户ID
  25. SpecialName string // 专栏名称
  26. Introduction string // 介绍
  27. Label string // 标签
  28. NickName string // 昵称
  29. RealName string // 姓名
  30. CompanyName string // 公司名
  31. Mobile string // 手机号
  32. CreateTime string // 创建时间
  33. ModifyTime time.Time // 修改时间
  34. HeadImg string // 头像
  35. BgImg string // 背景图
  36. BgImgDown string // 背景图下半部分
  37. Status int // 1启用2禁用
  38. CollectNum int // 被收藏数
  39. FollowNum int // 被关注数
  40. SpecialArticleNum int // 文章数
  41. LatestPublishTime time.Time // 最近更新时间
  42. LatestPublishDate string // 最近更新时间
  43. IsFollow int // 是否已关注 1已关注 0 未关注
  44. HasChangeHeadImg int // 是否更换过默认头像 1是,0否
  45. }
  46. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  47. o := orm.NewOrm()
  48. lastId, err = o.Insert(item)
  49. return
  50. }
  51. type EnableCygxYanxuanSpecialAuthorReq struct {
  52. UserId int // 用户ID
  53. Status int // 1启用2禁用
  54. }
  55. // 启用禁用作者
  56. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  57. o := orm.NewOrm()
  58. sql := ``
  59. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  60. _, err = o.Raw(sql, status, userId).Exec()
  61. return
  62. }
  63. func GetYanxuanSpecialAuthor(reqUserId, sysUserId int, cond string) (item *CygxYanxuanSpecialAuthorItem, err error) {
  64. o := orm.NewOrm()
  65. sql := ``
  66. sql = `SELECT
  67. a.*,
  68. ( 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,
  69. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  70. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  71. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id =? AND cf.user_id = ? ) AS is_follow
  72. FROM
  73. cygx_yanxuan_special_author as a WHERE a.user_id=? `
  74. if cond != "" {
  75. sql += cond
  76. }
  77. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  78. return
  79. }
  80. type SaveCygxYanxuanSpecialAuthorReq struct {
  81. UserId int // 用户ID
  82. SpecialName string // 专栏名称
  83. Introduction string // 介绍
  84. Label string // 标签
  85. NickName string // 昵称
  86. BgImg string // 背景图
  87. }
  88. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  89. o := orm.NewOrm()
  90. sql := ``
  91. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  92. ,modify_time=NOW() WHERE user_id = ? `
  93. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  94. return
  95. }
  96. func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
  97. o := orm.NewOrm()
  98. sql := ``
  99. sql = `SELECT
  100. a.*,
  101. 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
  102. FROM
  103. cygx_yanxuan_special_author AS a
  104. WHERE
  105. a.nick_name <> ''
  106. ORDER BY
  107. latest_publish_time DESC `
  108. _, err = o.Raw(sql).QueryRows(&items)
  109. return
  110. }
  111. type SpecialAuthorListResp struct {
  112. List []*CygxYanxuanSpecialAuthorItem
  113. IsAuthor bool
  114. }
  115. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  116. UserId int // 用户ID
  117. HeadImg string // 头像
  118. }
  119. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  120. o := orm.NewOrm()
  121. sql := ``
  122. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW(),has_change_head_img = 1 WHERE user_id = ? `
  123. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  124. return
  125. }