diff --git a/service/src/main/java/com/hfkj/dao/BsTradeOrderMapperExt.java b/service/src/main/java/com/hfkj/dao/BsTradeOrderMapperExt.java index d6b58b0..2f75066 100644 --- a/service/src/main/java/com/hfkj/dao/BsTradeOrderMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsTradeOrderMapperExt.java @@ -32,4 +32,8 @@ public interface BsTradeOrderMapperExt { "") Map countTradeOrderPrice(@Param("param") Map param); + + @Select("SELECT count(1) FROM `bs_trade_order` where user_phone = #{userPhone} and `status` = 3 and rebate_activity_part = 1 and pay_time BETWEEN #{timeS} and #{timeE} ") + Integer countUserTrade(@Param("userPhone") String userPhone, @Param("timeS") String timeS, @Param("timeE") String timeE); + } diff --git a/service/src/main/java/com/hfkj/dao/BsTransferAccountsMapperExt.java b/service/src/main/java/com/hfkj/dao/BsTransferAccountsMapperExt.java index 319cbf6..5444e8d 100644 --- a/service/src/main/java/com/hfkj/dao/BsTransferAccountsMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsTransferAccountsMapperExt.java @@ -14,10 +14,10 @@ public interface BsTransferAccountsMapperExt { @Select(" SELECT mer_no merNo," + " sum(rebate_activity_actual_price) totalPrice " + " FROM bs_trade_order where rebate_activity_part = 1 " + - " = #{startTimeS} ]]>" + + " = #{startTime} ]]>" + " " + " and `status` = 3" + " GROUP BY mer_no") - List> queryTradeRebate(@Param("startTimeS") String startTime, @Param("endTime") String endTime); + List> queryTradeRebate(@Param("startTime") String startTime, @Param("endTime") String endTime); } diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java index 83afef0..6893f7c 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderRefundServiceImpl.java @@ -74,6 +74,9 @@ public class BsTradeOrderRefundServiceImpl implements BsTradeOrderRefundService if (tradeOrder == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的交易订单"); } + if (tradeOrder.getRebateActivityPart().equals(true)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,交易订单已参加优惠活动"); + } if (StringUtils.isNotBlank(tradeOrder.getUserPhone())) { if (HsgIntegralService.recycleIntegral(tradeOrder.getId().toString(),tradeOrder.getOutTradeNo()).equals(false)) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户积分不足,暂时无法退款"); diff --git a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java index c511c00..03ba4bf 100644 --- a/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/impl/BsTradeOrderServiceImpl.java @@ -224,60 +224,134 @@ public class BsTradeOrderServiceImpl implements BsTradeOrderService { editOrder(tradeOrder); - // 商户活动金活动 - BsRebateActivity rebateActivity = rebateActivityService.getMerCurrentActivity(mer.getMerNo()); - if (rebateActivity != null && rebateActivity.getEndTime().compareTo(new Date()) >= 0) { - if (rebateActivity.getActivityType().equals(RebateActivityTypeEnum.type1.getNumber())) { - if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type1.getNumber())) { - // 达到满减门槛 - if (tradeOrder.getTradeAmount().compareTo(rebateActivity.getCondition()) >= 0) { - tradeOrder.setRebateActivityPart(true); - tradeOrder.setRebateActivityId(rebateActivity.getId()); - tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); - tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); - tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); - tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); - tradeOrder.setRebateActivityActualPrice(rebateActivity.getPrice()); - tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + if (StringUtils.isNotBlank(userPhone)) { + // 查询商户的活动金 优惠活动 + BsRebateActivity rebateActivity = rebateActivityService.getMerCurrentActivity(mer.getMerNo()); + if (rebateActivity != null && rebateActivity.getEndTime().compareTo(new Date()) >= 0) { + // 优惠活动限制 + if (rebateActivity.getRestrictPartakeType().equals(RebateActivityPartakeTypeEnum.type1.getNumber())) { + // 查询用户交易次数 + Calendar timeS = Calendar.getInstance(); + timeS.setTime(new Date()); + timeS.set(Calendar.HOUR_OF_DAY, 00); + timeS.set(Calendar.MINUTE, 00); + timeS.set(Calendar.SECOND, 00); + + Calendar timeE = Calendar.getInstance(); + timeE.setTime(new Date()); + timeE.set(Calendar.HOUR_OF_DAY, 23); + timeE.set(Calendar.MINUTE, 59); + timeE.set(Calendar.SECOND, 59); + Integer userTrade = tradeOrderMapper.countUserTrade( + userPhone, + DateUtil.format(timeS.getTime(), "yyyy-MM-dd HH:mm:ss"), + DateUtil.format(timeE.getTime(), "yyyy-MM-dd HH:mm:ss")); + if (userTrade < rebateActivity.getRestrictPartakeNum()) { + if (rebateActivity.getActivityType().equals(RebateActivityTypeEnum.type1.getNumber())) { + if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type1.getNumber())) { + // 达到满减门槛 + if (tradeOrder.getTradeAmount().compareTo(rebateActivity.getCondition()) >= 0) { + tradeOrder.setRebateActivityPart(true); + tradeOrder.setRebateActivityId(rebateActivity.getId()); + tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); + tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); + tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); + tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); + tradeOrder.setRebateActivityActualPrice(rebateActivity.getPrice()); + tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + } + } else if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type2.getNumber())) { + tradeOrder.setRebateActivityPart(true); + tradeOrder.setRebateActivityId(rebateActivity.getId()); + tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); + tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); + tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); + tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); + tradeOrder.setRebateActivityActualPrice(rebateActivity.getPrice()); + tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + + } else if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type3.getNumber())) { + tradeOrder.setRebateActivityPart(true); + tradeOrder.setRebateActivityId(rebateActivity.getId()); + tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); + tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); + tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); + tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); + + // 优惠折扣 + BigDecimal priceRate = tradeOrder.getRebateActivityPrice().divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_DOWN); + tradeOrder.setRebateActivityActualPrice(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getTradeActualAmount().multiply(priceRate).setScale(2, BigDecimal.ROUND_HALF_UP))); + tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + } + } + } + } else { + if (rebateActivity.getActivityType().equals(RebateActivityTypeEnum.type1.getNumber())) { + if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type1.getNumber())) { + // 达到满减门槛 + if (tradeOrder.getTradeAmount().compareTo(rebateActivity.getCondition()) >= 0) { + tradeOrder.setRebateActivityPart(true); + tradeOrder.setRebateActivityId(rebateActivity.getId()); + tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); + tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); + tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); + tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); + tradeOrder.setRebateActivityActualPrice(rebateActivity.getPrice()); + tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + } + } else if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type2.getNumber())) { + tradeOrder.setRebateActivityPart(true); + tradeOrder.setRebateActivityId(rebateActivity.getId()); + tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); + tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); + tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); + tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); + tradeOrder.setRebateActivityActualPrice(rebateActivity.getPrice()); + tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + + } else if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type3.getNumber())) { + tradeOrder.setRebateActivityPart(true); + tradeOrder.setRebateActivityId(rebateActivity.getId()); + tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); + tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); + tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); + tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); + + // 优惠折扣 + BigDecimal priceRate = tradeOrder.getRebateActivityPrice().divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_DOWN); + tradeOrder.setRebateActivityActualPrice(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getTradeActualAmount().multiply(priceRate).setScale(2, BigDecimal.ROUND_HALF_UP))); + tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); + } + } + } + + if (tradeOrder.getRebateActivityPart().equals(true)) { + RebateActivityAccountTradeObject accountTradeObject = new RebateActivityAccountTradeObject(); + accountTradeObject.setTradeObjectType(RebateActivityAccountObjectTypeEnum.type3); + accountTradeObject.setTradeObjectId(tradeOrder.getId()); + accountTradeObject.setTradeObjectContent("创建交易" + tradeOrder.getOutTradeNo()); + + Boolean activityAccount = rebateActivityAccountService.accountTrade( + tradeOrder.getRebateActivityNo(), + RebateActivityAccountTradeTypeEnum.type2, + tradeOrder.getRebateActivityActualPrice(), + accountTradeObject); + if (activityAccount.equals(true)) { + editOrder(tradeOrder); + } else { + tradeOrder.setRebateActivityPart(false); + tradeOrder.setRebateActivityId(null); + tradeOrder.setRebateActivityNo(null); + tradeOrder.setRebateActivityType(null); + tradeOrder.setRebateActivityPreferentialType(null); + tradeOrder.setRebateActivityPrice(null); + tradeOrder.setRebateActivityActualPrice(null); + tradeOrder.setTradeActualAmount(null); } - } else if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type2.getNumber())) { - tradeOrder.setRebateActivityPart(true); - tradeOrder.setRebateActivityId(rebateActivity.getId()); - tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); - tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); - tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); - tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); - tradeOrder.setRebateActivityActualPrice(rebateActivity.getPrice()); - tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); - - } else if (rebateActivity.getPreferentialType().equals(RebateActivityPreferentialTypeEnum.type3.getNumber())) { - tradeOrder.setRebateActivityPart(true); - tradeOrder.setRebateActivityId(rebateActivity.getId()); - tradeOrder.setRebateActivityNo(rebateActivity.getActivityNo()); - tradeOrder.setRebateActivityType(rebateActivity.getActivityType()); - tradeOrder.setRebateActivityPreferentialType(rebateActivity.getPreferentialType()); - tradeOrder.setRebateActivityPrice(rebateActivity.getPrice()); - - // 优惠折扣 - BigDecimal priceRate = tradeOrder.getRebateActivityPrice().divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_DOWN); - tradeOrder.setRebateActivityActualPrice(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getTradeActualAmount().multiply(priceRate).setScale(2, BigDecimal.ROUND_HALF_UP))); - tradeOrder.setTradeActualAmount(tradeOrder.getTradeActualAmount().subtract(tradeOrder.getRebateActivityActualPrice())); } - editOrder(tradeOrder); - } - if (tradeOrder.getRebateActivityPart().equals(true)) { - RebateActivityAccountTradeObject accountTradeObject = new RebateActivityAccountTradeObject(); - accountTradeObject.setTradeObjectType(RebateActivityAccountObjectTypeEnum.type3); - accountTradeObject.setTradeObjectId(tradeOrder.getId()); - accountTradeObject.setTradeObjectContent("创建交易" + tradeOrder.getOutTradeNo()); - rebateActivityAccountService.accountTrade( - tradeOrder.getRebateActivityNo(), - RebateActivityAccountTradeTypeEnum.type2, - tradeOrder.getRebateActivityActualPrice(), - accountTradeObject - ); } + } Map returnParam = new HashMap<>(); diff --git a/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityAccountServiceImpl.java b/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityAccountServiceImpl.java index b41625d..d3be5cc 100644 --- a/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityAccountServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityAccountServiceImpl.java @@ -221,7 +221,7 @@ public class BsRebateActivityAccountServiceImpl implements BsRebateActivityAccou } else if (tradeType.getNumber().equals(RebateActivityAccountTradeTypeEnum.type2.getNumber())) { // 扣款金额是否大于账户余额 - if (tradeAmount.compareTo(account.getAmount()) >= 0) { + if (tradeAmount.compareTo(account.getAmount()) > 0) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "账户余额不足"); } account.setAmount(account.getAmount().subtract(tradeAmount)); diff --git a/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityServiceImpl.java b/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityServiceImpl.java index 2e14e31..f04112e 100644 --- a/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/rebate/impl/BsRebateActivityServiceImpl.java @@ -97,7 +97,7 @@ public class BsRebateActivityServiceImpl implements BsRebateActivityService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "活动状态错误"); } activity.setStatus(RebateActivityStatusEnum.status3.getNumber()); - activity.setRestrictPartakeType(rebateActivityEndTypeEnum.getNumber()); + activity.setRealityEndType(rebateActivityEndTypeEnum.getNumber()); if (RebateActivityEndTypeEnum.type1.getNumber().equals(rebateActivityEndTypeEnum.getNumber())) { activity.setRealityEndTime(activity.getEndTime());