bgm.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/growup/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. xtime "go-common/library/time"
  10. )
  11. // JoinBgm join bgm
  12. func (s *Service) JoinBgm(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. ok, err := s.checkBgmStat(c, mid)
  23. if err != nil {
  24. log.Info("s.checkBgmStat error(%v)", err)
  25. return
  26. }
  27. if !ok {
  28. return ecode.GrowupDisabled
  29. }
  30. count, err := s.dao.BGMCount(c, mid)
  31. if err != nil {
  32. log.Info("s.dao.BGMCount error(%v)", err)
  33. return
  34. }
  35. avStat, err := s.dao.GetAccountState(c, "up_info_video", mid)
  36. if err != nil {
  37. return
  38. }
  39. if avStat >= 5 && avStat <= 7 {
  40. return ecode.GrowupDisabled
  41. }
  42. columnStat, err := s.dao.GetAccountState(c, "up_info_column", mid)
  43. if err != nil {
  44. return
  45. }
  46. if columnStat >= 5 && columnStat <= 7 {
  47. return ecode.GrowupDisabled
  48. }
  49. card, err := s.dao.Card(c, mid)
  50. if err != nil {
  51. log.Error("s.dao.Card(%d) error(%v)", mid, err)
  52. return
  53. }
  54. fans, err := s.dao.Fans(c, mid)
  55. if err != nil {
  56. return
  57. }
  58. now := xtime.Time(time.Now().Unix())
  59. // sign_type: 1.basic; 2.first publish; 0:default.
  60. v := &model.UpInfo{
  61. MID: mid,
  62. Nickname: card.Name,
  63. AccountType: accountType,
  64. Fans: fans,
  65. SignType: signType,
  66. SignedAt: now,
  67. Bgms: count,
  68. }
  69. var tx *sql.Tx
  70. if tx, err = s.dao.BeginTran(c); err != nil {
  71. return
  72. }
  73. if _, err = s.dao.TxInsertBgmUpInfo(tx, v); err != nil {
  74. tx.Rollback()
  75. return
  76. }
  77. if _, err = s.dao.TxInsertCreditScore(tx, mid); err != nil {
  78. tx.Rollback()
  79. return
  80. }
  81. err = tx.Commit()
  82. if err != nil {
  83. log.Error("tx.Commit error(%v)", err)
  84. }
  85. return
  86. }