cygx_yanxuan_special_user.go 4.3 KB

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