cygx_yanxuan_special_user.go 10 KB

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