cygx_yanxuan_special_user.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. MomentsImg string `description:"分享到朋友圈的封面图片"`
  47. YanxuanSpecialCenter *CygxYanxuanSpecialCenterAuthorResp // 研选专栏文章内容
  48. }
  49. type CygxYanxuanSpecialCenterAuthorResp struct {
  50. Id int //研选专栏ID
  51. UserId int // 用户ID
  52. PublishTime string // 提审过审或驳回时间
  53. Title string // 标题
  54. }
  55. func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
  56. o := orm.NewOrm()
  57. lastId, err = o.Insert(item)
  58. return
  59. }
  60. type EnableCygxYanxuanSpecialAuthorReq struct {
  61. UserId int // 用户ID
  62. Status int // 1启用2禁用
  63. }
  64. // 启用禁用作者
  65. func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
  66. o := orm.NewOrm()
  67. sql := ``
  68. sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
  69. _, err = o.Raw(sql, status, userId).Exec()
  70. return
  71. }
  72. func GetYanxuanSpecialAuthor(reqUserId, sysUserId int, cond string) (item *CygxYanxuanSpecialAuthorItem, err error) {
  73. o := orm.NewOrm()
  74. sql := ``
  75. sql = `SELECT
  76. a.*,
  77. ( 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,
  78. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  79. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  80. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id =? AND cf.user_id = ? ) AS is_follow
  81. FROM
  82. cygx_yanxuan_special_author as a WHERE a.user_id=? `
  83. if cond != "" {
  84. sql += cond
  85. }
  86. err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
  87. return
  88. }
  89. // 根据用户ID获取专栏详情
  90. func GetCygxYanxuanSpecialAuthorByUserId(userId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT * FROM cygx_yanxuan_special_author WHERE user_id = ? `
  93. err = o.Raw(sql, userId).QueryRow(&item)
  94. return
  95. }
  96. type SaveCygxYanxuanSpecialAuthorReq struct {
  97. UserId int // 用户ID
  98. SpecialName string // 专栏名称
  99. Introduction string // 介绍
  100. Label string // 标签
  101. NickName string // 昵称
  102. BgImg string // 背景图
  103. }
  104. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  105. o := orm.NewOrm()
  106. sql := ``
  107. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  108. ,modify_time=NOW() WHERE user_id = ? `
  109. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
  110. return
  111. }
  112. // 获取数量
  113. func GetCygxYanxuanSpecialAuthorCount(condition string, pars []interface{}) (count int, err error) {
  114. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_author as a WHERE 1= 1 `
  115. if condition != "" {
  116. sqlCount += condition
  117. }
  118. o := orm.NewOrm()
  119. err = o.Raw(sqlCount, pars).QueryRow(&count)
  120. return
  121. }
  122. func GetYanxuanSpecialAuthorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialAuthorItem, err error) {
  123. o := orm.NewOrm()
  124. sql := ``
  125. sql = `SELECT
  126. a.*,
  127. 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
  128. FROM
  129. cygx_yanxuan_special_author AS a
  130. WHERE 1= 1 `
  131. if condition != "" {
  132. sql += condition
  133. }
  134. sql += ` LIMIT ?,? `
  135. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  136. return
  137. }
  138. type SpecialAuthorListResp struct {
  139. Paging *paging.PagingItem `description:"分页数据"`
  140. List []*CygxYanxuanSpecialAuthorItem
  141. IsAuthor bool
  142. }
  143. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  144. UserId int // 用户ID
  145. HeadImg string // 头像
  146. }
  147. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  148. o := orm.NewOrm()
  149. sql := ``
  150. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW(),has_change_head_img = 1 WHERE user_id = ? `
  151. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  152. return
  153. }
  154. // UpdateCygxYanxuanSpecialAuthorPv 修改研选专栏作者的阅读Pv
  155. func UpdateCygxYanxuanSpecialAuthorPv(userId int) (err error) {
  156. o := orm.NewOrm()
  157. sql := ``
  158. sql = `UPDATE cygx_yanxuan_special_author SET pv=pv+1 WHERE user_id = ? `
  159. _, err = o.Raw(sql, userId).Exec()
  160. return
  161. }
  162. // UpdateCygxYanxuanSpecialAuthorUv 修改研选专栏作者的阅读Uv
  163. func UpdateCygxYanxuanSpecialAuthorUv(userId int) (err error) {
  164. o := orm.NewOrm()
  165. sql := ``
  166. sql = `UPDATE cygx_yanxuan_special_author SET uv=uv+1 WHERE user_id = ? `
  167. _, err = o.Raw(sql, userId).Exec()
  168. return
  169. }
  170. // 增加收藏数量
  171. func UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(userId int) (err error) {
  172. o := orm.NewOrm()
  173. sql := ``
  174. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num +1 WHERE id = ? `
  175. _, err = o.Raw(sql, userId).Exec()
  176. return
  177. }
  178. // 减少收藏数量
  179. func UpdateYanxuanSpecialAuthorArticleCollectNumReduce(userId int) (err error) {
  180. o := orm.NewOrm()
  181. sql := ``
  182. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  183. _, err = o.Raw(sql, userId).Exec()
  184. return
  185. }
  186. // 更新收藏数量
  187. func UpdateYanxuanSpecialAuthorArticleCollectNum(collectNum, userId int) (err error) {
  188. o := orm.NewOrm()
  189. sql := ``
  190. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = ? WHERE user_id = ? `
  191. _, err = o.Raw(sql, collectNum, userId).Exec()
  192. return
  193. }
  194. // 增加粉丝数量
  195. func UpdateYanxuanSpecialAuthorFansNumIncrease(userId int) (err error) {
  196. o := orm.NewOrm()
  197. sql := ``
  198. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num +1 WHERE id = ? `
  199. _, err = o.Raw(sql, userId).Exec()
  200. return
  201. }
  202. // 减少粉丝数量
  203. func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
  204. o := orm.NewOrm()
  205. sql := ``
  206. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num - 1 WHERE id = ? `
  207. _, err = o.Raw(sql, userId).Exec()
  208. return
  209. }
  210. // 更新粉丝数量
  211. func UpdateYanxuanSpecialAuthorFansNum(fansNum, userId int) (err error) {
  212. o := orm.NewOrm()
  213. sql := ``
  214. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = ? WHERE user_id = ? `
  215. _, err = o.Raw(sql, fansNum, userId).Exec()
  216. return
  217. }
  218. // 更新作者发布文章的数量
  219. func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
  220. o := orm.NewOrm()
  221. sql := ``
  222. sql = `UPDATE cygx_yanxuan_special_author SET article_num = ? ,article_publish_time = NOW(), modify_time = NOW() WHERE user_id = ? `
  223. _, err = o.Raw(sql, articleNum, userId).Exec()
  224. return
  225. }
  226. func UpdateYanxuanSpecialauthorPvNUm(pv, userId int) (err error) {
  227. o := orm.NewOrm()
  228. sql := `UPDATE cygx_yanxuan_special_author SET pv = ? WHERE user_id = ? `
  229. _, err = o.Raw(sql, pv, userId).Exec()
  230. return
  231. }
  232. func UpdateYanxuanSpecialauthorUvUm(pv, userId int) (err error) {
  233. o := orm.NewOrm()
  234. sql := `UPDATE cygx_yanxuan_special_author SET uv = ? WHERE user_id = ? `
  235. _, err = o.Raw(sql, pv, userId).Exec()
  236. return
  237. }
  238. // 更新作者分享到朋友圈的封面图片
  239. func UpdateYanxuanSpecialauthorMomentsImg(momentsImg string, userId int) (err error) {
  240. o := orm.NewOrm()
  241. sql := `UPDATE cygx_yanxuan_special_author SET moments_img = ? WHERE user_id = ? `
  242. _, err = o.Raw(sql, momentsImg, userId).Exec()
  243. return
  244. }