cygx_yanxuan_special_user.go 10 KB

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