chaodian.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package order
  2. import (
  3. "context"
  4. "go-common/app/interface/main/creative/model/order"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. "net/url"
  9. "strconv"
  10. )
  11. // ExecuteOrders orders.
  12. func (d *Dao) ExecuteOrders(c context.Context, mid int64, ip string) (orders []*order.Order, err error) {
  13. params := url.Values{}
  14. params.Set("up_mid", strconv.FormatInt(mid, 10))
  15. var res struct {
  16. Code int `json:"code"`
  17. Orders []*order.Order `json:"data"`
  18. }
  19. if err = d.chaodian.Get(c, d.executeOrdersURI, ip, params, &res); err != nil {
  20. log.Error("chaodian url(%s) response(%v) error(%v)", d.executeOrdersURI+"?"+params.Encode(), res, err)
  21. err = ecode.CreativeOrderAPIErr
  22. return
  23. }
  24. log.Info("chaodian url(%s)", d.executeOrdersURI+"?"+params.Encode())
  25. if res.Code != 0 {
  26. log.Error("chaodian url(%s) res(%v)", d.executeOrdersURI, res)
  27. orders = nil
  28. return
  29. }
  30. orders = res.Orders
  31. return
  32. }
  33. // Ups ups
  34. func (d *Dao) Ups(c context.Context) (ups map[int64]int64, err error) {
  35. params := url.Values{}
  36. var res struct {
  37. Code int `json:"code"`
  38. Ups []int64 `json:"data"`
  39. }
  40. if err = d.chaodian.Get(c, d.upsURI, "", params, &res); err != nil {
  41. log.Error("chaodian url(%s) response(%v) error(%v)", d.upsURI+"?"+params.Encode(), res, err)
  42. err = ecode.CreativeOrderAPIErr
  43. return
  44. }
  45. log.Info("chaodian url(%s)", d.upsURI+"?"+params.Encode())
  46. if res.Code != 0 {
  47. log.Error("chaodian url(%s) res(%v)", d.upsURI, res)
  48. err = ecode.CreativeOrderAPIErr
  49. return
  50. }
  51. ups = make(map[int64]int64)
  52. for _, v := range res.Ups {
  53. ups[v] = v
  54. }
  55. return
  56. }
  57. // OrderByAid order by aid.
  58. func (d *Dao) OrderByAid(c context.Context, aid int64) (orderID int64, orderName string, gameBaseID int64, err error) {
  59. params := url.Values{}
  60. params.Set("av_id", strconv.FormatInt(aid, 10))
  61. var res struct {
  62. Code int `json:"code"`
  63. Order order.Order `json:"data"`
  64. }
  65. if err = d.chaodian.Get(c, d.getOrderByAidURI, "", params, &res); err != nil {
  66. log.Error("chaodian url(%s) response(%v) error(%v)", d.getOrderByAidURI+"?"+params.Encode(), res, err)
  67. err = ecode.CreativeOrderAPIErr
  68. return
  69. }
  70. log.Info("chaodian (%s)", d.getOrderByAidURI+"?"+params.Encode())
  71. if res.Code != 0 {
  72. log.Error("chaodian url(%s) res(%v)", d.getOrderByAidURI, res)
  73. orderID = 0
  74. return
  75. }
  76. orderID = res.Order.ExeOdID
  77. orderName = res.Order.BzOdName
  78. gameBaseID = res.Order.GameBaseID
  79. log.Info("chaodian GetOrderByAid Res OrderInfo (%+v)", res.Order)
  80. return
  81. }
  82. // Unbind unbind order id.
  83. func (d *Dao) Unbind(c context.Context, mid, aid int64, ip string) (err error) {
  84. params := url.Values{}
  85. params.Set("status", "-1")
  86. params.Set("av_id", strconv.FormatInt(aid, 10))
  87. var res struct {
  88. Code int `json:"code"`
  89. Message string `json:"message"`
  90. }
  91. if err = d.chaodian.Post(c, d.archiveStatusURI, ip, params, &res); err != nil {
  92. log.Error("chaodian d.chaodian.POST uri(%s) aid(%d) mid(%d) error(%v)", d.archiveStatusURI+"?"+params.Encode(), mid, aid, err)
  93. return
  94. }
  95. log.Info("chaodian Unbind url with params: (%s)", d.archiveStatusURI+"?"+params.Encode())
  96. if res.Code != 0 {
  97. err = ecode.Int(res.Code)
  98. log.Error("chaodian unbind uri(%s) aid(%d) mid(%d) res.code(%d) error(%v)", d.archiveStatusURI+"?"+params.Encode(), mid, aid, res.Code, err)
  99. }
  100. return
  101. }
  102. // Oasis for orders.
  103. func (d *Dao) Oasis(c context.Context, mid int64, ip string) (oa *order.Oasis, err error) {
  104. params := url.Values{}
  105. params.Set("up_id", strconv.FormatInt(mid, 10))
  106. var res struct {
  107. Code int `json:"code"`
  108. Data *order.Oasis `json:"data"`
  109. }
  110. if err = d.chaodian.Get(c, d.oasisURI, ip, params, &res); err != nil {
  111. log.Error("chaodian up_execute_order_statics url(%s) response(%v) error(%v)", d.oasisURI+"?"+params.Encode(), res, err)
  112. err = ecode.CreativeOrderAPIErr
  113. return
  114. }
  115. log.Info("chaodian up_execute_order_statics mid(%d) url(%s) res(%+v)", mid, d.oasisURI+"?"+params.Encode(), res)
  116. if res.Code != 0 {
  117. log.Error("chaodian up_execute_order_statics url(%s) res(%v)", d.oasisURI, res)
  118. oa = nil
  119. return
  120. }
  121. oa = res.Data
  122. return
  123. }
  124. // LaunchTime publish time from order id.
  125. func (d *Dao) LaunchTime(c context.Context, orderID int64, ip string) (beginDate xtime.Time, err error) {
  126. params := url.Values{}
  127. params.Set("execute_order_id", strconv.FormatInt(orderID, 10))
  128. var res struct {
  129. Code int `json:"code"`
  130. Data struct {
  131. BeginDate xtime.Time `json:"begin_date"`
  132. } `json:"data"`
  133. }
  134. if err = d.chaodian.Get(c, d.launchTimeURI, "", params, &res); err != nil {
  135. log.Error("chaodian LaunchTime url(%s) response(%v) error(%v)", d.launchTimeURI+"?"+params.Encode(), res, err)
  136. err = ecode.CreativeOrderAPIErr
  137. return
  138. }
  139. log.Info("chaodian LaunchTime url(%s)", d.launchTimeURI+"?"+params.Encode())
  140. if res.Code != 0 {
  141. log.Error("chaodian LaunchTime url(%s) res(%v)", d.launchTimeURI, res)
  142. err = ecode.CreativeOrderAPIErr
  143. return
  144. }
  145. beginDate = res.Data.BeginDate
  146. return
  147. }