cygx_yanxuan_special_user.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. }
  39. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  40. o := orm.NewOrm()
  41. lastId, err = o.Insert(item)
  42. return
  43. }
  44. type EnableCygxYanxuanSpecialAuthorReq struct {
  45. UserId int // 用户ID
  46. Status int // 1启用2禁用
  47. }
  48. // 启用禁用作者
  49. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  50. o := orm.NewOrm()
  51. sql := ``
  52. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  53. _, err = o.Raw(sql, status, userId).Exec()
  54. return
  55. }
  56. func GetYanxuanSpecialAuthor(userId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  57. o := orm.NewOrm()
  58. sql := ``
  59. sql = `SELECT
  60. a.*,c.company_name,
  61. ( 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,
  62. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num
  63. FROM
  64. cygx_yanxuan_special_author as a
  65. INNER JOIN wx_user AS u ON u.user_id = a.user_id
  66. INNER JOIN company AS c ON c.company_id = u.company_id WHERE a.user_id=? `
  67. err = o.Raw(sql, userId).QueryRow(&item)
  68. return
  69. }
  70. type SaveCygxYanxuanSpecialAuthorReq struct {
  71. Id int
  72. UserId int // 用户ID
  73. SpecialName string // 专栏名称
  74. Introduction string // 介绍
  75. Label string // 标签
  76. NickName string // 昵称
  77. RealName string // 姓名
  78. Mobile string // 手机号
  79. CreateTime time.Time // 创建时间
  80. ModifyTime time.Time // 修改时间
  81. HeadImg 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. head_img=?,modify_time=NOW() WHERE id = ? `
  89. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.HeadImg).Exec()
  90. return
  91. }