dao.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package account
  2. import (
  3. "context"
  4. accapi "go-common/app/service/main/account/api"
  5. "go-common/app/service/main/assist/conf"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // Dao is account dao.
  10. type Dao struct {
  11. c *conf.Config
  12. acc accapi.AccountClient
  13. }
  14. // New new a dao.
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. c: c,
  18. }
  19. var err error
  20. if d.acc, err = accapi.NewClient(c.AccClient); err != nil {
  21. panic(err)
  22. }
  23. return
  24. }
  25. // IsFollow check assist follow up.
  26. func (d *Dao) IsFollow(c context.Context, mid, assistMid int64) (follow bool, err error) {
  27. var arg = &accapi.RelationReq{
  28. Mid: assistMid,
  29. Owner: mid,
  30. }
  31. res, err := d.acc.Relation3(c, arg)
  32. if err != nil {
  33. log.Error("d.acc.Relation2(%d,%d) error(%v)", mid, assistMid, err)
  34. return
  35. }
  36. follow = res.Following
  37. return
  38. }
  39. // IdentifyInfo 获取用户实名认证状态
  40. func (d *Dao) IdentifyInfo(c context.Context, mid int64, ip string) (err error) {
  41. var (
  42. arg = &accapi.MidReq{
  43. Mid: mid,
  44. }
  45. rpcRes *accapi.ProfileReply
  46. mf *accapi.Profile
  47. )
  48. if rpcRes, err = d.acc.Profile3(c, arg); err != nil {
  49. log.Error("d.acc.Profile3 error(%v) | mid(%d) ip(%s) arg(%v)", err, mid, ip, arg)
  50. err = ecode.CreativeAccServiceErr
  51. return
  52. }
  53. if rpcRes != nil {
  54. mf = rpcRes.Profile
  55. }
  56. if mf.Identification == 1 {
  57. return
  58. }
  59. if err = d.switchIDInfoRet(mf.TelStatus); err != nil {
  60. log.Error("switchIDInfoRet res(%v)", mf.TelStatus)
  61. return
  62. }
  63. return
  64. }
  65. func (d *Dao) switchIDInfoRet(phoneRet int32) (err error) {
  66. switch phoneRet {
  67. case 0:
  68. err = ecode.UserCheckNoPhone
  69. case 1:
  70. err = nil
  71. case 2:
  72. err = ecode.UserCheckInvalidPhone
  73. }
  74. return
  75. }
  76. // UserBanned 获取用户封禁状态, disabled when spacesta == 2
  77. func (d *Dao) UserBanned(c context.Context, mid int64) (err error) {
  78. var card *accapi.Card
  79. if card, err = d.Card(c, mid, ""); err != nil {
  80. log.Error("d.Card() error(%v)", err)
  81. err = nil
  82. return
  83. }
  84. if card.Silence == 1 {
  85. err = ecode.UserDisabled
  86. return
  87. }
  88. return
  89. }
  90. // Card get account.
  91. func (d *Dao) Card(c context.Context, mid int64, ip string) (res *accapi.Card, err error) {
  92. var (
  93. rpcRes *accapi.CardReply
  94. arg = &accapi.MidReq{
  95. Mid: mid,
  96. }
  97. )
  98. if rpcRes, err = d.acc.Card3(c, arg); err != nil {
  99. log.Error("s.acc.Card3() error(%v)", err)
  100. err = ecode.CreativeAccServiceErr
  101. }
  102. if rpcRes != nil {
  103. res = rpcRes.Card
  104. }
  105. return
  106. }
  107. // Cards get infos for space
  108. func (d *Dao) Cards(c context.Context, mids []int64) (res map[int64]*accapi.Card, err error) {
  109. var (
  110. arg = &accapi.MidsReq{
  111. Mids: mids,
  112. }
  113. rpcRes *accapi.CardsReply
  114. )
  115. if rpcRes, err = d.acc.Cards3(c, arg); err != nil {
  116. log.Error("s.acc.Cards3() error(%v)", err)
  117. err = ecode.CreativeAccServiceErr
  118. }
  119. if rpcRes != nil {
  120. res = rpcRes.Cards
  121. }
  122. return
  123. }