cygx_yanxuan_special_user.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.*,c.company_name,
  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
  73. LEFT JOIN wx_user AS u ON u.user_id = a.user_id
  74. LEFT JOIN company AS c ON c.company_id = u.company_id WHERE a.user_id=? `
  75. if cond != "" {
  76. sql += cond
  77. }
  78. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  79. return
  80. }
  81. type SaveCygxYanxuanSpecialAuthorReq struct {
  82. UserId int // 用户ID
  83. SpecialName string // 专栏名称
  84. Introduction string // 介绍
  85. Label string // 标签
  86. NickName string // 昵称
  87. BgImg string // 背景图
  88. }
  89. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  90. o := orm.NewOrm()
  91. sql := ``
  92. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  93. ,modify_time=NOW() WHERE user_id = ? `
  94. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  95. return
  96. }
  97. func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
  98. o := orm.NewOrm()
  99. sql := ``
  100. sql = `SELECT
  101. a.*,
  102. c.company_name,
  103. 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
  104. FROM
  105. cygx_yanxuan_special_author AS a
  106. INNER JOIN wx_user AS u ON u.user_id = a.user_id
  107. INNER JOIN company AS c ON c.company_id = u.company_id
  108. WHERE
  109. a.nick_name <> ''
  110. ORDER BY
  111. latest_publish_time DESC `
  112. _, err = o.Raw(sql).QueryRows(&items)
  113. return
  114. }
  115. type SpecialAuthorListResp struct {
  116. List []*CygxYanxuanSpecialAuthorItem
  117. IsAuthor bool
  118. }
  119. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  120. UserId int // 用户ID
  121. HeadImg string // 头像
  122. }
  123. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  124. o := orm.NewOrm()
  125. sql := ``
  126. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW() WHERE user_id = ? `
  127. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  128. return
  129. }