Pu Zhibing
2025-01-04 c8ea2d96f5b0522a09f3203ae98fe796084d2d15
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
@@ -15,18 +15,22 @@
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.mapper.ShoppingCartMapper;
import com.ruoyi.order.model.Order;
import com.ruoyi.order.model.OrderBalancePayment;
import com.ruoyi.order.model.OrderGood;
import com.ruoyi.order.model.ShoppingCart;
import com.ruoyi.order.service.CommissionService;
import com.ruoyi.order.service.OrderGoodService;
import com.ruoyi.order.service.OrderService;
import com.ruoyi.order.service.ShoppingCartService;
import com.ruoyi.order.service.*;
import com.ruoyi.order.util.payment.PaymentUtil;
import com.ruoyi.order.util.payment.model.CloseOrderResult;
import com.ruoyi.order.util.payment.model.UniPayCallbackResult;
import com.ruoyi.order.util.payment.model.UniPayResult;
import com.ruoyi.order.vo.*;
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.api.feignClient.*;
import com.ruoyi.other.api.vo.GetGoodsBargainPrice;
import com.ruoyi.other.api.vo.GetGoodsShopByGoodsIds;
import com.ruoyi.other.api.vo.GetSeckillActivityInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -34,9 +38,11 @@
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
@@ -103,11 +109,22 @@
   @Resource
   private UserChangeLogClient userChangeLogClient;
   @Resource
   private PointSettingClient pointSettingClient;
   @Resource
   private OrderBalancePaymentService orderBalancePaymentService;
   @Resource
   private RedisTemplate redisTemplate;
   /**
    * 获取购物车列表
    * @param type
@@ -165,10 +182,11 @@
            area.setCityCode(appUser.getCityCode());
            area.setProvinceCode(appUser.getProvinceCode());
            area.setVip(appUser.getVipId());
            area.setGoodsId(goodsId);
            GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData();
            if(null == goodsArea){
               //没有地区价格,则使用会员价格
               GoodsVip goodsVip = goodsVipClient.getGoodsVip(appUser.getVipId()).getData();
               GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData();
               if(null == goodsVip){
                  //没有配置价格,直接使用原始基础价格
                  return null;
@@ -181,6 +199,7 @@
                  price.setSuperiorSubcommission(goodsVip.getSuperiorSubcommission());
                  price.setSuperiorRebatePoints(goodsVip.getSuperiorRebatePoints());
                  price.setSuperiorType(goodsVip.getSuperiorType());
                  price.setSuperiorPriceType(goodsVip.getSuperiorPriceType());
                  price.setServuceShopCharges(goodsVip.getServuceShopCharges());
                  price.setServuceShopPoints(goodsVip.getServuceShopPoints());
                  price.setTechnicianPoints(goodsVip.getTechnicianPoints());
@@ -198,6 +217,7 @@
               price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission());
               price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints());
               price.setSuperiorType(goodsArea.getSuperiorType());
               price.setSuperiorPriceType(goodsArea.getSuperiorPriceType());
               price.setServuceShopCharges(goodsArea.getServuceShopCharges());
               price.setServuceShopPoints(goodsArea.getServuceShopPoints());
               price.setTechnicianPoints(goodsArea.getTechnicianPoints());
@@ -222,6 +242,7 @@
            price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission());
            price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints());
            price.setSuperiorType(goodsArea.getSuperiorType());
            price.setSuperiorPriceType(goodsArea.getSuperiorPriceType());
            price.setServuceShopCharges(goodsArea.getServuceShopCharges());
            price.setServuceShopPoints(goodsArea.getServuceShopPoints());
            price.setTechnicianPoints(goodsArea.getTechnicianPoints());
@@ -249,6 +270,7 @@
         price.setSuperiorSubcommission(goodsSeckill.getSuperiorSubcommission());
         price.setSuperiorRebatePoints(goodsSeckill.getSuperiorRebatePoints());
         price.setSuperiorType(goodsSeckill.getSuperiorType());
         price.setSuperiorPriceType(goodsSeckill.getSuperiorPriceType());
         price.setServuceShopCharges(goodsSeckill.getServuceShopCharges());
         price.setServuceShopPoints(goodsSeckill.getServuceShopPoints());
         price.setTechnicianPoints(goodsSeckill.getTechnicianPoints());
@@ -357,7 +379,7 @@
         confirmOrderVo.setDiscountAmount(orderMoney.subtract(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
      }
      BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData();
      confirmOrderVo.setUseSimultaneously(baseSetting.getContent().equals("1"));
      confirmOrderVo.setUseSimultaneously(JSON.parseObject(baseSetting.getContent()).getInteger("status") == 1);
      int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum();
      confirmOrderVo.setEarnPoint(earnPoint);
      //支付金额,订单金额-订单优惠
@@ -365,8 +387,10 @@
      confirmOrderVo.setResidualPoint(appUser.getLavePoint().intValue());
      //获取默认收货地址
      UserAddress userAddress = userAddressClient.getDefaultUserAddress(userid).getData();
      userAddress.setIdStr(userAddress.getId().toString());
      confirmOrderVo.setUserAddress(userAddress);
      if(null != userAddress){
         userAddress.setIdStr(userAddress.getId().toString());
         confirmOrderVo.setUserAddress(userAddress);
      }
      confirmOrderVo.setPaymentType(confirmOrder.getPaymentType());
      //获取用户优惠券,用户全部优惠券,不能使用的需要标识出来置灰展示
      PaymentUserCoupon paymentUserCoupon = new PaymentUserCoupon();
@@ -377,7 +401,7 @@
         List<PaymentUserCouponVo> data = userCouponClient.getPaymentUserCoupon(paymentUserCoupon).getData();
         if(null != data){
            for (PaymentUserCouponVo couponInfo : data) {
               List<Integer> forGoodIds = couponInfo.getForGoodIds();
               List<String> forGoodIds = couponInfo.getForGoodIds();
               //全部商品适用
               if(null == forGoodIds){
                  //满减券
@@ -414,19 +438,19 @@
      //获取快递策略
      SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
      JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
      confirmOrderVo.setExpressFee(jsonObject.getBigDecimal("expressFee"));
      List<Integer> vip = jsonObject.getJSONArray("vip").toList(Integer.class);
      confirmOrderVo.setExpressFee(jsonObject.getBigDecimal("freight"));
      List<String> vip = Arrays.asList(jsonObject.getString("freeVip").split(","));
      //包邮条件(所有会员或者满足条件的会员)
      if(vip.get(0) == -1 || vip.contains(appUser.getVipId())){
      if(vip.get(0).equals("0") || vip.contains(appUser.getVipId().toString())){
         if(confirmOrder.getPaymentType() == 1){
            //现金支付,支付金额满足包邮条件
            BigDecimal cash = jsonObject.getBigDecimal("cash");
            BigDecimal cash = jsonObject.getBigDecimal("freeFreight");
            if(confirmOrderVo.getPayMoney().compareTo(cash) >= 0){
               confirmOrderVo.setExpressFee(BigDecimal.ZERO);
            }
         }else{
            //积分支付,支付积分是否满足包邮条件
            Integer point = jsonObject.getInteger("point");
            Integer point = jsonObject.getInteger("freeIntegral");
            if(confirmOrderVo.getOrderPoint().compareTo(point) >= 0){
               confirmOrderVo.setExpressFee(BigDecimal.ZERO);
            }
@@ -492,18 +516,20 @@
            List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getAppUserId, appUser.getId()).eq(Order::getDelFlag, 0).in(Order::getOrderStatus, Arrays.asList(4, 8)));
            List<Long> orderIds = orders.stream().map(Order::getId).collect(Collectors.toList());
            int sum = 0;
            if(orderIds.size() > 0){
            if(!orderIds.isEmpty()){
               List<OrderGood> orderGoodList = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().in(OrderGood::getOrderId, orderIds)
                     .eq(OrderGood::getGoodsId, shoppingCart.getGoodsId()).eq(OrderGood::getDelFlag, 0));
               sum = orderGoodList.stream().mapToInt(OrderGood::getNum).sum();
            }
            vo.setPurchaseLimit((num + sum) > goods.getPurchaseLimit());
            vo.setPurchaseLimitNum(goods.getPurchaseLimit() - sum);
         }
         vo.setDistributionMode(goods.getDistributionMode());
         vo.setEarnSpendingPoints(price.getEarnSpendingPoints());
         vo.setSuperiorSubcommission(price.getSuperiorSubcommission());
         vo.setSuperiorRebatePoints(price.getSuperiorRebatePoints());
         vo.setSuperiorType(price.getSuperiorType());
         vo.setSuperiorPriceType(price.getSuperiorPriceType());
         vo.setServuceShopCharges(price.getServuceShopCharges());
         vo.setServuceShopPoints(price.getServuceShopPoints());
         vo.setTechnicianPoints(price.getTechnicianPoints());
@@ -584,7 +610,7 @@
         String goodsName = "";
         for (Integer goodsId : goodsIds) {
            Goods goods = goodsClient.getGoodsById(goodsId).getData();
            if(1 == goods.getAppointStore() && !collect.contains(goodsId)){
            if(goods.getType() == 1 && 1 == goods.getAppointStore() && !collect.contains(goodsId)){
               goodsName = goods.getName();
               break;
            }
@@ -605,7 +631,6 @@
            orderMoney = orderMoney.add(myShoppingCartVo.getCash().multiply(new BigDecimal(myShoppingCartVo.getNumber())));
         }
      }else{
         orderPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getPoint).sum();
         for (MyShoppingCartVo myShoppingCartVo : goodsList) {
            orderPoint += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber());
         }
@@ -629,9 +654,10 @@
      if(null != shoppingCartPayment.getUserCouponId() && 3 != shoppingCartPayment.getPaymentType()){
         couponInfoVo = userCouponClient.getCouponInfo(shoppingCartPayment.getUserCouponId()).getData();
         String forGoodIds = couponInfoVo.getForGoodIds();
         List<Integer> parseArray = JSON.parseArray(forGoodIds, Integer.class);
         String[] split = forGoodIds.split(",");
         List<String> parseArray = Arrays.asList(split);
         //全部商品
         if(parseArray.contains(-1)){
         if("-1".equals(forGoodIds)){
            //满减
            if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(paymentMoney) <= 0){
               paymentMoney = paymentMoney.subtract(couponInfoVo.getDiscountAmount());
@@ -658,7 +684,7 @@
            paymentMoney = BigDecimal.ZERO;
            BigDecimal goodsMoney = BigDecimal.ZERO;
            for (MyShoppingCartVo myShoppingCartVo : goodsList) {
               Integer goodsId = myShoppingCartVo.getGoodsId();
               String goodsId = myShoppingCartVo.getGoodsId().toString();
               BigDecimal cash = myShoppingCartVo.getCash();
               if(parseArray.contains(goodsId)){
                  goodsMoney = goodsMoney.add(cash);
@@ -714,9 +740,6 @@
      for (MyShoppingCartVo myShoppingCartVo : goodsList) {
         earnPoint += (myShoppingCartVo.getEarnSpendingPoints() * myShoppingCartVo.getNumber());
      }
      if(null != shoppingCartPayment.getUserAddressId()){
         userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData();
      }
      //获取快递策略,计算快递费
      BigDecimal expressFee = BigDecimal.ZERO;
@@ -724,19 +747,19 @@
         SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
         JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
         //快递费
         expressFee = jsonObject.getBigDecimal("expressFee");
         List<Integer> vip = jsonObject.getJSONArray("vip").toList(Integer.class);
         expressFee = jsonObject.getBigDecimal("freight");
         List<String> vip = Arrays.asList(jsonObject.getString("freeVip").split(","));
         //包邮条件(所有会员或者满足条件的会员)
         if(vip.get(0) == -1 || vip.contains(appUser.getVipId())){
         if(vip.get(0).equals("0") || vip.contains(appUser.getVipId().toString())){
            if(shoppingCartPayment.getPaymentType() != 3){
               //现金支付,支付金额满足包邮条件
               BigDecimal cash = jsonObject.getBigDecimal("cash");
               BigDecimal cash = jsonObject.getBigDecimal("freeFreight");
               if(paymentMoney.compareTo(cash) >= 0){
                  expressFee = BigDecimal.ZERO;
               }
            }else{
               //积分支付,支付积分是否满足包邮条件
               Integer point = jsonObject.getInteger("point");
               Integer point = jsonObject.getInteger("freeIntegral");
               if(orderPoint.compareTo(point) >= 0){
                  expressFee = BigDecimal.ZERO;
               }
@@ -796,6 +819,12 @@
            return R.fail("账户余额不足");
         }
      }
      if(3 == shoppingCartPayment.getPaymentType()){
         Integer availablePoint = appUser.getAvailablePoint();
         if(availablePoint < orderPoint){
            return R.fail("账户积分不足");
         }
      }
      //判断运费支付是否足够
      if(null != shoppingCartPayment.getFreightPaymentType() && 2 == shoppingCartPayment.getFreightPaymentType() && expressFee.compareTo(BigDecimal.ZERO) > 0){
         BigDecimal balance = appUser.getBalance();
@@ -834,6 +863,7 @@
         orderGood.setSuperiorSubcommission(myShoppingCartVo.getSuperiorSubcommission());
         orderGood.setSuperiorRebatePoints(myShoppingCartVo.getSuperiorRebatePoints());
         orderGood.setSuperiorType(myShoppingCartVo.getSuperiorType());
         orderGood.setSuperiorPriceType(myShoppingCartVo.getSuperiorPriceType());
         orderGood.setServuceShopCharges(myShoppingCartVo.getServuceShopCharges());
         orderGood.setServuceShopPoints(myShoppingCartVo.getServuceShopPoints());
         orderGood.setTechnicianPoints(myShoppingCartVo.getTechnicianPoints());
@@ -848,23 +878,36 @@
      //现金支付
      paymentMoney = paymentMoney.add(expressFee).setScale(2, RoundingMode.HALF_EVEN);
      if(1 == shoppingCartPayment.getPaymentType()){
         //调起微信支付 TODO 待完善
         //调起微信支付
         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(), "");
         if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){
            return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg());
         }
         String rc_result = uniPayResult.getRc_Result();
         //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。
         long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC);
         redisTemplate.opsForZSet().add("OrderPayment", order.getOrderNumber(), second);
         return R.ok(rc_result);
      }
      //账户余额
      BigDecimal redPacketAmount = BigDecimal.ZERO;
      BigDecimal distributionAmount = BigDecimal.ZERO;
      if(2 == shoppingCartPayment.getPaymentType()){
         BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount();
         BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount();
         BigDecimal balance = appUser.getBalance();
         //红包金额满足支付
         if(paymentMoney.compareTo(totalRedPacketAmount) <= 0){
            totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney);
            balance = balance.subtract(paymentMoney);
            appUser.setTotalRedPacketAmount(totalRedPacketAmount);
            appUser.setBalance(balance);
            redPacketAmount = paymentMoney;
         }else{
            paymentMoney = paymentMoney.subtract(totalRedPacketAmount);
            redPacketAmount = totalRedPacketAmount;
            totalRedPacketAmount = BigDecimal.ZERO;
            if(paymentMoney.compareTo(totalDistributionAmount) <= 0){
               totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney);
@@ -872,6 +915,7 @@
               appUser.setTotalRedPacketAmount(totalRedPacketAmount);
               appUser.setTotalDistributionAmount(totalDistributionAmount);
               appUser.setBalance(balance);
               distributionAmount = paymentMoney;
            }else{
               paymentMoney = paymentMoney.subtract(totalDistributionAmount);
               totalDistributionAmount = BigDecimal.ZERO;
@@ -879,13 +923,23 @@
               appUser.setTotalRedPacketAmount(totalRedPacketAmount);
               appUser.setTotalDistributionAmount(totalDistributionAmount);
               appUser.setBalance(balance);
               distributionAmount = totalDistributionAmount;
            }
         }
         //构建积分流水记录
         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);
            if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){
               appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1);
            }
            UserPoint userPoint = new UserPoint();
            userPoint.setType(1);
@@ -900,6 +954,8 @@
         appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
         appUser.setLastShopTime(LocalDateTime.now());
         appUserClient.editAppUserById(appUser);
         //变更等级
         appUserClient.vipUpgrade(appUser.getId());
         //构建余额明细变动记录
         BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
         balanceChangeRecord.setAppUserId(appUser.getId());
@@ -919,48 +975,62 @@
         orderService.updateById(order);
         //删除购物车数据
         this.removeBatchByIds(ids);
         //检查消费积分满足后升级会员
         vipUpgrade(appUser);
      }
      //积分支付
      if(3 == shoppingCartPayment.getPaymentType()){
         //先完成快递费支付后再处理后续的逻辑
         if(expressFee.compareTo(BigDecimal.ZERO) > 0){
            if(shoppingCartPayment.getFreightPaymentType() == 1){
               //调起微信支付
               UniPayResult uniPayResult = PaymentUtil.uniPay(order.getOrderNumber() + appUser.getId(), expressFee.doubleValue(), order.getOrderType() == 1 ? "购买服务商品快递费" : "购买单品商品快递费",
                     "快递费", "", "/order/shopping-cart/shoppingCartMaterialFlowPaymentCallback", appUser.getWxOpenid(), "");
               if(null == uniPayResult || !"100".equals(uniPayResult.getRa_Code())){
                  return R.fail(null == uniPayResult ? "支付失败" : uniPayResult.getRb_CodeMsg());
               }
               String rc_result = uniPayResult.getRc_Result();
               //将支付数据添加到redis队列中,便于定时任务去校验是否完成支付,没有完成支付支付,15分钟后关闭订单。
               long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC);
               redisTemplate.opsForZSet().add("MaterialFlowPayment", order.getOrderNumber() + appUser.getId(), second);
               return R.ok(rc_result);
            }
         }
         Integer lavePoint = appUser.getLavePoint();
         appUser.setLavePoint(lavePoint - orderPoint);
         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);
         appUser.setShopPoint(appUser.getShopPoint() + earnPoint);
         appUser.setLavePoint(appUser.getLavePoint() + earnPoint);
         appUser.setAvailablePoint(appUser.getAvailablePoint() + earnPoint1);
         if(null != pointSetting && 1 == pointSetting.getBuyPointGift()){
            appUser.setTransferablePoint(appUser.getTransferablePoint() + earnPoint1);
         }
         appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint);
         appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN));
         appUser.setLastShopTime(LocalDateTime.now());
         appUserClient.editAppUserById(appUser);
         //检查消费积分满足后升级会员
         vipUpgrade(appUser);
         //变更等级
         appUserClient.vipUpgrade(appUser.getId());
         //构建积分流水记录
         UserPoint userPoint = new UserPoint();
         userPoint.setType(4);
         userPoint.setType(1);
         userPoint.setHistoricalPoint(lavePoint);
         userPoint.setVariablePoint(orderPoint);
         Integer point = appUser.getLavePoint() - lavePoint;
         userPoint.setVariablePoint(point >= 0 ? point : point * -1);
         userPoint.setBalance(appUser.getLavePoint());
         userPoint.setCreateTime(LocalDateTime.now());
         userPoint.setAppUserId(appUser.getId());
         userPoint.setObjectId(order.getId());
         userPointClient.saveUserPoint(userPoint);
         if(earnPoint > 0){
            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);
         }
         //如果有运费,需要先扣除账户积分,再进行支付。支付成功后修改订单状态,未支付成功则回退积分,删除的订单
         if(expressFee.compareTo(BigDecimal.ZERO) > 0){
            if(shoppingCartPayment.getFreightPaymentType() == 1){
               //调起微信支付
            }
            if(shoppingCartPayment.getFreightPaymentType() == 2){
               BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount();
               BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount();
@@ -970,8 +1040,10 @@
                  balance = balance.subtract(expressFee);
                  appUser.setTotalRedPacketAmount(totalRedPacketAmount);
                  appUser.setBalance(balance);
                  redPacketAmount = expressFee;
               }else{
                  expressFee = expressFee.subtract(totalRedPacketAmount);
                  redPacketAmount = totalRedPacketAmount;
                  totalRedPacketAmount = BigDecimal.ZERO;
                  if(expressFee.compareTo(totalDistributionAmount) <= 0){
                     totalDistributionAmount = totalDistributionAmount.subtract(expressFee);
@@ -979,6 +1051,7 @@
                     appUser.setTotalRedPacketAmount(totalRedPacketAmount);
                     appUser.setTotalDistributionAmount(totalDistributionAmount);
                     appUser.setBalance(balance);
                     distributionAmount = expressFee;
                  }else{
                     expressFee = expressFee.subtract(totalDistributionAmount);
                     totalDistributionAmount = BigDecimal.ZERO;
@@ -986,6 +1059,7 @@
                     appUser.setTotalRedPacketAmount(totalRedPacketAmount);
                     appUser.setTotalDistributionAmount(totalDistributionAmount);
                     appUser.setBalance(balance);
                     distributionAmount = totalDistributionAmount;
                  }
               }
@@ -1021,10 +1095,18 @@
            this.removeBatchByIds(ids);
         }
      }
      //添加账户余额支付明细
      if(redPacketAmount.compareTo(BigDecimal.ZERO) > 0 || distributionAmount.compareTo(BigDecimal.ZERO) > 0){
         OrderBalancePayment orderBalancePayment = new OrderBalancePayment();
         orderBalancePayment.setOrderId(order.getId());
         orderBalancePayment.setRedPacketAmount(redPacketAmount);
         orderBalancePayment.setDistributionAmount(distributionAmount);
         orderBalancePaymentService.save(orderBalancePayment);
      }
      return R.ok(order.getId().toString());
   }
   public String getNumber(Integer size){
      String str = "";
      for (Integer i = 0; i < size; i++) {
@@ -1032,49 +1114,165 @@
      }
      return str;
   }
   /**
    * 会员等级变化
    * @param appUser
    * 线上支付回调逻辑处理
    * @param uniPayCallbackResult
    * @return
    */
   public void vipUpgrade(AppUser appUser){
      Integer shopPoint = appUser.getShopPoint();
      Integer vipId = appUser.getVipId();
      //钻石会员
      VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData();
      Integer vipLevelUpShopRole = vipSetting3.getVipLevelUpShopRole();
      Integer vipLevelUpShop = vipSetting3.getVipLevelUpShop();
      if(null != vipLevelUpShopRole && 1 == vipLevelUpShopRole && appUser.getVipId() < 3 && shopPoint >= vipLevelUpShop){
         appUser.setVipId(3);
         appUserClient.editAppUserById(appUser);
         //添加等级变化记录
         UserChangeLog userChangeLog = new UserChangeLog();
         userChangeLog.setDelFlag(0);
         userChangeLog.setCreateTime(LocalDateTime.now());
         userChangeLog.setAppUserId(appUser.getId());
         userChangeLog.setBeforeVipId(vipId);
         userChangeLog.setAfterVipId(appUser.getVipId());
         userChangeLog.setChangeType(1);
         userChangeLogClient.saveUserChangeLog(userChangeLog);
         return;
   @Override
   public R shoppingCartPaymentCallback(UniPayCallbackResult uniPayCallbackResult) {
      Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, uniPayCallbackResult.getR2_OrderNo()));
      if(null == order || order.getPayStatus() == 2){
         return R.ok();
      }
      //黄金会员
      VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData();
      vipLevelUpShopRole = vipSetting2.getVipLevelUpShopRole();
      vipLevelUpShop = vipSetting2.getVipLevelUpShop();
      if(null != vipLevelUpShopRole && 1 == vipLevelUpShopRole && appUser.getVipId() < 2 && shopPoint >= vipLevelUpShop){
         appUser.setVipId(2);
         appUserClient.editAppUserById(appUser);
         //添加等级变化记录
         UserChangeLog userChangeLog = new UserChangeLog();
         userChangeLog.setDelFlag(0);
         userChangeLog.setCreateTime(LocalDateTime.now());
         userChangeLog.setAppUserId(appUser.getId());
         userChangeLog.setBeforeVipId(vipId);
         userChangeLog.setAfterVipId(appUser.getVipId());
         userChangeLog.setChangeType(1);
         userChangeLogClient.saveUserChangeLog(userChangeLog);
      Integer earnPoint = order.getGetPoint();
      AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
      BigDecimal paymentMoney = order.getPaymentAmount();
      //构建积分流水记录
      if(earnPoint > 0){
         PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
         int earnPoint1 = earnPoint;
         if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){
            earnPoint1 = new BigDecimal(earnPoint1).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);
         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);
      }
      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);
      //删除购物车数据
      Long userid = tokenService.getLoginUserApplet().getUserid();
      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));
      return R.ok();
   }
   /**
    * 订单物流支付回调处理逻辑
    * @param uniPayCallbackResult
    * @return
    */
   @Override
   public R shoppingCartMaterialFlowPaymentCallback(UniPayCallbackResult uniPayCallbackResult) {
      String r2_orderNo = uniPayCallbackResult.getR2_OrderNo();
      r2_orderNo = r2_orderNo.substring(0, 23);
      Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, r2_orderNo));
      if(null == order || order.getPayStatus() == 2){
         return R.ok();
      }
      Integer earnPoint = order.getGetPoint();
      AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
      Integer lavePoint = appUser.getLavePoint();
      Integer orderPoint = order.getPoint();
      PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
      int earnPoint1 = earnPoint;
      //计算可用积分比例
      if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){
         earnPoint1 = new BigDecimal(earnPoint1).multiply(pointSetting.getBuyPoint().divide(new BigDecimal(100))).intValue();
      }
      //扣减订单支付积分
      appUser.setLavePoint(appUser.getLavePoint() - orderPoint);
      appUser.setAvailablePoint(appUser.getAvailablePoint() - orderPoint);
      appUser.setShopPoint(appUser.getShopPoint() + earnPoint);
      appUser.setLavePoint(appUser.getLavePoint() + earnPoint);
      appUser.setAvailablePoint(appUser.getAvailablePoint() + 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.setHistoricalPoint(lavePoint);
      Integer point = appUser.getLavePoint() - lavePoint;
      userPoint.setVariablePoint(point >= 0 ? point : point * -1);
      userPoint.setBalance(appUser.getLavePoint());
      userPoint.setCreateTime(LocalDateTime.now());
      userPoint.setAppUserId(appUser.getId());
      userPoint.setObjectId(order.getId());
      userPointClient.saveUserPoint(userPoint);
      //修改订支付状态
      order.setPayStatus(2);
      //自提
      if(order.getOrderType() == 1 && StringUtils.isEmpty(order.getAddressJson())){
         order.setOrderStatus(2);
      }
      orderService.updateById(order);
      //删除购物车数据
      Long userid = tokenService.getLoginUserApplet().getUserid();
      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));
      return R.ok();
   }
   /**
    * 定时任务关闭订单
    */
   @Override
   public void closeOrder() {
      //订单支付数据
      long second = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
      Set<String> orderPayment = redisTemplate.opsForZSet().range("OrderPayment", 0, second);
      for (String code : orderPayment) {
         Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code));
         if(null == order || order.getPayStatus() != 1){
            continue;
         }
         //开始执行关闭订单操作
         CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(code);
         if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) &&
               Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){
            redisTemplate.opsForZSet().add("OrderPayment", code, 0);
            log.error("关闭订单失败:{}---->{}", code, JSON.toJSONString(closeOrderResult));
         }
      }
      //快递支付
      Set<String> materialFlowPayment = redisTemplate.opsForZSet().range("MaterialFlowPayment", 0, second);
      for (String code : materialFlowPayment) {
         code = code.substring(0, 23);
         Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code));
         if(null == order || order.getPayStatus() != 1){
            continue;
         }
         //开始执行关闭订单操作
         CloseOrderResult closeOrderResult = PaymentUtil.closeOrder(code);
         if((null == closeOrderResult || !closeOrderResult.getRa_Status().equals("100")) &&
               Arrays.asList("0", "4", "101", "10080000", "10080002", "10083004", "10083005").contains(closeOrderResult.getRb_Code())){
            redisTemplate.opsForZSet().add("MaterialFlowPayment", code, 0);
            log.error("关闭订单失败:{}---->{}", code, JSON.toJSONString(closeOrderResult));
         }
      }
   }
}