api.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package elec
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _showURL = "/internal/member/show"
  11. _arcOpenURI = "/internal/archice/partin"
  12. _arcCloseURI = "/internal/archice/exit"
  13. )
  14. // ArcShow return archive elec show, contains rank.
  15. func (d *Dao) ArcShow(c context.Context, mid, aid int64, ip string) (show bool, err error) {
  16. params := url.Values{}
  17. params.Set("upmid", strconv.FormatInt(mid, 10))
  18. params.Set("aid", strconv.FormatInt(aid, 10))
  19. params.Set("nolist", "0")
  20. var res struct {
  21. Code int `json:"code"`
  22. Data struct {
  23. Show bool `json:"show"`
  24. } `json:"data"`
  25. }
  26. if err = d.client.Get(c, d.showURI, ip, params, &res); err != nil {
  27. log.Error("elec url(%s) error(%v)", d.showURI+"?"+params.Encode(), err)
  28. err = ecode.CreativeElecErr
  29. return
  30. }
  31. log.Info("ArcShow d.showURI url(%s)|res(%+v)", d.showURI+"?"+params.Encode(), res)
  32. if res.Code != 0 {
  33. log.Error("d.client.Get(%s) code(%d) error(%v)", d.showURI+"?"+params.Encode(), res.Code, err)
  34. err = ecode.Int(res.Code)
  35. return
  36. }
  37. show = res.Data.Show
  38. return
  39. }
  40. // ArcUpdate arc open or close elec.
  41. func (d *Dao) ArcUpdate(c context.Context, mid, aid int64, openElec int8, ip string) (err error) {
  42. params := url.Values{}
  43. params.Set("mid", strconv.FormatInt(mid, 10))
  44. params.Set("aid", strconv.FormatInt(aid, 10))
  45. var url string
  46. if openElec == 1 {
  47. url = d.arcOpenURL
  48. } else if openElec == 0 {
  49. url = d.arcCloseURL
  50. }
  51. var res struct {
  52. Code int `json:"code"`
  53. }
  54. if err = d.client.Post(c, url, ip, params, &res); err != nil {
  55. log.Error("d.client.Do uri(%s) aid(%d) mid(%d) orderID(%d) code(%d) error(%v)", url+"?"+params.Encode(), mid, aid, openElec, res.Code, err)
  56. err = ecode.CreativeElecErr
  57. return
  58. }
  59. log.Info("dealElec ArcUpdate url(%s)", url+"?"+params.Encode())
  60. if res.Code != 0 {
  61. log.Error("arc elec update state url(%s) res(%v); mid(%d), aid(%d), ip(%s), code(%d), error(%v)", url, res, mid, aid, ip, res.Code, err)
  62. err = ecode.Int(res.Code)
  63. return
  64. }
  65. return
  66. }