diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index 6c6a8e9..cd5d2c4 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -1408,4 +1408,29 @@ public class AppVerifyController extends BaseController } return toAjax(etOrderService.useCoupon(orderNo,logId)); } + + /** + * 0元订单处理 + */ + @Log(title = "0元订单处理", businessType = BusinessType.ZEROORDER) + @PostMapping("/zeroOrder") + public AjaxResult zeroOrder(String orderNo) + { + logger.info("0元订单处理:【orderNo="+orderNo+"】"); + EtOrder order = etOrderService.selectEtOrderByOrderNo(orderNo); + // 骑行结束并且订单金额等于0,并且未支付 + if(ServiceConstants.ORDER_STATUS_RIDING_END.equals(order.getStatus()) && order.getTotalFee().compareTo(BigDecimal.ZERO) == 0 && order.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_NON_PAYMENT)){ + order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); + order.setPayTime(new Date()); + order.setPayType(ServiceConstants.PAY_TYPE_SYS); + order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); + int updateEtOrder = etOrderMapper.updateEtOrder(order); + if(updateEtOrder == 0){ + throw new ServiceException("更新订单outTradeNo失败"); + }else { + logger.info("【isInOrder接口】更新订单outTradeNo成功"); + } + } + return toAjax(1); + } } diff --git a/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java b/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java index e4407de..c5d453d 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java +++ b/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java @@ -206,4 +206,9 @@ public enum BusinessType * 使用优惠券 */ USECOUPON, + + /** + * 0元订单 + */ + ZEROORDER, } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java index 10ed840..60153a8 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java @@ -6,7 +6,6 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.aliyuncs.exceptions.ClientException; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.ServiceConstants; @@ -198,6 +197,16 @@ public class CallbackServiceImpl implements CallbackService { order.setPayTime(DateUtils.getNowDate()); order.setPayType(ServiceConstants.PAY_TYPE_WX); order.setLocking("0"); + // 如果使用了优惠券则扣除一次使用次数 + if(ObjectUtil.isNotNull(order.getLogId())){ + EtCouponUserLog couponUserLog = etCouponClaimLogMapper.selectEtCouponClaimLogByLogId(order.getLogId()); + EtCoupon etCoupon = etCouponMapper.selectEtCouponByCouponId(couponUserLog.getCouponId()); + logger.info("【微信支付回调】优惠券信息 : " + JSON.toJSONString(etCoupon)); + if(ObjectUtil.isNotNull(etCoupon) && (etCoupon.getType().equals(ServiceConstants.COUPON_TYPE_DISCOUNT_CARD) || etCoupon.getType().equals(ServiceConstants.COUPON_TYPE_VOUCHER)) && couponUserLog.getLimitNum() > 0){ + etCouponClaimLogMapper.deductLimitNum(couponUserLog.getLogId()); + logger.info("【微信支付回调】优惠券使用次数-1"); + } + } if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_RIDING)){ logger.info("【微信支付回调】骑行支付"); // 1-骑行支付 关锁 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index c7df9f9..c3f1a77 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -1813,19 +1813,6 @@ public class EtOrderServiceImpl implements IEtOrderService if(ObjectUtil.isNotNull(etCoupon)){ order.setCoupon(etCoupon); } - // 骑行结束并且订单金额等于0,并且未支付 - if(ServiceConstants.ORDER_STATUS_RIDING_END.equals(order.getStatus()) && order.getTotalFee().compareTo(BigDecimal.ZERO) == 0 && order.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_NON_PAYMENT)){ - order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); - order.setPayTime(new Date()); - order.setPayType(ServiceConstants.PAY_TYPE_SYS); - order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); - int updateEtOrder = etOrderMapper.updateEtOrder(order); - if(updateEtOrder == 0){ - throw new ServiceException("更新订单outTradeNo失败"); - }else { - log.info("【isInOrder接口】更新订单outTradeNo成功"); - } - } } return inOrder; } @@ -2020,14 +2007,20 @@ public class EtOrderServiceImpl implements IEtOrderService * 抵用券:总金额 - 抵用金额 次数减一 */ private EtOrder calculateCoupon(EtOrder order,Long logId) { - Long couponId = order.getCouponId(); - EtCoupon etCoupon = etCouponMapper.selectEtCouponByCouponId(couponId); Long userId = order.getUserId(); AsUser asUser = asUserMapper.selectUserById(userId); - + log.info("【用户】:【{}】",JSON.toJSON(asUser)); EtCouponUserLog etCouponUserLog1 = etCouponClaimLogMapper.selectEtCouponClaimLogByLogId(logId); - - if(etCoupon.getType().equals(asUser.getVipType()) || asUser.getExpirationTime().compareTo(new Date()) < 0){ + log.info("【使用优惠券】优惠券信息:【{}】",JSON.toJSON(etCouponUserLog1)); + EtCoupon etCoupon = etCouponMapper.selectEtCouponByCouponId(etCouponUserLog1.getCouponId()); + log.info("【优惠券】优惠券:【{}】",JSON.toJSON(etCoupon)); + if(etCouponUserLog1 == null){ + throw new ServiceException("用户没有优惠券"); + } + if(etCoupon == null){ + throw new ServiceException("优惠券不存在"); + } + if(ObjectUtil.isNotNull(asUser.getExpirationTime()) && asUser.getExpirationTime().compareTo(new Date()) < 0){ throw new ServiceException("会员已过期"); } @@ -2053,10 +2046,6 @@ public class EtOrderServiceImpl implements IEtOrderService throw new ServiceException("优惠券类型错误"); } - // 扣除一次使用次数 - if(etCoupon.getType().equals(ServiceConstants.COUPON_TYPE_DISCOUNT_CARD) || etCoupon.getType().equals(ServiceConstants.COUPON_TYPE_VOUCHER) && etCouponUserLog1.getLimitNum() > 0){ - etCouponClaimLogMapper.deductLimitNum(etCouponUserLog1.getLogId()); - } return order; }