package com.ydd.third.waimai; import com.alibaba.fastjson.JSONObject; import com.ydd.common.exception.BusinessException; import com.ydd.third.common.utils.HttpUtils; import com.ydd.third.common.utils.StringUtils; import com.ydd.third.common.vo.ResObject; import com.ydd.third.common.vo.waimai.*; import com.ydd.third.common.vo.waimai.meituan.RefundFoodItemVo; import com.ydd.third.waimai.eleRetai.EleRetaiClient; import com.ydd.third.waimai.eleme.ElemeClient; import com.ydd.third.waimai.meituan.MeituanClient; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; /** * @ClassName Client * @Deacription TODO * @Author peakren * @Date 2/4/21 10:20 PM * @Version 1.0 **/ @Slf4j @Service("waimaiClient") public class Client { @Autowired MeituanClient meituanClient; @Autowired ElemeClient elemeClient; @Autowired EleRetaiClient eleRetaiClient; /** * ok * 查询订单 * @param queryOrderVo * @return */ public ResObject queryOrderById(QueryOrderVo queryOrderVo) { String client = queryOrderVo.getLbClient(); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } if (client.equals("meituan")) { ResObject res = meituanClient.queryOrderById(queryOrderVo); return res; } else if (client.equals("eleme")) { ResObject res = elemeClient.getOrder(queryOrderVo); return res; } else { throw new BusinessException("lb_client参数不正确"); } } /** * ok * 对订单进行确认 * @param confirmOrderVo * @return */ public ResObject confirmOrder(ConfirmOrderVo confirmOrderVo){ // JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr); String client = confirmOrderVo.getLbClient(); //jsonParams.getString("lb_client"); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res ; if (client.equals("meituan")) { res = meituanClient.confirmOrder(confirmOrderVo); } else if (client.equals("eleme")) { res = elemeClient.confirmOrder(confirmOrderVo); } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 取消订单 * @param cancelOrderVo * @return */ public ResObject cancelOrder(CancelOrderVo cancelOrderVo) { // JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr); String client = cancelOrderVo.getLbClient(); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res; if (client.equals("meituan")) { res = meituanClient.cancelOrder(cancelOrderVo); } else if (client.equals("eleme")) { res = elemeClient.cancelOrder(cancelOrderVo); } else if (client.equals("elemeretail")) { res = eleRetaiClient.cancelOrder(cancelOrderVo); } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 自配订单同步配送信息 * @param syncRiderPositionVo * @return */ public ResObject syncRiderPositionStatus(SyncRiderPositionStatusVo syncRiderPositionVo) { ; String client = syncRiderPositionVo.getLbClient(); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res= new ResObject(); if (client.equals("meituan")) { res = meituanClient.syncRiderPosition(syncRiderPositionVo); } else if (client.equals("eleme")) { //同步位置 if(syncRiderPositionVo.getLongitude()!=null&&syncRiderPositionVo.getLongitude().compareTo(BigDecimal.ZERO)>0 &&("DELIVERY_START".equals(syncRiderPositionVo.getDeliverState().name()))){ res = elemeClient.selfDeliveryLocationSync(syncRiderPositionVo); } //同步状态 res = elemeClient.selfDeliveryStateSync(syncRiderPositionVo); }else if (client.equals("elemeretail")){ if(syncRiderPositionVo.getLogisticsStatus()==16){ res= eleRetaiClient.complete(syncRiderPositionVo.getOrderId(),syncRiderPositionVo.getCourierPhone()); }else{ if(syncRiderPositionVo.getLongitude()!=null&&syncRiderPositionVo.getLongitude().compareTo(BigDecimal.ZERO)>0){ eleRetaiClient.syncRiderPosition(syncRiderPositionVo); } if(syncRiderPositionVo.getLogisticsStatus().intValue()!=-1){ res= eleRetaiClient.syncRiderPositionStatus(syncRiderPositionVo); } } }else if (client.equals("shantang")){ String json = syncRiderPositionVo.getShanTangdto(); res = new ResObject(); try { String resp = HttpUtils.sendJsonPost("https://business-api.hsst100.com/order/delivery/delivery/callback",json); res.setCode(0); res.setMsg("操作成功"+resp); } catch (Exception e) { e.printStackTrace(); } } else { throw new BusinessException("lb_client参数不正确"); } return res; } /** * ok * 订单同意退款 * @param agreeOrderRefundVo * @return */ public ResObject agreeOrderRefund(AgreeOrderRefundVo agreeOrderRefundVo) { String client = agreeOrderRefundVo.getLbClient(); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res; if (client.equals("meituan")) { res = meituanClient.agreeOrderRefund(agreeOrderRefundVo); } else if (client.equals("eleme")) { res = elemeClient.agreeRefundOrder(agreeOrderRefundVo); } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 订单拒绝退款 * @param rejectOrderRefundVo * @return */ public ResObject rejectOrderRefund(RejectOrderRefundVo rejectOrderRefundVo) { String client = rejectOrderRefundVo.getLbClient(); //jsonParams.getString("lb_client"); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res; if (client.equals("meituan")) { res = meituanClient.rejectOrderRefund(rejectOrderRefundVo); } else if (client.equals("eleme")) { res = elemeClient.disagreeRefundOrder(rejectOrderRefundVo); } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 部分退款-查询部分退款商品 * @param queryPartRefundFoodsVo * @return */ public ResObject> queryPartRefundFoods(QueryPartRefundFoodsVo queryPartRefundFoodsVo) { String client = queryPartRefundFoodsVo.getLbClient(); //jsonParams.getString("lb_client"); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject> res; if (client.equals("meituan")) { res = meituanClient.queryPartRefundFoods(queryPartRefundFoodsVo); } else if (client.equals("eleme")) { res = new ResObject<>(); res.setMsg("饿了么没有相应的接口"); } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 部分退款-申请部分退款 * @param applyPartRefundVo * @return */ public ResObject applyPartRefund(ApplyPartRefundVo applyPartRefundVo) { //JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr); String client = applyPartRefundVo.getLbClient(); // .getLjsonParams.getString("lb_client"); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res; if (client.equals("meituan")) { res = meituanClient.applyPartRefund(applyPartRefundVo); } else if (client.equals("eleme")) { res = elemeClient.refundParty(applyPartRefundVo); //商家部分退款 } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 催单回复 * @param orderRemindReplyVo * @return */ public ResObject orderRemindReply(OrderRemindReplyVo orderRemindReplyVo) { String client = orderRemindReplyVo.getLbClient(); //jsonParams.getString("lb_client"); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lbClient参数"); } ResObject res; if (client.equals("meituan")) { res = meituanClient.orderRemindReply(orderRemindReplyVo); } else if (client.equals("eleme")) { res = elemeClient.replyReminder(orderRemindReplyVo); //回复催单 } else { throw new BusinessException("lbClient参数不正确"); } return res; } /** * ok * 查询门店信息 * @param jsonParamsStr * @return */ public String queryShopInfo(String jsonParamsStr) { JSONObject jsonParams = JSONObject.parseObject(jsonParamsStr); String client = jsonParams.getString("lb_client"); if (StringUtils.isBlank(client)) { throw new BusinessException("未指定lb_client参数"); } String res = ""; if (client.equals("meituan")) { res = meituanClient.queryPoiInfo(jsonParamsStr); } else if (client.equals("eleme")) { res = elemeClient.getShop(jsonParamsStr); //回复催单 } else { throw new BusinessException("lb_client参数不正确"); } return res; } }