bug
jiangqs
2023-08-02 bb58e108a9da48d84b84d30b73c01106dd642550
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -243,7 +243,7 @@
                    } else if (couponType == 2 && appMemberCouponVo.getDiscountPercent() != null) {
                        discountPercent = appMemberCouponVo.getDiscountPercent();
                        goodsRealPrice = goodsTotalPrice.multiply(discountPercent).divide(BigDecimal.TEN,2,BigDecimal.ROUND_HALF_UP);
                        discountMoney = goodsRealPrice.subtract(goodsTotalPrice);
                        discountMoney = goodsTotalPrice.subtract(goodsRealPrice);
                        useCoupon = 1;
                        userCouponIdSet.add(memberCouponId);
                        appSureOrderGoodsVo.setMemberCouponId(memberCouponId);
@@ -415,8 +415,12 @@
        if (activityGoodsGetVo.getActivityStatus() == 2) {
            throw new ServiceException(AppErrorConstant.ACTIVITY_END);
        }
        if (activityGoodsGetVo.getAvailableBuyNum() < 1) {
        Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS+"-"+activityId+"-"+goodsId);
        if(surpNum==null||surpNum<1){
            throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_NULL);
        }
        if (activityGoodsGetVo.getAvailableBuyNum() < 1) {
            throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_BEYOND);
        }
        if (activityGoodsGetVo.getAvailableBuyNum() < buyNum) {
            throw new ServiceException(AppErrorConstant.ACTIVITY_GOODS_BEYOND);
@@ -593,7 +597,7 @@
                    } else if (couponType == 2 && appMemberCouponVo.getDiscountPercent() != null) {
                        discountPercent = appMemberCouponVo.getDiscountPercent();
                        goodsRealPrice = goodsTotalPrice.multiply(discountPercent).divide(BigDecimal.TEN,2, BigDecimal.ROUND_HALF_UP);
                        discountMoney = goodsRealPrice.subtract(goodsTotalPrice);
                        discountMoney = goodsTotalPrice.subtract(goodsRealPrice);
                        useCoupon = 1;
                    } else if (couponType == 3 && appMemberCouponVo.getDiscountMoney() != null) {
                        discountMoney = appMemberCouponVo.getDiscountMoney();
@@ -1122,6 +1126,12 @@
        appUserOrderGetVo.setShopName(shop.getShopName());
        appUserOrderGetVo.setAppUserOrderGoodsPageVoList(appUserOrderGoodsPageVoList);
        appUserOrderGetVo.setVerifyCode("1-" + orderId);
        //生成自动取消订单延时任务
        Integer delayTime = 30;
        if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){
            delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME);
        }
        appUserOrderGetVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(),delayTime));
        return appUserOrderGetVo;
    }
@@ -1274,28 +1284,57 @@
        Goods goods;
        List<ConsumerGoods> consumerGoodsList = new ArrayList<>();
        for (AppUserOrderGoodsPageVo appUserOrderGoodsPageVo : appUserOrderGoodsPageVoList) {
            consumerGoods = new ConsumerGoods();
            goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId());
            consumerGoodsId = IdUtils.simpleUUID();
            consumerGoods.setConsumerGoodsId(consumerGoodsId);
            consumerGoods.setDelFlag(0);
            consumerGoods.setServiceStatus(1);
            consumerGoods.setShopId(order.getShopId());
            consumerGoods.setUserId(order.getUserId());
            consumerGoods.setOrderId(orderId);
            consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
            consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
            consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
            consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
            consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
            consumerGoods.setUsedNum(0);
            consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
            consumerGoods.setCreateTime(nowTime);
            consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
            consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
            consumerGoods.setGoodsNurses(goods.getGoodsNurses());
            consumerGoods.setSourceFrom(1);
            consumerGoodsList.add(consumerGoods);
            Integer buyNum = appUserOrderGoodsPageVo.getBuyNum();
            if(appUserOrderGoodsPageVo.getCycleNumFlag()==0){
                consumerGoods = new ConsumerGoods();
                goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId());
                consumerGoodsId = IdUtils.simpleUUID();
                consumerGoods.setConsumerGoodsId(consumerGoodsId);
                consumerGoods.setDelFlag(0);
                consumerGoods.setServiceStatus(1);
                consumerGoods.setShopId(order.getShopId());
                consumerGoods.setUserId(order.getUserId());
                consumerGoods.setOrderId(orderId);
                consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
                consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
                consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
                consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
                consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
                consumerGoods.setUsedNum(0);
                consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
                consumerGoods.setCreateTime(nowTime);
                consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
                consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                consumerGoods.setSourceFrom(1);
                consumerGoods.setSureNum(buyNum);
                consumerGoodsList.add(consumerGoods);
            }else{
                for(int i=0;i<buyNum;i++){
                    consumerGoods = new ConsumerGoods();
                    goods = goodsMap.get(appUserOrderGoodsPageVo.getGoodsId());
                    consumerGoodsId = IdUtils.simpleUUID();
                    consumerGoods.setConsumerGoodsId(consumerGoodsId);
                    consumerGoods.setDelFlag(0);
                    consumerGoods.setServiceStatus(1);
                    consumerGoods.setShopId(order.getShopId());
                    consumerGoods.setUserId(order.getUserId());
                    consumerGoods.setOrderId(orderId);
                    consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
                    consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
                    consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
                    consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
                    consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
                    consumerGoods.setUsedNum(0);
                    consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
                    consumerGoods.setCreateTime(nowTime);
                    consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
                    consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                    consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                    consumerGoods.setSourceFrom(1);
                    consumerGoodsList.add(consumerGoods);
                }
            }
        }
        consumerGoodsService.saveBatchConsumerGoods(consumerGoodsList);
        //生成返回
@@ -1792,29 +1831,61 @@
        List<AppUserOrderGoodsPageVo> appUserOrderGoodsPageVoList = orderGoodsService.listAppVoByOrderId(orderId);
        ConsumerGoods consumerGoods;
        String consumerGoodsId;
        List<ConsumerGoods> consumerGoodsList = new ArrayList<>();
        for (AppUserOrderGoodsPageVo appUserOrderGoodsPageVo : appUserOrderGoodsPageVoList) {
            consumerGoods = new ConsumerGoods();
            goods = remoteGoodsService.getGoods(appUserOrderGoodsPageVo.getGoodsId()).getData();
            consumerGoodsId = IdUtils.simpleUUID();
            consumerGoods.setConsumerGoodsId(consumerGoodsId);
            consumerGoods.setDelFlag(0);
            consumerGoods.setServiceStatus(1);
            consumerGoods.setShopId(order.getShopId());
            consumerGoods.setUserId(order.getUserId());
            consumerGoods.setOrderId(orderId);
            consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
            consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
            consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
            consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
            consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
            consumerGoods.setUsedNum(0);
            consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
            consumerGoods.setCreateTime(nowTime);
            consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
            consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
            consumerGoods.setGoodsNurses(goods.getGoodsNurses());
            consumerGoodsService.save(consumerGoods);
            Integer buyGoodsNum = appUserOrderGoodsPageVo.getBuyNum();
            if(appUserOrderGoodsPageVo.getCycleNumFlag()==0){
                consumerGoods = new ConsumerGoods();
                goods = remoteGoodsService.getGoods(appUserOrderGoodsPageVo.getGoodsId()).getData();
                consumerGoodsId = IdUtils.simpleUUID();
                consumerGoods.setConsumerGoodsId(consumerGoodsId);
                consumerGoods.setDelFlag(0);
                consumerGoods.setServiceStatus(1);
                consumerGoods.setShopId(order.getShopId());
                consumerGoods.setUserId(order.getUserId());
                consumerGoods.setOrderId(orderId);
                consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
                consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
                consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
                consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
                consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
                consumerGoods.setUsedNum(0);
                consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
                consumerGoods.setCreateTime(nowTime);
                consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
                consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                consumerGoods.setSourceFrom(1);
                consumerGoods.setSureNum(buyGoodsNum);
                consumerGoodsList.add(consumerGoods);
            }else{
                for(int i=0;i<buyGoodsNum;i++) {
                    consumerGoods = new ConsumerGoods();
                    goods = remoteGoodsService.getGoods(appUserOrderGoodsPageVo.getGoodsId()).getData();
                    consumerGoodsId = IdUtils.simpleUUID();
                    consumerGoods.setConsumerGoodsId(consumerGoodsId);
                    consumerGoods.setDelFlag(0);
                    consumerGoods.setServiceStatus(1);
                    consumerGoods.setShopId(order.getShopId());
                    consumerGoods.setUserId(order.getUserId());
                    consumerGoods.setOrderId(orderId);
                    consumerGoods.setOrderGoodsId(appUserOrderGoodsPageVo.getOrderGoodsId());
                    consumerGoods.setGoodsId(appUserOrderGoodsPageVo.getGoodsId());
                    consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
                    consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
                    consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
                    consumerGoods.setUsedNum(0);
                    consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
                    consumerGoods.setCreateTime(nowTime);
                    consumerGoods.setGoodsIntroduction(goods.getGoodsIntroduction());
                    consumerGoods.setGoodsPicture(appUserOrderGoodsPageVo.getGoodsPicture());
                    consumerGoods.setGoodsNurses(goods.getGoodsNurses());
                    consumerGoods.setSourceFrom(1);
                    consumerGoodsList.add(consumerGoods);
                }
            }
        }
        consumerGoodsService.saveBatchConsumerGoods(consumerGoodsList);
        Member member = remoteMemberService.getMember(userId).getData();
        if (member != null && member.getBindingFlag() != 1) {
            //绑定商户
@@ -1850,6 +1921,18 @@
     */
    @Override
    public List<MerOrderPageVo> pageMerOrder(Page page, MerOrderPageDto merOrderPageDto) {
        if(StringUtils.isNotBlank(merOrderPageDto.getKeyword())){
            MgtUserIdByKeywordDto userIdByKeywordDto = new MgtUserIdByKeywordDto();
            userIdByKeywordDto.setKeyword(merOrderPageDto.getKeyword());
            MgtUserIdByKeywordVo userIdByKeywordVo = remoteMemberService.getUserIdByKeyword(userIdByKeywordDto).getData();
            if(StringUtils.isNotBlank(userIdByKeywordVo.getUserIds())){
                List<Long> userIdList = Arrays.stream(userIdByKeywordVo.getUserIds().split(","))
                        .map(Long::parseLong)
                        .collect(Collectors.toList());
                merOrderPageDto.setMemberUserIdList(userIdList);
                merOrderPageDto.setMemberUserId(null);
            }
        }
        List<MerOrderPageVo> merOrderPageVoList = orderMapper.pageMerOrder(page, merOrderPageDto);
        if (merOrderPageVoList != null && !merOrderPageVoList.isEmpty()) {
            Long userId;
@@ -1883,9 +1966,13 @@
            Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream()
                    .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity()));
            for (MerOrderPageVo merOrderPageVo : merOrderPageVoList) {
                merOrderPageVo.setUserName(userMap.get(merOrderPageVo.getUserId()).getRealName());
                merOrderPageVo.setNickName(userMap.get(merOrderPageVo.getUserId()).getNickName());
                merOrderPageVo.setUserMobile(userMap.get(merOrderPageVo.getUserId()).getUserMobile());
                if(merOrderPageVo.getUserId()!=null&&userMap.get(merOrderPageVo.getUserId())!=null){
                    merOrderPageVo.setUserName(userMap.get(merOrderPageVo.getUserId()).getRealName());
                    merOrderPageVo.setNickName(userMap.get(merOrderPageVo.getUserId()).getNickName());
                    merOrderPageVo.setUserMobile(userMap.get(merOrderPageVo.getUserId()).getUserMobile());
                }else{
                    log.debug("订单merOrderPageVo"+merOrderPageVo.getOrderId()+"缺少用户");
                }
            }
        }
        return merOrderPageVoList;
@@ -2251,7 +2338,11 @@
        mgtOrderDetailVo.setCancelTime(order.getCancelTime());
        mgtOrderDetailVo.setOrderRemark(order.getOrderRemark());
        mgtOrderDetailVo.setShopId(order.getShopId());
        mgtOrderDetailVo.setShopName(shop.getShopName());
        if(shop!=null){
            mgtOrderDetailVo.setShopName(shop.getShopName());
        }else{
            mgtOrderDetailVo.setShopName("商户已被删除");
        }
        mgtOrderDetailVo.setVerifyTime(order.getUseTime());
        //获取支付记录
        List<MgtOrderPayListVo> orderPayListVoList = payRecordService.listMgtOrderPayVo(orderId);
@@ -3004,9 +3095,9 @@
        }
        MerOrderDistributionTotalVo orderDistributionTotalVo = new MerOrderDistributionTotalVo();
        // 获取订单年龄用户列表
        List<MerOrderAgeUserVo> orderAgeUserVoList = remoteMemberService.listOrderAgeUser(merTotalDto).getData();
        //List<MerOrderAgeUserVo> orderAgeUserVoList = remoteMemberService.listOrderAgeUser(merTotalDto).getData();
        // 如果订单年龄用户列表不为空
        if (orderAgeUserVoList != null && !orderAgeUserVoList.isEmpty()) {
        /*if (orderAgeUserVoList != null && !orderAgeUserVoList.isEmpty()) {
            // 定义变量
            Integer ageType;
            List<Long> userIdList;
@@ -3047,12 +3138,23 @@
                    orderTotalValue[i] = 0;
                    orderMoneyValue[i] = BigDecimal.ZERO;
                }
            }*/
            List<MgtMapTotalPlusVo> mgtMapTotalPlusVoList =  orderMapper.listMerOrderDistributionTotal(merTotalDto);
            if(mgtMapTotalPlusVoList!=null&&!mgtMapTotalPlusVoList.isEmpty()) {
                String[] orderTotalKey = new String[mgtMapTotalPlusVoList.size()];
                Integer[] orderTotalValue = new Integer[mgtMapTotalPlusVoList.size()];
                BigDecimal[] orderMoneyValue = new BigDecimal[mgtMapTotalPlusVoList.size()];
                MgtMapTotalPlusVo mgtMapTotalPlusVo;
                for (int i = 0; i < mgtMapTotalPlusVoList.size(); i++) {
                    mgtMapTotalPlusVo = mgtMapTotalPlusVoList.get(i);
                    orderTotalKey[i] = mgtMapTotalPlusVo.getMapKey();
                    orderTotalValue[i] = mgtMapTotalPlusVo.getMapValueFirst();
                    orderMoneyValue[i] = mgtMapTotalPlusVo.getMapValueSecond();
                }
                orderDistributionTotalVo.setOrderTotalKey(orderTotalKey);
                orderDistributionTotalVo.setOrderTotalValue(orderTotalValue);
                orderDistributionTotalVo.setOrderMoneyValue(orderMoneyValue);
            }
            // 设置订单分布总数对象的属性值
            orderDistributionTotalVo.setOrderTotalKey(orderTotalKey);
            orderDistributionTotalVo.setOrderTotalValue(orderTotalValue);
            orderDistributionTotalVo.setOrderMoneyValue(orderMoneyValue);
        }
        // 返回订单分布总数对象
        return orderDistributionTotalVo;
    }
@@ -3157,11 +3259,11 @@
    }
    /**
     * @param merBaseDto
     * @return MerTotalOrderVo
     * @description 商户端订单管理统计
     * @author jqs
     * @date 2023/7/4 16:27
     * @description  商户端订单管理统计
     * @author  jqs
     * @date    2023/7/31 10:53
     * @param merOrderPageDto
     * @return  MerTotalOrderVo
     */
    @Override
    public MerTotalOrderVo totalMerOrder(MerOrderPageDto merOrderPageDto) {
@@ -3839,14 +3941,14 @@
            delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME);
        }
        delayTime = delayTime + 5;
        Date checkTime = DateUtils.addMinutes(new Date(),delayTime);
        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){
            for(Order order: orderList){
                autoTimeCancelOrder(order);
            }
        }