|
|
@@ -20,8 +20,10 @@ import com.yami.shop.common.exception.GlobalException;
|
|
|
import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
import com.yami.shop.common.util.RefundSnUtils;
|
|
|
+import com.yami.shop.dao.OrderItemMapper;
|
|
|
import com.yami.shop.dao.OrderRefundRecordMapper;
|
|
|
import com.yami.shop.dao.OrderRefundSkuMapper;
|
|
|
+import com.yami.shop.dao.PointsRecordMapper;
|
|
|
import com.yami.shop.delivery.comment.api.paotui.PaoTuiApi;
|
|
|
import com.yami.shop.delivery.comment.api.paotui.model.request.AddWithoutShopRequest;
|
|
|
import com.yami.shop.delivery.comment.api.paotui.model.request.DeliveryCpriceRequest;
|
|
|
@@ -81,6 +83,9 @@ public class OrderRefundController {
|
|
|
|
|
|
private final UserAddrService userAddrService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderItemMapper orderItemMapper;
|
|
|
+
|
|
|
|
|
|
private final TransportManagerService transportManagerService;
|
|
|
|
|
|
@@ -99,6 +104,9 @@ public class OrderRefundController {
|
|
|
@Autowired
|
|
|
private SkuService skuService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ PointsRecordMapper pointsRecordMapper;
|
|
|
+
|
|
|
|
|
|
@GetMapping("getIsDistribution")
|
|
|
@ApiOperation(value = "获取是否在配送中")
|
|
|
@@ -378,7 +386,8 @@ public class OrderRefundController {
|
|
|
long refundPoints = Math.round(refundTotalPoints);
|
|
|
newOrderRefund.setOffsetPoints(Math.min(refundPoints, orderPoints));
|
|
|
}
|
|
|
-
|
|
|
+ //需要再这里调用获取过期积分和退款积分
|
|
|
+ getExpiredAndReturn(newOrderRefund,order,orderRefundSkuList);
|
|
|
OrderRefund orderRefund = orderRefundService.applyRefund(newOrderRefund);
|
|
|
if (!orderRefundSkuList.isEmpty()) {
|
|
|
orderRefundSkuList.forEach(c -> {
|
|
|
@@ -801,4 +810,63 @@ public class OrderRefundController {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取过期积分和退还积分
|
|
|
+ * @param orderRefund
|
|
|
+ * @param order
|
|
|
+ * @param orderRefundSkuList
|
|
|
+ */
|
|
|
+ private void getExpiredAndReturn(OrderRefund orderRefund,Order order,List<OrderRefundSku> orderRefundSkuList){
|
|
|
+ //退款的积分 将所有的钱都转为积分对比
|
|
|
+ int totalRefundScore = 0;//需要退款的积分,部分退款时不需要退运费。
|
|
|
+ //该未过期的积分
|
|
|
+ long noRefundExpiredScore = 0L;
|
|
|
+ //改订单总的积分
|
|
|
+ long orderSumScore = 0L;
|
|
|
+
|
|
|
+ int freightAmountScore = -(int) Arith.mul(order.getFreightAmount(), 100);//需要退的总积分,先把运费剔除掉
|
|
|
+ for (OrderRefundSku orderRefundSku : orderRefundSkuList) {
|
|
|
+ Integer productCount = orderRefundSku.getProductCount();
|
|
|
+ OrderItem orderItem = orderItemMapper.selectById(orderRefundSku.getOrderItemId());
|
|
|
+ totalRefundScore = (int) (totalRefundScore+ Arith.mul(productCount * orderItem.getPrice(), 100));
|
|
|
+ }
|
|
|
+ if (orderRefund.getRefundType()==1){
|
|
|
+ totalRefundScore+=freightAmountScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PointsRecord> pointsRecords = pointsRecordMapper.findByOrderNumber(order.getOrderNumber(), 2);
|
|
|
+ for (PointsRecord pointsRecord : pointsRecords) {
|
|
|
+ if (pointsRecord.getExpiryStatus()==1){
|
|
|
+ int i=0;
|
|
|
+ if (pointsRecord.getPointsAudit()==2){
|
|
|
+ i =pointsRecord.getVariablePoints().intValue();
|
|
|
+ }else if(pointsRecord.getPointsAudit()==1){
|
|
|
+ i = pointsRecord.getPoints().intValue();
|
|
|
+ }
|
|
|
+ noRefundExpiredScore+=i;
|
|
|
+ }
|
|
|
+ if (pointsRecord.getPointsAudit()==2){
|
|
|
+ orderSumScore +=pointsRecord.getVariablePoints().intValue();
|
|
|
+ }else if(pointsRecord.getPointsAudit()==1){
|
|
|
+ orderSumScore += pointsRecord.getPoints().intValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (order.getOffsetPoints()>0&&totalRefundScore!=0){
|
|
|
+ if (order.getOffsetPoints()>=totalRefundScore){
|
|
|
+ orderRefund.setOffsetPoints(Long.valueOf(totalRefundScore));
|
|
|
+ if (totalRefundScore<=orderSumScore){
|
|
|
+ if (totalRefundScore>noRefundExpiredScore){
|
|
|
+ orderRefund.setRefundExpiredScore(totalRefundScore-noRefundExpiredScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ orderRefund.setOffsetPoints(order.getOffsetPoints());
|
|
|
+ if (order.getOffsetPoints()<=orderSumScore){
|
|
|
+ if (order.getOffsetPoints()>noRefundExpiredScore){
|
|
|
+ orderRefund.setRefundExpiredScore(order.getOffsetPoints()-noRefundExpiredScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|