cygx_yanxuan_special_user.go 9.7 KB

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