cygx_yanxuan_special_user.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. MomentsImg string `description:"分享到朋友圈的封面图片"`
  143. }
  144. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  145. UserId int // 用户ID
  146. HeadImg string // 头像
  147. }
  148. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  149. o := orm.NewOrm()
  150. sql := ``
  151. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW(),has_change_head_img = 1 WHERE user_id = ? `
  152. _, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
  153. return
  154. }
  155. // UpdateCygxYanxuanSpecialAuthorPv 修改研选专栏作者的阅读Pv
  156. func UpdateCygxYanxuanSpecialAuthorPv(userId int) (err error) {
  157. o := orm.NewOrm()
  158. sql := ``
  159. sql = `UPDATE cygx_yanxuan_special_author SET pv=pv+1 WHERE user_id = ? `
  160. _, err = o.Raw(sql, userId).Exec()
  161. return
  162. }
  163. // UpdateCygxYanxuanSpecialAuthorUv 修改研选专栏作者的阅读Uv
  164. func UpdateCygxYanxuanSpecialAuthorUv(userId int) (err error) {
  165. o := orm.NewOrm()
  166. sql := ``
  167. sql = `UPDATE cygx_yanxuan_special_author SET uv=uv+1 WHERE user_id = ? `
  168. _, err = o.Raw(sql, userId).Exec()
  169. return
  170. }
  171. // 增加收藏数量
  172. func UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(userId int) (err error) {
  173. o := orm.NewOrm()
  174. sql := ``
  175. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num +1 WHERE id = ? `
  176. _, err = o.Raw(sql, userId).Exec()
  177. return
  178. }
  179. // 减少收藏数量
  180. func UpdateYanxuanSpecialAuthorArticleCollectNumReduce(userId int) (err error) {
  181. o := orm.NewOrm()
  182. sql := ``
  183. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  184. _, err = o.Raw(sql, userId).Exec()
  185. return
  186. }
  187. // 更新收藏数量
  188. func UpdateYanxuanSpecialAuthorArticleCollectNum(collectNum, userId int) (err error) {
  189. o := orm.NewOrm()
  190. sql := ``
  191. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = ? WHERE user_id = ? `
  192. _, err = o.Raw(sql, collectNum, userId).Exec()
  193. return
  194. }
  195. // 增加粉丝数量
  196. func UpdateYanxuanSpecialAuthorFansNumIncrease(userId int) (err error) {
  197. o := orm.NewOrm()
  198. sql := ``
  199. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num +1 WHERE id = ? `
  200. _, err = o.Raw(sql, userId).Exec()
  201. return
  202. }
  203. // 减少粉丝数量
  204. func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
  205. o := orm.NewOrm()
  206. sql := ``
  207. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num - 1 WHERE id = ? `
  208. _, err = o.Raw(sql, userId).Exec()
  209. return
  210. }
  211. // 更新粉丝数量
  212. func UpdateYanxuanSpecialAuthorFansNum(fansNum, userId int) (err error) {
  213. o := orm.NewOrm()
  214. sql := ``
  215. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = ? WHERE user_id = ? `
  216. _, err = o.Raw(sql, fansNum, userId).Exec()
  217. return
  218. }
  219. // 更新作者发布文章的数量
  220. func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
  221. o := orm.NewOrm()
  222. sql := ``
  223. sql = `UPDATE cygx_yanxuan_special_author SET article_num = ? WHERE user_id = ? `
  224. _, err = o.Raw(sql, articleNum, userId).Exec()
  225. return
  226. }
  227. func UpdateYanxuanSpecialauthorPvNUm(pv, userId int) (err error) {
  228. o := orm.NewOrm()
  229. sql := `UPDATE cygx_yanxuan_special_author SET pv = ? WHERE user_id = ? `
  230. _, err = o.Raw(sql, pv, userId).Exec()
  231. return
  232. }
  233. func UpdateYanxuanSpecialauthorUvUm(pv, userId int) (err error) {
  234. o := orm.NewOrm()
  235. sql := `UPDATE cygx_yanxuan_special_author SET uv = ? WHERE user_id = ? `
  236. _, err = o.Raw(sql, pv, userId).Exec()
  237. return
  238. }