credit_log.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package upcrm
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/admin/main/up/model/upcrmmodel"
  7. "go-common/library/log"
  8. )
  9. const (
  10. creditLogURL = "http://api.bilibili.co/x/internal/upcredit/log/get"
  11. )
  12. //
  13. //type ArgGetLogHistory struct {
  14. // Mid int64 `params:"mid;Required"`
  15. // FromDate systime.Time `params:"from_date"`
  16. // ToDate systime.Time `params:"to_date"`
  17. // Limit int `params:"limit" default:"20"`
  18. //}
  19. //LogList it's log list
  20. type LogList struct {
  21. LogList []upcrmmodel.SimpleCreditLogWithContent `json:"log_list"`
  22. }
  23. //CreditLogHTTPResult it's log result from http server
  24. type CreditLogHTTPResult struct {
  25. Code int `json:"code"`
  26. Data LogList `json:"data"`
  27. Msg string `json:"message"`
  28. }
  29. //GetCreditLog get credit log from upcredit server
  30. func (d *Dao) GetCreditLog(mid int64, limit int) (result []upcrmmodel.SimpleCreditLogWithContent, err error) {
  31. params := url.Values{}
  32. params.Set("mid", fmt.Sprintf("%d", mid))
  33. //params.Set("from_date", fromDate.Time().Format("2006-01-02"))
  34. //params.Set("to_date", toDate.Time().Format("2006-01-02"))
  35. params.Set("limit", fmt.Sprintf("%d", limit))
  36. var c = context.Background()
  37. var httpResult = CreditLogHTTPResult{}
  38. err = d.httpClient.Get(c, creditLogURL, "", params, &httpResult)
  39. if err != nil {
  40. log.Error("get credit log http fail, request=%s?%s, err=%+v", creditLogURL, params.Encode(), err)
  41. return
  42. }
  43. log.Info("get credit log http ok, result=%+v", httpResult)
  44. result = httpResult.Data.LogList
  45. return
  46. }