luodangjia
2024-09-12 c5462d60b99823adb10d9e9eda671920118538f7
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TGoodsController.java
@@ -185,6 +185,7 @@
        //检查当前用户积分是否够
        Long userId = tokenService.getLoginUserApplet().getUserId();
        Integer point = 0;
        TAppUser user = appUserClient.getUserById(userId).getData();
        if (exchangeDto.getGoodType()==1) {
            //查询当前商品信息
@@ -195,7 +196,6 @@
            if (good.getLimitExchangeTimes() != -1 && count >= good.getLimitExchangeTimes()) {
                return AjaxResult.error("当前用户已兑换"+count+"张");
            }
        TAppUser user = appUserClient.getUserById(userId).getData();
        if (user.getPoints()<good.getRedeemPoints()){
            return AjaxResult.error("当前用户积分不足");
             }
@@ -206,6 +206,9 @@
            Long count = orderClient.getExchangeById(exchangeDto.getGoodId(), userId,exchangeDto.getGoodType()).getData();
            if (coupon.getInventoryQuantity() != -1 && count >= coupon.getInventoryQuantity()) {
                return AjaxResult.error("当前用户已到达兑换"+coupon+"次");
            }
            if (user.getPoints()<point){
                return AjaxResult.error("当前用户积分不足");
            }
        }
        exchangeDto.setPoint(point);
@@ -239,7 +242,7 @@
        Long userId = tokenService.getLoginUserApplet().getUserId();
        TAppUser user = appUserClient.getUserById(userId).getData();
        boolean isVip = false;
        if (user.getVipEndTime().isAfter(LocalDateTime.now())){
        if (user.getVipEndTime()!=null&&user.getVipEndTime().isAfter(LocalDateTime.now())){
            isVip = true;
        }
        //计算价格
@@ -256,7 +259,7 @@
                    originalPrice = good.getVipPrice();
                }
            }
            orderPrice.add(originalPrice.multiply(BigDecimal.valueOf(exchangeDto.getNum())));
            orderPrice =  orderPrice.add(originalPrice.multiply(BigDecimal.valueOf(exchangeDto.getNum())));
        }else {
            TCoupon coupon = couponService.getById(exchangeDto.getGoodId());
            BigDecimal originalPrice = coupon.getPaymentAmount();
@@ -266,7 +269,7 @@
                    originalPrice = coupon.getVipPaymentAmount();
                }
            }
            orderPrice.add(originalPrice);
            orderPrice  = orderPrice.add(originalPrice);
        }
        exchangeDto.setOrderPrice(orderPrice);
@@ -283,19 +286,21 @@
            payPrice = orderPrice.subtract(coupon.getDiscountAmount());
            discountPrice = coupon.getDiscountAmount();
        }
        exchangeDto.setPayPrice(payPrice);
        exchangeDto.setPayPrice(orderPrice);
        exchangeDto.setDiscountPrice(discountPrice);
        exchangeDto.setVipDiscount(vipDiscount);
        exchangeDto.setUserId(userId);
        //创建订单
        TShoppingOrder shopOrder = orderClient.shopCreate(exchangeDto).getData();
        if (exchangeDto.getPayMethod()==1) {
            //调起支付
            PaymentOrder paymentOrder = new PaymentOrder();
            paymentOrder.setCode(shopOrder.getCode());
            paymentOrder.setAmount(shopOrder.getPaymentAmount());
            paymentOrder.setAmount(exchangeDto.getOrderPrice());
            paymentOrder.setOpenId(user.getWxOpenid());
            paymentOrder.setDescription("购买商品");
         return    wxPaymentClient.orderPay(paymentOrder);
            R<Map<String, Object>> mapR = wxPaymentClient.orderPay(paymentOrder);
            return    mapR;
        }else {
            //todo 罗 支付宝支付
            return R.ok();