ElemeRetailWaiMaiCallback.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package com.ydd.app.callback.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ydd.api.EleRetailApi;
  4. import com.ydd.app.service.ApiWaimaiPlatformService;
  5. import com.ydd.app.service.ApiWaimaiService;
  6. import com.ydd.module.service.IWaimaiOrderService;
  7. import com.ydd.third.common.vo.ResObject;
  8. import com.ydd.third.common.vo.waimai.ElemeRetailMerchantResultVo;
  9. import com.ydd.third.waimai.eleRetai.common.EleRetaiApi;
  10. import com.ydd.third.waimai.eleRetai.vo.EleReatiVO;
  11. import com.ydd.third.waimai.eleRetai.vo.EleRetailResultVO;
  12. import com.ydd.third.waimai.eleRetai.vo.SourceOrderVO;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import javax.annotation.Resource;
  19. import java.util.Map;
  20. @Slf4j
  21. @RestController
  22. @RequestMapping("/app/waimai/elemeRetail/callback")
  23. public class ElemeRetailWaiMaiCallback {
  24. @Resource
  25. private ApiWaimaiService apiWaimaiService;
  26. // @Autowired
  27. // private ElemeretailCallback callback;
  28. @Autowired
  29. private IWaimaiOrderService iWaimaiOrderService;
  30. @Autowired
  31. private EleRetailApi eleRetaiClient;
  32. @Autowired
  33. ApiWaimaiPlatformService apiWaimaiPlatformService;
  34. // @RequestMapping("/saveShop")
  35. // public String saveShop(@RequestParam Map<String, String> params) {
  36. // JSONObject res = new JSONObject();
  37. //
  38. // if (null == params || params.size() == 0) {
  39. // return "";
  40. // }
  41. //
  42. // log.info("饿了么零售授权回调--------" + JSONObject.toJSONString(params));
  43. // ResObject<ElemeRetailMerchantResultVo> callbackRes = callback.doStoreMap(params);
  44. //
  45. // ElemeRetailMerchantResultVo vo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class);
  46. // callbackRes.getData().setBindResult(vo.getBindResult());
  47. // callbackRes.getData().setOperatingTime(vo.getOperatingTime());
  48. // callbackRes.getData().setOperatingUser(vo.getOperatingUser());
  49. // callbackRes.getData().setShopList(vo.getShopList());
  50. //
  51. // if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) {
  52. // ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData();
  53. // apiWaimaiService.saveShop(shopMappingVo);
  54. // return res.toJSONString();
  55. // } else {
  56. // log.error(callbackRes.getMsg());
  57. // }
  58. //
  59. // return "";
  60. // }
  61. @RequestMapping("/doOAuth")
  62. public Object updateShop(@RequestParam Map<String, String> params) {
  63. JSONObject res = new JSONObject();
  64. log.info("=========饿了么零售绑定回调信息--------" + JSONObject.toJSONString(params));
  65. EleRetailResultVO resultVO = new EleRetailResultVO();
  66. resultVO.setCmd(params.get("cmd"));
  67. resultVO.setSign(params.get("sign"));
  68. resultVO.setSource(params.get("source"));
  69. resultVO.setTicket(params.get("ticket"));
  70. resultVO.setVersion(params.get("version"));
  71. resultVO.setTimestamp(Long.parseLong(params.get("timestamp")));
  72. EleReatiVO reatiVO = new EleReatiVO();
  73. reatiVO.setErrno("0");
  74. reatiVO.setError("success");
  75. resultVO.setBody(reatiVO);
  76. if (null == params || params.size() == 0) {
  77. return resultVO;
  78. }
  79. ResObject<ElemeRetailMerchantResultVo> callbackRes = eleRetaiClient.doStoreMap(params);
  80. /**门店绑定*/
  81. if (params.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_BIND_MSG)) {
  82. ElemeRetailMerchantResultVo vo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class);
  83. callbackRes.getData().setBindResult(vo.getBindResult());
  84. callbackRes.getData().setOperatingTime(vo.getOperatingTime());
  85. callbackRes.getData().setOperatingUser(vo.getOperatingUser());
  86. callbackRes.getData().setShopList(vo.getShopList());
  87. if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) {
  88. ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData();
  89. apiWaimaiPlatformService.saveShop(shopMappingVo);
  90. } else {
  91. log.error(callbackRes.getMsg());
  92. }
  93. return resultVO;
  94. }
  95. /**门店解除绑定*/
  96. if (params.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_UNBIND_MSG)) {
  97. ElemeRetailMerchantResultVo vo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class);
  98. callbackRes.getData().setBindResult(vo.getBindResult());
  99. callbackRes.getData().setOperatingTime(vo.getOperatingTime());
  100. callbackRes.getData().setOperatingUser(vo.getOperatingUser());
  101. callbackRes.getData().setShopList(vo.getShopList());
  102. if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) {
  103. ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData();
  104. // apiWaimaiPlatformService.updateShop(shopMappingVo);
  105. } else {
  106. log.error(callbackRes.getMsg());
  107. }
  108. return resultVO;
  109. }
  110. return reatiVO;
  111. }
  112. @RequestMapping("/doOrder")
  113. public Object doOrder(@RequestParam(required = false) Map<String, String> jsonParams) {
  114. log.info("---------------->");
  115. log.info("收到饿百推送消息-------" + jsonParams);
  116. EleRetailResultVO vo = new EleRetailResultVO();
  117. vo.setCmd(jsonParams.get("cmd"));
  118. vo.setSign(jsonParams.get("sign"));
  119. vo.setSource(jsonParams.get("source"));
  120. vo.setTicket(jsonParams.get("ticket"));
  121. vo.setVersion(jsonParams.get("version"));
  122. vo.setTimestamp(Long.parseLong(jsonParams.get("timestamp")));
  123. EleReatiVO reatiVO = new EleReatiVO();
  124. reatiVO.setErrno("0");
  125. reatiVO.setError("success");
  126. if (jsonParams == null) {
  127. return vo;
  128. }
  129. String body = jsonParams.get("body");
  130. JSONObject jsonObject = JSONObject.parseObject(body);
  131. //接到新订单通知
  132. if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_ORDER_CREATE)) {
  133. // OrderGetResult orderGetResult = eleRetaiClient.getOrder(jsonObject.get("order_id").toString());
  134. // if (orderGetResult.getData().getOrder().getDown_flag() == 1) {
  135. // orderGetResult = eleRetaiClient.getOrder(jsonObject.get("order_id").toString());
  136. // }
  137. // String orderId = apiWaimaiService.createOrder(orderGetResult);
  138. String orderId = apiWaimaiService.newEBaiOrder(jsonObject.get("order_id").toString(),jsonObject.get("platform_shop_id").toString());
  139. reatiVO.setData(new SourceOrderVO(orderId));
  140. vo.setBody(reatiVO);
  141. return vo;
  142. }
  143. /**订单状态推送*/
  144. if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_ORDER_STATUS_PUSH)) {
  145. apiWaimaiService.updateOrderStatus(jsonObject);
  146. vo.setBody(reatiVO);
  147. return vo;
  148. }
  149. /**用户申请订单取消 退款*/
  150. if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_ORDER_USER_CANCEL)) {
  151. apiWaimaiService.doEleRetaiCancel(jsonObject.getString("order_id"), jsonObject.getInteger("type"));
  152. vo.setBody(reatiVO);
  153. return vo;
  154. }
  155. ResObject<ElemeRetailMerchantResultVo> callbackRes = eleRetaiClient.doStoreMap(jsonParams);
  156. /**门店绑定*/
  157. if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_BIND_MSG)) {
  158. ElemeRetailMerchantResultVo elemeRetailMerchantResultVo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class);
  159. callbackRes.getData().setBindResult(elemeRetailMerchantResultVo.getBindResult());
  160. callbackRes.getData().setOperatingTime(elemeRetailMerchantResultVo.getOperatingTime());
  161. callbackRes.getData().setOperatingUser(elemeRetailMerchantResultVo.getOperatingUser());
  162. callbackRes.getData().setShopList(elemeRetailMerchantResultVo.getShopList());
  163. if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) {
  164. ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData();
  165. apiWaimaiPlatformService.saveShop(shopMappingVo);
  166. } else {
  167. log.error(callbackRes.getMsg());
  168. }
  169. vo.setBody(reatiVO);
  170. return vo;
  171. }
  172. /**门店解除绑定*/
  173. if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_UNBIND_MSG)) {
  174. ElemeRetailMerchantResultVo elemeRetailMerchantResultVo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class);
  175. callbackRes.getData().setBindResult(elemeRetailMerchantResultVo.getBindResult());
  176. callbackRes.getData().setOperatingTime(elemeRetailMerchantResultVo.getOperatingTime());
  177. callbackRes.getData().setOperatingUser(elemeRetailMerchantResultVo.getOperatingUser());
  178. callbackRes.getData().setShopList(elemeRetailMerchantResultVo.getShopList());
  179. if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) {
  180. ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData();
  181. apiWaimaiPlatformService.updateShop(shopMappingVo);
  182. } else {
  183. log.error(callbackRes.getMsg());
  184. }
  185. vo.setBody(reatiVO);
  186. return vo;
  187. }
  188. vo.setBody(reatiVO);
  189. return vo;
  190. }
  191. }