service.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package elec
  2. import (
  3. "context"
  4. "go-common/library/log"
  5. "go-common/app/interface/main/creative/conf"
  6. "go-common/app/interface/main/creative/dao/account"
  7. "go-common/app/interface/main/creative/dao/archive"
  8. "go-common/app/interface/main/creative/dao/elec"
  9. elecMdl "go-common/app/interface/main/creative/model/elec"
  10. "go-common/app/interface/main/creative/service"
  11. )
  12. //Service struct.
  13. type Service struct {
  14. c *conf.Config
  15. elec *elec.Dao
  16. acc *account.Dao
  17. arc *archive.Dao
  18. }
  19. //New get service.
  20. func New(c *conf.Config, rpcdaos *service.RPCDaos) *Service {
  21. s := &Service{
  22. c: c,
  23. elec: elec.New(c),
  24. acc: rpcdaos.Acc,
  25. arc: rpcdaos.Arc,
  26. }
  27. return s
  28. }
  29. // UserState get user elec state.
  30. func (s *Service) UserState(c context.Context, mid int64, ip, ak, ck string) (data *elecMdl.UserState, err error) {
  31. data, err = s.elec.UserState(c, mid, ip)
  32. return
  33. }
  34. // ArchiveState get arc elec state.
  35. func (s *Service) ArchiveState(c context.Context, aid, mid int64, ip string) (data *elecMdl.ArcState, err error) {
  36. data, err = s.elec.ArchiveState(c, aid, mid, ip)
  37. return
  38. }
  39. // CheckIsFriend check paymid state.
  40. func (s *Service) CheckIsFriend(c context.Context, data []*elecMdl.Rank, mid int64, ip string) (res []*elecMdl.Rank, err error) {
  41. var mids []int64
  42. for _, v := range data {
  43. mids = append(mids, v.PayMID)
  44. }
  45. richRel, err := s.acc.RichRelation(c, mid, mids, ip)
  46. if err != nil {
  47. log.Error("s.acc.RichRelation error(%d, %v)", mid, err)
  48. return
  49. }
  50. if len(richRel) > 0 {
  51. for _, v := range data {
  52. if richRel[v.PayMID] == 3 || richRel[v.PayMID] == 4 {
  53. v.IsFriend = true
  54. } else {
  55. v.IsFriend = false
  56. }
  57. }
  58. }
  59. res = data
  60. return
  61. }