123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package com.ydd.app.callback.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.ydd.api.DeliveryCallbackApi;
- import com.ydd.app.service.ApiOrderBackService;
- import com.ydd.app.service.ApiShopService;
- import com.ydd.app.service.impl.ApiCallBackContent;
- import com.ydd.app.service.impl.ApiCallBackFengNiao;
- import com.ydd.common.enums.DeliveryTypeEnums;
- import com.ydd.module.domain.DspDelivery;
- import com.ydd.module.domain.OrderDelivery;
- import com.ydd.module.dto.CallBackOrderDto;
- import com.ydd.module.service.IDspDeliveryService;
- import com.ydd.module.service.IOrderDeliveryService;
- import com.ydd.third.common.dto.FengniaoV3Token;
- import com.ydd.third.common.utils.StringUtils;
- import com.ydd.third.common.vo.ResObject;
- import com.ydd.third.common.vo.callback.CallBackOrderVo;
- import com.ydd.third.common.vo.callback.FengniaoV3CallbackOrderVo;
- import com.ydd.third.common.vo.callback.FengniaoV3CallbackStoreVo;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- @Slf4j
- @RestController
- @RequestMapping("/app/delivery/fengniao/callback")
- public class FengniaoDeliveryCallback {
- @Autowired
- private DeliveryCallbackApi callback;
- @Resource
- private ApiShopService apiShopService;
- @Resource
- private ApiOrderBackService apiOrderService;
- @Resource
- IDspDeliveryService iDspDeliveryService;
- @Resource
- private IOrderDeliveryService iOrderDeliveryService;
- @RequestMapping("/doAuth")
- public String doAuth(@RequestBody JSONObject jsonParam) {
- String code = jsonParam.getString("code");
- String merchantId = jsonParam.getString("merchant_id");
- // String code = params.get("code");
- // String state = params.get("state");
- if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(merchantId)) {
- ResObject<FengniaoV3Token> res = callback.doToken(code, merchantId);
- log.info("res:" + JSONObject.toJSONString(res));
- if (res.getCode() == 0) {
- FengniaoV3Token tokenVo = res.getData();
- log.info("data:" + JSONObject.toJSONString(tokenVo));
- String appId = tokenVo.getAppId(); //应用id
- String merchantI= tokenVo.getMerchantId(); //商户id
- String accessToken = tokenVo.getAccessToken(); //凭证token
- String refreshToken = tokenVo.getRefreshToken(); //刷新token
- Long expiresIn = tokenVo.getExpireIn(); //access_token剩余有效时间
- Long reExpireIn = tokenVo.getReExpireIn(); //refresh_token剩余有效时间
- //进行业务处理
- DspDelivery delivery = new DspDelivery();
- delivery.setAuthToken(accessToken);
- delivery.setRefreshToken(refreshToken);
- delivery.setExpiresIn(expiresIn);
- delivery.setReExpireIn(reExpireIn);
- iDspDeliveryService.update(delivery,new UpdateWrapper<DspDelivery>().eq("shop_id",merchantId));
- return "获取token成功";
- } else {
- return res.getMsg();
- }
- } else {
- return "非法访问!";
- }
- }
- /**
- * 蜂鸟V3的回调
- * @param jsonParam
- * @return
- */
- @PostMapping("/doOrderAndStore")
- public String doOrderAndStore(@RequestBody JSONObject jsonParam){
- if(null == jsonParam) {
- return "";
- }
- JSONObject dataJson = jsonParam.getJSONObject("business_data");
- if (null == dataJson) {
- return "";
- }
- String businessType = dataJson.getString("callback_business_type");
- if (StringUtils.isBlank("businessType")) {
- return "";
- }
- log.info("蜂鸟回调参数"+jsonParam);
- if (businessType.equals("orderStatusNotify") || businessType.equals("abnormalReportNotify")
- || businessType.equals("cookingFinishNotify")) {
- CallBackOrderVo vo = new CallBackOrderVo();
- vo.setLbClient(DeliveryTypeEnums.FENG_NIAO.getName());
- vo.setParams(jsonParam);
- ResObject<FengniaoV3CallbackOrderVo> callbackRes = (ResObject<FengniaoV3CallbackOrderVo>) callback.doOrder(vo);
- if (callbackRes.getCode() == 0) {
- FengniaoV3CallbackOrderVo orderVo = callbackRes.getData();
- Integer orderStatus = orderVo.getOrderStatus();
- if (businessType.equals("orderStatusNotify")) { //订单状态变更回调
- if (null != orderStatus) {
- //订单生成0,,20:骑手接单,80:骑手到店,2:配送中,3:已完成,4:已取消,5:配送异常
- ApiCallBackContent content = new ApiCallBackContent(new ApiCallBackFengNiao(orderVo));
- OrderDelivery orderDelivery = iOrderDeliveryService.getOne(new QueryWrapper<OrderDelivery>().eq("child_order_sn",orderVo.getPartnerOrderCode()));
- DspDelivery delivery = iDspDeliveryService.findById(orderDelivery.getDeliveryId());
- CallBackOrderDto dto = content.createCallBack();
- dto.setParentOrderSn(orderDelivery.getOrderSn());
- dto.setDeliveryType(delivery.getType());
- apiOrderService.callBackOrder(dto);
- }
- } else if (businessType.equals("abnormalReportNotify")) { //异常报备回调
- //此处处理订单异常
- } else { //商户出餐回调
- //此处处理商户出餐回调
- }
- }
- } else if (businessType.equals("chainstoreStatusNotify") ) {
- ResObject<FengniaoV3CallbackStoreVo> callbackRes = callback.doStore(jsonParam);
- FengniaoV3CallbackStoreVo storeVo = callbackRes.getData();
- Integer status = storeVo.getStatus(); // 门店认证状态
- Integer modifyStatus = storeVo.getModifyStatus(); //门店修改状态
- if (null != status) { // 门店认证状态
- String statusDesc = "";
- //10-上架审核中,20-正常(已上架),30-上架审核失败,40-已冻结,50-已下架
- apiShopService.callBackCreate(storeVo);
- }
- if (null != modifyStatus) { //门店修改状态
- String modifyStatusDesc = "";
- //0-无修改,10-资料修改审核中,20-审核通过,30-审核驳回
- apiShopService.callBackEdit(storeVo);
- }
- }
- return "ok";
- }
- }
|