| | |
| | | import cn.lili.modules.goods.entity.dos.Goods; |
| | | import cn.lili.modules.goods.entity.dto.GoodsCompleteMessage; |
| | | import cn.lili.modules.goods.service.GoodsService; |
| | | 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.service.CouponVirtualService; |
| | | import cn.lili.modules.member.entity.dos.Member; |
| | | import cn.lili.modules.member.entity.dto.MemberAddressDTO; |
| | | import cn.lili.modules.member.mapper.MemberMapper; |
| | |
| | | import cn.lili.modules.permission.entity.dos.AdminUser; |
| | | import cn.lili.modules.permission.service.AdminUserService; |
| | | import cn.lili.modules.permission.service.RoleService; |
| | | import cn.lili.modules.promotion.entity.dos.Coupon; |
| | | 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.store.entity.dto.StoreDeliverGoodsAddressDTO; |
| | | import cn.lili.modules.store.service.StoreDetailService; |
| | |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.apache.rocketmq.spring.core.RocketMQTemplate; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | |
| | | @Resource |
| | | private RedisTemplate<Object,Object> redisTemplate; |
| | | |
| | | @Autowired |
| | | private CouponService couponService; |
| | | |
| | | @Autowired |
| | | private CouponVirtualService couponVirtualService; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | |
| | | 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:"; |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void intoDB(TradeDTO tradeDTO) { |
| | |
| | | //查询订单和自订单,然后写入vo返回 |
| | | return new OrderDetailVO(order, orderItems, orderLogs, receipt); |
| | | } |
| | | @Override |
| | | public OrderDetailVO queryEditAddressDetail(String orderSn) { |
| | | Order order = this.getBySn(orderSn); |
| | | if (order == null) { |
| | | throw new ServiceException(ResultCode.ORDER_NOT_EXIST); |
| | | } |
| | | //查询订单项信息 |
| | | List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn); |
| | | |
| | | //查询订单和自订单,然后写入vo返回 |
| | | return new OrderDetailVO(order, orderItems, null, null); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | |
| | | return order; |
| | | } |
| | | @Override |
| | | @SystemLogPoint(description = "修改订单", customerLog = "'订单[' + #orderSn + ']收货信息修改,修改为'+#memberAddressDTO.consigneeDetail") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Order updateAddressConsignee(String orderSn, MemberAddressDTO memberAddressDTO) { |
| | | Order order = this.getBySn(orderSn); |
| | | if (order == null) { |
| | | throw new ServiceException(ResultCode.ORDER_NOT_EXIST); |
| | | } |
| | | //限制30秒只能请求一次避免出现重新提交问题 |
| | | Boolean b = redisTemplate.opsForValue().setIfAbsent(LOCK_EDIT_ORDER_ADDRESS + orderSn, orderSn,30, TimeUnit.SECONDS); |
| | | if ( Boolean.FALSE.equals(b)){ |
| | | throw new ServiceException("请在30秒后重试"); |
| | | } |
| | | String modifyAddressFlag = order.getModifyAddressFlag(); |
| | | if (StringUtils.isNotBlank(modifyAddressFlag)) { |
| | | throw new ServiceException("当前订单已经被领取"); |
| | | } |
| | | QueryWrapper<Order> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id", order.getId()); |
| | | // 使用 last 方法拼接 FOR UPDATE 语句 |
| | | wrapper.last("FOR UPDATE"); |
| | | baseMapper.selectOne(wrapper); |
| | | //要记录之前的收货地址,所以需要以代码方式进行调用 不采用注解 |
| | | String message = "订单[" + orderSn + "]收货信息修改,由[" +order.getConsigneeAddressPath()+ order.getConsigneeDetail() + "]修改为[" + memberAddressDTO.getConsigneeAddressPath()+ memberAddressDTO.getConsigneeDetail() + "]"; |
| | | //记录订单操作日志 |
| | | BeanUtil.copyProperties(memberAddressDTO, order); |
| | | order.setModifyAddressFlag(ModifyAddressEnums.USED.name()); |
| | | this.updateById(order); |
| | | OrderLog orderLog = new OrderLog(orderSn, UserContext.getCurrentUser().getId(), UserContext.getCurrentUser().getRole().getRole(), |
| | | UserContext.getCurrentUser().getUsername(), message); |
| | | orderLogService.save(orderLog); |
| | | |
| | | return order; |
| | | } |
| | | @Override |
| | | @OrderLogPoint(description = "'订单['+#orderSn+']发货,发货单号['+#logisticsNo+']'", orderSn = "#orderSn") |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | @OrderLogPoint(description = "'订单['+#orderSn+']核销,核销码['+#verificationCode+']'", orderSn = "#orderSn") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Order take(String orderSn, String verificationCode) { |
| | | Order order; |
| | | RLock lock = redissonClient.getLock(LOCK_COUPON_CARD + orderSn); |
| | | try { |
| | | lock.lock(); |
| | | //获取订单信息 |
| | | order = this.getBySn(orderSn); |
| | | //检测虚拟订单信息 |
| | | checkVerificationOrder(order, verificationCode); |
| | | order.setOrderStatus(OrderStatusEnum.COMPLETED.name()); |
| | | //订单完成 |
| | | //获取所有的订单子项用于生成优惠卷订单信息 |
| | | List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn); |
| | | List<CouponVirtual> couponVirtuals = new ArrayList<>(); |
| | | for (OrderItem orderItem : orderItems) { |
| | | String couponId = orderItem.getCouponId(); |
| | | if (StringUtils.isBlank(couponId)) { |
| | | continue; |
| | | } |
| | | String storeId = order.getStoreId(); |
| | | Coupon one = couponService.getOne(Wrappers.<Coupon>lambdaQuery().eq(Coupon::getStoreId, storeId).eq(Coupon::getId, couponId)); |
| | | if (one == null) { |
| | | 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); |
| | | couponVirtual.setCouponNo(String.format("%08d", i)); |
| | | couponVirtuals.add(couponVirtual); |
| | | } |
| | | } |
| | | |
| | | //获取订单信息 |
| | | Order order = this.getBySn(orderSn); |
| | | //检测虚拟订单信息 |
| | | checkVerificationOrder(order, verificationCode); |
| | | order.setOrderStatus(OrderStatusEnum.COMPLETED.name()); |
| | | //订单完成 |
| | | this.complete(orderSn); |
| | | } |
| | | } |
| | | if (!couponVirtuals.isEmpty()) { |
| | | order.setCouponFlag(CouPonFlagEnum.COUPON.name()); |
| | | couponVirtualService.saveBatch(couponVirtuals); |
| | | //更新状态用于后续小程序判断弹出卷列表 |
| | | this.updateById(order); |
| | | } |
| | | this.complete(orderSn); |
| | | } finally { |
| | | assert lock != null; |
| | | if (lock.isHeldByCurrentThread()) { |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | return order; |
| | | } |
| | | |
| | | private static CouponVirtual getCouponVirtual(OrderItem orderItem) { |
| | | CouponVirtual couponVirtual = new CouponVirtual(); |
| | | couponVirtual.setOrderId(orderItem.getSn()); |
| | | couponVirtual.setCouponId(orderItem.getCouponId()); |
| | | couponVirtual.setCouponName(orderItem.getCouponName()); |
| | | couponVirtual.setGoodsId(orderItem.getGoodsId()); |
| | | couponVirtual.setSkuId(orderItem.getSkuId()); |
| | | couponVirtual.setItemOrderId(orderItem.getId()); |
| | | couponVirtual.setSkuName(orderItem.getGoodsName()); |
| | | couponVirtual.setName(orderItem.getCouponName()); |
| | | couponVirtual.setShareStatus(ShareStatusEnum.NOT_SHARE.name()); |
| | | couponVirtual.setClaimStatus(ClaimStatusEnum.NOT_CLAIM.name()); |
| | | return couponVirtual; |
| | | } |
| | | @Override |
| | | public Order take(String verificationCode) { |
| | | String storeId = OperationalJudgment.judgment(UserContext.getCurrentUser()).getStoreId(); |
| | |
| | | this.update(new LambdaUpdateWrapper<Order>() |
| | | .eq(Order::getSn, orderSn) |
| | | .set(Order::getOrderStatus, orderStatusEnum.name())); |
| | | //修改订单商品 todo 所有的订单需要审核后才能退款 |
| | | orderItemService.update(new LambdaUpdateWrapper<OrderItem>() |
| | | .eq(OrderItem::getOrderSn,orderSn) |
| | | .set(OrderItem::getAfterSaleStatus, OrderItemAfterSaleStatusEnum.NOT_APPLIED.name()) |
| | | .set(OrderItem::getCommentStatus,CommentStatusEnum.UNFINISHED.name()) |
| | | .set(OrderItem::getComplainStatus, OrderComplaintStatusEnum.NO_APPLY.name())); |
| | | //修改订单 |
| | | OrderMessage orderMessage = new OrderMessage(); |
| | | orderMessage.setNewStatus(orderStatusEnum); |