From c927b4d36b9e04a8b2ba08c8789f5277aa1c277d Mon Sep 17 00:00:00 2001 From: jiangqs <jiangqs> Date: 星期四, 27 七月 2023 21:01:15 +0800 Subject: [PATCH] bug --- ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java | 220 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 183 insertions(+), 37 deletions(-) diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java index 4a4ddf8..46d54f3 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java @@ -28,6 +28,7 @@ import com.ruoyi.system.api.constant.DelayTaskEnum; import com.ruoyi.system.api.constant.SecurityConstant; import com.ruoyi.system.api.domain.dto.*; +import com.ruoyi.system.api.domain.poji.activity.ActivityRecord; import com.ruoyi.system.api.domain.poji.config.DelayTask; import com.ruoyi.system.api.domain.poji.goods.Goods; import com.ruoyi.system.api.domain.poji.goods.GoodsFile; @@ -175,7 +176,10 @@ List<AppMemberCouponVo> appMemberCouponVoList = remoteCouponService.listVoMemberCouponByUserId(merBaseDto).getData(); // 将优惠券列表转换为Map,以优惠券ID为键 - Map<String, AppMemberCouponVo> appMemberCouponVoMap = appMemberCouponVoList.stream().collect(Collectors.toMap(AppMemberCouponVo::getMemberCouponId, Function.identity())); + Map<String, AppMemberCouponVo> appMemberCouponVoMap = new HashMap<>(); + if(appMemberCouponVoList!=null&&!appMemberCouponVoList.isEmpty()){ + appMemberCouponVoMap = appMemberCouponVoList.stream().collect(Collectors.toMap(AppMemberCouponVo::getMemberCouponId, Function.identity())); + } AppMemberCouponVo appMemberCouponVo; Integer couponType; BigDecimal moneyThreshold; @@ -232,8 +236,8 @@ couponType = appMemberCouponVo.getCouponType(); if (couponType == 1 && appMemberCouponVo.getMoneyThreshold() != null && appMemberCouponVo.getDiscountMoney() != null) { moneyThreshold = appMemberCouponVo.getMoneyThreshold(); - if (goodsTotalPrice.compareTo(moneyThreshold) >= 0) { - discountMoney = appMemberCouponVo.getDiscountMoney(); + discountMoney = appMemberCouponVo.getDiscountMoney(); + if (goodsTotalPrice.compareTo(moneyThreshold) >= 0 && goodsTotalPrice.compareTo(discountMoney)>0) { goodsRealPrice = goodsTotalPrice.subtract(discountMoney); useCoupon = 1; userCouponIdSet.add(memberCouponId); @@ -248,13 +252,15 @@ appSureOrderGoodsVo.setMemberCouponId(memberCouponId); } else if (couponType == 3 && appMemberCouponVo.getDiscountMoney() != null) { discountMoney = appMemberCouponVo.getDiscountMoney(); - goodsRealPrice = goodsTotalPrice.subtract(discountMoney); - if(goodsRealPrice.compareTo(BigDecimal.ZERO)<0){ - goodsRealPrice = BigDecimal.ZERO; + if(goodsTotalPrice.compareTo(discountMoney)>0){ + goodsRealPrice = goodsTotalPrice.subtract(discountMoney); + if(goodsRealPrice.compareTo(BigDecimal.ZERO)<0){ + goodsRealPrice = BigDecimal.ZERO; + } + useCoupon = 1; + userCouponIdSet.add(memberCouponId); + appSureOrderGoodsVo.setMemberCouponId(memberCouponId); } - useCoupon = 1; - userCouponIdSet.add(memberCouponId); - appSureOrderGoodsVo.setMemberCouponId(memberCouponId); } } } @@ -262,7 +268,6 @@ appSureOrderGoodsVo.setGoodsTotalPrice(goodsTotalPrice); appSureOrderGoodsVo.setCouponDiscount(discountMoney); appSureOrderGoodsVo.setGoodsRealPrice(goodsRealPrice); - goodsDeposit = goods.getSubscription(); // 获取商品押金 goodsDeposit = goods.getSubscription(); if (goodsDeposit != null && goodsDeposit.compareTo(BigDecimal.ZERO)>0) { @@ -290,6 +295,8 @@ }else{ entity.setUseFlag(0); } + + } // 过滤商品优惠券列表 List<AppMemberCouponVo> appGoodsMemberCouponVoList; @@ -297,10 +304,14 @@ appGoodsMemberCouponVoList = new ArrayList<>(); for(AppMemberCouponVo entity : appMemberCouponVoList){ if(StringUtils.isBlank(entity.getRelGoodsIds())||entity.getRelGoodsIds().contains(sureOrderGoodsVo.getGoodsId())){ - if(entity.getCouponType()!=1){ + if(entity.getCouponType()==1){ + if(entity.getMoneyThreshold().compareTo(sureOrderGoodsVo.getGoodsTotalPrice())<0&&entity.getDiscountMoney().compareTo(sureOrderGoodsVo.getGoodsTotalPrice())<0){ + appGoodsMemberCouponVoList.add(entity); + } + }else if(entity.getCouponType()==2){ appGoodsMemberCouponVoList.add(entity); - }else{ - if(entity.getMoneyThreshold().compareTo(sureOrderGoodsVo.getGoodsTotalPrice())<0){ + }else if(entity.getCouponType()==3){ + if(entity.getDiscountMoney().compareTo(sureOrderGoodsVo.getGoodsTotalPrice())<0){ appGoodsMemberCouponVoList.add(entity); } } @@ -410,10 +421,14 @@ if (activityGoodsGetVo.getAvailableBuyNum() < 1) { throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_NULL); } + if (activityGoodsGetVo.getAvailableBuyNum() < buyNum) { + throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_BEYOND); + } Goods goods = remoteGoodsService.getGoods(goodsId).getData(); if(goods.getGoodsStatus()!=1){ throw new ServiceException(AppErrorConstant.GOODS_DOWN); } + appPanicBuyVo.setActivityId(activityId); appPanicBuyVo.setGoodsId(goodsId); appPanicBuyVo.setGoodsName(goods.getGoodsName()); appPanicBuyVo.setGoodsIntroduction(goods.getGoodsIntroduction()); @@ -726,7 +741,7 @@ //减去优惠券 - if(memberCouponSJ!=null){ + if(memberCouponSJ!=null&&StringUtils.isNotBlank(memberCouponSJ.toString())){ remoteCouponService.useMemberCoupon(memberCouponSJ.toString()); } //生成自动取消订单延时任务 @@ -814,8 +829,8 @@ if (activityGoodsGetVo.getAvailableBuyNum() < 1) { throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_NULL); } - if (buyNum < activityGoodsGetVo.getAvailableBuyNum()) { - throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_NULL); + if (activityGoodsGetVo.getAvailableBuyNum() < buyNum) { + throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_BEYOND); } // 创建订单ID和订单号 String orderId = IdUtils.simpleUUID(); @@ -1000,7 +1015,19 @@ appPlaceOrderVo.setTradeType(res.getSignType()); appPlaceOrderVo.setPaySign(res.getPaySign()); */ - + //生成活动参加记录 + ActivityRecord activityRecord = new ActivityRecord(); + activityRecord.setDelFlag(0); + activityRecord.setActivityId(activityId); + activityRecord.setUserId(userId); + activityRecord.setOrderTime(order.getCreateTime()); + activityRecord.setOrderMoney(order.getOrderMoney()); + activityRecord.setOrderId(orderId); + activityRecord.setCreateTime(new Date()); + activityRecord.setBuyNum(orderGoods.getBuyNum()); + activityRecord.setGoodsId(orderGoods.getGoodsId()); + activityRecord.setActivityMoney(activityGoodsGetVo.getActivityPrice()); + remoteActivityService.addActivityRecord(activityRecord); //生成自动取消订单延时任务 Integer delayTime = 30; if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){ @@ -1184,9 +1211,9 @@ merVerifyOrderVo.setUseTime(order.getUseTime()); merVerifyOrderVo.setAppUserOrderGoodsPageVoList(appUserOrderGoodsPageVoList); // 根据订单用户ID获取用户信息 - SysUser sysUser = remoteUserService.getSysUser(order.getUserId()).getData(); - merVerifyOrderVo.setUserName(sysUser.getNickName()); - merVerifyOrderVo.setUserMobile(sysUser.getPhonenumber()); + Member member = remoteMemberService.getMember(order.getUserId()).getData(); + merVerifyOrderVo.setUserName(member.getRealName()); + merVerifyOrderVo.setUserMobile(member.getMobile()); merVerifyOrderVo.setCloseFlag(order.getCloseFlag()); // 返回结果 return merVerifyOrderVo; @@ -1210,6 +1237,7 @@ if (order.getOrderStatus() != 2) { throw new ServiceException(AppErrorConstant.VERIFY_USED); } + ShopRelUserVo shopRelUserVo = remoteShopService.getShopByUserId(merVerifyOrderDto.getUserId()).getData(); if(!shopRelUserVo.getShopId().equals(order.getShopId())){ throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); @@ -1220,8 +1248,12 @@ order.setOfflinePayMoney(relPayMoney); order.setOffPayTime(nowTime); order.setPayMoney(order.getPayMoney().add(relPayMoney)); - order.setCloseFlag(1); order.setChangeReceivableMoney(relReceiveMoney); + if(order.getPayMoney().compareTo(order.getChangeReceivableMoney())>=0){ + order.setCloseFlag(1); + }else{ + order.setCloseFlag(0); + } this.saveOrUpdate(order); //创建服务商品 List<AppUserOrderGoodsPageVo> appUserOrderGoodsPageVoList = orderGoodsService.listAppVoByOrderId(orderId); @@ -1278,9 +1310,10 @@ merVerifyOrderVo.setCreateTime(order.getCreateTime()); merVerifyOrderVo.setPayTime(order.getPayTime()); merVerifyOrderVo.setUseTime(order.getUseTime()); - SysUser sysUser = remoteUserService.getSysUser(order.getUserId()).getData(); - merVerifyOrderVo.setUserName(sysUser.getNickName()); - merVerifyOrderVo.setUserMobile(sysUser.getPhonenumber()); + Member member = remoteMemberService.getMember(order.getUserId()).getData(); + merVerifyOrderVo.setUserName(member.getRealName()); + merVerifyOrderVo.setUserMobile(member.getMobile()); + merVerifyOrderVo.setCloseFlag(order.getCloseFlag()); // if(order.getOrderFrom()==2){ @@ -1312,7 +1345,7 @@ Long userId = verifyCouponGetVo.getUserId(); // 调用remoteMemberService的getMember方法获取Member对象 Member member = remoteMemberService.getMember(userId).getData(); - merVerifyCouponVo.setUserName(member.getNickName()); + merVerifyCouponVo.setUserName(member.getRealName()); merVerifyCouponVo.setUserMobile(member.getMobile()); merVerifyCouponVo.setCouponFrom(verifyCouponGetVo.getCouponFrom()); merVerifyCouponVo.setCouponName(verifyCouponGetVo.getMemberCoupon().getCouponName()); @@ -1404,7 +1437,7 @@ throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); } Member member = remoteMemberService.getMember(memberGiftRecord.getUserId()).getData(); - merVerifyAwardVo.setUserName(member.getNickName()); + merVerifyAwardVo.setUserName(member.getRealName()); merVerifyAwardVo.setUserMobile(member.getMobile()); if(memberGiftRecord.getGiftFrom()==1){ merVerifyAwardVo.setGiftFrom("平台生日卡"); @@ -1508,10 +1541,14 @@ @Override public void merCloseOrder(MerCloseOrderDto merCloseOrderDto) { Order order = this.getById(merCloseOrderDto.getOrderId()); - order.setOfflinePayMoney(merCloseOrderDto.getPayMoney()); + order.setOfflinePayMoney(order.getOfflinePayMoney().add(merCloseOrderDto.getPayMoney())); order.setOffPayTime(new Date()); order.setPayMoney(order.getPayMoney().add(merCloseOrderDto.getPayMoney())); - order.setCloseFlag(1); + if(order.getPayMoney().compareTo(order.getChangeReceivableMoney())>=0){ + order.setCloseFlag(0); + }else{ + order.setCloseFlag(1); + } this.saveOrUpdate(order); } @@ -1524,6 +1561,8 @@ public void createNewOrder(MerNewOrderDto merNewOrderDto) { Long userId = merNewOrderDto.getBuyUserId(); Date nowTime = new Date(); + Long shopId = merNewOrderDto.getShopId(); + Shop shop = remoteShopService.getShop(shopId).getData(); //如果非指定用户判断是否需要通过手机号创建新用户 if (userId == null) { String name = merNewOrderDto.getName(); @@ -1551,6 +1590,9 @@ member.setMobile(mobile); member.setRealName(name); member.setNickName(name); + member.setBindingFlag(1); + member.setRelationShopId(shopId); + member.setRelationShopName(shop.getShopName()); remoteMemberService.createNewMember(member); } userId = sysUser.getUserId(); @@ -1567,8 +1609,6 @@ BigDecimal goodsPrice; BigDecimal goodsTotalPrice; BigDecimal goodsRealPrice; - Long shopId = merNewOrderDto.getShopId(); - Shop shop = remoteShopService.getShop(shopId).getData(); MerBaseDto merBaseDto = new MerBaseDto(); merBaseDto.setUserId(userId); merBaseDto.setShopId(shopId); @@ -1709,7 +1749,6 @@ order.setPayMoney(orderPayMoney); order.setOnlinePayMoney(new BigDecimal("0.00")); order.setOfflinePayMoney(orderPayMoney); - order.setCloseFlag(1); order.setOrderRemark(merNewOrderDto.getOrderRemark()); order.setGoodsNum(goodsNum); order.setCreateTime(nowTime); @@ -1721,7 +1760,11 @@ order.setOfflinePayMoney(merNewOrderDto.getPayMoney()); order.setOffPayTime(nowTime); order.setPayType(1); - order.setCloseFlag(1); + if(order.getPayMoney().compareTo(order.getChangeReceivableMoney())>=0){ + order.setCloseFlag(0); + }else{ + order.setCloseFlag(1); + } this.save(order); //创建服务 List<AppUserOrderGoodsPageVo> appUserOrderGoodsPageVoList = orderGoodsService.listAppVoByOrderId(orderId); @@ -2752,17 +2795,21 @@ throw new ServiceException(AppErrorConstant.COUPON_EXPIRED); } else if (couponStatus == 2) { throw new ServiceException(AppErrorConstant.COUPON_USED); - } else if (couponStatus != 0) { + } else if (couponStatus != 1) { throw new ServiceException(AppErrorConstant.COUPON_NO_FIND); } - if (!memberCoupon.getShopId().equals(shopId)) { + if (memberCoupon.getCouponFrom()==2&&!memberCoupon.getShopId().equals(shopId)) { throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); + } + //如果是平台优惠券 + if(memberCoupon.getCouponFrom()==1&&memberCoupon.getShopId()==null){ + memberCoupon.setShopId(shopId); } List<Goods> goodsList = verifyCouponGetVo.getGoodsList(); Long userId = verifyCouponGetVo.getUserId(); // 调用remoteMemberService的getMember方法获取Member对象 Member member = remoteMemberService.getMember(userId).getData(); - merVerifyCouponVo.setUserName(member.getNickName()); + merVerifyCouponVo.setUserName(member.getRealName()); merVerifyCouponVo.setUserMobile(member.getMobile()); merVerifyCouponVo.setCouponFrom(verifyCouponGetVo.getCouponFrom()); merVerifyCouponVo.setCouponName(verifyCouponGetVo.getMemberCoupon().getCouponName()); @@ -2811,7 +2858,7 @@ throw new ServiceException(AppErrorConstant.VERIFY_SHOP_ERROR); } Member member = remoteMemberService.getMember(memberGiftRecord.getUserId()).getData(); - merVerifyAwardVo.setUserName(member.getNickName()); + merVerifyAwardVo.setUserName(member.getRealName()); merVerifyAwardVo.setUserMobile(member.getMobile()); if(memberGiftRecord.getGiftFrom()==1){ merVerifyAwardVo.setGiftFrom("平台生日卡"); @@ -3077,7 +3124,9 @@ */ @Override public MerTotalOrderVo totalMerOrder(MerBaseDto merBaseDto) { - return orderMapper.totalMerOrder(merBaseDto.getShopId()); + MerTotalOrderVo merTotalOrderVo = new MerTotalOrderVo(); + merTotalOrderVo = orderMapper.totalMerOrder(merBaseDto.getShopId()); + return merTotalOrderVo; } /** @@ -3177,6 +3226,13 @@ agStockChangeDto.setShopId(order.getShopId()); agStockChangeDto.setUserId(order.getUserId()); remoteActivityService.changeActivityStock(agStockChangeDto); + //删除活动记录 + ActivityRecord activityRecord = new ActivityRecord(); + activityRecord.setActivityId(order.getActivityId()); + activityRecord.setGoodsId(orderGoods.getGoodsId()); + activityRecord.setUserId(order.getUserId()); + activityRecord.setOrderTime(order.getCreateTime()); + remoteActivityService.delActivityRecord(activityRecord); } } }else{ @@ -3394,6 +3450,13 @@ agStockChangeDto.setShopId(order.getShopId()); agStockChangeDto.setUserId(order.getUserId()); remoteActivityService.changeActivityStock(agStockChangeDto); + //删除活动记录 + ActivityRecord activityRecord = new ActivityRecord(); + activityRecord.setActivityId(order.getActivityId()); + activityRecord.setGoodsId(orderGoods.getGoodsId()); + activityRecord.setUserId(order.getUserId()); + activityRecord.setOrderTime(order.getCreateTime()); + remoteActivityService.delActivityRecord(activityRecord); }else{ memberCouponSJ.add(orderGoods.getCouponId()); } @@ -3718,4 +3781,87 @@ } return dateList; } + + /** + * @description 检查订单状态定时任务 + * @author jqs + * @date 2023/7/25 14:40 + * @param + * @return void + */ + @Override + public void checkOrderStatus(){ + Integer delayTime = 30; + if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){ + delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME); + } + delayTime = delayTime + 5; + Date checkTime = DateUtils.addMinutes(new Date(),delayTime); + LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Order::getDelFlag,0); + queryWrapper.lt(Order::getCreateTime,checkTime); + queryWrapper.eq(Order::getOrderStatus,1); + List<Order> orderList = this.list(queryWrapper); + if(orderList!=null&&!orderList.isEmpty()){ + for(Order order: orderList){ + autoTimeCancelOrder(order); + } + } + } + + private void autoTimeCancelOrder(Order order){ + String orderId = order.getOrderId(); + order.setOrderStatus(0); + order.setCancelTime(new Date()); + this.saveOrUpdate(order); + //活动订单回退库存 + if(order.getOrderFrom()==2){ + List<OrderGoods> orderGoodsList = orderGoodsService.listByOrderId(orderId); + if(orderGoodsList!=null&&!orderGoodsList.isEmpty()){ + for(OrderGoods orderGoods : orderGoodsList){ + //redis库存控制极简版 + String goodsLock = "goods_lock_"+order.getActivityId()+"_"+orderGoods.getGoodsId(); + RLock redissonLock = redissonClient.getLock(goodsLock); + try{ + redissonLock.lock(30, TimeUnit.SECONDS); + Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS+"-"+order.getActivityId()+"-"+orderGoods.getGoodsId()); + redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS+"-"+order.getActivityId()+"-"+orderGoods.getGoodsId(),surpNum+orderGoods.getBuyNum()); + }finally{ + redissonLock.unlock(); + } + //改变活动库存 + AGStockChangeDto agStockChangeDto = new AGStockChangeDto(); + agStockChangeDto.setActivityId(order.getActivityId()); + agStockChangeDto.setGoodsId(orderGoods.getGoodsId()); + agStockChangeDto.setChangeType(1); + agStockChangeDto.setChangeNum(orderGoods.getBuyNum()); + agStockChangeDto.setShopId(order.getShopId()); + agStockChangeDto.setUserId(order.getUserId()); + remoteActivityService.changeActivityStock(agStockChangeDto); + //删除活动记录 + ActivityRecord activityRecord = new ActivityRecord(); + activityRecord.setActivityId(order.getActivityId()); + activityRecord.setGoodsId(orderGoods.getGoodsId()); + activityRecord.setUserId(order.getUserId()); + activityRecord.setOrderTime(order.getCreateTime()); + remoteActivityService.delActivityRecord(activityRecord); + } + } + }else{ + if(order.getCouponMoney().compareTo(BigDecimal.ZERO)>0){ + //回退优惠券 + List<OrderGoods> orderGoodsList = orderGoodsService.listByOrderId(orderId); + if(orderGoodsList!=null&&!orderGoodsList.isEmpty()) { + StringJoiner memberCouponSJ = new StringJoiner(","); + for (OrderGoods orderGoods : orderGoodsList) { + memberCouponSJ.add(orderGoods.getCouponId()); + } + if(memberCouponSJ!=null){ + remoteCouponService.backMemberCoupon(memberCouponSJ.toString()); + + } + } + } + } + } } -- Gitblit v1.7.1