cygx_yanxuan_special_user.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }
  40. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  41. o := orm.NewOrm()
  42. lastId, err = o.Insert(item)
  43. return
  44. }
  45. type EnableCygxYanxuanSpecialAuthorReq struct {
  46. UserId int // 用户ID
  47. Status int // 1启用2禁用
  48. }
  49. // 启用禁用作者
  50. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  51. o := orm.NewOrm()
  52. sql := ``
  53. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  54. _, err = o.Raw(sql, status, userId).Exec()
  55. return
  56. }
  57. func GetYanxuanSpecialAuthor(userId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  58. o := orm.NewOrm()
  59. sql := ``
  60. sql = `SELECT
  61. a.*,c.company_name,
  62. ( 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,
  63. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  64. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id ) AS special_article_num
  65. FROM
  66. cygx_yanxuan_special_author as a
  67. INNER JOIN wx_user AS u ON u.user_id = a.user_id
  68. INNER JOIN company AS c ON c.company_id = u.company_id WHERE a.user_id=? `
  69. err = o.Raw(sql, userId).QueryRow(&item)
  70. return
  71. }
  72. type SaveCygxYanxuanSpecialAuthorReq struct {
  73. UserId int // 用户ID
  74. SpecialName string // 专栏名称
  75. Introduction string // 介绍
  76. Label string // 标签
  77. NickName string // 昵称
  78. BgImg string // 背景图
  79. }
  80. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  81. o := orm.NewOrm()
  82. sql := ``
  83. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  84. ,modify_time=NOW() WHERE user_id = ? `
  85. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  86. return
  87. }