| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.feignClient.BalanceChangeRecordClient; |
| | | import com.ruoyi.account.api.feignClient.UserPointClient; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.BalanceChangeRecord; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | 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.domain.ShopBalanceStatement; |
| | | import com.ruoyi.other.api.domain.ShopPoint; |
| | | import com.ruoyi.other.api.domain.Technician; |
| | | import com.ruoyi.other.api.feignClient.ShopBalanceStatementClient; |
| | | import com.ruoyi.other.api.feignClient.ShopClient; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import com.ruoyi.other.api.feignClient.ShopPointClient; |
| | | import com.ruoyi.other.api.feignClient.TechnicianClient; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | @Resource |
| | | private ShopClient shopClient; |
| | | @Resource |
| | | private RedisTemplate<String, String> redisTemplate; |
| | | private BalanceChangeRecordClient balanceChangeRecordClient; |
| | | @Resource |
| | | private UserPointClient userPointClient; |
| | | @Resource |
| | | private ShopBalanceStatementClient shopBalanceStatementClient; |
| | | @Resource |
| | | private ShopPointClient shopPointClient; |
| | | @Resource |
| | | private TechnicianClient technicianClient; |
| | | |
| | | /** |
| | | * 返佣延迟队列(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 |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void calculationCommission(Set<String> 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) { |
| | | public void calculationCommission() { |
| | | List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getIsCommission, 0).isNotNull(Order::getAfterSaleTime) |
| | | .eq(Order::getDelFlag, 0).last(" and after_sale_time <= now()")); |
| | | List<Long> collect = list.stream().map(Order::getId).collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | return; |
| | | } |
| | | |
| | | for (Order order : list) { |
| | | if(order.getPayMethod() == 3){ |
| | | continue; |
| | | } |
| | | order.setIsCommission(1); |
| | | orderService.updateById(order); |
| | | 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); |
| | | |
| | | // 获取直帮上级用户 |
| | | R<AppUser> superiorLeaderR = appUserClient.getSuperiorLeader(appUserId); |
| | | if (!R.isSuccess(superiorLeaderR)) { |
| | | throw new RuntimeException("获取直帮上级信息失败"); |
| | | } |
| | | AppUser superiorLeader = superiorLeaderR.getData(); |
| | | |
| | | for (OrderGood og : v) {// 累计分销金额 |
| | | |
| | | // 直推上级分佣金额 |
| | | Integer superiorType = og.getSuperiorType(); |
| | | if (superiorType == 1 && inviteUser != null){ |
| | | // 分佣金额 |
| | | BigDecimal superiorSubcommission = og.getSuperiorSubcommission(); |
| | | BigDecimal totalDistributionAmount = inviteUser.getTotalDistributionAmount(); |
| | | totalDistributionAmount = totalDistributionAmount.add(superiorSubcommission); |
| | | inviteUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | |
| | | // 分佣积分 |
| | | Integer sharePoint = inviteUser.getSharePoint(); |
| | | Integer superiorRebatePoints = og.getSuperiorRebatePoints(); |
| | | sharePoint = sharePoint + superiorRebatePoints; |
| | | inviteUser.setSharePoint(sharePoint); |
| | | |
| | | appUserClient.editAppUserById(inviteUser); |
| | | }else |
| | | // 直帮上级分佣金额 |
| | | if (superiorType == 2 && superiorLeader != null){ |
| | | // 分佣金额 |
| | | BigDecimal superiorSubcommission = og.getSuperiorSubcommission(); |
| | | BigDecimal totalDistributionAmount = superiorLeader.getTotalDistributionAmount(); |
| | | totalDistributionAmount = totalDistributionAmount.add(superiorSubcommission); |
| | | superiorLeader.setTotalDistributionAmount(totalDistributionAmount); |
| | | |
| | | // 分佣积分 |
| | | Integer sharePoint = superiorLeader.getSharePoint(); |
| | | Integer superiorRebatePoints = og.getSuperiorRebatePoints(); |
| | | sharePoint = sharePoint + superiorRebatePoints; |
| | | superiorLeader.setSharePoint(sharePoint); |
| | | |
| | | appUserClient.editAppUserById(superiorLeader); |
| | | List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>() |
| | | .eq(OrderGood::getGoodsId, order.getId())); |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | | //直推上级分佣金额 |
| | | BigDecimal ztsj_price = BigDecimal.ZERO; |
| | | //直帮上级分佣金额 |
| | | BigDecimal zbsj_price = BigDecimal.ZERO; |
| | | //直推上级分佣积分 |
| | | Integer ztsj_point = 0; |
| | | //直帮上级分佣积分 |
| | | Integer zbsj_point = 0; |
| | | //核销门店分佣金额 |
| | | BigDecimal hxmd_price = BigDecimal.ZERO; |
| | | //核销门店分佣积分 |
| | | Integer hxmd_point = 0; |
| | | //技师分佣积分 |
| | | Integer js_point = 0; |
| | | //绑定门店分佣金额 |
| | | BigDecimal bdmd_price = BigDecimal.ZERO; |
| | | //绑定门店分佣积分 |
| | | Integer bdmd_point = 0; |
| | | //绑定门店上级门店分佣金额 |
| | | BigDecimal bdmdsj_price = BigDecimal.ZERO; |
| | | //绑定门店上级门店分佣积分 |
| | | Integer bdmdsj_point = 0; |
| | | for (OrderGood orderGood : orderGoods) { |
| | | //上级获得分佣金额(直推上级|直帮上级) |
| | | BigDecimal superiorSubcommission = orderGood.getSuperiorSubcommission(); |
| | | //上级获得分佣积分(直推上级|直帮上级) |
| | | Integer superiorRebatePoints = orderGood.getSuperiorRebatePoints(); |
| | | String[] split = orderGood.getSuperiorPriceType().split(","); |
| | | for (String s : split) { |
| | | //直推上级 |
| | | if("1".equals(s)){ |
| | | ztsj_price = ztsj_price.add(superiorSubcommission); |
| | | ztsj_point += superiorRebatePoints; |
| | | } |
| | | //直帮上级 |
| | | if("2".equals(s)){ |
| | | zbsj_price = zbsj_price.add(superiorSubcommission); |
| | | zbsj_point += superiorRebatePoints; |
| | | } |
| | | } |
| | | |
| | | //核销门店获取服务费 |
| | | hxmd_price = hxmd_price.add(orderGood.getServuceShopCharges()); |
| | | //核销门店可获得积分 |
| | | hxmd_point += orderGood.getServuceShopPoints(); |
| | | //技师分佣金额 |
| | | if(order.getOrderType() == 1){ |
| | | js_point += orderGood.getTechnicianPoints(); |
| | | } |
| | | //绑定门店分佣金额 |
| | | bdmd_price = bdmd_price.add(orderGood.getBoundShopCharges()); |
| | | //绑定门店分佣积分 |
| | | bdmd_point += orderGood.getBoundShopPoints(); |
| | | //绑定门店上级门店分佣金额 |
| | | bdmdsj_price = bdmdsj_price.add(orderGood.getBoundShopSuperiorsCharges()); |
| | | //绑定门店上级门店分佣积分 |
| | | bdmdsj_point += orderGood.getBoundShopSuperiorsPoints(); |
| | | } |
| | | //直推上级 |
| | | AppUser inviteUser = appUserClient.getAppUserById(appUser.getInviteUserId()); |
| | | if(null != inviteUser){ |
| | | BigDecimal balance = inviteUser.getBalance(); |
| | | Integer lavePoint = inviteUser.getLavePoint(); |
| | | if(ztsj_price.compareTo(BigDecimal.ZERO) > 0){ |
| | | inviteUser.setTotalDistributionAmount(inviteUser.getTotalDistributionAmount().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | inviteUser.setBalance(inviteUser.getBalance().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | inviteUser.setWithdrawableAmount(inviteUser.getWithdrawableAmount().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | } |
| | | if(ztsj_point > 0){ |
| | | inviteUser.setSharePoint(inviteUser.getSharePoint() + ztsj_point); |
| | | inviteUser.setLavePoint(inviteUser.getLavePoint() + ztsj_point); |
| | | inviteUser.setTotalPoint(inviteUser.getTotalPoint() + ztsj_point); |
| | | } |
| | | appUserClient.editAppUserById(inviteUser); |
| | | //添加明细记录 |
| | | if(!inviteUser.getBalance().equals(balance)){ |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(inviteUser.getId()); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setChangeType(4); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | | balanceChangeRecord.setChangeAmount(ztsj_price); |
| | | balanceChangeRecord.setAfterAmount(inviteUser.getBalance()); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | //添加积分明细 |
| | | if(!inviteUser.getLavePoint().equals(lavePoint)){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(2); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(ztsj_point); |
| | | userPoint.setBalance(inviteUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(inviteUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPoint.setExtention(order.getOrderNumber()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | } |
| | | //直帮上级 |
| | | AppUser superiorLeader = appUserClient.getSuperiorLeader(appUser.getId()).getData(); |
| | | if(null != superiorLeader){ |
| | | BigDecimal balance = superiorLeader.getBalance(); |
| | | Integer lavePoint = superiorLeader.getLavePoint(); |
| | | if(zbsj_price.compareTo(BigDecimal.ZERO) > 0){ |
| | | superiorLeader.setTotalDistributionAmount(superiorLeader.getTotalDistributionAmount().add(zbsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | superiorLeader.setBalance(superiorLeader.getBalance().add(zbsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | superiorLeader.setWithdrawableAmount(superiorLeader.getWithdrawableAmount().add(zbsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | } |
| | | if(zbsj_point > 0){ |
| | | superiorLeader.setSharePoint(superiorLeader.getSharePoint() + zbsj_point); |
| | | superiorLeader.setLavePoint(superiorLeader.getLavePoint() + zbsj_point); |
| | | superiorLeader.setTotalPoint(superiorLeader.getTotalPoint() + zbsj_point); |
| | | } |
| | | appUserClient.editAppUserById(superiorLeader); |
| | | //添加明细记录 |
| | | if(!superiorLeader.getBalance().equals(balance)){ |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(superiorLeader.getId()); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setChangeType(4); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | | balanceChangeRecord.setChangeAmount(zbsj_price); |
| | | balanceChangeRecord.setAfterAmount(superiorLeader.getBalance()); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | //添加积分明细 |
| | | if(!superiorLeader.getLavePoint().equals(lavePoint)){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(2); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(zbsj_point); |
| | | userPoint.setBalance(superiorLeader.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(superiorLeader.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPoint.setExtention(order.getOrderNumber()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | } |
| | | |
| | | //核销门店 |
| | | Shop shop = shopClient.getShopById(order.getShopId()).getData(); |
| | | AppUser shopAppUser = appUserClient.getAppUserById(shop.getAppUserId()); |
| | | if(null != shopAppUser){ |
| | | BigDecimal balance = shopAppUser.getBalance(); |
| | | BigDecimal shopBalance = shop.getBalance(); |
| | | Integer lavePoint = shopAppUser.getLavePoint(); |
| | | Integer shopLavePoint = shop.getLavePoint(); |
| | | if(hxmd_price.compareTo(BigDecimal.ZERO) > 0){ |
| | | shopAppUser.setTotalDistributionAmount(shopAppUser.getTotalDistributionAmount().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shopAppUser.setBalance(shopAppUser.getBalance().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shopAppUser.setWithdrawableAmount(shopAppUser.getWithdrawableAmount().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shopAppUser.setShopServiceFee(shopAppUser.getShopServiceFee().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | //门店返佣 |
| | | shop.setGiveawayAllMoney(shop.getGiveawayAllMoney().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop.setServerGiveawayMoney(shop.getServerGiveawayMoney().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop.setCanWithdrawMoney(shop.getCanWithdrawMoney().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop.setBalance(shop.getBalance().add(hxmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | } |
| | | if(hxmd_point > 0){ |
| | | shopAppUser.setSharePoint(shopAppUser.getSharePoint() + hxmd_point); |
| | | shopAppUser.setLavePoint(shopAppUser.getLavePoint() + hxmd_point); |
| | | shopAppUser.setTotalPoint(shopAppUser.getTotalPoint() + hxmd_point); |
| | | //门店返佣 |
| | | shop.setShopAllPoint(shop.getShopAllPoint() + hxmd_point); |
| | | shop.setServerPoint(shop.getServerPoint() + hxmd_point); |
| | | shop.setLavePoint(shop.getLavePoint() + hxmd_point); |
| | | } |
| | | appUserClient.editAppUserById(shopAppUser); |
| | | shopClient.updateShop(shop); |
| | | //添加明细记录 |
| | | if(!shopAppUser.getBalance().equals(balance)){ |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(shopAppUser.getId()); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setChangeType(4); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | | balanceChangeRecord.setChangeAmount(hxmd_price); |
| | | balanceChangeRecord.setAfterAmount(shopAppUser.getBalance()); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | |
| | | if(!shop.getBalance().equals(shopBalance)){ |
| | | ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement(); |
| | | shopBalanceStatement.setShopId(shop.getId()); |
| | | shopBalanceStatement.setType(3); |
| | | shopBalanceStatement.setHistoricalBalance(shopBalance); |
| | | shopBalanceStatement.setVariableAmount(hxmd_price); |
| | | shopBalanceStatement.setBalance(shop.getBalance()); |
| | | shopBalanceStatement.setCreateTime(LocalDateTime.now()); |
| | | shopBalanceStatement.setCreateUserId(order.getAppUserId()); |
| | | shopBalanceStatement.setObjectId(order.getId()); |
| | | shopBalanceStatement.setExtension(order.getOrderNumber()); |
| | | shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement); |
| | | } |
| | | //添加积分明细 |
| | | if(!shopAppUser.getLavePoint().equals(lavePoint)){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(9); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(hxmd_point); |
| | | userPoint.setBalance(shopAppUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(shopAppUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPoint.setExtention(order.getOrderNumber()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | |
| | | if(!shop.getLavePoint().equals(shopLavePoint)){ |
| | | ShopPoint shopPoint = new ShopPoint(); |
| | | shopPoint.setShopId(shop.getId()); |
| | | shopPoint.setType(4); |
| | | shopPoint.setHistoricalPoint(shopLavePoint); |
| | | shopPoint.setVariablePoint(hxmd_point); |
| | | shopPoint.setBalance(shop.getLavePoint()); |
| | | shopPoint.setCreateTime(LocalDateTime.now()); |
| | | shopPoint.setCreateUserId(order.getAppUserId()); |
| | | shopPoint.setObjectId(order.getId()); |
| | | shopPoint.setOrderNum(order.getOrderNumber()); |
| | | shopPointClient.saveShopPoint(shopPoint); |
| | | } |
| | | } |
| | | |
| | | //技师服务积分 |
| | | if(order.getOrderType() == 1){ |
| | | Technician technician = technicianClient.shopdetail(order.getTechnicianId()).getData(); |
| | | AppUser technicianAppUser = appUserClient.getAppUserById(technician.getAppUserId()); |
| | | Integer lavePoint = technicianAppUser.getLavePoint(); |
| | | if(js_point > 0){ |
| | | technicianAppUser.setLavePoint(technicianAppUser.getLavePoint() + js_point); |
| | | technicianAppUser.setTotalPoint(technicianAppUser.getTotalPoint() + js_point); |
| | | technicianAppUser.setTotalPerformancePoint(technicianAppUser.getTotalPerformancePoint() + js_point); |
| | | } |
| | | appUserClient.editAppUserById(technicianAppUser); |
| | | //添加积分明细 |
| | | if(!technicianAppUser.getLavePoint().equals(lavePoint)){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(10); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(js_point); |
| | | userPoint.setBalance(technicianAppUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(technicianAppUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPoint.setExtention(order.getOrderNumber()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | } |
| | | |
| | | //绑定门店分佣 |
| | | Shop shop1 = shopClient.getShopById(appUser.getShopId()).getData(); |
| | | if(null != shop1){ |
| | | AppUser bdShopAppUser = appUserClient.getAppUserById(shop1.getAppUserId()); |
| | | if(null != bdShopAppUser){ |
| | | BigDecimal balance = bdShopAppUser.getBalance(); |
| | | BigDecimal shopBalance = shop1.getBalance(); |
| | | Integer lavePoint = bdShopAppUser.getLavePoint(); |
| | | Integer shopLavePoint = shop1.getLavePoint(); |
| | | if(bdmd_price.compareTo(BigDecimal.ZERO) > 0){ |
| | | bdShopAppUser.setTotalDistributionAmount(bdShopAppUser.getTotalDistributionAmount().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | bdShopAppUser.setBalance(bdShopAppUser.getBalance().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | bdShopAppUser.setWithdrawableAmount(bdShopAppUser.getWithdrawableAmount().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | bdShopAppUser.setShopCommission(bdShopAppUser.getShopCommission().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | //门店返佣 |
| | | shop1.setGiveawayAllMoney(shop1.getGiveawayAllMoney().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop1.setGiveawayMoney(shop1.getGiveawayMoney().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop1.setCanWithdrawMoney(shop1.getCanWithdrawMoney().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop1.setBalance(shop1.getBalance().add(bdmd_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | } |
| | | if(bdmd_point > 0){ |
| | | bdShopAppUser.setSharePoint(bdShopAppUser.getSharePoint() + bdmd_point); |
| | | bdShopAppUser.setLavePoint(bdShopAppUser.getLavePoint() + bdmd_point); |
| | | bdShopAppUser.setTotalPoint(bdShopAppUser.getTotalPoint() + bdmd_point); |
| | | //门店返佣 |
| | | shop1.setShopAllPoint(shop1.getShopAllPoint() + bdmd_point); |
| | | shop1.setSharePoint(shop1.getSharePoint() + bdmd_point); |
| | | shop1.setLavePoint(shop1.getLavePoint() + bdmd_point); |
| | | } |
| | | appUserClient.editAppUserById(bdShopAppUser); |
| | | shopClient.updateShop(shop1); |
| | | //添加明细记录 |
| | | if(!bdShopAppUser.getBalance().equals(balance)){ |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(bdShopAppUser.getId()); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setChangeType(4); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | | balanceChangeRecord.setChangeAmount(bdmd_price); |
| | | balanceChangeRecord.setAfterAmount(bdShopAppUser.getBalance()); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | |
| | | if(!shop1.getBalance().equals(shopBalance)){ |
| | | ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement(); |
| | | shopBalanceStatement.setShopId(shop1.getId()); |
| | | shopBalanceStatement.setType(4); |
| | | shopBalanceStatement.setHistoricalBalance(shopBalance); |
| | | shopBalanceStatement.setVariableAmount(bdmd_price); |
| | | shopBalanceStatement.setBalance(shop1.getBalance()); |
| | | shopBalanceStatement.setCreateTime(LocalDateTime.now()); |
| | | shopBalanceStatement.setCreateUserId(order.getAppUserId()); |
| | | shopBalanceStatement.setObjectId(order.getId()); |
| | | shopBalanceStatement.setExtension(order.getOrderNumber()); |
| | | shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement); |
| | | } |
| | | //添加积分明细 |
| | | if(!bdShopAppUser.getLavePoint().equals(lavePoint)){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(9); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(bdmd_point); |
| | | userPoint.setBalance(bdShopAppUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(bdShopAppUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPoint.setExtention(order.getOrderNumber()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | |
| | | if(!shop1.getLavePoint().equals(shopLavePoint)){ |
| | | ShopPoint shopPoint = new ShopPoint(); |
| | | shopPoint.setShopId(shop1.getId()); |
| | | shopPoint.setType(2); |
| | | shopPoint.setHistoricalPoint(shopLavePoint); |
| | | shopPoint.setVariablePoint(bdmd_point); |
| | | shopPoint.setBalance(shop1.getLavePoint()); |
| | | shopPoint.setCreateTime(LocalDateTime.now()); |
| | | shopPoint.setCreateUserId(order.getAppUserId()); |
| | | shopPoint.setObjectId(order.getId()); |
| | | shopPoint.setOrderNum(order.getOrderNumber()); |
| | | shopPointClient.saveShopPoint(shopPoint); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //上级门店分佣 |
| | | Integer pid = shopClient.getShopById(order.getShopId()).getData().getPid(); |
| | | Shop shop2 = shopClient.getShopById(pid).getData(); |
| | | if(null != shop2){ |
| | | AppUser sjShopAppUser = appUserClient.getAppUserById(shop2.getAppUserId()); |
| | | if(null != sjShopAppUser){ |
| | | BigDecimal balance = sjShopAppUser.getBalance(); |
| | | BigDecimal shopBalance = shop2.getBalance(); |
| | | Integer lavePoint = sjShopAppUser.getLavePoint(); |
| | | Integer shopLavePoint = shop2.getLavePoint(); |
| | | if(bdmdsj_price.compareTo(BigDecimal.ZERO) > 0){ |
| | | sjShopAppUser.setTotalDistributionAmount(sjShopAppUser.getTotalDistributionAmount().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | sjShopAppUser.setBalance(sjShopAppUser.getBalance().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | sjShopAppUser.setWithdrawableAmount(sjShopAppUser.getWithdrawableAmount().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | //门店返佣 |
| | | shop2.setGiveawayAllMoney(shop2.getGiveawayAllMoney().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop2.setLowerLevelGiveawayMoney(shop2.getLowerLevelGiveawayMoney().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop2.setCanWithdrawMoney(shop2.getCanWithdrawMoney().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | shop2.setBalance(shop2.getBalance().add(bdmdsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | } |
| | | if(bdmdsj_point > 0){ |
| | | sjShopAppUser.setSharePoint(sjShopAppUser.getSharePoint() + bdmdsj_point); |
| | | sjShopAppUser.setLavePoint(sjShopAppUser.getLavePoint() + bdmdsj_point); |
| | | sjShopAppUser.setTotalPoint(sjShopAppUser.getTotalPoint() + bdmdsj_point); |
| | | sjShopAppUser.setShopSharePoint(sjShopAppUser.getShopSharePoint() + bdmdsj_point); |
| | | //门店返佣 |
| | | shop2.setShopAllPoint(shop2.getShopAllPoint() + bdmdsj_point); |
| | | shop2.setSharePoint(shop2.getSharePoint() + bdmdsj_point); |
| | | shop2.setLavePoint(shop2.getLavePoint() + bdmdsj_point); |
| | | } |
| | | appUserClient.editAppUserById(sjShopAppUser); |
| | | shopClient.updateShop(shop2); |
| | | //添加明细记录 |
| | | if(!sjShopAppUser.getBalance().equals(balance)){ |
| | | BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); |
| | | balanceChangeRecord.setAppUserId(sjShopAppUser.getId()); |
| | | balanceChangeRecord.setOrderId(order.getId()); |
| | | balanceChangeRecord.setChangeType(4); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | | balanceChangeRecord.setChangeAmount(bdmdsj_price); |
| | | balanceChangeRecord.setAfterAmount(sjShopAppUser.getBalance()); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | } |
| | | |
| | | if(!shop2.getBalance().equals(shopBalance)){ |
| | | ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement(); |
| | | shopBalanceStatement.setShopId(shop2.getId()); |
| | | shopBalanceStatement.setType(2); |
| | | shopBalanceStatement.setHistoricalBalance(shopBalance); |
| | | shopBalanceStatement.setVariableAmount(bdmdsj_price); |
| | | shopBalanceStatement.setBalance(shop2.getBalance()); |
| | | shopBalanceStatement.setCreateTime(LocalDateTime.now()); |
| | | shopBalanceStatement.setCreateUserId(order.getAppUserId()); |
| | | shopBalanceStatement.setObjectId(order.getId()); |
| | | shopBalanceStatement.setExtension(order.getOrderNumber()); |
| | | shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement); |
| | | } |
| | | //添加积分明细 |
| | | if(!sjShopAppUser.getLavePoint().equals(lavePoint)){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(14); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(bdmdsj_point); |
| | | userPoint.setBalance(sjShopAppUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(sjShopAppUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPoint.setExtention(order.getOrderNumber()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | |
| | | if(!shop2.getLavePoint().equals(shopLavePoint)){ |
| | | ShopPoint shopPoint = new ShopPoint(); |
| | | shopPoint.setShopId(shop2.getId()); |
| | | shopPoint.setType(3); |
| | | shopPoint.setHistoricalPoint(shopLavePoint); |
| | | shopPoint.setVariablePoint(bdmdsj_point); |
| | | shopPoint.setBalance(shop2.getLavePoint()); |
| | | shopPoint.setCreateTime(LocalDateTime.now()); |
| | | shopPoint.setCreateUserId(order.getAppUserId()); |
| | | shopPoint.setObjectId(order.getId()); |
| | | shopPoint.setOrderNum(order.getOrderNumber()); |
| | | shopPointClient.saveShopPoint(shopPoint); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |