package com.ydd.app.callback.controller; import com.alibaba.fastjson.JSONObject; import com.ydd.api.EleRetailApi; import com.ydd.app.service.ApiWaimaiPlatformService; import com.ydd.app.service.ApiWaimaiService; import com.ydd.module.service.IWaimaiOrderService; import com.ydd.third.common.vo.ResObject; import com.ydd.third.common.vo.waimai.ElemeRetailMerchantResultVo; import com.ydd.third.waimai.eleRetai.common.EleRetaiApi; import com.ydd.third.waimai.eleRetai.vo.EleReatiVO; import com.ydd.third.waimai.eleRetai.vo.EleRetailResultVO; import com.ydd.third.waimai.eleRetai.vo.SourceOrderVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.Map; @Slf4j @RestController @RequestMapping("/app/waimai/elemeRetail/callback") public class ElemeRetailWaiMaiCallback { @Resource private ApiWaimaiService apiWaimaiService; // @Autowired // private ElemeretailCallback callback; @Autowired private IWaimaiOrderService iWaimaiOrderService; @Autowired private EleRetailApi eleRetaiClient; @Autowired ApiWaimaiPlatformService apiWaimaiPlatformService; // @RequestMapping("/saveShop") // public String saveShop(@RequestParam Map params) { // JSONObject res = new JSONObject(); // // if (null == params || params.size() == 0) { // return ""; // } // // log.info("饿了么零售授权回调--------" + JSONObject.toJSONString(params)); // ResObject callbackRes = callback.doStoreMap(params); // // ElemeRetailMerchantResultVo vo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class); // callbackRes.getData().setBindResult(vo.getBindResult()); // callbackRes.getData().setOperatingTime(vo.getOperatingTime()); // callbackRes.getData().setOperatingUser(vo.getOperatingUser()); // callbackRes.getData().setShopList(vo.getShopList()); // // if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) { // ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData(); // apiWaimaiService.saveShop(shopMappingVo); // return res.toJSONString(); // } else { // log.error(callbackRes.getMsg()); // } // // return ""; // } @RequestMapping("/doOAuth") public Object updateShop(@RequestParam Map params) { JSONObject res = new JSONObject(); log.info("=========饿了么零售绑定回调信息--------" + JSONObject.toJSONString(params)); EleRetailResultVO resultVO = new EleRetailResultVO(); resultVO.setCmd(params.get("cmd")); resultVO.setSign(params.get("sign")); resultVO.setSource(params.get("source")); resultVO.setTicket(params.get("ticket")); resultVO.setVersion(params.get("version")); resultVO.setTimestamp(Long.parseLong(params.get("timestamp"))); EleReatiVO reatiVO = new EleReatiVO(); reatiVO.setErrno("0"); reatiVO.setError("success"); resultVO.setBody(reatiVO); if (null == params || params.size() == 0) { return resultVO; } ResObject callbackRes = eleRetaiClient.doStoreMap(params); /**门店绑定*/ if (params.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_BIND_MSG)) { ElemeRetailMerchantResultVo vo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class); callbackRes.getData().setBindResult(vo.getBindResult()); callbackRes.getData().setOperatingTime(vo.getOperatingTime()); callbackRes.getData().setOperatingUser(vo.getOperatingUser()); callbackRes.getData().setShopList(vo.getShopList()); if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) { ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData(); apiWaimaiPlatformService.saveShop(shopMappingVo); } else { log.error(callbackRes.getMsg()); } return resultVO; } /**门店解除绑定*/ if (params.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_UNBIND_MSG)) { ElemeRetailMerchantResultVo vo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class); callbackRes.getData().setBindResult(vo.getBindResult()); callbackRes.getData().setOperatingTime(vo.getOperatingTime()); callbackRes.getData().setOperatingUser(vo.getOperatingUser()); callbackRes.getData().setShopList(vo.getShopList()); if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) { ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData(); // apiWaimaiPlatformService.updateShop(shopMappingVo); } else { log.error(callbackRes.getMsg()); } return resultVO; } return reatiVO; } @RequestMapping("/doOrder") public Object doOrder(@RequestParam(required = false) Map jsonParams) { log.info("---------------->"); log.info("收到饿百推送消息-------" + jsonParams); EleRetailResultVO vo = new EleRetailResultVO(); vo.setCmd(jsonParams.get("cmd")); vo.setSign(jsonParams.get("sign")); vo.setSource(jsonParams.get("source")); vo.setTicket(jsonParams.get("ticket")); vo.setVersion(jsonParams.get("version")); vo.setTimestamp(Long.parseLong(jsonParams.get("timestamp"))); EleReatiVO reatiVO = new EleReatiVO(); reatiVO.setErrno("0"); reatiVO.setError("success"); if (jsonParams == null) { return vo; } String body = jsonParams.get("body"); JSONObject jsonObject = JSONObject.parseObject(body); //接到新订单通知 if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_ORDER_CREATE)) { // OrderGetResult orderGetResult = eleRetaiClient.getOrder(jsonObject.get("order_id").toString()); // if (orderGetResult.getData().getOrder().getDown_flag() == 1) { // orderGetResult = eleRetaiClient.getOrder(jsonObject.get("order_id").toString()); // } // String orderId = apiWaimaiService.createOrder(orderGetResult); String orderId = apiWaimaiService.newEBaiOrder(jsonObject.get("order_id").toString(),jsonObject.get("platform_shop_id").toString()); reatiVO.setData(new SourceOrderVO(orderId)); vo.setBody(reatiVO); return vo; } /**订单状态推送*/ if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_ORDER_STATUS_PUSH)) { apiWaimaiService.updateOrderStatus(jsonObject); vo.setBody(reatiVO); return vo; } /**用户申请订单取消 退款*/ if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_ORDER_USER_CANCEL)) { apiWaimaiService.doEleRetaiCancel(jsonObject.getString("order_id"), jsonObject.getInteger("type")); vo.setBody(reatiVO); return vo; } ResObject callbackRes = eleRetaiClient.doStoreMap(jsonParams); /**门店绑定*/ if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_BIND_MSG)) { ElemeRetailMerchantResultVo elemeRetailMerchantResultVo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class); callbackRes.getData().setBindResult(elemeRetailMerchantResultVo.getBindResult()); callbackRes.getData().setOperatingTime(elemeRetailMerchantResultVo.getOperatingTime()); callbackRes.getData().setOperatingUser(elemeRetailMerchantResultVo.getOperatingUser()); callbackRes.getData().setShopList(elemeRetailMerchantResultVo.getShopList()); if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) { ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData(); apiWaimaiPlatformService.saveShop(shopMappingVo); } else { log.error(callbackRes.getMsg()); } vo.setBody(reatiVO); return vo; } /**门店解除绑定*/ if (jsonParams.get("cmd").equals(EleRetaiApi.ELE_RETAI_SHOP_UNBIND_MSG)) { ElemeRetailMerchantResultVo elemeRetailMerchantResultVo = JSONObject.parseObject(callbackRes.getData().getBody(), ElemeRetailMerchantResultVo.class); callbackRes.getData().setBindResult(elemeRetailMerchantResultVo.getBindResult()); callbackRes.getData().setOperatingTime(elemeRetailMerchantResultVo.getOperatingTime()); callbackRes.getData().setOperatingUser(elemeRetailMerchantResultVo.getOperatingUser()); callbackRes.getData().setShopList(elemeRetailMerchantResultVo.getShopList()); if (callbackRes.getData().getBindResult() == 1 && callbackRes.getCode() == 0) { ElemeRetailMerchantResultVo shopMappingVo = callbackRes.getData(); apiWaimaiPlatformService.updateShop(shopMappingVo); } else { log.error(callbackRes.getMsg()); } vo.setBody(reatiVO); return vo; } vo.setBody(reatiVO); return vo; } }