FengniaoDeliveryCallback.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package com.ydd.app.callback.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  5. import com.ydd.api.DeliveryCallbackApi;
  6. import com.ydd.app.service.ApiOrderBackService;
  7. import com.ydd.app.service.ApiShopService;
  8. import com.ydd.app.service.impl.ApiCallBackContent;
  9. import com.ydd.app.service.impl.ApiCallBackFengNiao;
  10. import com.ydd.common.enums.DeliveryTypeEnums;
  11. import com.ydd.module.domain.DspDelivery;
  12. import com.ydd.module.domain.OrderDelivery;
  13. import com.ydd.module.dto.CallBackOrderDto;
  14. import com.ydd.module.service.IDspDeliveryService;
  15. import com.ydd.module.service.IOrderDeliveryService;
  16. import com.ydd.third.common.dto.FengniaoV3Token;
  17. import com.ydd.third.common.utils.StringUtils;
  18. import com.ydd.third.common.vo.ResObject;
  19. import com.ydd.third.common.vo.callback.CallBackOrderVo;
  20. import com.ydd.third.common.vo.callback.FengniaoV3CallbackOrderVo;
  21. import com.ydd.third.common.vo.callback.FengniaoV3CallbackStoreVo;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.RequestBody;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.RestController;
  28. import javax.annotation.Resource;
  29. @Slf4j
  30. @RestController
  31. @RequestMapping("/app/delivery/fengniao/callback")
  32. public class FengniaoDeliveryCallback {
  33. @Autowired
  34. private DeliveryCallbackApi callback;
  35. @Resource
  36. private ApiShopService apiShopService;
  37. @Resource
  38. private ApiOrderBackService apiOrderService;
  39. @Resource
  40. IDspDeliveryService iDspDeliveryService;
  41. @Resource
  42. private IOrderDeliveryService iOrderDeliveryService;
  43. @RequestMapping("/doAuth")
  44. public String doAuth(@RequestBody JSONObject jsonParam) {
  45. String code = jsonParam.getString("code");
  46. String merchantId = jsonParam.getString("merchant_id");
  47. // String code = params.get("code");
  48. // String state = params.get("state");
  49. if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(merchantId)) {
  50. ResObject<FengniaoV3Token> res = callback.doToken(code, merchantId);
  51. log.info("res:" + JSONObject.toJSONString(res));
  52. if (res.getCode() == 0) {
  53. FengniaoV3Token tokenVo = res.getData();
  54. log.info("data:" + JSONObject.toJSONString(tokenVo));
  55. String appId = tokenVo.getAppId(); //应用id
  56. String merchantI= tokenVo.getMerchantId(); //商户id
  57. String accessToken = tokenVo.getAccessToken(); //凭证token
  58. String refreshToken = tokenVo.getRefreshToken(); //刷新token
  59. Long expiresIn = tokenVo.getExpireIn(); //access_token剩余有效时间
  60. Long reExpireIn = tokenVo.getReExpireIn(); //refresh_token剩余有效时间
  61. //进行业务处理
  62. DspDelivery delivery = new DspDelivery();
  63. delivery.setAuthToken(accessToken);
  64. delivery.setRefreshToken(refreshToken);
  65. delivery.setExpiresIn(expiresIn);
  66. delivery.setReExpireIn(reExpireIn);
  67. iDspDeliveryService.update(delivery,new UpdateWrapper<DspDelivery>().eq("shop_id",merchantId));
  68. return "获取token成功";
  69. } else {
  70. return res.getMsg();
  71. }
  72. } else {
  73. return "非法访问!";
  74. }
  75. }
  76. /**
  77. * 蜂鸟V3的回调
  78. * @param jsonParam
  79. * @return
  80. */
  81. @PostMapping("/doOrderAndStore")
  82. public String doOrderAndStore(@RequestBody JSONObject jsonParam){
  83. if(null == jsonParam) {
  84. return "";
  85. }
  86. JSONObject dataJson = jsonParam.getJSONObject("business_data");
  87. if (null == dataJson) {
  88. return "";
  89. }
  90. String businessType = dataJson.getString("callback_business_type");
  91. if (StringUtils.isBlank("businessType")) {
  92. return "";
  93. }
  94. log.info("蜂鸟回调参数"+jsonParam);
  95. if (businessType.equals("orderStatusNotify") || businessType.equals("abnormalReportNotify")
  96. || businessType.equals("cookingFinishNotify")) {
  97. CallBackOrderVo vo = new CallBackOrderVo();
  98. vo.setLbClient(DeliveryTypeEnums.FENG_NIAO.getName());
  99. vo.setParams(jsonParam);
  100. ResObject<FengniaoV3CallbackOrderVo> callbackRes = (ResObject<FengniaoV3CallbackOrderVo>) callback.doOrder(vo);
  101. if (callbackRes.getCode() == 0) {
  102. FengniaoV3CallbackOrderVo orderVo = callbackRes.getData();
  103. Integer orderStatus = orderVo.getOrderStatus();
  104. if (businessType.equals("orderStatusNotify")) { //订单状态变更回调
  105. if (null != orderStatus) {
  106. //订单生成0,,20:骑手接单,80:骑手到店,2:配送中,3:已完成,4:已取消,5:配送异常
  107. ApiCallBackContent content = new ApiCallBackContent(new ApiCallBackFengNiao(orderVo));
  108. OrderDelivery orderDelivery = iOrderDeliveryService.getOne(new QueryWrapper<OrderDelivery>().eq("child_order_sn",orderVo.getPartnerOrderCode()));
  109. DspDelivery delivery = iDspDeliveryService.findById(orderDelivery.getDeliveryId());
  110. CallBackOrderDto dto = content.createCallBack();
  111. dto.setParentOrderSn(orderDelivery.getOrderSn());
  112. dto.setDeliveryType(delivery.getType());
  113. apiOrderService.callBackOrder(dto);
  114. }
  115. } else if (businessType.equals("abnormalReportNotify")) { //异常报备回调
  116. //此处处理订单异常
  117. } else { //商户出餐回调
  118. //此处处理商户出餐回调
  119. }
  120. }
  121. } else if (businessType.equals("chainstoreStatusNotify") ) {
  122. ResObject<FengniaoV3CallbackStoreVo> callbackRes = callback.doStore(jsonParam);
  123. FengniaoV3CallbackStoreVo storeVo = callbackRes.getData();
  124. Integer status = storeVo.getStatus(); // 门店认证状态
  125. Integer modifyStatus = storeVo.getModifyStatus(); //门店修改状态
  126. if (null != status) { // 门店认证状态
  127. String statusDesc = "";
  128. //10-上架审核中,20-正常(已上架),30-上架审核失败,40-已冻结,50-已下架
  129. apiShopService.callBackCreate(storeVo);
  130. }
  131. if (null != modifyStatus) { //门店修改状态
  132. String modifyStatusDesc = "";
  133. //0-无修改,10-资料修改审核中,20-审核通过,30-审核驳回
  134. apiShopService.callBackEdit(storeVo);
  135. }
  136. }
  137. return "ok";
  138. }
  139. }