Selaa lähdekoodia

添加退款时积分支付状态和

zhangxin 1 päivä sitten
vanhempi
commit
006f774fd2

+ 69 - 1
yami-shop-api/src/main/java/com/yami/shop/api/controller/OrderRefundController.java

@@ -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);
+                    }
+                }
+            }
+        }
+    }
 }

+ 2 - 0
yami-shop-api/src/main/java/com/yami/shop/api/listener/SubmitOrderListener.java

@@ -23,6 +23,7 @@ import com.yami.shop.bean.enums.OrderType;
 import com.yami.shop.bean.event.SubmitOrderEvent;
 import com.yami.shop.bean.model.*;
 import com.yami.shop.bean.order.SubmitOrderOrder;
+import com.yami.shop.common.enums.PayType;
 import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.Arith;
 import com.yami.shop.dao.*;
@@ -150,6 +151,7 @@ public class SubmitOrderListener {
                     Double mul = Arith.mul(actualTotal, 100);
                     Double vp = Double.valueOf(point);
                     if (vp >= mul) {
+                        order.setPayType(PayType.SCOREPAY.value());
                         order.setIsPayed(1);
                         order.setPayTime(new Date());
                         order.setHbOrderStatus(OrderStatus.CONSIGNMENT.value());

+ 1 - 1
yami-shop-service/src/main/resources/mapper/PointsRecordMapper.xml

@@ -62,7 +62,7 @@
         select id,user_id,channel_id,order_number,
                code,parent_code,points,variable_points,points_type,points_audit,expiry_date,creation_date,currently_available_points,points_id,
                CASE
-               WHEN expiry_date > NOW() THEN 1
+               WHEN expiry_date >= NOW() THEN 1
                ELSE 2 END AS expiryStatus
         from tz_points_record where order_number = #{orderNumber} and points_type =#{pointsType} order by  expiry_date desc
     </select>