cygx_yanxuan_special_user.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type CygxYanxuanSpecialAuthor struct {
  8. Id int `orm:"column(id);pk"`
  9. UserId int // 用户ID
  10. SpecialName string // 专栏名称
  11. Introduction string // 介绍
  12. Label string // 标签
  13. NickName string // 昵称
  14. RealName string // 姓名
  15. Mobile string // 手机号
  16. CreateTime time.Time // 创建时间
  17. ModifyTime time.Time // 修改时间
  18. HeadImg string // 头像
  19. BgImg string // 背景图上部分
  20. BgImgDown string // 背景图下部分
  21. Status int // 1启用2禁用
  22. }
  23. type CygxYanxuanSpecialAuthorItem struct {
  24. Id int `orm:"column(id);pk"`
  25. UserId int // 用户ID
  26. SpecialName string // 专栏名称
  27. Introduction string // 介绍
  28. Label string // 标签
  29. NickName string // 昵称
  30. RealName string // 姓名
  31. CompanyName string // 公司名
  32. Mobile string // 手机号
  33. CreateTime string // 创建时间
  34. ModifyTime time.Time // 修改时间
  35. HeadImg string // 头像
  36. BgImg string // 背景图
  37. BgImgDown string // 背景图下半部分
  38. Status int // 1启用2禁用
  39. CollectNum int // 被收藏数
  40. FollowNum int // 被关注数
  41. SpecialArticleNum int // 文章数
  42. LatestPublishTime time.Time // 最近更新时间
  43. LatestPublishDate string // 最近更新时间
  44. IsFollow int // 是否已关注 1已关注 0 未关注
  45. HasChangeHeadImg int // 是否更换过默认头像 1是,0否
  46. YanxuanSpecialCenter *CygxYanxuanSpecialCenterAuthorResp // 研选专栏文章内容
  47. }
  48. type CygxYanxuanSpecialCenterAuthorResp struct {
  49. Id int //研选专栏ID
  50. UserId int // 用户ID
  51. PublishTime string // 提审过审或驳回时间
  52. Title string // 标题
  53. }
  54. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  55. o := orm.NewOrm()
  56. lastId, err = o.Insert(item)
  57. return
  58. }
  59. type EnableCygxYanxuanSpecialAuthorReq struct {
  60. UserId int // 用户ID
  61. Status int // 1启用2禁用
  62. }
  63. // 启用禁用作者
  64. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  65. o := orm.NewOrm()
  66. sql := ``
  67. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  68. _, err = o.Raw(sql, status, userId).Exec()
  69. return
  70. }
  71. func GetYanxuanSpecialAuthor(reqUserId, sysUserId int, cond string) (item *CygxYanxuanSpecialAuthorItem, err error) {
  72. o := orm.NewOrm()
  73. sql := ``
  74. sql = `SELECT
  75. a.*,
  76. ( 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,
  77. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  78. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  79. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id =? AND cf.user_id = ? ) AS is_follow
  80. FROM
  81. cygx_yanxuan_special_author as a WHERE a.user_id=? `
  82. if cond != "" {
  83. sql += cond
  84. }
  85. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  86. return
  87. }
  88. type SaveCygxYanxuanSpecialAuthorReq struct {
  89. UserId int // 用户ID
  90. SpecialName string // 专栏名称
  91. Introduction string // 介绍
  92. Label string // 标签
  93. NickName string // 昵称
  94. BgImg string // 背景图
  95. }
  96. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  97. o := orm.NewOrm()
  98. sql := ``
  99. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  100. ,modify_time=NOW() WHERE user_id = ? `
  101. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  102. return
  103. }
  104. // 获取数量
  105. func GetCygxYanxuanSpecialAuthorCount(condition string, pars []interface{}) (count int, err error) {
  106. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_author as a WHERE 1= 1 `
  107. if condition != "" {
  108. sqlCount += condition
  109. }
  110. o := orm.NewOrm()
  111. err = o.Raw(sqlCount, pars).QueryRow(&count)
  112. return
  113. }
  114. func GetYanxuanSpecialAuthorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialAuthorItem, err error) {
  115. o := orm.NewOrm()
  116. sql := ``
  117. sql = `SELECT
  118. a.*,
  119. 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
  120. FROM
  121. cygx_yanxuan_special_author AS a
  122. WHERE 1= 1 `
  123. if condition != "" {
  124. sql += condition
  125. }
  126. sql += ` LIMIT ?,? `
  127. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  128. return
  129. }
  130. type SpecialAuthorListResp struct {
  131. Paging *paging.PagingItem `description:"分页数据"`
  132. List []*CygxYanxuanSpecialAuthorItem
  133. IsAuthor bool
  134. }
  135. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  136. UserId int // 用户ID
  137. HeadImg string // 头像
  138. }
  139. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  140. o := orm.NewOrm()
  141. sql := ``
  142. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW(),has_change_head_img = 1 WHERE user_id = ? `
  143. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  144. return
  145. }