| | |
| | | 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; |
| | |
| | | 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.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; |
| | |
| | | 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; |
| | |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Cell; |
| | |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | 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; |
| | |
| | | @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:"; |
| | |
| | | // 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)); |
| | | } |
| | | ); |
| | |
| | | @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()); |
| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | if (!couponVirtuals.isEmpty()) { |
| | | log.info("生成的兑换卡为{}",JSON.toJSONString(couponVirtuals)); |
| | | order.setCouponFlag(CouPonFlagEnum.COUPON.name()); |
| | | couponVirtualService.saveBatch(couponVirtuals); |
| | | //更新状态用于后续小程序判断弹出卷列表 |
| | |
| | | |
| | | 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()); |
| | |
| | | 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); |
| | |
| | | order.setSellerRemark(sellerRemark); |
| | | this.updateById(order); |
| | | return order; |
| | | } |
| | | |
| | | @Override |
| | | public Result getOrderCount(StatisticsQueryParam queryParam) { |
| | | LocalDateTime startTime = null; |
| | | LocalDateTime endTime = LocalDateTime.now(); // 结束时间默认是当前时间 |
| | | int days = 0; |
| | | |
| | | switch (queryParam.getSearchType()) { |
| | | case "TODAY": |
| | | // 今天:从今天0点到现在 |
| | | startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN); |
| | | days = 1; |
| | | break; |
| | | case "YESTERDAY": |
| | | // 昨天:从昨天0点到昨天23:59:59 |
| | | LocalDate yesterday = LocalDate.now().minusDays(1); |
| | | startTime = LocalDateTime.of(yesterday, LocalTime.MIN); |
| | | endTime = LocalDateTime.of(yesterday, LocalTime.MAX); |
| | | days = 1; |
| | | break; |
| | | case "LAST_SEVEN": |
| | | // 过去七天:从7天前0点到现在 |
| | | startTime = LocalDateTime.of(LocalDate.now().minusDays(6), LocalTime.MIN); |
| | | days = 7; |
| | | break; |
| | | case "LAST_THIRTY": |
| | | // 过去30天:从30天前0点到现在 |
| | | startTime = LocalDateTime.of(LocalDate.now().minusDays(29), LocalTime.MIN); |
| | | days = 30; |
| | | break; |
| | | default: |
| | | return Result.error("不支持的时间范围类型"); |
| | | } |
| | | |
| | | // 2. 查询该时间范围内的每日订单数量(按日期分组) |
| | | // LambdaQueryWrapper<Order> queryWrapper = Wrappers.lambdaQuery(); |
| | | // queryWrapper.between(Order::getCreateTime, startTime, endTime); |
| | | // // 按日期分组(提取日期部分) |
| | | // |
| | | // // 执行查询,返回日期和数量的映射(day -> count) |
| | | // List<Map<String, Object>> maps = baseMapper.selectMaps(queryWrapper); |
| | | // Map<String, Long> dayCountMap = maps.stream() |
| | | // .collect(Collectors.toMap( |
| | | // map -> map.get("day").toString(), // 日期字符串(如2023-09-19) |
| | | // map -> Long.valueOf(map.get("count").toString()) // 订单数量 |
| | | // )); |
| | | // |
| | | // // 3. 生成完整的日期列表(确保即使某天没有订单也会返回0) |
| | | // List<Long> orderCounts = new ArrayList<>(days); |
| | | // for (int i = 0; i < days; i++) { |
| | | // // 计算当前循环对应的日期(从startTime开始的第i天) |
| | | // LocalDate currentDate = startTime.toLocalDate().plusDays(i); |
| | | // String dateStr = currentDate.toString(); // 转为yyyy-MM-dd格式 |
| | | // // 从映射中获取数量,没有则为0 |
| | | // orderCounts.add(dayCountMap.getOrDefault(dateStr, 0L)); |
| | | // } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | for (Order unpaidOrder : unpaidOrders) { |
| | | this.systemCancel(unpaidOrder.getSn(), "拼团活动结束订单未付款,系统自动取消订单", false); |
| | | } |
| | | |
| | | } |
| | | List<Order> paidOrders = listMap.get(PayStatusEnum.PAID.name()); |
| | | //如待参团人数大于0,并已开启虚拟成团 |
| | |
| | | // 创建表头 |
| | | Row header = sheet.createRow(0); |
| | | String[] headers = {"主订单编号", "子订单编号", "选购商品", "商品数量", "商品ID", "商品单价", "订单应付金额", |
| | | "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式","买家名称", "收件人", "收件人手机号", |
| | | "运费", "优惠总金额", "平台优惠", "商家优惠", "商家改价", "支付方式","会员ID","买家名称", "收件人", "收件人手机号", |
| | | "省", "市", "区", "街道", "详细地址", "买家留言", "订单提交时间", "支付完成时间", "来源", |
| | | "订单状态", "订单类型", "售后状态", "取消原因", "发货时间", "完成时间", "店铺"}; |
| | | |
| | |
| | | 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()); |
| | | } |
| | | |
| | | //修改列宽 |