|
|
@@ -10,17 +10,8 @@
|
|
|
|
|
|
package com.yami.shop.listener;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.yami.shop.bean.enums.OrderCloseType;
|
|
|
-import com.yami.shop.bean.enums.OrderStatus;
|
|
|
-import com.yami.shop.bean.enums.OrderType;
|
|
|
-import com.yami.shop.bean.enums.ShopWalletChangeReason;
|
|
|
import com.yami.shop.bean.event.ReceiptOrderEvent;
|
|
|
-import com.yami.shop.bean.model.ShopWallet;
|
|
|
import com.yami.shop.bean.order.ConfirmOrderOrder;
|
|
|
-import com.yami.shop.common.exception.GlobalException;
|
|
|
-import com.yami.shop.common.exception.YamiShopBindException;
|
|
|
-import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.dao.ShopWalletMapper;
|
|
|
import com.yami.shop.service.OrderRefundService;
|
|
|
import com.yami.shop.service.OrderService;
|
|
|
@@ -32,9 +23,6 @@ import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 确认收货的事件
|
|
|
@@ -57,55 +45,59 @@ public class ReceiptOrderListener {
|
|
|
@EventListener(ReceiptOrderEvent.class)
|
|
|
@Order(ConfirmOrderOrder.DISTRIBUTION)
|
|
|
public void defaultReceiptOrderEvent(ReceiptOrderEvent event) {
|
|
|
- com.yami.shop.bean.model.Order order = event.getOrder();
|
|
|
- //如果是积分订单无需操作
|
|
|
- if(Objects.equals(order.getOrderType() , OrderType.SCORE.value())){
|
|
|
- return;
|
|
|
- }
|
|
|
- Long shopId = order.getShopId();
|
|
|
- ShopWallet shopWallet = shopWalletMapper.selectOne(new LambdaQueryWrapper<ShopWallet>().eq(ShopWallet::getShopId, shopId));
|
|
|
- ShopWallet newShopWallet = mapperFacade.map(shopWallet, ShopWallet.class);
|
|
|
- newShopWallet.setUpdateTime(new Date());
|
|
|
-
|
|
|
- // 退款成功金额
|
|
|
- double refundSuccessAmount = orderRefundService.sumRefundSuccessAmountByOrderId(order.getOrderId());
|
|
|
-
|
|
|
- // 分销占用金额
|
|
|
- double distributionAmount = orderService.sumTotalDistributionAmountByOrderItem(order.getOrderItems());
|
|
|
- // 平台占用金额
|
|
|
- double platformAmount = orderRefundService.sumRefundSuccessPlatformAmountByOrderId(order.getOrderId());
|
|
|
-
|
|
|
-
|
|
|
- // 结算金额 = (用户支付金额 + 平台补贴金额) - 退款成功金额 - 分销占用金额
|
|
|
- double shopAmount = Arith.add(order.getActualTotal(), order.getPlatformAmount());
|
|
|
- double settledAmount = Arith.sub(Arith.sub(Arith.sub(shopAmount, refundSuccessAmount), distributionAmount),platformAmount);
|
|
|
- // 减去未结算金额
|
|
|
- newShopWallet.setUnsettledAmount(Arith.sub(shopWallet.getUnsettledAmount(),settledAmount));
|
|
|
- // 增加结算金额
|
|
|
- newShopWallet.setSettledAmount(Arith.add(shopWallet.getSettledAmount(),settledAmount));
|
|
|
- // 增加总结算金额
|
|
|
- newShopWallet.setTotalSettledAmount(Arith.add(shopWallet.getTotalSettledAmount(),settledAmount));
|
|
|
- // 插入收入记录
|
|
|
- //'海博订单状态:0-待支付,
|
|
|
- // 20-订单已接单(待拣货),
|
|
|
- // 30-订单待配送(拣货完成/自提类订单为待自提),
|
|
|
- // 40-订单配送中 ,
|
|
|
- // 50-订单取消待审核,
|
|
|
- // 60-订单已取消,
|
|
|
- // 70-订单已送达,
|
|
|
- // 80-订单已完成'
|
|
|
- if (Objects.equals(order.getHbOrderStatus(), OrderStatus.CLOSE.value()) && Objects.equals(order.getCloseType(), OrderCloseType.REFUND.value())) {
|
|
|
- shopWalletLogService.saveShopWalletLog(shopWallet,newShopWallet, ShopWalletChangeReason.ORDER_REFUND,order.getOrderNumber());
|
|
|
- } else {
|
|
|
- shopWalletLogService.saveShopWalletLog(shopWallet,newShopWallet, ShopWalletChangeReason.ORDER_SUCCESS,order.getOrderNumber());
|
|
|
- }
|
|
|
- // 使用乐观锁进行更新
|
|
|
- if (shopWalletMapper.updateById(newShopWallet)!=1) {
|
|
|
- log.error("更新店铺钱包失败,无法确认收货,稍后再试");
|
|
|
- // 不要让用户看到更新店铺钱包失败的信息
|
|
|
- throw new GlobalException("服务器繁忙,请稍后再试");
|
|
|
- }
|
|
|
-
|
|
|
+//
|
|
|
+// com.yami.shop.bean.model.Order order = event.getOrder();
|
|
|
+// //如果是积分订单无需操作
|
|
|
+// if(Objects.equals(order.getOrderType() , OrderType.SCORE.value())){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// Long shopId = order.getShopId();
|
|
|
+// System.out.println(shopId);
|
|
|
+// ShopWallet shopWallet = shopWalletMapper.selectOne(new LambdaQueryWrapper<ShopWallet>().eq(ShopWallet::getShopId, shopId));
|
|
|
+// System.out.println(shopWallet);
|
|
|
+// ShopWallet newShopWallet = mapperFacade.map(shopWallet, ShopWallet.class);
|
|
|
+//
|
|
|
+// System.out.println(newShopWallet);
|
|
|
+// newShopWallet.setUpdateTime(new Date());
|
|
|
+//
|
|
|
+// // 退款成功金额
|
|
|
+// double refundSuccessAmount = orderRefundService.sumRefundSuccessAmountByOrderId(order.getOrderId());
|
|
|
+//
|
|
|
+// // 分销占用金额
|
|
|
+// double distributionAmount = orderService.sumTotalDistributionAmountByOrderItem(order.getOrderItems());
|
|
|
+// // 平台占用金额
|
|
|
+// double platformAmount = orderRefundService.sumRefundSuccessPlatformAmountByOrderId(order.getOrderId());
|
|
|
+//
|
|
|
+//
|
|
|
+// // 结算金额 = (用户支付金额 + 平台补贴金额) - 退款成功金额 - 分销占用金额
|
|
|
+// double shopAmount = Arith.add(order.getActualTotal(), order.getPlatformAmount());
|
|
|
+// double settledAmount = Arith.sub(Arith.sub(Arith.sub(shopAmount, refundSuccessAmount), distributionAmount),platformAmount);
|
|
|
+// // 减去未结算金额
|
|
|
+// newShopWallet.setUnsettledAmount(Arith.sub(shopWallet.getUnsettledAmount(),settledAmount));
|
|
|
+// // 增加结算金额
|
|
|
+// newShopWallet.setSettledAmount(Arith.add(shopWallet.getSettledAmount(),settledAmount));
|
|
|
+// // 增加总结算金额
|
|
|
+// newShopWallet.setTotalSettledAmount(Arith.add(shopWallet.getTotalSettledAmount(),settledAmount));
|
|
|
+// // 插入收入记录
|
|
|
+// //'海博订单状态:0-待支付,
|
|
|
+// // 20-订单已接单(待拣货),
|
|
|
+// // 30-订单待配送(拣货完成/自提类订单为待自提),
|
|
|
+// // 40-订单配送中 ,
|
|
|
+// // 50-订单取消待审核,
|
|
|
+// // 60-订单已取消,
|
|
|
+// // 70-订单已送达,
|
|
|
+// // 80-订单已完成'
|
|
|
+// if (Objects.equals(order.getHbOrderStatus(), OrderStatus.CLOSE.value()) && Objects.equals(order.getCloseType(), OrderCloseType.REFUND.value())) {
|
|
|
+// shopWalletLogService.saveShopWalletLog(shopWallet,newShopWallet, ShopWalletChangeReason.ORDER_REFUND,order.getOrderNumber());
|
|
|
+// } else {
|
|
|
+// shopWalletLogService.saveShopWalletLog(shopWallet,newShopWallet, ShopWalletChangeReason.ORDER_SUCCESS,order.getOrderNumber());
|
|
|
+// }
|
|
|
+// // 使用乐观锁进行更新
|
|
|
+// if (shopWalletMapper.updateById(newShopWallet)!=1) {
|
|
|
+// log.error("更新店铺钱包失败,无法确认收货,稍后再试");
|
|
|
+// // 不要让用户看到更新店铺钱包失败的信息
|
|
|
+// throw new GlobalException("服务器繁忙,请稍后再试");
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
}
|