cygx_yanxuan_special_user.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. FansNum int // 粉丝数量
  45. LabelKeywordImgLink string `description:"标签关键词ico"`
  46. SpecialLikeCount int `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. func GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  97. o := orm.NewOrm()
  98. sql := ``
  99. sql = `SELECT
  100. a.*,
  101. ( 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,
  102. ( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf WHERE cf.follow_user_id = a.user_id ) AS follow_num,
  103. ( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
  104. ( 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
  105. WHERE cf.user_id = ? AND ca.id = ? ) AS is_follow
  106. FROM
  107. cygx_yanxuan_special_author as a
  108. WHERE a.id=? `
  109. err = o.Raw(sql, sysUserId, specialColumnId, specialColumnId).QueryRow(&item)
  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. type SaveCygxYanxuanSpecialAuthorReq struct {
  123. SpecialColumnId int // 专栏栏目ID
  124. SpecialName string // 专栏名称
  125. Introduction string // 介绍
  126. Label string // 标签
  127. NickName string // 昵称
  128. BgImg string // 背景图
  129. }
  130. func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
  131. o := orm.NewOrm()
  132. sql := ``
  133. sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
  134. ,modify_time=NOW() WHERE id = ? `
  135. _, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.Id).Exec()
  136. return
  137. }
  138. func GetYanxuanSpecialAuthorList(conditionUserSort, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialAuthorItem, err error) {
  139. o := orm.NewOrm()
  140. sql := ``
  141. sql = `SELECT ` + conditionUserSort +
  142. ` a.*, a.article_num as special_article_num, a.article_collect_num as collect_num,
  143. 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
  144. FROM
  145. cygx_yanxuan_special_author AS a
  146. WHERE 1= 1 `
  147. if condition != "" {
  148. sql += condition
  149. }
  150. sql += ` LIMIT ?,? `
  151. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  152. return
  153. }
  154. type SpecialAuthorListResp struct {
  155. Paging *paging.PagingItem `description:"分页数据"`
  156. List []*CygxYanxuanSpecialAuthorItem
  157. IsAuthor bool
  158. IsImproveInformation bool `description:"作者信息是否完善"`
  159. HeadImg string // 头像
  160. SpecialColumnId int // 专栏栏目ID
  161. }
  162. type SpecialAuthorCheckResp struct {
  163. IsAuthor bool
  164. IsImproveInformation bool `description:"作者信息是否完善"`
  165. HeadImg string // 头像
  166. SpecialColumnId int // 专栏栏目ID
  167. }
  168. type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
  169. Paging *paging.PagingItem `description:"分页数据"`
  170. SpecialColumnId int // 专栏栏目ID
  171. HeadImg string // 头像
  172. }
  173. func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
  174. o := orm.NewOrm()
  175. sql := ``
  176. sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW() WHERE id = ? `
  177. _, err = o.Raw(sql, item.HeadImg, item.Id).Exec()
  178. return
  179. }
  180. func GetYanxuanSpecialAuthorById(specialColumnId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
  181. o := orm.NewOrm()
  182. sql := ``
  183. sql = `SELECT * FROM cygx_yanxuan_special_author WHERE id = ? `
  184. err = o.Raw(sql, specialColumnId).QueryRow(&item)
  185. return
  186. }
  187. // UpdateCygxYanxuanSpecialAuthorPv 修改研选专栏作者的阅读Pv
  188. func UpdateCygxYanxuanSpecialAuthorPv(userId int) (err error) {
  189. o := orm.NewOrm()
  190. sql := ``
  191. sql = `UPDATE cygx_yanxuan_special_author SET pv=pv+1 WHERE user_id = ? `
  192. _, err = o.Raw(sql, userId).Exec()
  193. return
  194. }
  195. // UpdateCygxYanxuanSpecialAuthorUv 修改研选专栏作者的阅读Uv
  196. func UpdateCygxYanxuanSpecialAuthorUv(userId int) (err error) {
  197. o := orm.NewOrm()
  198. sql := ``
  199. sql = `UPDATE cygx_yanxuan_special_author SET uv=uv+1 WHERE user_id = ? `
  200. _, err = o.Raw(sql, userId).Exec()
  201. return
  202. }
  203. // 增加收藏数量
  204. func UpdateYanxuanSpecialAuthorArticleCollectNumIncrease(userId int) (err error) {
  205. o := orm.NewOrm()
  206. sql := ``
  207. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num +1 WHERE id = ? `
  208. _, err = o.Raw(sql, userId).Exec()
  209. return
  210. }
  211. // 减少收藏数量
  212. func UpdateYanxuanSpecialAuthorArticleCollectNumReduce(userId int) (err error) {
  213. o := orm.NewOrm()
  214. sql := ``
  215. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  216. _, err = o.Raw(sql, userId).Exec()
  217. return
  218. }
  219. // 增加粉丝数量
  220. func UpdateYanxuanSpecialAuthorFansNumIncrease(userId int) (err error) {
  221. o := orm.NewOrm()
  222. sql := ``
  223. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num +1 WHERE id = ? `
  224. _, err = o.Raw(sql, userId).Exec()
  225. return
  226. }
  227. // 减少粉丝数量
  228. func UpdateYanxuanSpecialAuthorFansNumReduce(userId int) (err error) {
  229. o := orm.NewOrm()
  230. sql := ``
  231. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = fans_num - 1 WHERE id = ? `
  232. _, err = o.Raw(sql, userId).Exec()
  233. return
  234. }
  235. // 更新收藏数量
  236. func UpdateYanxuanSpecialAuthorArticleCollectNum(collectNum, userId int) (err error) {
  237. o := orm.NewOrm()
  238. sql := ``
  239. sql = `UPDATE cygx_yanxuan_special_author SET article_collect_num = ? WHERE user_id = ? `
  240. _, err = o.Raw(sql, collectNum, userId).Exec()
  241. return
  242. }
  243. // 更新粉丝数量
  244. func UpdateYanxuanSpecialAuthorFansNum(fansNum, userId int) (err error) {
  245. o := orm.NewOrm()
  246. sql := ``
  247. sql = `UPDATE cygx_yanxuan_special_author SET fans_num = ? WHERE user_id = ? `
  248. _, err = o.Raw(sql, fansNum, userId).Exec()
  249. return
  250. }
  251. // 更新作者发布文章的数量
  252. func UdpateYanxuanSpecialauthorArticleNum(articleNum, userId int) (err error) {
  253. o := orm.NewOrm()
  254. sql := ``
  255. sql = `UPDATE cygx_yanxuan_special_author SET article_num = ? ,article_publish_time = NOW(), modify_time = NOW() WHERE user_id = ? `
  256. _, err = o.Raw(sql, articleNum, userId).Exec()
  257. return
  258. }
  259. // 更新作者分享到朋友圈的封面图片
  260. func UpdateYanxuanSpecialauthorMomentsImg(momentsImg string, userId int) (err error) {
  261. o := orm.NewOrm()
  262. sql := `UPDATE cygx_yanxuan_special_author SET moments_img = ? WHERE user_id = ? `
  263. _, err = o.Raw(sql, momentsImg, userId).Exec()
  264. return
  265. }