account.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/interface/main/growup/model"
  8. account "go-common/app/service/main/account/model"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. "go-common/library/xstr"
  12. "github.com/pkg/errors"
  13. )
  14. // AccountInfos get account infos
  15. func (d *Dao) AccountInfos(c context.Context, mids []int64) (infos map[int64]*model.ActUpInfo, err error) {
  16. if len(mids) == 0 {
  17. return
  18. }
  19. infos = make(map[int64]*model.ActUpInfo)
  20. results := new(model.AccountInfosResult)
  21. uv := url.Values{}
  22. uv.Set("mids", xstr.JoinInts(mids))
  23. if err = d.httpRead.Get(c, d.c.Host.AccountURI, "", uv, results); err != nil {
  24. return
  25. }
  26. if results.Code != ecode.OK.Code() {
  27. err = errors.Wrap(ecode.Int(results.Code), fmt.Sprintf("search account failed: %s?%s", d.c.Host.AccountURI, uv.Get("mids")))
  28. return
  29. }
  30. for mid, account := range results.Data {
  31. infos[mid] = &model.ActUpInfo{Nickname: account.Name, Face: account.Face}
  32. }
  33. return
  34. }
  35. // UpBusinessInfos get business infos
  36. func (d *Dao) UpBusinessInfos(c context.Context, mid int64) (identify *model.UpIdentify, err error) {
  37. identify = new(model.UpIdentify)
  38. results := new(model.UperInfosResult)
  39. uv := url.Values{}
  40. uv.Set("mid", strconv.FormatInt(mid, 10))
  41. if err = d.httpRead.Get(c, d.c.Host.UperURI, "", uv, results); err != nil {
  42. return
  43. }
  44. if results.Code != ecode.OK.Code() {
  45. err = errors.Wrap(ecode.Int(results.Code), fmt.Sprintf("search uper failed: %s?%s", d.c.Host.UperURI, uv.Get("mid")))
  46. return
  47. }
  48. identify = results.Data["identify"]
  49. return
  50. }
  51. // Card get account.
  52. func (d *Dao) Card(c context.Context, mid int64) (res *account.Card, err error) {
  53. var arg = &account.ArgMid{
  54. Mid: mid,
  55. }
  56. if res, err = d.acc.Card3(c, arg); err != nil {
  57. log.Error("d.acc.Card3() error(%v)", err)
  58. err = ecode.CreativeAccServiceErr
  59. }
  60. return
  61. }
  62. // ProfileWithStat get account.
  63. func (d *Dao) ProfileWithStat(c context.Context, mid int64) (res *account.ProfileStat, err error) {
  64. var arg = &account.ArgMid{
  65. Mid: mid,
  66. }
  67. if res, err = d.acc.ProfileWithStat3(c, arg); err != nil {
  68. log.Error("d.acc.ProfileWithStat3() error(%v)", err)
  69. err = ecode.CreativeAccServiceErr
  70. }
  71. return
  72. }