New file |
| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.order.service.CommissionService; |
| | | import com.ruoyi.order.service.OrderGoodService; |
| | | import com.ruoyi.order.service.OrderService; |
| | | import com.ruoyi.other.api.domain.Shop; |
| | | import com.ruoyi.other.api.feignClient.ShopClient; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class CommissionServiceImpl implements CommissionService { |
| | | @Resource |
| | | private OrderService orderService; |
| | | @Resource |
| | | private OrderGoodService orderGoodService; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | @Resource |
| | | private ShopClient shopClient; |
| | | @Resource |
| | | private RedisTemplate<String, String> redisTemplate; |
| | | |
| | | /** |
| | | * 返佣延迟队列(redis有序集合) |
| | | * |
| | | * @param orderId 订单ID |
| | | * @param afterSalesDeadline 售后截止日期(计算日期) |
| | | */ |
| | | @Override |
| | | public void addToCommissionDelayQueue(Long orderId, LocalDateTime afterSalesDeadline) { |
| | | // 获取订单售后截止日期时间戳(秒) |
| | | long deadlineTimestamp = afterSalesDeadline.atZone(ZoneId.systemDefault()).toEpochSecond(); |
| | | redisTemplate.opsForZSet().add("delay_queue:commission", orderId.toString(), deadlineTimestamp); |
| | | } |
| | | |
| | | @Override |
| | | public void calculationCommission(List<Long> orderIds) { |
| | | List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>() |
| | | .in(OrderGood::getOrderId, orderIds)); |
| | | |
| | | Map<Long, List<OrderGood>> ogMap = orderGoods.stream().collect(Collectors.groupingBy(OrderGood::getOrderId)); |
| | | |
| | | for (Map.Entry<Long, List<OrderGood>> entry : ogMap.entrySet()) { |
| | | Long k = entry.getKey(); |
| | | List<OrderGood> v = entry.getValue(); |
| | | Order order = orderService.getById(k); |
| | | if (order.getIsCommission() == 1) { |
| | | continue; |
| | | } |
| | | R<Shop> r = shopClient.getShopById(order.getShopId()); |
| | | if (!R.isSuccess(r)) { |
| | | throw new RuntimeException("获取门店信息失败"); |
| | | } |
| | | Shop shop = r.getData(); |
| | | if (shop == null) { |
| | | throw new RuntimeException("获取门店信息失败"); |
| | | } |
| | | |
| | | Long appUserId = order.getAppUserId(); |
| | | AppUser appUser = appUserClient.getAppUserById(appUserId); |
| | | if (appUser == null) { |
| | | throw new RuntimeException("获取用户信息失败"); |
| | | } |
| | | Long inviteUserId = appUser.getInviteUserId(); |
| | | AppUser inviteUser = appUserClient.getAppUserById(inviteUserId); |
| | | |
| | | for (OrderGood og : v) {// 累计分销金额 |
| | | |
| | | // 上级分销金额 |
| | | if (inviteUser != null){ |
| | | BigDecimal superiorSubcommission = og.getSuperiorSubcommission(); |
| | | BigDecimal totalDistributionAmount = inviteUser.getTotalDistributionAmount(); |
| | | totalDistributionAmount = totalDistributionAmount.add(superiorSubcommission); |
| | | // |
| | | Integer superiorType = og.getSuperiorType(); |
| | | Integer sharePoint = inviteUser.getSharePoint(); |
| | | if (superiorType == 1) { |
| | | Integer superiorRebatePoints = og.getSuperiorRebatePoints(); |
| | | sharePoint = sharePoint + superiorRebatePoints; |
| | | } else if (superiorType == 2) { |
| | | |
| | | } else { |
| | | continue; |
| | | } |
| | | inviteUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | inviteUser.setSharePoint(sharePoint); |
| | | } |
| | | |
| | | // 门店分销金额 |
| | | og.getBoundShopCharges(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |