associate_ele_api.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package dao
  2. import (
  3. "context"
  4. eleclient "go-common/app/service/main/vip/dao/ele-api-client"
  5. "go-common/app/service/main/vip/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // api name
  10. const (
  11. _oauthGenerateAccessTokenURI = "/base.openservice/oauth_generate_access_token"
  12. _unionReceivePrizesURI = "/member/bilibili/union/receive_prizes"
  13. _unionUpdateOpenIDURI = "/member/bilibili/union/update_open_id"
  14. _bindUnionURI = "/member/bilibili/bind_union"
  15. _canPurchaseURI = "/member/bilibili/union/can_purchase"
  16. _getUnionMobileURI = "/member/bilibili/union/get_union_mobile"
  17. _hongbaosURI = "/member/bilibili/union/hongbaos"
  18. _specailFoodsURI = "/member/bilibili/union/special_foods"
  19. )
  20. // EleOauthGenerateAccessToken get access_token by auth_code.
  21. func (d *Dao) EleOauthGenerateAccessToken(c context.Context, a *model.ArgEleAccessToken) (data *model.EleAccessTokenResp, err error) {
  22. args := new(struct {
  23. Request *model.ArgEleAccessToken `json:"request"`
  24. })
  25. args.Request = a
  26. resp := new(struct {
  27. Message string `json:"message"`
  28. Name string `json:"name"`
  29. Data *model.EleAccessTokenResp `json:"data"`
  30. })
  31. err = d.eleclient.Post(c, d.c.Host.Ele, _oauthGenerateAccessTokenURI, args, resp)
  32. if err != nil {
  33. log.Error("ele faild api(%s) a(%+v) resp(%+v) error(%+v)", _oauthGenerateAccessTokenURI, a, resp, err)
  34. err = ecode.VipEleUnionReqErr
  35. return
  36. }
  37. if !eleclient.IsSuccess(resp.Message) {
  38. log.Error("ele message faild api(%s) a(%+v) resp(%+v) error(%+v)", _oauthGenerateAccessTokenURI, a, resp, err)
  39. err = ecode.VipEleUnionRespCodeErr
  40. return
  41. }
  42. data = resp.Data
  43. log.Info("ele success api(%s) a(%+v) resp(%+v) data(%+v)", _oauthGenerateAccessTokenURI, a, resp, data)
  44. return
  45. }
  46. // EleUnionReceivePrizes union receive prizes.
  47. func (d *Dao) EleUnionReceivePrizes(c context.Context, a *model.ArgEleReceivePrizes) (data []*model.EleReceivePrizesResp, err error) {
  48. args := new(struct {
  49. Request *model.ArgEleReceivePrizes `json:"request"`
  50. })
  51. args.Request = a
  52. resp := new(struct {
  53. Message string `json:"message"`
  54. Name string `json:"name"`
  55. Data []*model.EleReceivePrizesResp `json:"data"`
  56. })
  57. err = d.eleclient.Post(c, d.c.Host.Ele, _unionReceivePrizesURI, args, resp)
  58. if err != nil {
  59. log.Error("ele faild api(%s) a(%+v) resp(%+v) error(%+v)", _unionReceivePrizesURI, a, resp, err)
  60. err = ecode.VipEleUnionReqErr
  61. return
  62. }
  63. if !eleclient.IsSuccess(resp.Message) {
  64. log.Error("ele message faild api(%s) a(%+v) resp(%+v) error(%+v)", _unionReceivePrizesURI, a, resp, err)
  65. err = ecode.VipEleUnionRespCodeErr
  66. return
  67. }
  68. data = resp.Data
  69. log.Info("ele success api(%s) a(%+v) resp(%+v) data(%+v)", _unionReceivePrizesURI, a, resp, data)
  70. return
  71. }
  72. // EleUnionUpdateOpenID update_open_id req.
  73. func (d *Dao) EleUnionUpdateOpenID(c context.Context, a *model.ArgEleUnionUpdateOpenID) (data *model.EleUnionUpdateOpenIDResp, err error) {
  74. args := new(struct {
  75. Request *model.ArgEleUnionUpdateOpenID `json:"request"`
  76. })
  77. args.Request = a
  78. resp := new(struct {
  79. Message string `json:"message"`
  80. Name string `json:"name"`
  81. Data *model.EleUnionUpdateOpenIDResp `json:"data"`
  82. })
  83. err = d.eleclient.Post(c, d.c.Host.Ele, _unionUpdateOpenIDURI, args, resp)
  84. if err != nil {
  85. log.Error("ele faild api(%s) a(%+v) resp(%+v) error(%+v)", _unionUpdateOpenIDURI, a, resp, err)
  86. err = ecode.VipEleUnionReqErr
  87. return
  88. }
  89. if !eleclient.IsSuccess(resp.Message) {
  90. log.Error("ele message faild api(%s) a(%+v) resp(%+v) error(%+v)", _unionUpdateOpenIDURI, a, resp, err)
  91. err = ecode.VipEleUnionRespCodeErr
  92. return
  93. }
  94. data = resp.Data
  95. log.Info("ele success api(%s) a(%+v) resp(%+v) data(%+v)", _unionUpdateOpenIDURI, a, resp, data)
  96. return
  97. }
  98. // EleBindUnion ele bind union salary vip.
  99. func (d *Dao) EleBindUnion(c context.Context, a *model.ArgEleBindUnion) (data *model.EleBindUnionResp, err error) {
  100. args := new(struct {
  101. Request *model.ArgEleBindUnion `json:"request"`
  102. })
  103. args.Request = a
  104. resp := new(struct {
  105. Message string `json:"message"`
  106. Name string `json:"name"`
  107. Data *model.EleBindUnionResp `json:"data"`
  108. })
  109. err = d.eleclient.Post(c, d.c.Host.Ele, _bindUnionURI, args, resp)
  110. if err != nil {
  111. log.Error("ele faild api(%s) a(%+v) resp(%+v) error(%+v)", _bindUnionURI, a, resp, err)
  112. err = ecode.VipEleUnionReqErr
  113. return
  114. }
  115. if !eleclient.IsSuccess(resp.Message) {
  116. log.Error("ele message faild api(%s) a(%+v) resp(%+v) error(%+v)", _bindUnionURI, a, resp, err)
  117. err = ecode.VipEleUnionRespCodeErr
  118. return
  119. }
  120. data = resp.Data
  121. // 1.发放成功
  122. if data.Status != 1 && data.Status != 6 {
  123. log.Error("ele status faild api(%s) a(%+v) resp(%+v) data(%+v) error(%+v)", _bindUnionURI, a, resp, data, err)
  124. err = ecode.VipOrderEleVipGrantFaildErr
  125. }
  126. log.Info("ele success api(%s) a(%+v) resp(%+v) data(%+v)", _bindUnionURI, a, resp, data)
  127. return
  128. }
  129. // EleCanPurchase ele can purchase.
  130. func (d *Dao) EleCanPurchase(c context.Context, a *model.ArgEleCanPurchase) (data *model.EleCanPurchaseResp, err error) {
  131. args := new(struct {
  132. Request *model.ArgEleCanPurchase `json:"request"`
  133. })
  134. args.Request = a
  135. resp := new(struct {
  136. Message string `json:"message"`
  137. Name string `json:"name"`
  138. Data *model.EleCanPurchaseResp `json:"data"`
  139. })
  140. err = d.eleclient.Post(c, d.c.Host.Ele, _canPurchaseURI, args, resp)
  141. if err != nil {
  142. log.Error("ele faild api(%s) a(%+v) resp(%+v) error(%+v)", _canPurchaseURI, a, resp, err)
  143. err = ecode.VipEleUnionReqErr
  144. return
  145. }
  146. // 系统请求是否有误
  147. if !eleclient.IsSuccess(resp.Message) {
  148. log.Error("ele message faild api(%s) a(%+v) resp(%+v) error(%+v)", _canPurchaseURI, a, resp, err)
  149. err = ecode.VipEleUnionRespCodeErr
  150. return
  151. }
  152. // 业务逻辑是否有误
  153. data = resp.Data
  154. if data.Status != 1 {
  155. log.Error("ele status faild api(%s) a(%+v) resp(%+v) data(%+v) error(%+v)", _canPurchaseURI, a, resp, data, err)
  156. err = ecode.VipEleUnionBuyCanPurchaseErr
  157. return
  158. }
  159. log.Info("ele success api(%s) a(%+v) resp(%+v) data(%+v)", _canPurchaseURI, a, resp, data)
  160. return
  161. }
  162. // EleUnionMobile get ele union mobile.
  163. func (d *Dao) EleUnionMobile(c context.Context, a *model.ArgEleUnionMobile) (data *model.EleUnionMobileResp, err error) {
  164. args := new(struct {
  165. Request *model.ArgEleUnionMobile `json:"request"`
  166. })
  167. args.Request = a
  168. resp := new(struct {
  169. Message string `json:"message"`
  170. Name string `json:"name"`
  171. Data *model.EleUnionMobileResp `json:"data"`
  172. })
  173. err = d.eleclient.Post(c, d.c.Host.Ele, _getUnionMobileURI, args, resp)
  174. if err != nil {
  175. log.Error("ele faild api(%s) a(%+v) resp(%+v) error(%+v)", _getUnionMobileURI, a, resp, err)
  176. err = ecode.VipEleUnionReqErr
  177. return
  178. }
  179. if !eleclient.IsSuccess(resp.Message) {
  180. log.Error("ele message faild api(%s) a(%+v) resp(%+v) error(%+v)", _getUnionMobileURI, a, resp, err)
  181. err = ecode.VipEleUnionRespCodeErr
  182. return
  183. }
  184. data = resp.Data
  185. log.Info("ele success api(%s) a(%+v) resp(%+v) data(%+v)", _getUnionMobileURI, a, resp, data)
  186. return
  187. }
  188. // EleRedPackages get ele red packages.
  189. func (d *Dao) EleRedPackages(c context.Context) (data []*model.EleRedPackagesResp, err error) {
  190. args := new(struct{})
  191. resp := new(struct {
  192. Message string `json:"message"`
  193. Name string `json:"name"`
  194. Data []*model.EleRedPackagesResp `json:"data"`
  195. })
  196. err = d.eleclient.Post(c, d.c.Host.Ele, _hongbaosURI, args, resp)
  197. if err != nil {
  198. log.Error("ele faild api(%s)resp(%+v) error(%+v)", _hongbaosURI, resp, err)
  199. err = ecode.VipEleUnionReqErr
  200. return
  201. }
  202. if !eleclient.IsSuccess(resp.Message) {
  203. log.Error("ele message faild api(%s) resp(%+v) error(%+v)", _hongbaosURI, resp, err)
  204. err = ecode.VipEleUnionRespCodeErr
  205. return
  206. }
  207. data = resp.Data
  208. log.Info("ele success api(%s) resp(%+v) data(%+v)", _hongbaosURI, resp, data)
  209. return
  210. }
  211. // EleSpecailFoods get ele specail foods.
  212. func (d *Dao) EleSpecailFoods(c context.Context) (data []*model.EleSpecailFoodsResp, err error) {
  213. args := new(struct{})
  214. resp := new(struct {
  215. Message string `json:"message"`
  216. Name string `json:"name"`
  217. Data []*model.EleSpecailFoodsResp `json:"data"`
  218. })
  219. err = d.eleclient.Post(c, d.c.Host.Ele, _specailFoodsURI, args, resp)
  220. if err != nil {
  221. log.Error("ele faild api(%s)resp(%+v) error(%+v)", _specailFoodsURI, resp, err)
  222. err = ecode.VipEleUnionReqErr
  223. return
  224. }
  225. if !eleclient.IsSuccess(resp.Message) {
  226. log.Error("ele message faild api(%s) resp(%+v) error(%+v)", _specailFoodsURI, resp, err)
  227. err = ecode.VipEleUnionRespCodeErr
  228. return
  229. }
  230. data = resp.Data
  231. log.Info("ele success api(%s) resp(%+v) data(%+v)", _specailFoodsURI, resp, data)
  232. return
  233. }