jiangqs
2023-07-06 1f9b64476716a6a1de3bcb886bf4e64b123f7523
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -83,6 +83,8 @@
    @Resource
    private RemoteCouponService remoteCouponService;
    @Resource
    private RemoteActivityService remoteActivityService;
    /**
     * @description: buyGoods
@@ -135,7 +137,6 @@
            //商品图片
            goodsFile = remoteGoodsService.getGoodsFile(goodsId).getData();
            appSureOrderGoodsVo.setGoodsPicture(goodsFile.getFileUrl());
            buyNum = appBuyGoodsDto.getBuyNum();
            appSureOrderGoodsVo.setBuyNum(buyNum);
            goodsPrice = goods.getSalesPrice();
            //商户定制价格
@@ -209,6 +210,84 @@
    }
    /**
     * @description  抢购商品
     * @author  jqs
     * @date    2023/7/6 11:45
     * @param appPanicBuyDto
     * @return  AppSureOrderVo
     */
    @Override
    public AppPanicBuyVo panicBuyGoods(AppPanicBuyDto appPanicBuyDto){
        Long userId = appPanicBuyDto.getUserId();
        AppPanicBuyVo appPanicBuyVo = new AppPanicBuyVo();
        String activityId = appPanicBuyDto.getActivityId();
        String goodsId = appPanicBuyDto.getGoodsId();
        Integer buyNum = appPanicBuyDto.getBuyNum();
        BigDecimal buyNumBig;
        BigDecimal goodsPrice;
        BigDecimal goodsTotalPrice;
        BigDecimal goodsRealPrice;
        BigDecimal goodsDeposit;
        BigDecimal goodsActivityPrice;
        GoodsFile goodsFile;
        BigDecimal orderGoodsMoney = new BigDecimal("0.00");
        BigDecimal orderPayDeposit = new BigDecimal("0.00");
        BigDecimal orderPayMoney = new BigDecimal("0.00");
        ActivityGoodsGetDto activityGoodsGetDto = new ActivityGoodsGetDto();
        activityGoodsGetDto.setActivityId(activityId);
        activityGoodsGetDto.setGoodsId(goodsId);
        activityGoodsGetDto.setUserId(userId);
        ActivityGoodsGetVo activityGoodsGetVo = remoteActivityService.getUserActivityGoods(activityGoodsGetDto).getData();
        if(activityGoodsGetVo.getActivityStatus()==0){
            throw new ServiceException(AppErrorConstant.ACTIVITY_NO_START);
        }
        if(activityGoodsGetVo.getActivityStatus()==2){
            throw new ServiceException(AppErrorConstant.ACTIVITY_END);
        }
        if(activityGoodsGetVo.getAvailableBuyNum()<1){
            throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_NULL);
        }
        Goods goods = remoteGoodsService.getGoods(goodsId).getData();
        appPanicBuyVo.setGoodsId(goodsId);
        appPanicBuyVo.setGoodsName(goods.getGoodsName());
        appPanicBuyVo.setGoodsIntroduction(goods.getGoodsIntroduction());
        appPanicBuyVo.setGoodsType(goods.getGoodsType());
        //商品图片
        goodsFile = remoteGoodsService.getGoodsFile(goodsId).getData();
        appPanicBuyVo.setGoodsPicture(goodsFile.getFileUrl());
        appPanicBuyVo.setBuyNum(buyNum);
        goodsPrice = goods.getSalesPrice();
        //商户定制价格
        AppShopGoodsGetDto appShopGoodsGetDto = new AppShopGoodsGetDto();
        appShopGoodsGetDto.setGoodsId(goods.getGoodsId());
        appShopGoodsGetDto.setShopId(appPanicBuyDto.getShopId());
        ShopGoods shopGoods = remoteGoodsService.getShopGoods(appShopGoodsGetDto).getData();
        if (shopGoods != null) {
            goodsPrice = shopGoods.getSalesPrice();
        }
        appPanicBuyVo.setGoodsPrice(goodsPrice);
        buyNumBig = BigDecimal.valueOf(buyNum);
        goodsActivityPrice = activityGoodsGetVo.getActivityPrice();
        goodsTotalPrice = goodsActivityPrice.multiply(buyNumBig);
        goodsRealPrice = goodsTotalPrice;
        appPanicBuyVo.setActivityPrice(goodsActivityPrice);
        appPanicBuyVo.setGoodsTotalPrice(goodsTotalPrice);
        appPanicBuyVo.setGoodsRealPrice(goodsRealPrice);
        goodsDeposit = activityGoodsGetVo.getActivitySubscription();
        if (goodsDeposit == null) {
            goodsDeposit = new BigDecimal("0.00");
        }
        appPanicBuyVo.setGoodsDeposit(goodsDeposit);
        orderGoodsMoney = orderGoodsMoney.add(goodsTotalPrice);
        orderPayDeposit = orderPayDeposit.add(goodsDeposit);
        orderPayMoney = orderPayMoney.add(goodsRealPrice);
        appPanicBuyVo.setOrderGoodsMoney(orderGoodsMoney);
        appPanicBuyVo.setOrderPayDeposit(orderPayDeposit);
        appPanicBuyVo.setOrderPayMoney(orderPayMoney);
        return appPanicBuyVo;
    }
    /**
     * 创建订单
     *
     * @param appPlaceOrderDto
@@ -228,6 +307,7 @@
        Integer goodsNum = 0;
        String memberCouponId;
        Goods goods;
        GoodsFile goodsFile;
        BigDecimal goodsPrice;
        BigDecimal goodsTotalPrice;
        BigDecimal goodsRealPrice;
@@ -239,7 +319,6 @@
        BigDecimal discountMoney = new BigDecimal("0.00");
        BigDecimal discountPercent;
        BigDecimal goodsDeposit;
        GoodsFile goodsFile;
        Integer useCoupon;
        BigDecimal orderGoodsMoney = new BigDecimal("0.00");
        BigDecimal couponDiscount = new BigDecimal("0.00");
@@ -334,6 +413,8 @@
            orderGoods.setCycleNumFlag(goods.getCycleNumFlag());
            orderGoods.setServiceNum(serviceNum);
            orderGoods.setGoodsType(goods.getGoodsType());
            orderGoods.setGoodsName(goods.getGoodsName());
            orderGoods.setGoodsPicture(goodsFile.getFileUrl());
            orderGoodsService.save(orderGoods);
            //清空购物车
            AppShoppingCartDelDto appShoppingCartDelDto = new AppShoppingCartDelDto();
@@ -398,6 +479,174 @@
        return appPlaceOrderVo;
    }
    /**
     * @description  创建活动订单
     * @author  jqs
     * @date    2023/7/6 17:59
     * @param appPlaceActivityDto
     * @return  AppPlaceOrderVo
     */
    @Override
    public AppPlaceOrderVo placeActivityOrder( AppPlaceActivityDto appPlaceActivityDto){
        Long userId = appPlaceActivityDto.getUserId();
        AppPlaceOrderVo appPlaceOrderVo = new AppPlaceOrderVo();
        AppSureOrderGoodsVo appSureOrderGoodsVo;
        String activityId = appPlaceActivityDto.getActivityId();
        String goodsId = appPlaceActivityDto.getGoodsId();
        Integer buyNum = appPlaceActivityDto.getBuyNum();
        BigDecimal buyNumBig;
        Integer serviceNum;
        Integer goodsNum = 0;
        Goods goods;
        GoodsFile goodsFile;
        BigDecimal goodsPrice;
        BigDecimal goodsTotalPrice;
        BigDecimal goodsRealPrice;
        BigDecimal discountMoney = new BigDecimal("0.00");
        BigDecimal discountPercent;
        BigDecimal goodsDeposit;
        Integer useCoupon;
        BigDecimal orderGoodsMoney = new BigDecimal("0.00");
        BigDecimal couponDiscount = new BigDecimal("0.00");
        BigDecimal orderPayDeposit = new BigDecimal("0.00");
        BigDecimal orderPayMoney = new BigDecimal("0.00");
        ActivityGoodsGetDto activityGoodsGetDto = new ActivityGoodsGetDto();
        activityGoodsGetDto.setActivityId(activityId);
        activityGoodsGetDto.setGoodsId(goodsId);
        activityGoodsGetDto.setUserId(userId);
        ActivityGoodsGetVo activityGoodsGetVo = remoteActivityService.getUserActivityGoods(activityGoodsGetDto).getData();
        if(activityGoodsGetVo.getActivityStatus()==0){
            throw new ServiceException(AppErrorConstant.ACTIVITY_NO_START);
        }
        if(activityGoodsGetVo.getActivityStatus()==2){
            throw new ServiceException(AppErrorConstant.ACTIVITY_END);
        }
        if(activityGoodsGetVo.getAvailableBuyNum()<1){
            throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_NULL);
        }
        String orderId = IdUtils.simpleUUID();
        String orderNo = CodeFactoryUtil.getShopOrderNo();
        OrderGoods orderGoods;
        String orderGoodsId;
        HashSet<String> goodsTypeSet = new HashSet<>();
        appSureOrderGoodsVo = new AppSureOrderGoodsVo();
        useCoupon = 0;
        goodsId = appPlaceActivityDto.getGoodsId();
        goods = remoteGoodsService.getGoods(goodsId).getData();
        appSureOrderGoodsVo.setGoodsId(goodsId);
        appSureOrderGoodsVo.setGoodsName(goods.getGoodsName());
        appSureOrderGoodsVo.setGoodsIntroduction(goods.getGoodsIntroduction());
        appSureOrderGoodsVo.setGoodsType(goods.getGoodsType());
        //商品图片
        goodsFile = remoteGoodsService.getGoodsFile(goodsId).getData();
        appSureOrderGoodsVo.setGoodsPicture(goodsFile.getFileUrl());
        buyNum = appPlaceActivityDto.getBuyNum();
        appSureOrderGoodsVo.setBuyNum(buyNum);
        goodsPrice = goods.getSalesPrice();
        serviceNum = goods.getServiceNum();
        //活动价格
        goodsPrice = activityGoodsGetVo.getActivityPrice();
        appSureOrderGoodsVo.setGoodsPrice(goodsPrice);
        buyNumBig = BigDecimal.valueOf(buyNum);
        goodsTotalPrice = goodsPrice.multiply(buyNumBig);
        goodsRealPrice = goodsTotalPrice;
        appSureOrderGoodsVo.setUseCoupon(useCoupon);
        appSureOrderGoodsVo.setGoodsTotalPrice(goodsTotalPrice);
        appSureOrderGoodsVo.setCouponDiscount(discountMoney);
        appSureOrderGoodsVo.setGoodsRealPrice(goodsRealPrice);
        goodsDeposit = goods.getSubscription();
        if (goodsDeposit == null) {
            goodsDeposit = new BigDecimal("0.00");
        }
        appSureOrderGoodsVo.setGoodsDeposit(goodsDeposit);
        goodsNum = goodsNum + buyNum;
        orderGoodsMoney = orderGoodsMoney.add(goodsTotalPrice);
        couponDiscount = couponDiscount.add(discountMoney);
        orderPayDeposit = orderPayDeposit.add(goodsDeposit);
        orderPayMoney = orderPayMoney.add(goodsRealPrice);
        //创建OrderGoods
        orderGoods = new OrderGoods();
        orderGoodsId = IdUtils.simpleUUID();
        orderGoods.setOrderGoodsId(orderGoodsId);
        orderGoods.setDelFlag(0);
        orderGoods.setOrderId(orderId);
        orderGoods.setGoodsId(goodsId);
        orderGoods.setBuyNum(buyNum);
        orderGoods.setGoodsPrice(goodsPrice);
        orderGoods.setGoodsTotalMoney(orderGoodsMoney);
        orderGoods.setGoodsReceivableMoney(goodsRealPrice);
        orderGoods.setCycleNumFlag(goods.getCycleNumFlag());
        orderGoods.setServiceNum(serviceNum);
        orderGoods.setGoodsType(goods.getGoodsType());
        orderGoods.setGoodsName(goods.getGoodsName());
        orderGoods.setGoodsPicture(goodsFile.getFileUrl());
        orderGoodsService.save(orderGoods);
        //清空购物车
        AppShoppingCartDelDto appShoppingCartDelDto = new AppShoppingCartDelDto();
        appShoppingCartDelDto.setGoodsId(goodsId);
        appShoppingCartDelDto.setUserId(userId);
        remoteShoppingCartService.deleteShoppingCart(appShoppingCartDelDto);
        if (goods.getGoodsType() == 1) {
            goodsTypeSet.add("周期");
        } else if (goods.getGoodsType() == 2) {
            goodsTypeSet.add("服务");
        } else if (goods.getGoodsType() == 3) {
            goodsTypeSet.add("体验");
        } else if (goods.getGoodsType() == 4) {
            goodsTypeSet.add("单品");
        }
        Order order = new Order();
        order.setOrderId(orderId);
        order.setDelFlag(0);
        //为对接支付 直接付款成功
        order.setOrderStatus(1);
        order.setOrderNo(orderNo);
        order.setOrderFrom(1);
        order.setShopId(appPlaceActivityDto.getShopId());
        order.setUserId(userId);
        order.setOrderMoney(orderGoodsMoney);
        order.setCouponMoney(couponDiscount);
        order.setDiscountMoney(couponDiscount);
        order.setReceivableMoney(orderPayMoney);
        order.setReceivableDeposit(orderPayDeposit);
        order.setChangeReceivableMoney(orderPayMoney);
        order.setPayType(appPlaceActivityDto.getPayType());
        if (order.getPayType() == 1) {
            order.setPayMoney(orderPayMoney);
            order.setOnlinePayMoney(orderPayMoney);
            appPlaceOrderVo.setPayMoney(orderPayMoney);
            appPlaceOrderVo.setUnpaidMoney(order.getReceivableMoney().subtract(order.getPayMoney()));
            order.setCloseFlag(1);
        } else if (order.getPayType() == 2) {
            order.setPayMoney(orderPayDeposit);
            order.setOnlinePayMoney(orderPayDeposit);
            appPlaceOrderVo.setPayMoney(orderPayDeposit);
            appPlaceOrderVo.setUnpaidMoney(order.getReceivableMoney().subtract(order.getPayMoney()));
            order.setCloseFlag(0);
        }
        order.setOrderRemark(appPlaceActivityDto.getOrderRemark());
        order.setGoodsNum(goodsNum);
        order.setCreateTime(new Date());
        this.save(order);
        //更新用户商品类型
        if (goodsTypeSet != null && goodsTypeSet.size() > 0) {
            AppMemberGoodsTypeDto appMemberGoodsTypeDto = new AppMemberGoodsTypeDto();
            appMemberGoodsTypeDto.setUserId(userId);
            appMemberGoodsTypeDto.setGoodsTypeSet(goodsTypeSet);
            remoteMemberService.updateMemberGoodsType(appMemberGoodsTypeDto);
        }
        appPlaceOrderVo.setOrderId(orderId);
        appPlaceOrderVo.setOrderNo(orderNo);
        //调用支付
        return appPlaceOrderVo;
    }
    /**
     * 分页获取用户订单
@@ -878,6 +1127,7 @@
        String orderNo = CodeFactoryUtil.getShopOrderNo();
        OrderGoods orderGoods;
        String orderGoodsId;
        GoodsFile goodsFile;
        BigDecimal cycleMoney = new BigDecimal("0.00");
        BigDecimal experienceMoney = new BigDecimal("0.00");
        BigDecimal serviceMoney = new BigDecimal("0.00");
@@ -886,6 +1136,7 @@
            goodsId = appBuyGoodsDto.getGoodsId();
            memberCouponId = appBuyGoodsDto.getMemberCouponId();
            goods = remoteGoodsService.getGoods(goodsId).getData();
            goodsFile = remoteGoodsService.getGoodsFile(goodsId).getData();
            buyNum = appBuyGoodsDto.getBuyNum();
            goodsPrice = goods.getSalesPrice();
            serviceNum = goods.getServiceNum();
@@ -949,6 +1200,8 @@
            orderGoods.setCycleNumFlag(goods.getCycleNumFlag());
            orderGoods.setServiceNum(serviceNum);
            orderGoods.setGoodsType(goods.getGoodsType());
            orderGoods.setGoodsName(goods.getGoodsName());
            orderGoods.setGoodsPicture(goodsFile.getFileUrl());
            orderGoodsService.save(orderGoods);
            switch(orderGoods.getGoodsType()){
                case 1:
@@ -2306,10 +2559,17 @@
                        .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity()));
            }
            // 遍历列表,设置店铺名称、用户名称和未支付金额
            String userInfo;
            String mobile;
            for (MgtShopAllOrderPageVo mgtShopOrderPageVo : shopAllOrderPageVoList) {
                if (userMap != null && !userMap.isEmpty()) {
                    if (userMap.get(mgtShopOrderPageVo.getUserId()) != null) {
                        mgtShopOrderPageVo.setUserInfo(userMap.get(mgtShopOrderPageVo.getUserId()).getNickName()+"("+userMap.get(mgtShopOrderPageVo.getUserId()).getUserMobile()+")");
                        userInfo = userMap.get(mgtShopOrderPageVo.getUserId()).getNickName();
                        mobile = userMap.get(mgtShopOrderPageVo.getUserId()).getUserMobile();
                        if(StringUtils.isNotBlank(mobile)){
                            userInfo = userInfo + "(" + mobile + ")";
                        }
                        mgtShopOrderPageVo.setUserInfo(userInfo);
                    }
                }
            }