cygx_yanxuan_special_user.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. // 根据用户ID获取专栏详情
  89. func GetCygxYanxuanSpecialAuthorByUserId(userId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  90. o := orm.NewOrm()
  91. sql := `SELECT * FROM cygx_yanxuan_special_author WHERE user_id = ? `
  92. err = o.Raw(sql, userId).QueryRow(&item)
  93. return
  94. }
  95. type SaveCygxYanxuanSpecialAuthorReq struct {
  96. UserId int // 用户ID
  97. SpecialName string // 专栏名称
  98. Introduction string // 介绍
  99. Label string // 标签
  100. NickName string // 昵称
  101. BgImg string // 背景图
  102. }
  103. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  104. o := orm.NewOrm()
  105. sql := ``
  106. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  107. ,modify_time=NOW() WHERE user_id = ? `
  108. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  109. return
  110. }
  111. // 获取数量
  112. func GetCygxYanxuanSpecialAuthorCount(condition string, pars []interface{}) (count int, err error) {
  113. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_author as a WHERE 1= 1 `
  114. if condition != "" {
  115. sqlCount += condition
  116. }
  117. o := orm.NewOrm()
  118. err = o.Raw(sqlCount, pars).QueryRow(&count)
  119. return
  120. }
  121. func GetYanxuanSpecialAuthorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialAuthorItem, err error) {
  122. o := orm.NewOrm()
  123. sql := ``
  124. sql = `SELECT
  125. a.*,
  126. 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
  127. FROM
  128. cygx_yanxuan_special_author AS a
  129. WHERE 1= 1 `
  130. if condition != "" {
  131. sql += condition
  132. }
  133. sql += ` LIMIT ?,? `
  134. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  135. return
  136. }
  137. type SpecialAuthorListResp struct {
  138. Paging *paging.PagingItem `description:"分页数据"`
  139. List []*CygxYanxuanSpecialAuthorItem
  140. IsAuthor bool
  141. }
  142. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  143. UserId int // 用户ID
  144. HeadImg string // 头像
  145. }
  146. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  147. o := orm.NewOrm()
  148. sql := ``
  149. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW(),has_change_head_img = 1 WHERE user_id = ? `
  150. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  151. return
  152. }
  153. // UpdateCygxYanxuanSpecialAuthorPv 修改研选专栏作者的阅读Pv
  154. func UpdateCygxYanxuanSpecialAuthorPv(userId int) (err error) {
  155. o := orm.NewOrm()
  156. sql := ``
  157. sql = `UPDATE cygx_yanxuan_special_author SET pv=pv+1 WHERE user_id = ? `
  158. _, err = o.Raw(sql, userId).Exec()
  159. return
  160. }
  161. // UpdateCygxYanxuanSpecialAuthorUv 修改研选专栏作者的阅读Uv
  162. func UpdateCygxYanxuanSpecialAuthorUv(userId int) (err error) {
  163. o := orm.NewOrm()
  164. sql := ``
  165. sql = `UPDATE cygx_yanxuan_special_author SET uv=uv+1 WHERE user_id = ? `
  166. _, err = o.Raw(sql, userId).Exec()
  167. return
  168. }
  169. // 增加收藏数量
  170. func UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(userId int) (err error) {
  171. o := orm.NewOrm()
  172. sql := ``
  173. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num +1 WHERE id = ? `
  174. _, err = o.Raw(sql, userId).Exec()
  175. return
  176. }
  177. // 减少收藏数量
  178. func UpdateYanxuanSpecialAuthorArticleCollectNumReduce(userId int) (err error) {
  179. o := orm.NewOrm()
  180. sql := ``
  181. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  182. _, err = o.Raw(sql, userId).Exec()
  183. return
  184. }
  185. // 更新收藏数量
  186. func UpdateYanxuanSpecialAuthorArticleCollectNum(collectNum, userId int) (err error) {
  187. o := orm.NewOrm()
  188. sql := ``
  189. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = ? WHERE user_id = ? `
  190. _, err = o.Raw(sql, collectNum, userId).Exec()
  191. return
  192. }
  193. // 增加粉丝数量
  194. func UpdateYanxuanSpecialAuthorFansNumIncrease(userId int) (err error) {
  195. o := orm.NewOrm()
  196. sql := ``
  197. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num +1 WHERE id = ? `
  198. _, err = o.Raw(sql, userId).Exec()
  199. return
  200. }
  201. // 减少粉丝数量
  202. func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
  203. o := orm.NewOrm()
  204. sql := ``
  205. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num - 1 WHERE id = ? `
  206. _, err = o.Raw(sql, userId).Exec()
  207. return
  208. }
  209. // 更新粉丝数量
  210. func UpdateYanxuanSpecialAuthorFansNum(fansNum, userId int) (err error) {
  211. o := orm.NewOrm()
  212. sql := ``
  213. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = ? WHERE user_id = ? `
  214. _, err = o.Raw(sql, fansNum, userId).Exec()
  215. return
  216. }
  217. // 更新作者发布文章的数量
  218. func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
  219. o := orm.NewOrm()
  220. sql := ``
  221. sql = `UPDATE cygx_yanxuan_special_author SET article_num = ? WHERE user_id = ? `
  222. _, err = o.Raw(sql, articleNum, userId).Exec()
  223. return
  224. }
  225. func UpdateYanxuanSpecialauthorPvNUm(pv, userId int) (err error) {
  226. o := orm.NewOrm()
  227. sql := `UPDATE cygx_yanxuan_special_author SET pv = ? WHERE user_id = ? `
  228. _, err = o.Raw(sql, pv, userId).Exec()
  229. return
  230. }
  231. func UpdateYanxuanSpecialauthorUvUm(pv, userId int) (err error) {
  232. o := orm.NewOrm()
  233. sql := `UPDATE cygx_yanxuan_special_author SET uv = ? WHERE user_id = ? `
  234. _, err = o.Raw(sql, pv, userId).Exec()
  235. return
  236. }