From 60de92280e4cd66a914f41b0681656a62cde346d Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 14 一月 2025 14:50:52 +0800 Subject: [PATCH] 修改bug --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java | 420 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 298 insertions(+), 122 deletions(-) diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java index 36d8d92..b1e22d4 100644 --- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java +++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java @@ -144,8 +144,31 @@ //查询符合商品类型的商品数据 List<ShoppingCart> list = this.list(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid) .in(ShoppingCart::getGoodsId, goodsIds).eq(ShoppingCart::getStatus, 1)); + //删除过期的秒杀活动商品 + List<ShoppingCart> list1 = new ArrayList<>(); + for (ShoppingCart shoppingCart : list) { + if(shoppingCart.getType() == 2){ + GetSeckillActivityInfo info = new GetSeckillActivityInfo(); + info.setGoodsId(shoppingCart.getGoodsId()); + info.setVip(appUser.getVipId()); + GoodsSeckill data1 = seckillActivityInfoClient.getSeckillActivityInfo(info).getData(); + if(null != data1){ + SeckillActivityInfo seckillActivityInfo = seckillActivityInfoClient.getSeckillActivityInfoById(data1.getSeckillActivityInfoId()).getData(); + if(null != seckillActivityInfo && (seckillActivityInfo.getIsShelves() == 1 && + seckillActivityInfo.getStartTime().isBefore(LocalDateTime.now()) && seckillActivityInfo.getEndTime().isAfter(LocalDateTime.now()))){ + + list1.add(shoppingCart); + continue; + } + } + this.removeById(shoppingCart.getId()); + }else{ + list1.add(shoppingCart); + } + } + //构建返回数据 - List<MyShoppingCartVo> page = buildDetail(appUser, shopId, list, null); + List<MyShoppingCartVo> page = buildDetail(appUser, shopId, list1, null); return page; } @@ -410,6 +433,9 @@ //总优惠金额 BigDecimal activityAmount = BigDecimal.ZERO; + + BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData(); + confirmOrderVo.setUseSimultaneously(JSON.parseObject(baseSetting.getContent()).getInteger("status") == 1); //减去优惠券优惠金额 CouponInfoVo couponInfoVo = null; if(null != confirmOrder.getCouponId() && 2 != confirmOrder.getPaymentType()){ @@ -480,33 +506,44 @@ //查询当前是否有订单活动 List<OrderActivityInfo> orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); //满XX才打折,只有现金才能优惠 - if(null != orderActivityInfo && confirmOrder.getPaymentType() == 1){ + if((confirmOrderVo.getUseSimultaneously() || (!confirmOrderVo.getUseSimultaneously() && activityAmount.equals(BigDecimal.ZERO))) + && null != orderActivityInfo && confirmOrder.getPaymentType() == 1){ + BigDecimal zyh = BigDecimal.ZERO; + OrderActivityInfo activityInfo1 = null; for (OrderActivityInfo activityInfo : orderActivityInfo) { if(activityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){ - confirmOrderVo.setActivityName(activityInfo.getActivityName()); //优惠后的支付金额 BigDecimal multiply = activityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); //优惠金额 BigDecimal bigDecimal = paymentMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); - paymentMoney = multiply; - activityAmount = activityAmount.add(bigDecimal); - break; + if(bigDecimal.compareTo(zyh) > 0){ + zyh = bigDecimal; + activityInfo1 = activityInfo; + } } } + if(null != activityInfo1){ + confirmOrderVo.setActivityName(activityInfo1.getActivityName()); + paymentMoney = paymentMoney.subtract(zyh); + activityAmount = activityAmount.add(zyh); + } } confirmOrderVo.setDiscountAmount(activityAmount); - BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData(); - confirmOrderVo.setUseSimultaneously(JSON.parseObject(baseSetting.getContent()).getInteger("status") == 1); int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum(); confirmOrderVo.setEarnPoint(earnPoint); + if(null != paymentMoney && BigDecimal.ZERO.compareTo(paymentMoney) > 0){ + paymentMoney = BigDecimal.ZERO; + } + //支付金额,订单金额-订单优惠 confirmOrderVo.setPayMoney(paymentMoney); - confirmOrderVo.setResidualPoint(appUser.getLavePoint().intValue()); + confirmOrderVo.setResidualPoint(appUser.getAvailablePoint().intValue()); //获取默认收货地址 UserAddress userAddress = userAddressClient.getDefaultUserAddress(userid).getData(); if(null != userAddress){ userAddress.setIdStr(userAddress.getId().toString()); + userAddress.setRecieveAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress()); confirmOrderVo.setUserAddress(userAddress); } confirmOrderVo.setPaymentType(confirmOrder.getPaymentType()); @@ -532,11 +569,11 @@ } }else{ //部分商品适用 - BigDecimal goodsMoney = BigDecimal.ZERO; + BigDecimal goodsMoney = BigDecimal.ZERO; for (MyShoppingCartVo myShoppingCartVo : goodsList) { Integer goodsId = myShoppingCartVo.getGoodsId(); BigDecimal cash = myShoppingCartVo.getCash(); - if(forGoodIds.contains(goodsId)){ + if(forGoodIds.contains(String.valueOf(goodsId))){ goodsMoney = goodsMoney.add(cash); } } @@ -702,6 +739,14 @@ } } } + + if(goods.getStatus() == 1){ + throw new RuntimeException(goods.getName() + "商品已被下架"); + } + if(!goods.getCommodityAuthority().contains("-1") && !goods.getCommodityAuthority().contains(appUser.getVipId().toString())){ + throw new RuntimeException("无权限购买" + goods.getName()); + } + ids.add(id); } @@ -758,9 +803,6 @@ }else{ for (MyShoppingCartVo myShoppingCartVo : goodsList) { orderPoint += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber()); - } - if(appUser.getLavePoint().intValue() < orderPoint){ - return R.fail("账户剩余积分不足"); } } //现金的支付金额 @@ -854,17 +896,21 @@ OrderActivityInfo orderActivityInfo1 = null; if((1 == status || null == shoppingCartPayment.getUserCouponId()) && null != orderActivityInfo && shoppingCartPayment.getPaymentType() != 3){ + //找出最优会的金额 + BigDecimal zyh = BigDecimal.ZERO; for (OrderActivityInfo activityInfo : orderActivityInfo) { if(activityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){ BigDecimal paymentMoney1 = activityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN); - discount = activityInfo.getDiscount(); - paymentMoney = paymentMoney1; - activityAmount = activityAmount.add(bigDecimal); - orderActivityInfo1 = activityInfo; - break; + if(bigDecimal.compareTo(zyh) > 0){ + zyh = bigDecimal; + orderActivityInfo1 = activityInfo; + } } } + + paymentMoney = paymentMoney.subtract(zyh); + activityAmount = activityAmount.add(zyh); } //可获得的消费积分 @@ -898,6 +944,10 @@ } } } + if(BigDecimal.ZERO.compareTo(paymentMoney) > 0){ + paymentMoney = BigDecimal.ZERO; + } + //构建订单明细 Order order = new Order(); order.setAppUserId(userid); @@ -912,7 +962,7 @@ order.setGoodName(goodName.substring(0, goodName.length() - 1)); Goods goods = goodsClient.getGoodsById(goodsList.get(0).getGoodsId()).getData(); order.setOrderType(goods.getType()); - order.setOrderStatus(goods.getType() == 1 ? 3 : 1); + order.setOrderStatus(goods.getType() == 1 ? 3 : (shoppingCartPayment.getDistributionMode() == 2 ? 1 : 2)); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); order.setOrderNumber("QJS" + getNumber(3) + sdf.format(new Date())); order.setTotalAmount(orderMoney.setScale(2, RoundingMode.HALF_EVEN)); @@ -929,11 +979,12 @@ } if(3 != shoppingCartPayment.getPaymentType() && (fullReductionAmount.compareTo(BigDecimal.ZERO) > 0 ||moneyAmount.compareTo(BigDecimal.ZERO) > 0 || discountAmount.compareTo(BigDecimal.ZERO) > 0)){ order.setCouponJson(JSON.toJSONString(couponInfoVo)); + order.setUserCouponId(shoppingCartPayment.getUserCouponId()); } - if(activityAmount.compareTo(BigDecimal.ZERO) > 0){ + if(null != orderActivityInfo1){ order.setActivityJson(JSON.toJSONString(orderActivityInfo1)); } - if(null != shoppingCartPayment.getUserAddressId()){ + if(2 == shoppingCartPayment.getDistributionMode()){ UserAddress address = userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData(); order.setExpressAmount(expressFee); order.setAddressJson(JSON.toJSONString(address)); @@ -944,6 +995,7 @@ order.setDelFlag(0); order.setCreateTime(LocalDateTime.now()); order.setExpressPayMethod(shoppingCartPayment.getFreightPaymentType()); + order.setDistributionMode(shoppingCartPayment.getDistributionMode()); if(2 == shoppingCartPayment.getPaymentType()){ BigDecimal balance = appUser.getBalance(); @@ -954,7 +1006,7 @@ if(3 == shoppingCartPayment.getPaymentType()){ Integer availablePoint = appUser.getAvailablePoint(); if(availablePoint < orderPoint){ - return R.fail("账户积分不足"); + return R.fail("账户可用积分不足"); } } //判断运费支付是否足够 @@ -1007,27 +1059,108 @@ orderGood.setBoundShopPoints(myShoppingCartVo.getBoundShopPoints()); orderGood.setBoundShopSuperiorsCharges(myShoppingCartVo.getBoundShopSuperiorsCharges()); orderGood.setBoundShopSuperiorsPoints(myShoppingCartVo.getBoundShopSuperiorsPoints()); + orderGood.setCashPayment(myShoppingCartVo.getCashPayment() ? 1 : 0); + orderGood.setPointPayment(myShoppingCartVo.getPointPayment() ? 1 : 0); + orderGood.setSellingPrice(myShoppingCartVo.getCash()); + orderGood.setIntegral(myShoppingCartVo.getPoint()); orderGoodService.save(orderGood); } //开始构建支付数据 //现金支付 paymentMoney = paymentMoney.add(expressFee).setScale(2, RoundingMode.HALF_EVEN); + if(BigDecimal.ZERO.compareTo(paymentMoney) > 0){ + paymentMoney = BigDecimal.ZERO; + } if(1 == shoppingCartPayment.getPaymentType()){ - //调起微信支付 - String goodsNames = goodsList.stream().map(MyShoppingCartVo::getName).collect(Collectors.joining("\n")); - UniPayResult uniPayResult = PaymentUtil.uniPay(order.getOrderNumber(), paymentMoney.doubleValue(), order.getOrderType() == 1 ? "购买服务商品" : "购买单品商品", - goodsNames, "", "/order/shopping-cart/shoppingCartPaymentCallback", appUser.getWxOpenid(), null); - if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){ - return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg()); + if(BigDecimal.ZERO.compareTo(paymentMoney) < 0){ + //调起微信支付 + String goodsNames = goodsList.stream().map(MyShoppingCartVo::getName).collect(Collectors.joining("\n")); + UniPayResult uniPayResult = PaymentUtil.uniPay(order.getOrderNumber(), paymentMoney.doubleValue(), order.getOrderType() == 1 ? "购买服务商品" : "购买单品商品", + goodsNames, "", "/order/shopping-cart/shoppingCartPaymentCallback", appUser.getWxOpenid(), null); + if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){ + return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg()); + } + String rc_result = uniPayResult.getRc_Result(); + JSONObject jsonObject = JSON.parseObject(rc_result); + jsonObject.put("orderId", order.getId().toString()); + //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。 + long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC); + redisTemplate.opsForZSet().add("OrderPayment", order.getOrderNumber(), second); + return R.ok(jsonObject.toJSONString()); + }else{ + + earnPoint = order.getGetPoint(); + appUser = appUserClient.getAppUserById(order.getAppUserId()); + Integer lavePoint = appUser.getLavePoint(); + paymentMoney = order.getPaymentAmount(); + //构建积分流水记录 + if(earnPoint > 0){ + PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); + int earnPoint1 = 0; + if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ + earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); + } + appUser.setShopPoint(appUser.getShopPoint() + earnPoint); + appUser.setLavePoint(appUser.getLavePoint() + earnPoint); + appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); + appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1); + appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("shopPoint", earnPoint); + jsonObject.put("availablePoint", earnPoint1); + if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ + appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1); + jsonObject.put("transferablePoint", earnPoint1); + } + + UserPoint userPoint = new UserPoint(); + userPoint.setType(1); + userPoint.setHistoricalPoint(lavePoint); + userPoint.setVariablePoint(earnPoint); + userPoint.setBalance(appUser.getLavePoint()); + userPoint.setCreateTime(LocalDateTime.now()); + userPoint.setAppUserId(appUser.getId()); + userPoint.setObjectId(order.getId()); + userPoint.setExtention(jsonObject.toJSONString()); + userPointClient.saveUserPoint(userPoint); + } + appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); + appUser.setLastShopTime(LocalDateTime.now()); + appUserClient.editAppUserById(appUser); + //变更等级 + appUserClient.vipUpgrade(appUser.getId()); + //修改订支付状态 + order.setPayStatus(2); + //自提 + if(order.getOrderType() == 1 && StringUtils.isEmpty(order.getAddressJson())){ + order.setOrderStatus(2); + } + orderService.updateById(order); + + //处理优惠券 + if(null != order.getUserCouponId()){ + UserCoupon userCoupon = userCouponClient.getUserCoupon(order.getUserCouponId()).getData(); + if(null != userCoupon && null == userCoupon.getUseTime()){ + userCoupon.setStatus(2); + userCoupon.setUseTime(LocalDateTime.now()); + userCouponClient.editUserCoupon(userCoupon); + } + } + //添加查询快递信息队列 + if(StringUtils.isNotEmpty(order.getExpressJson())){ + //一小时后定时查询快递信息 + redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC)); + } + + //删除购物车数据 + userid = tokenService.getLoginUserApplet().getUserid(); + List<OrderGood> list1 = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId())); + List<Integer> goodsIds1 = list1.stream().map(OrderGood::getGoodsId).collect(Collectors.toList()); + this.remove(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds1)); + } - String rc_result = uniPayResult.getRc_Result(); - JSONObject jsonObject = JSON.parseObject(rc_result); - jsonObject.put("orderId", order.getId().toString()); - //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。 - long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC); - redisTemplate.opsForZSet().add("OrderPayment", order.getOrderNumber(), second); - return R.ok(jsonObject.toJSONString()); } //账户余额 BigDecimal redPacketAmount = BigDecimal.ZERO; @@ -1037,27 +1170,28 @@ BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount(); BigDecimal balance = appUser.getBalance(); //红包金额满足支付 - if(paymentMoney.compareTo(totalRedPacketAmount) <= 0){ - totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney); - balance = balance.subtract(paymentMoney); + BigDecimal paymentMoney1 = paymentMoney; + if(paymentMoney1.compareTo(totalRedPacketAmount) <= 0){ + totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney1); + balance = balance.subtract(paymentMoney1); appUser.setTotalRedPacketAmount(totalRedPacketAmount); appUser.setBalance(balance); - redPacketAmount = paymentMoney; + redPacketAmount = paymentMoney1; }else{ - paymentMoney = paymentMoney.subtract(totalRedPacketAmount); + paymentMoney1 = paymentMoney1.subtract(totalRedPacketAmount); redPacketAmount = totalRedPacketAmount; totalRedPacketAmount = BigDecimal.ZERO; - if(paymentMoney.compareTo(totalDistributionAmount) <= 0){ - totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney); - balance = balance.subtract(paymentMoney); + if(paymentMoney1.compareTo(totalDistributionAmount) <= 0){ + totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney1); + balance = balance.subtract(paymentMoney1); appUser.setTotalRedPacketAmount(totalRedPacketAmount); appUser.setTotalDistributionAmount(totalDistributionAmount); appUser.setBalance(balance); - distributionAmount = paymentMoney; + distributionAmount = paymentMoney1; }else{ - paymentMoney = paymentMoney.subtract(totalDistributionAmount); + paymentMoney1 = paymentMoney1.subtract(totalDistributionAmount); totalDistributionAmount = BigDecimal.ZERO; - balance = balance.subtract(paymentMoney); + balance = balance.subtract(paymentMoney1); appUser.setTotalRedPacketAmount(totalRedPacketAmount); appUser.setTotalDistributionAmount(totalDistributionAmount); appUser.setBalance(balance); @@ -1076,8 +1210,13 @@ appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1); appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("shopPoint", earnPoint); + jsonObject.put("availablePoint", earnPoint1); if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1); + jsonObject.put("transferablePoint", earnPoint1); } if(earnPoint > 0){ @@ -1089,6 +1228,7 @@ userPoint.setCreateTime(LocalDateTime.now()); userPoint.setAppUserId(appUser.getId()); userPoint.setObjectId(order.getId()); + userPoint.setExtention(jsonObject.toJSONString()); userPointClient.saveUserPoint(userPoint); } } @@ -1100,6 +1240,7 @@ //构建余额明细变动记录 BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); balanceChangeRecord.setAppUserId(appUser.getId()); + balanceChangeRecord.setVipId(appUser.getVipId()); balanceChangeRecord.setOrderId(order.getId()); balanceChangeRecord.setChangeType(5); balanceChangeRecord.setBeforeAmount(balance.add(paymentMoney)); @@ -1116,6 +1257,19 @@ orderService.updateById(order); //删除购物车数据 this.removeBatchByIds(ids); + //处理优惠券 + if(null != order.getUserCouponId()){ + UserCoupon userCoupon = userCouponClient.getUserCoupon(order.getUserCouponId()).getData(); + if(null != userCoupon && null == userCoupon.getUseTime()){ + userCoupon.setUseTime(LocalDateTime.now()); + userCouponClient.editUserCoupon(userCoupon); + } + } + //添加查询快递信息队列 + if(StringUtils.isNotEmpty(order.getExpressJson())){ + //一小时后定时查询快递信息 + redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC)); + } } //积分支付 if(3 == shoppingCartPayment.getPaymentType()){ @@ -1148,8 +1302,9 @@ if(transferablePoint > 0){ tra = transferablePoint - orderPoint; appUser.setTransferablePoint(tra >= 0 ? tra : 0); + }else{ + appUser.setTransferablePoint(appUser.getTransferablePoint() - orderPoint); } - appUser.setTransferablePoint(appUser.getTransferablePoint() - orderPoint); //构建积分流水记录 UserPoint userPoint = new UserPoint(); @@ -1163,65 +1318,41 @@ userPoint.setExtention((tra >= 0 ? orderPoint : transferablePoint) + ""); userPointClient.saveUserPoint(userPoint); - lavePoint = appUser.getLavePoint(); - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ - earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); - } - appUser.setShopPoint(appUser.getShopPoint() + earnPoint); - appUser.setLavePoint(appUser.getLavePoint() + earnPoint); - appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1); - appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1); - if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ - appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1); - } - appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); appUser.setLastShopTime(LocalDateTime.now()); appUserClient.editAppUserById(appUser); //变更等级 appUserClient.vipUpgrade(appUser.getId()); - //构建积分流水记录 - if(earnPoint > 0){ - userPoint = new UserPoint(); - userPoint.setType(1); - userPoint.setHistoricalPoint(lavePoint); - userPoint.setVariablePoint(earnPoint); - userPoint.setBalance(appUser.getLavePoint()); - userPoint.setCreateTime(LocalDateTime.now()); - userPoint.setAppUserId(appUser.getId()); - userPoint.setObjectId(order.getId()); - userPointClient.saveUserPoint(userPoint); - } + //积分支付不返佣 + //如果有运费,需要先扣除账户积分,再进行支付。支付成功后修改订单状态,未支付成功则回退积分,删除的订单 if(expressFee.compareTo(BigDecimal.ZERO) > 0){ if(shoppingCartPayment.getFreightPaymentType() == 2){ BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount(); BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount(); BigDecimal balance = appUser.getBalance(); - if(expressFee.compareTo(totalRedPacketAmount) <= 0){ - totalRedPacketAmount = totalRedPacketAmount.subtract(expressFee); - balance = balance.subtract(expressFee); + BigDecimal expressFee1 = expressFee; + if(expressFee1.compareTo(totalRedPacketAmount) <= 0){ + totalRedPacketAmount = totalRedPacketAmount.subtract(expressFee1); + balance = balance.subtract(expressFee1); appUser.setTotalRedPacketAmount(totalRedPacketAmount); appUser.setBalance(balance); - redPacketAmount = expressFee; + redPacketAmount = expressFee1; }else{ - expressFee = expressFee.subtract(totalRedPacketAmount); + expressFee1 = expressFee1.subtract(totalRedPacketAmount); redPacketAmount = totalRedPacketAmount; totalRedPacketAmount = BigDecimal.ZERO; - if(expressFee.compareTo(totalDistributionAmount) <= 0){ - totalDistributionAmount = totalDistributionAmount.subtract(expressFee); - balance = balance.subtract(expressFee); + if(expressFee1.compareTo(totalDistributionAmount) <= 0){ + totalDistributionAmount = totalDistributionAmount.subtract(expressFee1); + balance = balance.subtract(expressFee1); appUser.setTotalRedPacketAmount(totalRedPacketAmount); appUser.setTotalDistributionAmount(totalDistributionAmount); appUser.setBalance(balance); - distributionAmount = expressFee; + distributionAmount = expressFee1; }else{ - expressFee = expressFee.subtract(totalDistributionAmount); + expressFee1 = expressFee1.subtract(totalDistributionAmount); totalDistributionAmount = BigDecimal.ZERO; - balance = balance.subtract(expressFee); + balance = balance.subtract(expressFee1); appUser.setTotalRedPacketAmount(totalRedPacketAmount); appUser.setTotalDistributionAmount(totalDistributionAmount); appUser.setBalance(balance); @@ -1233,10 +1364,11 @@ //构建余额明细变动记录 BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); balanceChangeRecord.setAppUserId(appUser.getId()); + balanceChangeRecord.setVipId(appUser.getVipId()); balanceChangeRecord.setOrderId(order.getId()); balanceChangeRecord.setChangeType(5); - balanceChangeRecord.setBeforeAmount(balance.add(paymentMoney)); - balanceChangeRecord.setChangeAmount(paymentMoney); + balanceChangeRecord.setBeforeAmount(balance.add(expressFee)); + balanceChangeRecord.setChangeAmount(expressFee); balanceChangeRecord.setAfterAmount(balance); balanceChangeRecord.setDelFlag(0); balanceChangeRecord.setCreateTime(LocalDateTime.now()); @@ -1260,7 +1392,16 @@ //删除购物车数据 this.removeBatchByIds(ids); } + //添加查询快递信息队列 + if(StringUtils.isNotEmpty(order.getExpressJson())){ + //一小时后定时查询快递信息 + SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData(); + JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); + Integer waitTime = jsonObject.getInteger("waitTime"); + redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(waitTime).toEpochSecond(ZoneOffset.UTC)); + } } + //添加账户余额支付明细 if(redPacketAmount.compareTo(BigDecimal.ZERO) > 0 || distributionAmount.compareTo(BigDecimal.ZERO) > 0){ OrderBalancePayment orderBalancePayment = new OrderBalancePayment(); @@ -1295,31 +1436,39 @@ } Integer earnPoint = order.getGetPoint(); AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); + Integer lavePoint = appUser.getLavePoint(); BigDecimal paymentMoney = order.getPaymentAmount(); //构建积分流水记录 if(earnPoint > 0){ PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = earnPoint; + int earnPoint1 = 0; if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ - earnPoint1 = new BigDecimal(earnPoint1).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); + earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); } appUser.setShopPoint(appUser.getShopPoint() + earnPoint); appUser.setLavePoint(appUser.getLavePoint() + earnPoint); appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1); appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1); - - if(earnPoint > 0){ - UserPoint userPoint = new UserPoint(); - userPoint.setType(1); - userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint); - userPoint.setVariablePoint(earnPoint); - userPoint.setBalance(appUser.getLavePoint()); - userPoint.setCreateTime(LocalDateTime.now()); - userPoint.setAppUserId(appUser.getId()); - userPoint.setObjectId(order.getId()); - userPointClient.saveUserPoint(userPoint); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("shopPoint", earnPoint); + jsonObject.put("availablePoint", earnPoint1); + if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){ + appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1); + jsonObject.put("transferablePoint", earnPoint1); } + + UserPoint userPoint = new UserPoint(); + userPoint.setType(1); + userPoint.setHistoricalPoint(lavePoint); + userPoint.setVariablePoint(earnPoint); + userPoint.setBalance(appUser.getLavePoint()); + userPoint.setCreateTime(LocalDateTime.now()); + userPoint.setAppUserId(appUser.getId()); + userPoint.setObjectId(order.getId()); + userPoint.setExtention(jsonObject.toJSONString()); + userPointClient.saveUserPoint(userPoint); } appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); appUser.setLastShopTime(LocalDateTime.now()); @@ -1333,11 +1482,32 @@ order.setOrderStatus(2); } orderService.updateById(order); + + //处理优惠券 + if(null != order.getUserCouponId()){ + UserCoupon userCoupon = userCouponClient.getUserCoupon(order.getUserCouponId()).getData(); + if(null != userCoupon && null == userCoupon.getUseTime()){ + userCoupon.setStatus(2); + userCoupon.setUseTime(LocalDateTime.now()); + userCouponClient.editUserCoupon(userCoupon); + } + } + //添加查询快递信息队列 + if(StringUtils.isNotEmpty(order.getExpressJson())){ + //一小时后定时查询快递信息 + redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC)); + } + //删除购物车数据 - Long userid = tokenService.getLoginUserApplet().getUserid(); + Long userid = order.getAppUserId(); List<OrderGood> list = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId())); List<Integer> goodsIds = list.stream().map(OrderGood::getGoodsId).collect(Collectors.toList()); this.remove(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds)); + + //商品销量增加 + for (Integer goodsId : goodsIds) { + goodsClient.editGoodsNum(goodsId, 1); + } return R.ok(); } @@ -1355,35 +1525,41 @@ if(null == order || order.getPayStatus() == 2){ return R.ok(); } - Integer earnPoint = order.getGetPoint(); + Integer orderPoint = order.getPoint(); AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); + Integer lavePoint = appUser.getLavePoint(); - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ - earnPoint1 = new BigDecimal(earnPoint).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue(); + //扣减订单支付积分 + appUser.setLavePoint(appUser.getLavePoint() - orderPoint); + appUser.setAvailablePoint(appUser.getAvailablePoint() - orderPoint); + //可转增积分 + Integer transferablePoint = appUser.getTransferablePoint(); + Integer tra = 0; + if(transferablePoint > 0){ + tra = transferablePoint - orderPoint; + appUser.setTransferablePoint(tra >= 0 ? tra : 0); + }else{ + appUser.setTransferablePoint(appUser.getTransferablePoint() - orderPoint); } - appUser.setShopPoint(appUser.getShopPoint() + earnPoint); - appUser.setLavePoint(appUser.getLavePoint() + earnPoint); - appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1); - appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + earnPoint1); - appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); - appUser.setLastShopTime(LocalDateTime.now()); - appUserClient.editAppUserById(appUser); - //变更等级 - appUserClient.vipUpgrade(appUser.getId()); - + //构建积分流水记录 UserPoint userPoint = new UserPoint(); - userPoint.setType(1); + userPoint.setType(11); userPoint.setHistoricalPoint(lavePoint); - userPoint.setVariablePoint(earnPoint); + userPoint.setVariablePoint(orderPoint); userPoint.setBalance(appUser.getLavePoint()); userPoint.setCreateTime(LocalDateTime.now()); userPoint.setAppUserId(appUser.getId()); userPoint.setObjectId(order.getId()); + userPoint.setExtention((tra >= 0 ? orderPoint : transferablePoint) + ""); userPointClient.saveUserPoint(userPoint); + + //积分支付不反积分 + + appUser.setLastShopTime(LocalDateTime.now()); + appUserClient.editAppUserById(appUser); + //变更等级 + appUserClient.vipUpgrade(appUser.getId()); //修改订支付状态 order.setPayStatus(2); @@ -1408,7 +1584,7 @@ public void closeOrder() { //订单支付数据 long second = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); - Set<String> orderPayment = redisTemplate.opsForZSet().range("OrderPayment", 0, second); + Set<String> orderPayment = redisTemplate.opsForZSet().rangeByScore("OrderPayment", 0, second); if(orderPayment.size() > 0){ List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNumber, orderPayment)); for (Order order : list) { @@ -1428,7 +1604,7 @@ } //快递支付 - Set<String> materialFlowPayment = redisTemplate.opsForZSet().range("MaterialFlowPayment", 0, second); + Set<String> materialFlowPayment = redisTemplate.opsForZSet().rangeByScore("MaterialFlowPayment", 0, second); if(materialFlowPayment.size() > 0){ materialFlowPayment.forEach(s->s.substring(1)); List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().in(Order::getOrderNumber, materialFlowPayment)); -- Gitblit v1.7.1