bihs 2 тижнів тому
батько
коміт
5525300260

+ 8 - 7
qmjszx-business/src/main/java/beilv/vipCardLog/service/impl/VipCardLogServiceImpl.java

@@ -341,11 +341,11 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
             //计算已使用次数
             BigDecimal useSum = BigDecimal.valueOf(carInformation.getTotalNumber() - userMembershipCard.getRemainingNumber());
 
-            //计算需要支付的金额
-            BigDecimal userPrice = useSum.multiply(carInformation.getOriginalPrice());
+            //计算需要支付的金额 = 原价 / 总次数(四舍五入) * 已使用次数
+            BigDecimal userPrice = carInformation.getOriginalPrice().divide(BigDecimal.valueOf(carInformation.getTotalNumber()), 2, RoundingMode.HALF_UP).multiply(useSum);
 
             //实际支付的金额 - 需要支付的金额 = 退款金额
-            BigDecimal refundMoner = orderInfo.getMemberPrice().subtract(userPrice);
+            BigDecimal refundMoner = orderInfo.getPracticalMoney().subtract(userPrice);
 
             //判断如果退款金额 不大于0, 则设置退款金额为0
             refundMoner = refundMoner.compareTo(BigDecimal.ZERO) > 0 ? refundMoner : BigDecimal.ZERO;
@@ -378,6 +378,10 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
         vipCardLog.setRefundPrice(refundPrice);
         orderInfo.setRefundPrice(refundPrice);
 
+        //使用钱包支付的订单, 不走我微信退款
+        if (!"weChart".equals(orderInfo.getPaymentType())) {
+            executeUpdate = true;
+        }
         // executeUpdate=true 时才执行更新操作(包括订单状态、会员卡余额、次卡次数等)
         if (executeUpdate) {
             if ("vipCard".equals(orderInfo.getPaymentType())) {
@@ -425,10 +429,7 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
         }
 
         // executeUpdate=false 时只返回计算结果,不更新任何状态
-        if ("weChart".equals(orderInfo.getPaymentType())) {
-            return AjaxResult.success(orderInfo);
-        }
-        return AjaxResult.success("退款金额计算成功!");
+        return AjaxResult.success(orderInfo);
 
     }
 

+ 2 - 2
qmjszx-business/src/main/resources/mapper/card/UserMembershipCardMapper.xml

@@ -51,8 +51,8 @@
         c.type card_type
         FROM
         user_membership_card a
-        left join sys_member b on a.user_id = b.id
-        left join card_information c on a.card_info_id = c.id
+        inner join sys_member b on a.user_id = b.id
+        inner join card_information c on a.card_info_id = c.id
         <where>
             <if test="userId != null  and userId != ''">and a.user_id = #{userId}</if>
             <if test="cardType != null  and cardType != ''">and c.type = #{cardType}</if>

+ 5 - 5
qmjszx-pay/src/main/java/beilv/wx/pay/service/IWxPayService.java

@@ -502,17 +502,17 @@ public class IWxPayService {
                             order.setStatus(3); // 3表示已取消
                             order.setUpdateTime(new Date());
                             storeOrderMapper.updateStoreOrder(order);
+                            //如果使用了优惠券,释放优惠券
+                            VipCardLog orderInfo = vipCardLogService.selectVipCardLogById(orderId);
+                            if (StringUtils.isNotEmpty(orderInfo.getVoucherId())) {
+                                beilvVoucherMemberMapper.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(orderInfo.getVoucherId()), "1"));
+                            }
                             log.info("订单 {} 已超时,状态已更新为已取消", orderId);
                         } else if (order != null) {
                             log.info("订单 {} 已支付,无需处理", orderId);
                         } else {
                             log.warn("订单 {} 不存在", orderId);
                         }
-                        //如果使用了优惠券,释放优惠券
-                        VipCardLog orderInfo = vipCardLogService.selectVipCardLogById(orderId);
-                        if (StringUtils.isNotEmpty(orderInfo.getVoucherId())) {
-                            beilvVoucherMemberMapper.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(orderInfo.getVoucherId()), "1"));
-                        }
                         // 从延迟队列中移除订单
                         redisTemplate.opsForZSet().remove(ORDER_DELAY_QUEUE_PREFIX + "orders", orderId);
                         log.info("超时订单 {} 处理完成", orderId);