check.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/app/job/main/member/model"
  7. "go-common/library/log"
  8. )
  9. func (s *Service) checkExpAdd(c context.Context, mid int64, event string, now time.Time) (exp *model.NewExp, eo *model.ExpOper, added, ok bool, err error) {
  10. if eo, ok = model.ExpFlagOper[event]; !ok {
  11. log.Info("s.checkExpAdd(%d) oper(%s) not found", mid, event)
  12. return
  13. }
  14. var base *model.BaseInfo
  15. if base, err = s.dao.BaseInfo(c, mid); err != nil {
  16. log.Error("s.dao.BaseInfo(%d) error(%v)", mid, err)
  17. return
  18. }
  19. if base == nil {
  20. err = fmt.Errorf("No base info with mid(%v)", mid)
  21. log.Error("Failed to checkExpAdd with mid(%d) error: %+v", mid, err)
  22. return
  23. }
  24. if ok = !(base.Rank < 10000); !ok {
  25. log.Info("s.checkExpAdd(%d) mid.Rank<10000", mid)
  26. return
  27. }
  28. if added, err = s.dao.ExpAdded(c, mid, now.Day(), eo.Oper); err != nil || added {
  29. log.Info("s.dao.ExpAdded(%d) error(%v) added(%v)", mid, err, added)
  30. return
  31. }
  32. if exp, err = s.dao.SelExp(c, mid); err != nil {
  33. log.Error("s.dao.SelExp(%d) error(%v)", mid, err)
  34. return
  35. }
  36. if now.Unix()-int64(exp.Addtime) < 24*60*60 {
  37. added = exp.Flag&eo.Flag == eo.Flag
  38. return
  39. }
  40. if err = s.dao.InitExp(c, mid); err != nil {
  41. log.Error("s.dao.InitExp(%d) error(%v)", mid, err)
  42. return
  43. }
  44. exp.FlagDailyReset(now)
  45. if err = s.dao.UpdateExpFlag(c, mid, exp.Flag, exp.Addtime); err != nil {
  46. log.Error("s.dao.UpdateExpFlag(%d) flag(%d) addtime(%v)", mid, exp.Flag, exp.Addtime)
  47. return
  48. }
  49. added = exp.Flag&eo.Flag == eo.Flag
  50. return
  51. }
  52. // CheckExpInit check init user exp if exp not exist.
  53. func (s *Service) CheckExpInit(c context.Context, mid int64) (opers []*model.ExpOper, err error) {
  54. var aso *model.MemberAso
  55. if aso, err = s.dao.AsoStatus(c, mid); err != nil {
  56. log.Error("s.dao.AsoStatus(%d) error(%v)", mid, err)
  57. return
  58. }
  59. if aso.Spacesta >= 0 && len(aso.Email) != 0 {
  60. opers = append(opers, model.ExpFlagOper["email"])
  61. }
  62. if len(aso.Telphone) != 0 {
  63. opers = append(opers, model.ExpFlagOper["phone"])
  64. }
  65. if aso.SafeQs != 0 {
  66. opers = append(opers, model.ExpFlagOper["safe"])
  67. }
  68. var ri *model.RealnameInfo
  69. if ri, err = s.dao.RealnameInfo(c, mid); err != nil {
  70. log.Error("s.dao.RealnameInfo(%d) error(%+v)", mid, err)
  71. return
  72. }
  73. if ri != nil && ri.Status.IsPass() {
  74. opers = append(opers, model.ExpFlagOper["identify"])
  75. }
  76. log.Info("exp init opers with mid: %d: %+v", mid, opers)
  77. return
  78. }
  79. func sameAccInfo(base *model.BaseInfo, res *model.AccountInfo) (same bool) {
  80. return sameName(base, res)
  81. }
  82. func sameName(base *model.BaseInfo, res *model.AccountInfo) bool {
  83. return base.Name == res.Name
  84. }