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. 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. Status int // 1启用2禁用
  36. CollectNum int // 被收藏数
  37. FollowNum int // 被关注数
  38. SpecialArticleNum int // 文章数
  39. LatestPublishTime time.Time // 最近更新时间
  40. LatestPublishDate string // 最近更新时间
  41. IsFollow int // 是否已关注 1已关注 0 未关注
  42. }
  43. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  44. o := orm.NewOrm()
  45. lastId, err = o.Insert(item)
  46. return
  47. }
  48. type EnableCygxYanxuanSpecialAuthorReq struct {
  49. UserId int // 用户ID
  50. Status int // 1启用2禁用
  51. }
  52. // 启用禁用作者
  53. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  54. o := orm.NewOrm()
  55. sql := ``
  56. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  57. _, err = o.Raw(sql, status, userId).Exec()
  58. return
  59. }
  60. func GetYanxuanSpecialAuthor(reqUserId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  61. o := orm.NewOrm()
  62. sql := ``
  63. sql = `SELECT
  64. a.*,c.company_name,
  65. ( 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,
  66. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  67. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  68. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id =? AND cf.user_id = ? ) AS is_follow
  69. FROM
  70. cygx_yanxuan_special_author as a
  71. LEFT JOIN wx_user AS u ON u.user_id = a.user_id
  72. LEFT JOIN company AS c ON c.company_id = u.company_id WHERE a.user_id=? `
  73. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  74. return
  75. }
  76. type SaveCygxYanxuanSpecialAuthorReq struct {
  77. UserId int // 用户ID
  78. SpecialName string // 专栏名称
  79. Introduction string // 介绍
  80. Label string // 标签
  81. NickName string // 昵称
  82. BgImg string // 背景图
  83. }
  84. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  85. o := orm.NewOrm()
  86. sql := ``
  87. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  88. ,modify_time=NOW() WHERE user_id = ? `
  89. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  90. return
  91. }
  92. func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
  93. o := orm.NewOrm()
  94. sql := ``
  95. sql = `SELECT
  96. a.*,
  97. c.company_name,
  98. ( SELECT publish_time FROM cygx_yanxuan_special WHERE user_id = a.user_id AND STATUS = 3 ORDER BY publish_time DESC LIMIT 1 ) AS latest_publish_time
  99. FROM
  100. cygx_yanxuan_special_author AS a
  101. INNER JOIN wx_user AS u ON u.user_id = a.user_id
  102. INNER JOIN company AS c ON c.company_id = u.company_id
  103. WHERE
  104. a.nick_name <> ''
  105. AND a.STATUS = 1
  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() WHERE user_id = ? `
  123. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  124. return
  125. }