|
@@ -284,52 +284,24 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
|
|
|
}
|
|
|
|
|
|
private ErpOrderResponse getErpOrderResponseScrm(ErpOrder order) {
|
|
|
- FsSysConfig sysConfig = configUtil.getSysConfig();
|
|
|
- String shopCode = sysConfig.getErpWdShopCode();
|
|
|
-
|
|
|
//测试环境sid、appkey、密钥请到旺店通开放平台-自助对接-申请测试环境内查看,测试环境url=https://sandbox.wangdian.cn/openapi2/
|
|
|
//调用正式环境时请将sid、appkey、appsecret切换为实际参数,参数在旺店通开放平台-自助对接-应用管理内应用状态为已上线的应用中查看,调用正式环境注意切换正式环境url=https://api.wangdian.cn/openapi2/
|
|
|
|
|
|
+ FsSysConfig erpconfig = configUtil.getSysConfig();
|
|
|
ErpWdtBusinessRequestParams erpWdtBusinessRequestParams = new ErpWdtBusinessRequestParams();
|
|
|
- erpWdtBusinessRequestParams.setShopNo(shopCode);
|
|
|
+ erpWdtBusinessRequestParams.setShopNo(erpconfig.getErpWdShopCode());
|
|
|
erpWdtBusinessRequestParams.setSwitchMode(0);
|
|
|
ErpWdtTrade erpWdtTrade = new ErpWdtTrade();
|
|
|
- FsStoreOrderScrm fsStoreOrder = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(order.getPlatform_code());
|
|
|
- BigDecimal couponPrice = fsStoreOrder.getCouponPrice();
|
|
|
- if (couponPrice == null) {
|
|
|
- couponPrice = BigDecimal.ZERO;
|
|
|
- }
|
|
|
-
|
|
|
- // 平台状态
|
|
|
- erpWdtTrade.setTradeStatus(TradeStatus.PAID_WAITING_FOR_SHIPMENT.getValue());
|
|
|
|
|
|
// 订单id
|
|
|
erpWdtTrade.setTid(order.getPlatform_code());
|
|
|
+ // 平台状态
|
|
|
+ erpWdtTrade.setTradeStatus(TradeStatus.REFUNDED.getValue());
|
|
|
|
|
|
-
|
|
|
- // 如果是货到付款
|
|
|
- if("2".equals(fsStoreOrder.getPayType())){
|
|
|
- // 支付状态
|
|
|
- erpWdtTrade.setPayStatus(PaymentStatus.PARTIALLY_PAID.getValue());
|
|
|
- // 发货条件
|
|
|
- erpWdtTrade.setDeliveryTerm(DeliveryTerm.CASH_ON_DELIVERY.getValue());
|
|
|
- // 货到付款金额 = 物流代收金额-优惠金额
|
|
|
- erpWdtTrade.setCodAmount(fsStoreOrder.getPayDelivery().subtract(couponPrice));
|
|
|
-
|
|
|
- } else if("3".equals(fsStoreOrder.getPayType())){
|
|
|
- // 支付状态
|
|
|
- erpWdtTrade.setPayStatus(PaymentStatus.UNPAID.getValue());
|
|
|
- // 发货条件
|
|
|
- erpWdtTrade.setDeliveryTerm(DeliveryTerm.CASH_ON_DELIVERY.getValue());
|
|
|
- // 货到付款金额 = 物流代收金额-优惠金额
|
|
|
- erpWdtTrade.setCodAmount(fsStoreOrder.getPayDelivery().subtract(couponPrice));
|
|
|
- } else { // 如果是线上付款
|
|
|
- // 支付状态
|
|
|
- erpWdtTrade.setPayStatus(PaymentStatus.FULLY_PAID.getValue());
|
|
|
- // 发货条件
|
|
|
- erpWdtTrade.setDeliveryTerm(DeliveryTerm.PAYMENT_BEFORE_DELIVERY.getValue());
|
|
|
- }
|
|
|
-
|
|
|
+ // 支付状态
|
|
|
+ erpWdtTrade.setPayStatus(PaymentStatus.FULLY_PAID.getValue());
|
|
|
+ // 发货条件
|
|
|
+ erpWdtTrade.setDeliveryTerm(DeliveryTerm.PAYMENT_BEFORE_DELIVERY.getValue());
|
|
|
// 下单时间
|
|
|
erpWdtTrade.setTradeTime(order.getDeal_datetime());
|
|
|
// 支付时间
|
|
@@ -358,42 +330,41 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
|
|
|
erpWdtTrade.setSellerMemo(order.getSeller_memo());
|
|
|
erpWdtTrade.setWarehouseNo(order.getWarehouse_code());
|
|
|
|
|
|
+ // 已付金额
|
|
|
+ FsStoreOrderScrm fsStoreOrder = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(order.getPlatform_code());
|
|
|
// 运费金额
|
|
|
erpWdtTrade.setPostAmount(fsStoreOrder.getFreightPrice());
|
|
|
- // 已付金额
|
|
|
if(ObjectUtils.isNotNull(fsStoreOrder)){
|
|
|
erpWdtTrade.setPaid(fsStoreOrder.getPayMoney());
|
|
|
}
|
|
|
|
|
|
- List<com.fs.hisStore.vo.FsStoreOrderItemVO> fsStoreOrderItemVOS = fsStoreOrderItemScrmService.selectFsStoreOrderItemListByOrderId(fsStoreOrder.getId());
|
|
|
+ List<FsStoreOrderItemScrm> fsStoreOrderItemVOS = fsStoreOrderScrmService.selectFsStoreOrderItemList(String.valueOf(fsStoreOrder.getId()));
|
|
|
List<ErpWdtOrder> erpWdtOrderList = new ArrayList<>();
|
|
|
- // 商品总价
|
|
|
- BigDecimal totalPrice = fsStoreOrder.getTotalPrice();
|
|
|
|
|
|
- // 总折扣金额 = 优惠券金额 + 折扣金额
|
|
|
- BigDecimal totalDiscountPrice = BigDecimal.ZERO;
|
|
|
- // 折扣金额
|
|
|
- BigDecimal discountPrice = totalPrice.subtract(fsStoreOrder.getPayPrice());
|
|
|
- totalDiscountPrice = couponPrice.add(discountPrice);
|
|
|
|
|
|
- // 防止除零错误
|
|
|
- if (totalPrice.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- totalPrice = BigDecimal.ONE;
|
|
|
+ // 优惠券金额
|
|
|
+ BigDecimal couponPrice = fsStoreOrder.getCouponPrice();
|
|
|
+ if (fsStoreOrder.getCouponPrice().compareTo(BigDecimal.ZERO) == 0
|
|
|
+ && fsStoreOrder.getTotalPrice().compareTo(fsStoreOrder.getPayMoney()) > 0) {
|
|
|
+ couponPrice = fsStoreOrder.getTotalPrice().subtract(fsStoreOrder.getPayMoney());
|
|
|
}
|
|
|
+ // 商品总价
|
|
|
+ BigDecimal totalPrice = fsStoreOrder.getTotalPrice();
|
|
|
|
|
|
- for (com.fs.hisStore.vo.FsStoreOrderItemVO fsStoreOrderItem : fsStoreOrderItemVOS) {
|
|
|
+ for (FsStoreOrderItemScrm fsStoreOrderItem : fsStoreOrderItemVOS) {
|
|
|
ErpWdtOrder erpWdtOrder = new ErpWdtOrder();
|
|
|
//平台订单货品表主键
|
|
|
- erpWdtOrder.setOid(String.format("%s%s",fsStoreOrder.getOrderCode(),fsStoreOrderItem.getItemId()));
|
|
|
+ erpWdtOrder.setOid(String.format("%s%s",fsStoreOrderItem.getOrderCode(),fsStoreOrderItem.getItemId()));
|
|
|
erpWdtOrder.setNum(BigDecimal.valueOf(fsStoreOrderItem.getNum()));
|
|
|
FsStoreProductScrm fsStoreProduct = fsStoreProductScrmService.selectFsStoreProductById(fsStoreOrderItem.getProductId());
|
|
|
Asserts.check(ObjectUtils.isNotNull(fsStoreProduct),"该产品不存在! 产品id: {} ",fsStoreOrderItem.getProductId());
|
|
|
// 单价
|
|
|
erpWdtOrder.setPrice(fsStoreProduct.getPrice());
|
|
|
// 状态
|
|
|
- erpWdtOrder.setStatus(TradeStatus.PAID_WAITING_FOR_SHIPMENT.getValue());
|
|
|
+
|
|
|
+ erpWdtOrder.setStatus(TradeStatus.REFUNDED.getValue());
|
|
|
// 退款状态
|
|
|
- erpWdtOrder.setRefundStatus(RefundStatus.NO_REFUND.getValue());
|
|
|
+ erpWdtOrder.setRefundStatus(RefundStatus.REFUND_SUCCESSFUL.getValue());
|
|
|
|
|
|
// 平台货品ID
|
|
|
erpWdtOrder.setGoodsId(String.valueOf(fsStoreProduct.getProductId()));
|
|
@@ -411,7 +382,7 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
|
|
|
// 分摊比例
|
|
|
BigDecimal price = fsStoreProduct.getPrice().multiply(BigDecimal.valueOf(fsStoreOrderItem.getNum()));
|
|
|
BigDecimal divide = price.divide(totalPrice, RoundingMode.HALF_UP);
|
|
|
- erpWdtOrder.setShareDiscount(divide.multiply(totalDiscountPrice));
|
|
|
+ erpWdtOrder.setShareDiscount(divide.multiply(couponPrice));
|
|
|
|
|
|
erpWdtOrderList.add(erpWdtOrder);
|
|
|
}
|
|
@@ -421,7 +392,7 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
|
|
|
long size = erpWdtOrderList.size();
|
|
|
if(size > 1) {
|
|
|
ErpWdtOrder erpWdtOrder = erpWdtOrderList.get(erpWdtOrderList.size() - 1);
|
|
|
- erpWdtOrder.setShareDiscount(totalDiscountPrice.subtract(erpWdtOrderList.stream()
|
|
|
+ erpWdtOrder.setShareDiscount(couponPrice.subtract(erpWdtOrderList.stream()
|
|
|
.limit(size - 1L)
|
|
|
.map(item -> Optional.ofNullable(item.getShareDiscount()).orElse(BigDecimal.ZERO))
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add)));
|
|
@@ -440,17 +411,15 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
|
|
|
String response = client.execute("trade_push.php", map);
|
|
|
ParserConfig config = new ParserConfig();
|
|
|
config.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
|
|
|
+ log.info("Erp推送传参: {}", map);
|
|
|
ErpWdtApiResponse erpWdtApiResponse = JSON.parseObject(response, ErpWdtApiResponse.class,config);
|
|
|
if(ObjectUtil.equal(0,erpWdtApiResponse.getCode())){
|
|
|
log.info("订单推送成功: {}", response);
|
|
|
ErpOrderResponse erpOrderResponse = new ErpOrderResponse();
|
|
|
erpOrderResponse.setCode(order.getPlatform_code());
|
|
|
- erpOrderResponse.setSuccess(true);
|
|
|
- erpOrderResponse.setRequestRawData(JSON.toJSONString(map));
|
|
|
- erpOrderResponse.setResponseRawData(response);
|
|
|
return erpOrderResponse;
|
|
|
} else {
|
|
|
- throw new RuntimeException(String.format("订单推送失败,原因: %s",erpWdtApiResponse.getMessage()));
|
|
|
+ // throw new RuntimeException(String.format("订单推送失败,原因: %s",erpWdtApiResponse.getMessage()));
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|