| @@ -151,6 +151,9 @@ public class WxOrderController extends BaseController { | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| return new ResultData(Result.ERROR,e.getMessage()); | return new ResultData(Result.ERROR,e.getMessage()); | ||||
| } | } | ||||
| if(EnumPayWay.PAY_WAY_TT.equals(getPayWay())){ | |||||
| return new ResultData(Result.ERROR,"测试阶段,暂无法支付"); | |||||
| } | |||||
| List<OrderComposeSaveDto> list = new ArrayList<>(); | List<OrderComposeSaveDto> list = new ArrayList<>(); | ||||
| OrderComposeSaveDto dto = new OrderComposeSaveDto(); | OrderComposeSaveDto dto = new OrderComposeSaveDto(); | ||||
| dto.setSignleOrder(orderSaveDto); | dto.setSignleOrder(orderSaveDto); | ||||
| @@ -36,8 +36,8 @@ public class MqBaseConsumer { | |||||
| private FmInsideCouponVerifyMsgServiceImpl fmInsideCouponVerifyMsgService; | private FmInsideCouponVerifyMsgServiceImpl fmInsideCouponVerifyMsgService; | ||||
| @Autowired | @Autowired | ||||
| private FmInsideOrderRefundMsgServiceImpl fmInsideOrderRefundMsgService; | private FmInsideOrderRefundMsgServiceImpl fmInsideOrderRefundMsgService; | ||||
| @Autowired | |||||
| private FmInsideOrderPushMsgServiceImpl fmInsideOrderPushMsgService; | |||||
| // @Autowired | |||||
| // private FmInsideOrderPushMsgServiceImpl fmInsideOrderPushMsgService; | |||||
| @Autowired | @Autowired | ||||
| private FmInsideOrderPushDeliveryMsgServiceImpl fmInsideOrderPushDeliveryMsgServiceImpl; | private FmInsideOrderPushDeliveryMsgServiceImpl fmInsideOrderPushDeliveryMsgServiceImpl; | ||||
| @Autowired | @Autowired | ||||
| @@ -12,6 +12,8 @@ public enum EnumAppType { | |||||
| MP_S(3,"公众号-服务号"), | MP_S(3,"公众号-服务号"), | ||||
| MP_P(4, "公众号-订阅号"), | MP_P(4, "公众号-订阅号"), | ||||
| A(5, "A端"), | A(5, "A端"), | ||||
| TT_GOODS(10, "抖音商品库"), | |||||
| ; | ; | ||||
| public static EnumAppType getEnum(Integer code) { | public static EnumAppType getEnum(Integer code) { | ||||
| @@ -488,7 +488,7 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { | |||||
| WxAppinfo appinfoQ = new WxAppinfo(); | WxAppinfo appinfoQ = new WxAppinfo(); | ||||
| // appinfoQ.updateTenantInfo(tenantInfo); | // appinfoQ.updateTenantInfo(tenantInfo); | ||||
| appinfoQ.setPlat(EnumAppPlat.TOUTIAO.getCode()); | appinfoQ.setPlat(EnumAppPlat.TOUTIAO.getCode()); | ||||
| appinfoQ.setType(EnumAppType.A.getCode()); | |||||
| appinfoQ.setType(EnumAppType.TT_GOODS.getCode()); | |||||
| WxAppinfo appinfo = wxAppinfoMapper.selectOne(new QueryWrapper<>(appinfoQ)); | WxAppinfo appinfo = wxAppinfoMapper.selectOne(new QueryWrapper<>(appinfoQ)); | ||||
| TtWebService ttWebService = maUtil.getTtWebService(appinfo); | TtWebService ttWebService = maUtil.getTtWebService(appinfo); | ||||
| if (StringUtils.isBlank(appinfo.getAccessToken())) { | if (StringUtils.isBlank(appinfo.getAccessToken())) { | ||||
| @@ -1,183 +1,183 @@ | |||||
| package com.iformall.service.msg.impl; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.po.msg.BaseMsg; | |||||
| import com.iformall.domain.po.msg.FmInsideOrderPushMsg; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.TtCUserMapper; | |||||
| import com.iformall.mapper.TtOrderPushErrorMapper; | |||||
| import com.iformall.mapper.WxPayOrderMapper; | |||||
| import com.iformall.service.*; | |||||
| import com.iformall.service.msg.MsgSendService; | |||||
| import com.iformall.service.pay.PayServiceFactory; | |||||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||||
| import com.iformall.utils.DateUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| /** | |||||
| * | |||||
| * @author Stormeye Wu | |||||
| * @date 2019/5/10 | |||||
| */ | |||||
| @Service | |||||
| public class FmInsideOrderPushMsgServiceImpl implements MsgSendService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxOrderService orderService; | |||||
| @Autowired | |||||
| WxAppinfoService wxAppinfoService; | |||||
| @Autowired | |||||
| PayServiceFactory payServiceFactory; | |||||
| @Autowired | |||||
| WxPayOrderService wxPayOrderService; | |||||
| @Autowired | |||||
| TtCUserMapper ttCUserMapper; | |||||
| @Autowired | |||||
| WxPayOrderMapper wxPayOrderMapper; | |||||
| @Autowired | |||||
| TtOrderPushErrorMapper ttOrderPushErrorMapper; | |||||
| @Autowired | |||||
| private String fmExceptionEmails; | |||||
| @Autowired | |||||
| private MailService mailService; | |||||
| @Override | |||||
| public void send(BaseMsg baseMsg) throws Exception{ | |||||
| FmInsideOrderPushMsg msg = (FmInsideOrderPushMsg)baseMsg; | |||||
| try{ | |||||
| Thread.currentThread().sleep(1000);//延时秒 | |||||
| }catch(Exception e){} | |||||
| WxBatchOrder border = new WxBatchOrder(); | |||||
| border.setTenantId(msg.getTenantId()); | |||||
| border.setParentTenantId(msg.getParentTenantId()); | |||||
| border.setId(msg.getBatchOrderId()); | |||||
| WxBatchOrder batchOrder = orderService.batchOrderDetail(border); | |||||
| if(batchOrder == null){ | |||||
| logger.error("主订单未找到: " + msg.getBatchOrderId()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "主订单未找到" + msg.getBatchOrderId()); | |||||
| } | |||||
| if(EnumPayWay.PAY_WAY_TT.getCode().equals(batchOrder.getPayVendor()) | |||||
| && EnumComposeOrder.SINGLE.getCode().equals(batchOrder.getOrderType()) | |||||
| && batchOrder.getOrders().size() == 1){ | |||||
| WxAppinfo appinfo = wxAppinfoService.getCAppInfo(batchOrder,EnumPayWay.PAY_WAY_TT.getPlat()); | |||||
| try{ | |||||
| payOrderPush(appinfo,batchOrder); | |||||
| }catch(Exception e){ | |||||
| logger.error("订单同步异常batchOrderId"+batchOrder.getId()+"{}"+e.getMessage()); | |||||
| // String[] receivers = fmExceptionEmails.split(","); | |||||
| // StringBuilder sb = new StringBuilder(); | |||||
| // sb.append(DateUtils.date2String(new Date())); | |||||
| // sb.append("\n"); | |||||
| // sb.append("tenantId="+batchOrder.getTenantId()); | |||||
| // sb.append("\n"); | |||||
| // sb.append(e.getMessage()); | |||||
| // sb.append("\n"); | |||||
| // sb.append("batchOrderId="+batchOrder.getId()); | |||||
| // //发送邮件 | |||||
| // mailService.sendSimpleMail(receivers, batchOrder.getTenantId()+"订单同步异常", sb.toString()); | |||||
| TtOrderPushError pushError = new TtOrderPushError(); | |||||
| pushError.setId(batchOrder.getId()); | |||||
| pushError.updateTenantInfo(batchOrder); | |||||
| pushError.setErrMsg(e.getMessage()); | |||||
| saveOrUpdate(pushError); | |||||
| } | |||||
| // WxOrderCouponVo wxOrderCouponVo = batchOrder.getOrders().get(0); | |||||
| // if(EnumPayType.PAY_PAYMENT.getCode().equals(wxOrderCouponVo.getPaymentType())){ | |||||
| //package com.iformall.service.msg.impl; | |||||
| // | |||||
| //import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| //import com.iformall.common.ErrorCode; | |||||
| //import com.iformall.domain.po.*; | |||||
| //import com.iformall.domain.po.msg.BaseMsg; | |||||
| //import com.iformall.domain.po.msg.FmInsideOrderPushMsg; | |||||
| //import com.iformall.enums.*; | |||||
| //import com.iformall.exception.MallinkException; | |||||
| //import com.iformall.mapper.TtCUserMapper; | |||||
| //import com.iformall.mapper.TtOrderPushErrorMapper; | |||||
| //import com.iformall.mapper.WxPayOrderMapper; | |||||
| //import com.iformall.service.*; | |||||
| //import com.iformall.service.msg.MsgSendService; | |||||
| //import com.iformall.service.pay.PayServiceFactory; | |||||
| //import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||||
| //import com.iformall.utils.DateUtils; | |||||
| //import org.apache.commons.lang3.StringUtils; | |||||
| //import org.slf4j.Logger; | |||||
| //import org.slf4j.LoggerFactory; | |||||
| //import org.springframework.beans.factory.annotation.Autowired; | |||||
| //import org.springframework.stereotype.Service; | |||||
| // | |||||
| //import java.util.Date; | |||||
| //import java.util.List; | |||||
| // | |||||
| ///** | |||||
| // * | |||||
| // * @author Stormeye Wu | |||||
| // * @date 2019/5/10 | |||||
| // */ | |||||
| //@Service | |||||
| //public class FmInsideOrderPushMsgServiceImpl implements MsgSendService { | |||||
| // private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| // | |||||
| // @Autowired | |||||
| // private WxOrderService orderService; | |||||
| // | |||||
| // @Autowired | |||||
| // WxAppinfoService wxAppinfoService; | |||||
| // | |||||
| // @Autowired | |||||
| // PayServiceFactory payServiceFactory; | |||||
| // | |||||
| // @Autowired | |||||
| // WxPayOrderService wxPayOrderService; | |||||
| // | |||||
| // @Autowired | |||||
| // TtCUserMapper ttCUserMapper; | |||||
| // | |||||
| // @Autowired | |||||
| // WxPayOrderMapper wxPayOrderMapper; | |||||
| // | |||||
| // @Autowired | |||||
| // TtOrderPushErrorMapper ttOrderPushErrorMapper; | |||||
| // | |||||
| // @Autowired | |||||
| // private String fmExceptionEmails; | |||||
| // | |||||
| // @Autowired | |||||
| // private MailService mailService; | |||||
| // | |||||
| // | |||||
| // @Override | |||||
| // public void send(BaseMsg baseMsg) throws Exception{ | |||||
| // FmInsideOrderPushMsg msg = (FmInsideOrderPushMsg)baseMsg; | |||||
| // | |||||
| // try{ | |||||
| // Thread.currentThread().sleep(1000);//延时秒 | |||||
| // }catch(Exception e){} | |||||
| // | |||||
| // WxBatchOrder border = new WxBatchOrder(); | |||||
| // border.setTenantId(msg.getTenantId()); | |||||
| // border.setParentTenantId(msg.getParentTenantId()); | |||||
| // border.setId(msg.getBatchOrderId()); | |||||
| // WxBatchOrder batchOrder = orderService.batchOrderDetail(border); | |||||
| // if(batchOrder == null){ | |||||
| // logger.error("主订单未找到: " + msg.getBatchOrderId()); | |||||
| // throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "主订单未找到" + msg.getBatchOrderId()); | |||||
| // } | |||||
| // | |||||
| // if(EnumPayWay.PAY_WAY_TT.getCode().equals(batchOrder.getPayVendor()) | |||||
| // && EnumComposeOrder.SINGLE.getCode().equals(batchOrder.getOrderType()) | |||||
| // && batchOrder.getOrders().size() == 1){ | |||||
| // WxAppinfo appinfo = wxAppinfoService.getCAppInfo(batchOrder,EnumPayWay.PAY_WAY_TT.getPlat()); | |||||
| // try{ | |||||
| // payOrderPush(appinfo,batchOrder); | // payOrderPush(appinfo,batchOrder); | ||||
| // }else{ | |||||
| // //退款 | |||||
| // //通过退款订单找支付订单 | |||||
| // WxOrder ref_order = orderService.getById(wxOrderCouponVo.getOrderNumber(), wxOrderCouponVo.getTenantId()); | |||||
| // WxBatchOrder ref_border = new WxBatchOrder(); | |||||
| // ref_border.setTenantId(ref_order.getTenantId()); | |||||
| // ref_border.setParentTenantId(ref_order.getParentTenantId()); | |||||
| // ref_border.setId(ref_order.getComposeOrderId()); | |||||
| // WxBatchOrder ref_batchOrder = orderService.batchOrderDetail(ref_border); | |||||
| // if(ref_batchOrder == null){ | |||||
| // logger.error("退款 主订单未找到: " + ref_order.getComposeOrderId()); | |||||
| // throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "退款 主订单未找到" + ref_order.getComposeOrderId()); | |||||
| // } | |||||
| // if(EnumPayWay.PAY_WAY_TT.getCode().equals(ref_batchOrder.getPayVendor()) | |||||
| // && EnumComposeOrder.SINGLE.getCode().equals(ref_batchOrder.getOrderType()) | |||||
| // && ref_batchOrder.getOrders().size() == 1){ | |||||
| // for (WxOrderCouponVo ref_vo:ref_batchOrder.getOrders()) { | |||||
| // ref_vo.setOrderStatus(wxOrderCouponVo.getOrderStatus()); | |||||
| // } | |||||
| // payOrderPush(appinfo,ref_batchOrder); | |||||
| // } | |||||
| // }catch(Exception e){ | |||||
| // logger.error("订单同步异常batchOrderId"+batchOrder.getId()+"{}"+e.getMessage()); | |||||
| //// String[] receivers = fmExceptionEmails.split(","); | |||||
| //// StringBuilder sb = new StringBuilder(); | |||||
| //// sb.append(DateUtils.date2String(new Date())); | |||||
| //// sb.append("\n"); | |||||
| //// sb.append("tenantId="+batchOrder.getTenantId()); | |||||
| //// sb.append("\n"); | |||||
| //// sb.append(e.getMessage()); | |||||
| //// sb.append("\n"); | |||||
| //// sb.append("batchOrderId="+batchOrder.getId()); | |||||
| //// //发送邮件 | |||||
| //// mailService.sendSimpleMail(receivers, batchOrder.getTenantId()+"订单同步异常", sb.toString()); | |||||
| // | |||||
| // TtOrderPushError pushError = new TtOrderPushError(); | |||||
| // pushError.setId(batchOrder.getId()); | |||||
| // pushError.updateTenantInfo(batchOrder); | |||||
| // pushError.setErrMsg(e.getMessage()); | |||||
| // saveOrUpdate(pushError); | |||||
| // | // | ||||
| // } | // } | ||||
| } | |||||
| } | |||||
| private void saveOrUpdate(TtOrderPushError pushError){ | |||||
| Date now = new Date(); | |||||
| TtOrderPushError pushError1 = ttOrderPushErrorMapper.selectById(pushError.getId()); | |||||
| if(pushError1 != null){ | |||||
| pushError1.setErrMsg(pushError.getErrMsg()); | |||||
| pushError1.setUpdateDate(now); | |||||
| ttOrderPushErrorMapper.updateById(pushError1); | |||||
| }else{ | |||||
| pushError.setCreateDate(now); | |||||
| pushError.setUpdateDate(now); | |||||
| ttOrderPushErrorMapper.insert(pushError); | |||||
| } | |||||
| } | |||||
| private void payOrderPush(WxAppinfo appinfo, WxBatchOrder batchOrder) throws Exception{ | |||||
| WxPayOrder orderq = new WxPayOrder(); | |||||
| orderq.setOrderId(batchOrder.getId()); | |||||
| orderq.updateTenantInfo(batchOrder); | |||||
| WxPayOrder payOrder = wxPayOrderService.getByObj(orderq); | |||||
| if(payOrder == null){ | |||||
| logger.error("支付订单未找到: " + batchOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "支付订单未找到" + batchOrder.getId()); | |||||
| } | |||||
| if(StringUtils.isBlank(payOrder.getTransactionId())){ | |||||
| logger.error("担保支付订单未找到: " + batchOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "担保支付订单未找到" + batchOrder.getId()); | |||||
| } | |||||
| List<String> openIds = ttCUserMapper.findOpenIdList(batchOrder.getCUserId(),batchOrder.getTenantId()); | |||||
| if(openIds == null || openIds.size() > 1){ | |||||
| logger.error("支付订单找到多个用户 同步失败: " + batchOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "支付订单找到多个用户" + batchOrder.getId()); | |||||
| } | |||||
| PayAdapterResult payAdapterResult = payServiceFactory.getPayAdapterService(EnumPayWay.PAY_WAY_TT.getCode()) | |||||
| .payOrderPush(openIds.get(0), appinfo, batchOrder, payOrder); | |||||
| if(payAdapterResult.isSuccess()){ | |||||
| ttOrderPushErrorMapper.deleteById(batchOrder.getId()); | |||||
| }else{ | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(), payAdapterResult.getMsg() + batchOrder.getId()); | |||||
| } | |||||
| } | |||||
| } | |||||
| // | |||||
| // | |||||
| //// WxOrderCouponVo wxOrderCouponVo = batchOrder.getOrders().get(0); | |||||
| //// if(EnumPayType.PAY_PAYMENT.getCode().equals(wxOrderCouponVo.getPaymentType())){ | |||||
| //// payOrderPush(appinfo,batchOrder); | |||||
| //// }else{ | |||||
| //// //退款 | |||||
| //// //通过退款订单找支付订单 | |||||
| //// WxOrder ref_order = orderService.getById(wxOrderCouponVo.getOrderNumber(), wxOrderCouponVo.getTenantId()); | |||||
| //// WxBatchOrder ref_border = new WxBatchOrder(); | |||||
| //// ref_border.setTenantId(ref_order.getTenantId()); | |||||
| //// ref_border.setParentTenantId(ref_order.getParentTenantId()); | |||||
| //// ref_border.setId(ref_order.getComposeOrderId()); | |||||
| //// WxBatchOrder ref_batchOrder = orderService.batchOrderDetail(ref_border); | |||||
| //// if(ref_batchOrder == null){ | |||||
| //// logger.error("退款 主订单未找到: " + ref_order.getComposeOrderId()); | |||||
| //// throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "退款 主订单未找到" + ref_order.getComposeOrderId()); | |||||
| //// } | |||||
| //// if(EnumPayWay.PAY_WAY_TT.getCode().equals(ref_batchOrder.getPayVendor()) | |||||
| //// && EnumComposeOrder.SINGLE.getCode().equals(ref_batchOrder.getOrderType()) | |||||
| //// && ref_batchOrder.getOrders().size() == 1){ | |||||
| //// for (WxOrderCouponVo ref_vo:ref_batchOrder.getOrders()) { | |||||
| //// ref_vo.setOrderStatus(wxOrderCouponVo.getOrderStatus()); | |||||
| //// } | |||||
| //// payOrderPush(appinfo,ref_batchOrder); | |||||
| //// } | |||||
| //// | |||||
| //// } | |||||
| // } | |||||
| // } | |||||
| // | |||||
| // private void saveOrUpdate(TtOrderPushError pushError){ | |||||
| // Date now = new Date(); | |||||
| // TtOrderPushError pushError1 = ttOrderPushErrorMapper.selectById(pushError.getId()); | |||||
| // if(pushError1 != null){ | |||||
| // pushError1.setErrMsg(pushError.getErrMsg()); | |||||
| // pushError1.setUpdateDate(now); | |||||
| // ttOrderPushErrorMapper.updateById(pushError1); | |||||
| // }else{ | |||||
| // pushError.setCreateDate(now); | |||||
| // pushError.setUpdateDate(now); | |||||
| // ttOrderPushErrorMapper.insert(pushError); | |||||
| // } | |||||
| // } | |||||
| // | |||||
| // | |||||
| // private void payOrderPush(WxAppinfo appinfo, WxBatchOrder batchOrder) throws Exception{ | |||||
| // WxPayOrder orderq = new WxPayOrder(); | |||||
| // orderq.setOrderId(batchOrder.getId()); | |||||
| // orderq.updateTenantInfo(batchOrder); | |||||
| // WxPayOrder payOrder = wxPayOrderService.getByObj(orderq); | |||||
| // if(payOrder == null){ | |||||
| // logger.error("支付订单未找到: " + batchOrder.getId()); | |||||
| // throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "支付订单未找到" + batchOrder.getId()); | |||||
| // } | |||||
| // if(StringUtils.isBlank(payOrder.getTransactionId())){ | |||||
| // logger.error("担保支付订单未找到: " + batchOrder.getId()); | |||||
| // throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "担保支付订单未找到" + batchOrder.getId()); | |||||
| // } | |||||
| // List<String> openIds = ttCUserMapper.findOpenIdList(batchOrder.getCUserId(),batchOrder.getTenantId()); | |||||
| // if(openIds == null || openIds.size() > 1){ | |||||
| // logger.error("支付订单找到多个用户 同步失败: " + batchOrder.getId()); | |||||
| // throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "支付订单找到多个用户" + batchOrder.getId()); | |||||
| // } | |||||
| // | |||||
| // PayAdapterResult payAdapterResult = payServiceFactory.getPayAdapterService(EnumPayWay.PAY_WAY_TT.getCode()) | |||||
| // .payOrderPush(openIds.get(0), appinfo, batchOrder, payOrder); | |||||
| // | |||||
| // if(payAdapterResult.isSuccess()){ | |||||
| // ttOrderPushErrorMapper.deleteById(batchOrder.getId()); | |||||
| // }else{ | |||||
| // throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(), payAdapterResult.getMsg() + batchOrder.getId()); | |||||
| // } | |||||
| // } | |||||
| //} | |||||
| @@ -230,114 +230,115 @@ public class TtMiniAppPayAdapterService extends BaseTtPayAdapterService implemen | |||||
| @Override | @Override | ||||
| public PayAdapterResult payOrderPush(String openId,WxAppinfo appInfo, WxBatchOrder batchOrder,WxPayOrder payOrder) throws Exception { | public PayAdapterResult payOrderPush(String openId,WxAppinfo appInfo, WxBatchOrder batchOrder,WxPayOrder payOrder) throws Exception { | ||||
| boolean isPoiOrder = false; | |||||
| //第三方在抖音开放平台申请的ClientKey | |||||
| String clientKey = ""; | |||||
| if(batchOrder.getIsTtPoiOrder() != null && EnumYesOrNo.YES.getCode().equals(batchOrder.getIsTtPoiOrder())){ | |||||
| WxAppinfo appinfoQ = new WxAppinfo(); | |||||
| appinfoQ.updateTenantInfo(batchOrder); | |||||
| appinfoQ.setPlat(EnumAppPlat.TOUTIAO.getCode()); | |||||
| appinfoQ.setType(EnumAppType.A.getCode()); | |||||
| WxAppinfo appinfo = wxAppinfoMapper.selectOne(new QueryWrapper<>(appinfoQ)); | |||||
| if(appinfo != null){ | |||||
| clientKey = appinfo.getAppId(); | |||||
| isPoiOrder = true; | |||||
| } | |||||
| } | |||||
| //目前订单都是一笔一笔同步,暂不支持购物车 | |||||
| WxOrderCouponVo wxOrderCouponVo = batchOrder.getOrders().get(0); | |||||
| List<WxMerchantVo> merchantList = wxOrderCouponVo.getMerchantVoList().stream().sorted(Comparator.comparing(m -> m.getTtPoi(), Comparator.nullsLast(String::compareTo))).collect(toList()); | |||||
| TtMaService ttappService = maUtil.getTtMaService(appInfo); | |||||
| // map.put("access_token",appInfo.getAccessToken());//后面会自动加上 | |||||
| Map<String,Object> map = new HashMap<>(); | |||||
| map.put("app_name","douyin"); | |||||
| map.put("open_id",openId); | |||||
| map.put("payment_order_no", payOrder.getTransactionId()); | |||||
| if(isPoiOrder){ | |||||
| map.put("client_key",clientKey);//第三方在开放平台申请的 ClientKey(生活服务订单必传) | |||||
| map.put("ext_shop_id",merchantList.get(0).getId().toString());//生活服务外部商户 id,购买店铺 id (生活服务订单必传) | |||||
| map.put("order_type",9101); | |||||
| }else{ | |||||
| map.put("order_type",0); | |||||
| map.put("order_status", getTtOrderStatus(wxOrderCouponVo.getOrderStatus(),wxOrderCouponVo.getCouponOrderStatus()).getCode()); | |||||
| } | |||||
| map.put("update_time", wxOrderCouponVo.getUpdateDate().getTime()); | |||||
| // map.put("extra","");//自定义字段,用于关联具体业务场景下的特殊参数 | |||||
| // map.put("scene","");//小程序场景值 | |||||
| // map.put("location","");//小程序场景值 | |||||
| // map.put("launch_from","");//小程序场景值 | |||||
| Map<String,Object> orderDetail = new HashMap<>(); | |||||
| if(isPoiOrder){ | |||||
| orderDetail.put("ext_order_id",payOrder.getPayOrderNo()); | |||||
| orderDetail.put("status", getTtPoiOrderStatus(wxOrderCouponVo.getOrderStatus(),wxOrderCouponVo.getCouponOrderStatus()).getCode()); | |||||
| orderDetail.put("shop_name",merchantList.get(0).getMerchantName()); | |||||
| orderDetail.put("entry_type",2); | |||||
| orderDetail.put("entry_schema",getOrderEntrySchema(appInfo.getAppId(),batchOrder.getId())); | |||||
| orderDetail.put("create_order_time",batchOrder.getCreateDate().getTime()); | |||||
| // orderDetail.put("description","");//备注(长度500) | |||||
| orderDetail.put("total_price",batchOrder.getPayment()); | |||||
| if(EnumPayStatus.PAY_STATUS_SUCCESS.getCode().equals(payOrder.getPayOrderStatus())){ | |||||
| orderDetail.put("pay_time",payOrder.getPayTimeEnd().getTime()); | |||||
| } | |||||
| if(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode().equals(wxOrderCouponVo.getCouponOrderStatus()) | |||||
| && wxOrderCouponVo.getBMerchantId() != null){ | |||||
| orderDetail.put("ext_valid_shop_id",wxOrderCouponVo.getBMerchantId().toString()); | |||||
| TtMerchantPoi merchantPoi = ttMerchantPoiMapper.selectById(wxOrderCouponVo.getBMerchantId()); | |||||
| if(merchantPoi != null){ | |||||
| orderDetail.put("valid_poi_id_str",merchantPoi.getPoiId()); | |||||
| } | |||||
| } | |||||
| orderDetail.put("ext_goods_id",wxOrderCouponVo.getCouponChannelId().toString()); | |||||
| orderDetail.put("goods_name",wxOrderCouponVo.getTitle()); | |||||
| // orderDetail.put("goods_info","");//商品描述信息。向用户介绍商品,最多120字。 | |||||
| orderDetail.put("goods_cover_image",wxOrderCouponVo.getCoverImg()); | |||||
| orderDetail.put("goods_entry_type",2); | |||||
| orderDetail.put("goods_entry_schema",getGoodsEntrySchema(appInfo.getAppId(),wxOrderCouponVo.getCouponChannelId())); | |||||
| orderDetail.put("start_valid_time",DateUtils.date2String(wxOrderCouponVo.getValidStartDate())); | |||||
| orderDetail.put("end_valid_time",DateUtils.date2String(wxOrderCouponVo.getValidEndDate())); | |||||
| orderDetail.put("ticket_num",wxOrderCouponVo.getCouponNumber()); | |||||
| // orderDetail.put("ext_ticket_ids",); | |||||
| // orderDetail.put("ticket_description",); | |||||
| }else{ | |||||
| orderDetail.put("order_id",payOrder.getPayOrderNo()); | |||||
| orderDetail.put("create_time",batchOrder.getCreateDate().getTime()); | |||||
| orderDetail.put("status", getTtOrderStatus(wxOrderCouponVo.getOrderStatus(),wxOrderCouponVo.getCouponOrderStatus()).getMessage()); | |||||
| orderDetail.put("total_price",batchOrder.getPayment()); | |||||
| orderDetail.put("detail_url",batchOrder.getWeappOrderPath(EnumAppPlat.TOUTIAO)); | |||||
| List<Map> itemList = new ArrayList<>(); | |||||
| for (WxOrderCouponVo orderVo:batchOrder.getOrders()) { | |||||
| Map<String,Object> item = new HashMap<>(); | |||||
| item.put("img",orderVo.getCoverImg()); | |||||
| item.put("title",orderVo.getTitle()); | |||||
| item.put("sub_title",orderVo.getSubTitle()); | |||||
| item.put("price",orderVo.getSalePrice()); | |||||
| itemList.add(item); | |||||
| } | |||||
| orderDetail.put("item_list",itemList); | |||||
| } | |||||
| map.put("order_detail", JSON.toJSONString(orderDetail)); | |||||
| try { | |||||
| String response = ttappService.post(ttappService.ORDER_PUSH, map); | |||||
| log.info("订单同步结果{}"+response +"参数 {}"+ WxGsonBuilder.create().toJson(map)); | |||||
| JSONObject jsonObject = JSON.parseObject(response); | |||||
| Integer code = jsonObject.getInteger("err_code"); | |||||
| if (null != code && code.intValue() == 0 ) { | |||||
| return new PayAdapterResult(true, "SUCCESS", null, null); | |||||
| }else{ | |||||
| String err_msg = jsonObject.getString("err_msg"); | |||||
| return new PayAdapterResult(false, err_msg, null, null); | |||||
| } | |||||
| } catch (WxErrorException e) { | |||||
| return new PayAdapterResult(false, "订单同步异常"+e.getMessage(), null, null); | |||||
| } catch (Exception e){ | |||||
| return new PayAdapterResult(false, "订单同步异常"+e.getMessage(), null, null); | |||||
| } | |||||
| return null; | |||||
| // boolean isPoiOrder = false; | |||||
| // //第三方在抖音开放平台申请的ClientKey | |||||
| // String clientKey = ""; | |||||
| // if(batchOrder.getIsTtPoiOrder() != null && EnumYesOrNo.YES.getCode().equals(batchOrder.getIsTtPoiOrder())){ | |||||
| // WxAppinfo appinfoQ = new WxAppinfo(); | |||||
| // appinfoQ.updateTenantInfo(batchOrder); | |||||
| // appinfoQ.setPlat(EnumAppPlat.TOUTIAO.getCode()); | |||||
| // appinfoQ.setType(EnumAppType.A.getCode()); | |||||
| // WxAppinfo appinfo = wxAppinfoMapper.selectOne(new QueryWrapper<>(appinfoQ)); | |||||
| // if(appinfo != null){ | |||||
| // clientKey = appinfo.getAppId(); | |||||
| // isPoiOrder = true; | |||||
| // } | |||||
| // } | |||||
| // //目前订单都是一笔一笔同步,暂不支持购物车 | |||||
| // WxOrderCouponVo wxOrderCouponVo = batchOrder.getOrders().get(0); | |||||
| // List<WxMerchantVo> merchantList = wxOrderCouponVo.getMerchantVoList().stream().sorted(Comparator.comparing(m -> m.getTtPoi(), Comparator.nullsLast(String::compareTo))).collect(toList()); | |||||
| // | |||||
| // TtMaService ttappService = maUtil.getTtMaService(appInfo); | |||||
| //// map.put("access_token",appInfo.getAccessToken());//后面会自动加上 | |||||
| // Map<String,Object> map = new HashMap<>(); | |||||
| // map.put("app_name","douyin"); | |||||
| // map.put("open_id",openId); | |||||
| // map.put("payment_order_no", payOrder.getTransactionId()); | |||||
| // if(isPoiOrder){ | |||||
| // map.put("client_key",clientKey);//第三方在开放平台申请的 ClientKey(生活服务订单必传) | |||||
| // map.put("ext_shop_id",merchantList.get(0).getId().toString());//生活服务外部商户 id,购买店铺 id (生活服务订单必传) | |||||
| // map.put("order_type",9101); | |||||
| // }else{ | |||||
| // map.put("order_type",0); | |||||
| // map.put("order_status", getTtOrderStatus(wxOrderCouponVo.getOrderStatus(),wxOrderCouponVo.getCouponOrderStatus()).getCode()); | |||||
| // } | |||||
| // map.put("update_time", wxOrderCouponVo.getUpdateDate().getTime()); | |||||
| //// map.put("extra","");//自定义字段,用于关联具体业务场景下的特殊参数 | |||||
| //// map.put("scene","");//小程序场景值 | |||||
| //// map.put("location","");//小程序场景值 | |||||
| //// map.put("launch_from","");//小程序场景值 | |||||
| // | |||||
| // Map<String,Object> orderDetail = new HashMap<>(); | |||||
| // if(isPoiOrder){ | |||||
| // orderDetail.put("ext_order_id",payOrder.getPayOrderNo()); | |||||
| // orderDetail.put("status", getTtPoiOrderStatus(wxOrderCouponVo.getOrderStatus(),wxOrderCouponVo.getCouponOrderStatus()).getCode()); | |||||
| // orderDetail.put("shop_name",merchantList.get(0).getMerchantName()); | |||||
| // orderDetail.put("entry_type",2); | |||||
| // orderDetail.put("entry_schema",getOrderEntrySchema(appInfo.getAppId(),batchOrder.getId())); | |||||
| // orderDetail.put("create_order_time",batchOrder.getCreateDate().getTime()); | |||||
| //// orderDetail.put("description","");//备注(长度500) | |||||
| // orderDetail.put("total_price",batchOrder.getPayment()); | |||||
| // if(EnumPayStatus.PAY_STATUS_SUCCESS.getCode().equals(payOrder.getPayOrderStatus())){ | |||||
| // orderDetail.put("pay_time",payOrder.getPayTimeEnd().getTime()); | |||||
| // } | |||||
| // if(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode().equals(wxOrderCouponVo.getCouponOrderStatus()) | |||||
| // && wxOrderCouponVo.getBMerchantId() != null){ | |||||
| // orderDetail.put("ext_valid_shop_id",wxOrderCouponVo.getBMerchantId().toString()); | |||||
| // TtMerchantPoi merchantPoi = ttMerchantPoiMapper.selectById(wxOrderCouponVo.getBMerchantId()); | |||||
| // if(merchantPoi != null){ | |||||
| // orderDetail.put("valid_poi_id_str",merchantPoi.getPoiId()); | |||||
| // } | |||||
| // } | |||||
| // orderDetail.put("ext_goods_id",wxOrderCouponVo.getCouponChannelId().toString()); | |||||
| // orderDetail.put("goods_name",wxOrderCouponVo.getTitle()); | |||||
| //// orderDetail.put("goods_info","");//商品描述信息。向用户介绍商品,最多120字。 | |||||
| // orderDetail.put("goods_cover_image",wxOrderCouponVo.getCoverImg()); | |||||
| // orderDetail.put("goods_entry_type",2); | |||||
| // orderDetail.put("goods_entry_schema",getGoodsEntrySchema(appInfo.getAppId(),wxOrderCouponVo.getCouponChannelId())); | |||||
| // orderDetail.put("start_valid_time",DateUtils.date2String(wxOrderCouponVo.getValidStartDate())); | |||||
| // orderDetail.put("end_valid_time",DateUtils.date2String(wxOrderCouponVo.getValidEndDate())); | |||||
| // orderDetail.put("ticket_num",wxOrderCouponVo.getCouponNumber()); | |||||
| // | |||||
| //// orderDetail.put("ext_ticket_ids",); | |||||
| //// orderDetail.put("ticket_description",); | |||||
| // | |||||
| // }else{ | |||||
| // orderDetail.put("order_id",payOrder.getPayOrderNo()); | |||||
| // orderDetail.put("create_time",batchOrder.getCreateDate().getTime()); | |||||
| // orderDetail.put("status", getTtOrderStatus(wxOrderCouponVo.getOrderStatus(),wxOrderCouponVo.getCouponOrderStatus()).getMessage()); | |||||
| // orderDetail.put("total_price",batchOrder.getPayment()); | |||||
| // orderDetail.put("detail_url",batchOrder.getWeappOrderPath(EnumAppPlat.TOUTIAO)); | |||||
| // | |||||
| // List<Map> itemList = new ArrayList<>(); | |||||
| // for (WxOrderCouponVo orderVo:batchOrder.getOrders()) { | |||||
| // Map<String,Object> item = new HashMap<>(); | |||||
| // item.put("img",orderVo.getCoverImg()); | |||||
| // item.put("title",orderVo.getTitle()); | |||||
| // item.put("sub_title",orderVo.getSubTitle()); | |||||
| // item.put("price",orderVo.getSalePrice()); | |||||
| // itemList.add(item); | |||||
| // } | |||||
| // orderDetail.put("item_list",itemList); | |||||
| // } | |||||
| // map.put("order_detail", JSON.toJSONString(orderDetail)); | |||||
| // | |||||
| // try { | |||||
| // String response = ttappService.post(ttappService.ORDER_PUSH, map); | |||||
| // log.info("订单同步结果{}"+response +"参数 {}"+ WxGsonBuilder.create().toJson(map)); | |||||
| // JSONObject jsonObject = JSON.parseObject(response); | |||||
| // Integer code = jsonObject.getInteger("err_code"); | |||||
| // if (null != code && code.intValue() == 0 ) { | |||||
| // return new PayAdapterResult(true, "SUCCESS", null, null); | |||||
| // }else{ | |||||
| // String err_msg = jsonObject.getString("err_msg"); | |||||
| // return new PayAdapterResult(false, err_msg, null, null); | |||||
| // } | |||||
| // } catch (WxErrorException e) { | |||||
| // return new PayAdapterResult(false, "订单同步异常"+e.getMessage(), null, null); | |||||
| // } catch (Exception e){ | |||||
| // return new PayAdapterResult(false, "订单同步异常"+e.getMessage(), null, null); | |||||
| // } | |||||
| } | } | ||||
| private EnumTtOrderStatus getTtOrderStatus(Integer orderStatus,Integer couponOrderStatus) throws Exception { | private EnumTtOrderStatus getTtOrderStatus(Integer orderStatus,Integer couponOrderStatus) throws Exception { | ||||