peng
昨天 11079cf5c81a047c3a343581a5cc6001fb4a2ec8
framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java
@@ -10,6 +10,7 @@
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import cn.lili.base.Result;
import cn.lili.common.enums.ClientTypeEnum;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.common.enums.ResultCode;
@@ -25,11 +26,15 @@
import cn.lili.common.utils.StringUtils;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dto.GoodsCompleteMessage;
import cn.lili.modules.goods.service.GoodsService;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.lmk.domain.entity.CouponVirtual;
import cn.lili.modules.lmk.domain.vo.OrderCountByDayAndHourVO;
import cn.lili.modules.lmk.domain.vo.OrderCountVO;
import cn.lili.modules.lmk.enums.general.AdminRoleEnum;
import cn.lili.modules.lmk.enums.general.VirtualGoodsTypeEnum;
import cn.lili.modules.lmk.service.CouponVirtualService;
import cn.lili.modules.member.entity.dos.Member;
import cn.lili.modules.member.entity.dto.MemberAddressDTO;
@@ -53,6 +58,7 @@
import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.service.CouponService;
import cn.lili.modules.promotion.service.PintuanService;
import cn.lili.modules.statistics.entity.dto.StatisticsQueryParam;
import cn.lili.modules.store.entity.dto.StoreDeliverGoodsAddressDTO;
import cn.lili.modules.store.service.StoreDetailService;
import cn.lili.modules.system.aspect.annotation.SystemLogPoint;
@@ -83,7 +89,9 @@
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.reactivex.rxjava3.core.Maybe;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
@@ -106,6 +114,10 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -213,6 +225,8 @@
    @Autowired
    private RedissonClient redissonClient;
    @Autowired
    private GoodsSkuService goodsSkuService;
    private final static  String LOCK_ORDER_NO_MQ="lock_order_no_mq:";
    private final static  String LOCK_EDIT_ORDER_ADDRESS="lock_edit_order_address:";
    private final static  String LOCK_COUPON_CARD="lock_coupon_card:";
@@ -251,7 +265,21 @@
//                        item.getPriceDetailDTO().setPlatFormCommissionPoint(Double.valueOf(goods.getCommission().toString()));
//                        e.setPriceDetailDTO(item.getPriceDetailDTO());
//                        orderItems.add(e);
                        orderItems.add(new OrderItem(sku, item, tradeDTO));
                        //特殊处理线上礼品卡问题
                        String skuId = sku.getGoodsSku().getId();
                        GoodsSku skuInfo = goodsSkuService.getById(skuId);
                        OrderItem orderItem = new OrderItem(sku, item, tradeDTO);
                        if (skuInfo != null) {
                            String goodsId = skuInfo.getGoodsId();
                            Goods goodsInfo = goodsService.getById(goodsId);
                            if (goodsInfo != null&& VirtualGoodsTypeEnum.COUPON.name().equals(goodsInfo.getVirtualGoodsType())) {
                                String couponId = skuInfo.getCouponId();
                                String couponName = skuInfo.getCouponName();
                                orderItem.setCouponId(couponId);
                                orderItem.setCouponName(couponName);
                            }
                        }
                        orderItems.add(orderItem);
                        currentOrderItems.add(new OrderItem(sku, item, tradeDTO));
                    }
            );
@@ -801,12 +829,19 @@
    @OrderLogPoint(description = "'订单['+#orderSn+']核销,核销码['+#verificationCode+']'", orderSn = "#orderSn")
    @Transactional(rollbackFor = Exception.class)
    public Order take(String orderSn, String verificationCode) {
        log.info("订单核销订单号为:{},核销码为{}",orderSn,verificationCode);
        Order order;
        RLock lock = redissonClient.getLock(LOCK_COUPON_CARD + orderSn);
        try {
             lock.lock();
            //获取订单信息
            order = this.getBySn(orderSn);
            log.info("获取到的订单信息为{}",JSON.toJSONString(order));
            //订单幂等问题
            if (OrderStatusEnum.COMPLETED.name().equals(order.getOrderStatus())) {
                throw new ServiceException("当前订单已完成无法再次核验");
            }
            //检测虚拟订单信息
            checkVerificationOrder(order, verificationCode);
            order.setOrderStatus(OrderStatusEnum.COMPLETED.name());
@@ -815,6 +850,7 @@
            List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn);
            List<CouponVirtual> couponVirtuals = new  ArrayList<>();
            for (OrderItem orderItem : orderItems) {
                log.info("获取到的子订单信息为{}",JSON.toJSONString(orderItem));
                String couponId = orderItem.getCouponId();
                if (StringUtils.isBlank(couponId)) {
                    continue;
@@ -825,7 +861,7 @@
                    log.error("当前订单订单号为:{}不存在中的优惠卷不存在----------------------->{}",order.getId(),orderItem.getOrderSn());
                }else {
                    Integer num = orderItem.getNum();
                    //当购买数量部位空的时候进行
                    //当购买数量不为空的时候进行
                    if (num != null) {
                        for (int i = 1; i <= num; i++) {
                            CouponVirtual couponVirtual = getCouponVirtual(orderItem);
@@ -837,6 +873,7 @@
                }
            }
            if (!couponVirtuals.isEmpty()) {
                log.info("生成的兑换卡为{}",JSON.toJSONString(couponVirtuals));
                order.setCouponFlag(CouPonFlagEnum.COUPON.name());
                couponVirtualService.saveBatch(couponVirtuals);
                //更新状态用于后续小程序判断弹出卷列表
@@ -854,7 +891,7 @@
    private static CouponVirtual getCouponVirtual(OrderItem orderItem) {
        CouponVirtual couponVirtual = new CouponVirtual();
        couponVirtual.setOrderId(orderItem.getSn());
        couponVirtual.setOrderId(orderItem.getOrderSn());
        couponVirtual.setCouponId(orderItem.getCouponId());
        couponVirtual.setCouponName(orderItem.getCouponName());
        couponVirtual.setGoodsId(orderItem.getGoodsId());
@@ -1218,12 +1255,31 @@
        orderLogService.saveBatch(orderLogList);
        //判断订单货物是否全部发货完毕
        Boolean delivery = true;
        log.info("打印订单货物:{}",orderItemList);
        //需要再此处判断订单是否有申请售后状态
        for (OrderItem orderItem : orderItemList) {
            if (orderItem.getDeliverNumber() < orderItem.getNum()) {
                delivery = false;
                break;
            // 先判断是否是未申请售后的订单
            if (OrderItemAfterSaleStatusEnum.NOT_APPLIED.name().equals(orderItem.getAfterSaleStatus())){
                // 发货数量小于订单数量则全发
                log.info("打印发货数量:{},该商品订单数量货物对应的:{}",orderItem.getDeliverNumber(),orderItem.getNum());
                if (orderItem.getDeliverNumber() < orderItem.getNum()) {
                    delivery = false;
                    break;
                }
            }else{
                //全部退回情况
                if(Objects.equals(orderItem.getReturnGoodsNumber(), orderItem.getNum())){
                    break;
                }
                //存在情况 退回数量不是全部退回而是部分退回
                if (orderItem.getReturnGoodsNumber() + orderItem.getDeliverNumber() < orderItem.getNum()) {
                    delivery = false;
                    break;
                }
            }
        }
        log.info("delivery状态:{}",delivery);
        //是否全部发货
        if (delivery) {
            return delivery(orderSn, invoiceNumber, logisticsId);
@@ -1237,6 +1293,231 @@
        order.setSellerRemark(sellerRemark);
        this.updateById(order);
        return order;
    }
    @Override
    public Result getOrderCount(StatisticsQueryParam queryParam) {
        Date startTime = null;
        Date endTime = new Date(); // 结束时间默认是当前时间
        List<String> dateList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance(); // 用于日期计算的日历实例
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int days = 0;
        //判断是否是按年月查询
        if (queryParam.getYear() != null && queryParam.getMonth() != null) {
            Date[] dates =CommonUtil.getMonthStartAndEnd(queryParam.getYear(),queryParam.getMonth());
            startTime = dates[0];
            endTime = dates[1];
            System.out.println("开始打印");
            System.out.println(startTime);
            System.out.println(endTime);
            Calendar tempCalendar = Calendar.getInstance();
            tempCalendar.setTime(startTime);
            days = tempCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            for (int i = 0; i < days; i++) {
                dateList.add(sdf.format(tempCalendar.getTime()));
                tempCalendar.add(Calendar.DATE, 1); // 每天累加1天
            }
        }else{
            switch (queryParam.getSearchType()) {
                case "TODAY":
                    // 今天:从今天0点到现在
                    calendar.setTime(new Date()); // 重置为当前时间
                    calendar.set(Calendar.HOUR_OF_DAY, 0); // 小时设为0(24小时制)
                    calendar.set(Calendar.MINUTE, 0);      // 分钟设为0
                    calendar.set(Calendar.SECOND, 0);      // 秒设为0
                    calendar.set(Calendar.MILLISECOND, 0); // 毫秒设为0
                    startTime = calendar.getTime();        // 得到今天0点的Date对象
                    dateList.add(sdf.format(startTime));
                    break;
                case "YESTERDAY":
                    // 昨天:从昨天0点到昨天23:59:59.999
                    calendar.setTime(new Date());
                    calendar.add(Calendar.DATE, -1); // 日期减1天(变为昨天)
                    // 设置昨天0点
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 0);
                    startTime = calendar.getTime();
                    // 设置昨天23:59:59.999
                    calendar.set(Calendar.HOUR_OF_DAY, 23);
                    calendar.set(Calendar.MINUTE, 59);
                    calendar.set(Calendar.SECOND, 59);
                    calendar.set(Calendar.MILLISECOND, 999);
                    endTime = calendar.getTime();
                    dateList.add(sdf.format(startTime));
                    break;
                case "LAST_SEVEN":
                    // 过去七天:从7天前0点到现在(含今天共7天)
                    calendar.setTime(new Date());
                    calendar.add(Calendar.DATE, -6); // 日期减6天(7天前的今天)
                    // 设置7天前0点
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 0);
                    startTime = calendar.getTime();
                    days = 7;
                    // 循环生成7天的日期字符串
                    Calendar tempCalendar = Calendar.getInstance();
                    tempCalendar.setTime(startTime);
                    for (int i = 0; i < days; i++) {
                        dateList.add(sdf.format(tempCalendar.getTime()));
                        tempCalendar.add(Calendar.DATE, 1); // 每天累加1天
                    }
                    break;
                case "LAST_THIRTY":
                    // 过去30天:从30天前0点到现在(含今天共30天)
                    calendar.setTime(new Date());
                    calendar.add(Calendar.DATE, -29); // 日期减29天(30天前的今天)
                    // 设置30天前0点
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 0);
                    startTime = calendar.getTime();
                    days = 30;
                    // 循环生成30天的日期字符串
                    Calendar tempCalendar30 = Calendar.getInstance();
                    tempCalendar30.setTime(startTime);
                    for (int i = 0; i < days; i++) {
                        dateList.add(sdf.format(tempCalendar30.getTime()));
                        tempCalendar30.add(Calendar.DATE, 1); // 每天累加1天
                    }
                    break;
                default:
                    return Result.error("不支持的时间范围类型");
            }
        }
        List<Map<String, Object>> maps = baseMapper.selectOrderCountByDay(startTime,endTime);
        Map<String, Long> dayCountMap = maps.stream()
                .collect(Collectors.toMap(
                        map -> map.get("day").toString(),  // 日期字符串(如2023-09-19)
                        map -> Long.valueOf(map.get("count").toString())  // 订单数量
                ));
        List<Long> orderCounts = new ArrayList<>();
        for (String date : dateList) {
            // 核心:存在则取查询结果,不存在则补0
            orderCounts.add(dayCountMap.getOrDefault(date, 0L));
        }
        return Result.ok().data(orderCounts);
    }
    @Override
    public Result getOrderTimePeriod(StatisticsQueryParam queryParam) {
        Date startTime = null;
        Date endTime = new Date(); // 结束时间默认是当前时间
        List<String> dateList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance(); // 用于日期计算的日历实例
        for (int i =0;i<24;i++){
            dateList.add(i + "点");
        }
        if (queryParam.getYear() != null && queryParam.getMonth() != null) {
            Date[] dates =CommonUtil.getMonthStartAndEnd(queryParam.getYear(),queryParam.getMonth());
            startTime = dates[0];
            endTime = dates[1];
        }else{
            switch (queryParam.getSearchType()) {
                case "TODAY":
                    // 今天:从今天0点到现在
                    calendar.setTime(new Date()); // 重置为当前时间
                    calendar.set(Calendar.HOUR_OF_DAY, 0); // 小时设为0(24小时制)
                    calendar.set(Calendar.MINUTE, 0);      // 分钟设为0
                    calendar.set(Calendar.SECOND, 0);      // 秒设为0
                    calendar.set(Calendar.MILLISECOND, 0); // 毫秒设为0
                    startTime = calendar.getTime();        // 得到今天0点的Date对象
                    break;
                case "YESTERDAY":
                    // 昨天:从昨天0点到昨天23:59:59.999
                    calendar.setTime(new Date());
                    calendar.add(Calendar.DATE, -1); // 日期减1天(变为昨天)
                    // 设置昨天0点
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 0);
                    startTime = calendar.getTime();
                    // 设置昨天23:59:59.999
                    calendar.set(Calendar.HOUR_OF_DAY, 23);
                    calendar.set(Calendar.MINUTE, 59);
                    calendar.set(Calendar.SECOND, 59);
                    calendar.set(Calendar.MILLISECOND, 999);
                    endTime = calendar.getTime();
                    break;
                case "LAST_SEVEN":
                    // 过去七天:从7天前0点到现在(含今天共7天)
                    calendar.setTime(new Date());
                    calendar.add(Calendar.DATE, -6); // 日期减6天(7天前的今天)
                    // 设置7天前0点
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 0);
                    startTime = calendar.getTime();
                    break;
                case "LAST_THIRTY":
                    // 过去30天:从30天前0点到现在(含今天共30天)
                    calendar.setTime(new Date());
                    calendar.add(Calendar.DATE, -29); // 日期减29天(30天前的今天)
                    // 设置30天前0点
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    calendar.set(Calendar.MILLISECOND, 0);
                    startTime = calendar.getTime();
                    break;
                default:
                    return Result.error("不支持的时间范围类型");
            }
        }
        List<Map<String, Object>> maps = baseMapper.selectOrderTimePeriod(startTime,endTime);
        Map<String, Long> countByDayHour = maps.stream()
                .collect(Collectors.toMap(
                        map -> map.get("hour").toString(),
                        map -> Long.valueOf(map.get("count").toString()),
                        Long::sum  // 如果有重复,累加count
                ));
        // 遍历查看结果
        List<Long> countList = new ArrayList<>();
        for (int i = 0; i < 24; i++) {
            String hourKey = String.valueOf(i);
            Long count = countByDayHour.getOrDefault(hourKey, 0L);
            countList.add(count);
        }
        Map<String,Object> map = new HashMap<>();
        map.put("dateData",dateList);
        map.put("countData",countList);
        //TODO 浏览数据未加入
//        map.put();
        return Result.ok().data(map);
    }
    /**
@@ -1255,6 +1536,7 @@
            for (Order unpaidOrder : unpaidOrders) {
                this.systemCancel(unpaidOrder.getSn(), "拼团活动结束订单未付款,系统自动取消订单", false);
            }
        }
        List<Order> paidOrders = listMap.get(PayStatusEnum.PAID.name());
        //如待参团人数大于0,并已开启虚拟成团
@@ -1572,8 +1854,19 @@
            orderExportDetailDTO.setPaymentMethod(CharSequenceUtil.isNotBlank(orderExportDTO.getPaymentMethod()) ? PaymentMethodEnum.valueOf(orderExportDTO.getPaymentMethod()).paymentName() : "");
            orderExportDetailDTO.setClientType(ClientTypeEnum.valueOf(orderExportDTO.getClientType()).value());
            orderExportDetailDTO.setOrderType(orderExportDTO.getOrderType().equals(OrderTypeEnum.NORMAL.name()) ? "普通订单" : "虚拟订单");
            orderExportDetailDTO.setAfterSaleStatus(OrderItemAfterSaleStatusEnum.valueOf(orderExportDTO.getAfterSaleStatus()).description());
            String afterSaleStatus = orderExportDTO.getAfterSaleStatus();
            if (StringUtils.isNotBlank(afterSaleStatus)) {
                try {
                    orderExportDetailDTO.setAfterSaleStatus(OrderItemAfterSaleStatusEnum.valueOf(afterSaleStatus).description());
                } catch (IllegalArgumentException e) {
                    // 处理枚举值不存在的情况
                    orderExportDetailDTO.setAfterSaleStatus("未知状态");
                }
            } else {
                // 设置默认值或空字符串
                orderExportDetailDTO.setAfterSaleStatus("无售后状态");
            }
            //时间
            orderExportDetailDTO.setCreateTime(DateUtil.formatDateTime(orderExportDTO.getCreateTime()));
            orderExportDetailDTO.setPaymentTime(DateUtil.formatDateTime(orderExportDTO.getPaymentTime()));
@@ -1588,7 +1881,7 @@
        // 创建表头
        Row header = sheet.createRow(0);
        String[] headers = {"主订单编号", "子订单编号", "选购商品", "商品数量", "商品ID", "商品单价", "订单应付金额",
                "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式","买家名称", "收件人", "收件人手机号",
                "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式","会员ID","买家名称", "收件人", "收件人手机号",
                "省", "市", "区", "街道", "详细地址", "买家留言", "订单提交时间", "支付完成时间", "来源",
                "订单状态", "订单类型", "售后状态", "取消原因", "发货时间", "完成时间", "店铺"};
@@ -1603,7 +1896,7 @@
            row.createCell(0).setCellValue(dto.getOrderSn());
            row.createCell(1).setCellValue(dto.getOrderItemSn());
            row.createCell(2).setCellValue(dto.getGoodsName());
            row.createCell(3).setCellValue(dto.getNum());
            row.createCell(3).setCellValue(dto.getNum()!=null?dto.getNum():0);
            row.createCell(4).setCellValue(dto.getGoodsId());
            row.createCell(5).setCellValue(dto.getUnitPrice()!=null?dto.getUnitPrice():0);
            row.createCell(6).setCellValue(dto.getFlowPrice()!=null?dto.getFlowPrice():0);
@@ -1613,27 +1906,27 @@
            row.createCell(10).setCellValue(dto.getStoreMarketingCost()!=null?dto.getStoreMarketingCost():0);
            row.createCell(11).setCellValue(dto.getUpdatePrice()!=null?dto.getUpdatePrice():0);
            row.createCell(12).setCellValue(dto.getPaymentMethod());
            row.createCell(13).setCellValue(dto.getMemberId());
            row.createCell(14).setCellValue(dto.getNickName());
            row.createCell(13).setCellValue(dto.getNickName());
            row.createCell(14).setCellValue(dto.getConsigneeName());
            row.createCell(15).setCellValue(dto.getConsigneeMobile());
            row.createCell(16).setCellValue(dto.getProvince());
            row.createCell(17).setCellValue(dto.getCity());
            row.createCell(18).setCellValue(dto.getDistrict());
            row.createCell(19).setCellValue(dto.getStreet());
            row.createCell(20).setCellValue(dto.getConsigneeDetail());
            row.createCell(21).setCellValue(dto.getRemark());
            row.createCell(22).setCellValue(dto.getCreateTime());
            row.createCell(23).setCellValue(dto.getPaymentTime());
            row.createCell(24).setCellValue(dto.getClientType());
            row.createCell(25).setCellValue(dto.getOrderStatus());
            row.createCell(26).setCellValue(dto.getOrderType());
            row.createCell(27).setCellValue(dto.getAfterSaleStatus());
            row.createCell(28).setCellValue(dto.getCancelReason());
            row.createCell(29).setCellValue(dto.getLogisticsTime());
            row.createCell(30).setCellValue(dto.getCompleteTime());
            row.createCell(31).setCellValue(dto.getStoreName());
            row.createCell(15).setCellValue(dto.getConsigneeName());
            row.createCell(16).setCellValue(dto.getConsigneeMobile());
            row.createCell(17).setCellValue(dto.getProvince());
            row.createCell(18).setCellValue(dto.getCity());
            row.createCell(19).setCellValue(dto.getDistrict());
            row.createCell(20).setCellValue(dto.getStreet());
            row.createCell(21).setCellValue(dto.getConsigneeDetail());
            row.createCell(22).setCellValue(dto.getRemark());
            row.createCell(23).setCellValue(dto.getCreateTime());
            row.createCell(24).setCellValue(dto.getPaymentTime());
            row.createCell(25).setCellValue(dto.getClientType());
            row.createCell(26).setCellValue(dto.getOrderStatus());
            row.createCell(27).setCellValue(dto.getOrderType());
            row.createCell(28).setCellValue(dto.getAfterSaleStatus());
            row.createCell(29).setCellValue(dto.getCancelReason());
            row.createCell(30).setCellValue(dto.getLogisticsTime());
            row.createCell(31).setCellValue(dto.getCompleteTime());
            row.createCell(32).setCellValue(dto.getStoreName());
        }
        //修改列宽