cygx_yanxuan_special_user.go 7.3 KB

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