123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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<String, String> params) {
- // JSONObject res = new JSONObject();
- //
- // if (null == params || params.size() == 0) {
- // return "";
- // }
- //
- // log.info("饿了么零售授权回调--------" + JSONObject.toJSONString(params));
- // ResObject<ElemeRetailMerchantResultVo> 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<String, String> 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<ElemeRetailMerchantResultVo> 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<String, String> 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<ElemeRetailMerchantResultVo> 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;
- }
- }
|