cygx_yanxuan_special_user.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. }
  45. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  46. o := orm.NewOrm()
  47. lastId, err = o.Insert(item)
  48. return
  49. }
  50. type EnableCygxYanxuanSpecialAuthorReq struct {
  51. UserId int // 用户ID
  52. Status int // 1启用2禁用
  53. }
  54. // 启用禁用作者
  55. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  56. o := orm.NewOrm()
  57. sql := ``
  58. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  59. _, err = o.Raw(sql, status, userId).Exec()
  60. return
  61. }
  62. func GetYanxuanSpecialAuthor(reqUserId, sysUserId int,cond string) (item *CygxYanxuanSpecialAuthorItem, err error) {
  63. o := orm.NewOrm()
  64. sql := ``
  65. sql = `SELECT
  66. a.*,
  67. ( 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,
  68. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  69. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  70. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id =? AND cf.user_id = ? ) AS is_follow
  71. FROM
  72. cygx_yanxuan_special_author as a WHERE a.user_id=? `
  73. if cond != "" {
  74. sql += cond
  75. }
  76. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  77. return
  78. }
  79. type SaveCygxYanxuanSpecialAuthorReq struct {
  80. UserId int // 用户ID
  81. SpecialName string // 专栏名称
  82. Introduction string // 介绍
  83. Label string // 标签
  84. NickName string // 昵称
  85. BgImg string // 背景图
  86. }
  87. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  88. o := orm.NewOrm()
  89. sql := ``
  90. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  91. ,modify_time=NOW() WHERE user_id = ? `
  92. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  93. return
  94. }
  95. func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
  96. o := orm.NewOrm()
  97. sql := ``
  98. sql = `SELECT
  99. a.*,
  100. 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
  101. FROM
  102. cygx_yanxuan_special_author AS a
  103. WHERE
  104. a.nick_name <> ''
  105. ORDER BY
  106. latest_publish_time DESC `
  107. _, err = o.Raw(sql).QueryRows(&items)
  108. return
  109. }
  110. type SpecialAuthorListResp struct {
  111. List []*CygxYanxuanSpecialAuthorItem
  112. IsAuthor bool
  113. }
  114. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  115. UserId int // 用户ID
  116. HeadImg string // 头像
  117. }
  118. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  119. o := orm.NewOrm()
  120. sql := ``
  121. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW() WHERE user_id = ? `
  122. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  123. return
  124. }