cygx_yanxuan_special_user.go 9.8 KB

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