column.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/growup/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "go-common/library/net/metadata"
  9. xtime "go-common/library/time"
  10. )
  11. // JoinColumn join up to creative column
  12. func (s *Service) JoinColumn(c context.Context, mid int64, accountType, signType int) (err error) {
  13. id, err := s.dao.Blocked(c, mid)
  14. if err != nil {
  15. log.Error("s.dao.GetBlocked mid(%d) error(%v)", mid, err)
  16. return
  17. }
  18. if id != 0 {
  19. log.Info("mid(%d) is blocked", mid)
  20. return ecode.GrowupDisabled
  21. }
  22. // get up view
  23. ip := metadata.String(c, metadata.RemoteIP)
  24. stat, err := s.dao.ArticleStat(c, mid, ip)
  25. if err != nil {
  26. log.Error("s.dao.ArticleStat mid(%d) error(%v)", mid, err)
  27. return
  28. }
  29. if stat.View < s.conf.Threshold.LimitArticleView {
  30. log.Info("mid(%d) view(%s) not reach standard", mid, stat.View)
  31. return ecode.GrowupDisabled
  32. }
  33. // get up nickname
  34. card, err := s.dao.Card(c, mid)
  35. if err != nil {
  36. log.Error("s.dao.Card(%d) error(%v)", mid, err)
  37. return
  38. }
  39. fans, err := s.dao.Fans(c, mid)
  40. if err != nil {
  41. return
  42. }
  43. state, err := s.dao.GetAccountState(c, "up_info_column", mid)
  44. if err != nil {
  45. return
  46. }
  47. // if account state is 2 3 4 5 6 7 return
  48. if state >= 2 && state < 8 {
  49. return
  50. }
  51. now := xtime.Time(time.Now().Unix())
  52. // sign_type: 1.basic; 2.first publish; 0:default.
  53. v := &model.UpInfo{
  54. MID: mid,
  55. Nickname: card.Name,
  56. AccountType: accountType,
  57. MainCategory: 0,
  58. Fans: fans,
  59. AccountState: 2,
  60. SignType: signType,
  61. ApplyAt: now,
  62. TotalPlayCount: stat.View,
  63. }
  64. _, err = s.dao.InsertUpInfo(c, "up_info_column", "total_view_count", v)
  65. return
  66. }