blocked.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "strconv"
  6. "time"
  7. "go-common/app/job/main/credit/model"
  8. blkmdl "go-common/app/service/main/member/model/block"
  9. "go-common/library/log"
  10. xtime "go-common/library/time"
  11. )
  12. // InvalidJury invalid juryer.
  13. func (s *Service) InvalidJury(c context.Context, nwMsg []byte, oldMsg []byte) (err error) {
  14. mr := &model.BlockedInfo{}
  15. if err = json.Unmarshal(nwMsg, mr); err != nil {
  16. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  17. return
  18. }
  19. if err = s.dao.InvalidJury(c, model.JuryBlocked, mr.UID); err != nil {
  20. log.Error("s.dao.InvalidJury(%d %d) error(%v)", model.JuryBlocked, mr.UID, err)
  21. }
  22. return
  23. }
  24. // UnBlockAccount unblock account.
  25. func (s *Service) UnBlockAccount(c context.Context, nwMsg []byte, oldMsg []byte) (err error) {
  26. nMR := &model.BlockedInfo{}
  27. if err = json.Unmarshal(nwMsg, nMR); err != nil {
  28. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  29. return
  30. }
  31. oMR := &model.BlockedInfo{}
  32. if err = json.Unmarshal(oldMsg, oMR); err != nil {
  33. log.Error("json.Unmarshal(%s) error(%v)", string(oldMsg), err)
  34. return
  35. }
  36. if int8(oMR.Status) != model.StatusOpen {
  37. return
  38. }
  39. if int8(nMR.Status) != model.StatusClose {
  40. return
  41. }
  42. var id int64
  43. if id, err = s.dao.BlockedInfoID(c, nMR.UID); err != nil {
  44. log.Error("s.dao.BlockedInfoID(%+v) error(%v)", oMR, err)
  45. return
  46. }
  47. if id != nMR.ID {
  48. log.Warn("databus id(%d) do uid(%d) unblocked info(%d) not right!", nMR.ID, nMR.UID, id)
  49. return
  50. }
  51. if err = s.dao.UnBlockAccount(c, oMR); err != nil {
  52. log.Error("s.dao.UnBlockAccount(%+v) error(%v)", oMR, err)
  53. }
  54. return
  55. }
  56. // CheckBlock check user block state
  57. func (s *Service) CheckBlock(c context.Context, mid int64) (ok bool, err error) {
  58. var block *blkmdl.RPCResInfo
  59. if block, err = s.memRPC.BlockInfo(c, &blkmdl.RPCArgInfo{MID: mid}); err != nil {
  60. log.Error("s.memRPC.BlockInfo(%d) error(%+v)", err)
  61. return
  62. }
  63. status := int8(block.BlockStatus)
  64. if status == model.BlockStatusOn {
  65. log.Warn("mid(%d) in blocked", mid)
  66. return
  67. }
  68. if status == model.BlockStatusForever {
  69. log.Warn("mid(%d) in blocked forever", mid)
  70. return
  71. }
  72. ok = true
  73. return
  74. }
  75. // NotifyBlockAnswer notify block answer status
  76. func (s *Service) NotifyBlockAnswer(c context.Context, nwMsg []byte) (err error) {
  77. mr := &model.BlockLabourAnswerLog{}
  78. if err = json.Unmarshal(nwMsg, mr); err != nil {
  79. log.Error("json.Unmarshal(%s) error(%v)", string(nwMsg), err)
  80. return
  81. }
  82. if mr.Score < 100 {
  83. log.Warn("mid(%d) answer score(%d) lt 100", mr.Score, mr.Score)
  84. return
  85. }
  86. var ts time.Time
  87. if ts, err = time.ParseInLocation(model.TimeFormatSec, mr.CTime, time.Local); err != nil {
  88. log.Error("time.ParseInLocation(%s) error(%v)", mr.CTime, err)
  89. return
  90. }
  91. key := strconv.FormatInt(mr.MID, 10)
  92. msg := &model.LabourAnswer{MID: mr.MID, MTime: xtime.Time(ts.Unix())}
  93. if err = s.labourSub.Send(c, key, msg); err != nil {
  94. log.Error("PubLabour.Pub(%s, %+v) error (%v)", key, msg, err)
  95. }
  96. if err = s.dao.DelAnswerStateCache(c, mr.MID); err != nil {
  97. log.Error("DelAnswerStateCache(%d) error (%v)", mr.MID, err)
  98. }
  99. return
  100. }