From 1f09f6daaf73bc83cceb4ae22b862b7b365635cf Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 03 四月 2025 19:59:17 +0800 Subject: [PATCH] 修改反馈文档bug --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java | 1224 +++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 752 insertions(+), 472 deletions(-) diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java index bd55d78..14a362b 100644 --- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java +++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java @@ -1,35 +1,33 @@ package com.ruoyi.order.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.account.api.feignClient.AppUserClient; +import com.ruoyi.account.api.feignClient.AppUserGiveawayTemporaryClient; 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.common.core.utils.StringUtils; +import com.ruoyi.account.api.model.*; +import com.ruoyi.order.model.Order; +import com.ruoyi.order.model.OrderGood; import com.ruoyi.order.service.CommissionService; import com.ruoyi.order.service.OrderGoodService; import com.ruoyi.order.service.OrderService; import com.ruoyi.other.api.domain.*; import com.ruoyi.other.api.feignClient.*; -import com.ruoyi.order.model.Order; -import com.ruoyi.order.model.OrderGood; -import org.springframework.data.redis.core.RedisTemplate; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.time.ZoneId; +import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @Service +@Slf4j public class CommissionServiceImpl implements CommissionService { @Resource private OrderService orderService; @@ -51,301 +49,734 @@ private TechnicianClient technicianClient; @Resource private PointSettingClient pointSettingClient; - - - + @Resource + private AppUserGiveawayTemporaryClient appUserGiveawayTemporaryClient; + @Resource + private ShopGiveawayTemporaryClient shopGiveawayTemporaryClient; + + + @Override @Transactional(rollbackFor = Exception.class) - public void calculationCommission() { - List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getIsCommission, 0).isNotNull(Order::getAfterSaleTime) + public void calculationCommission(){ + List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getIsCommission, 2).isNotNull(Order::getAfterSaleTime) .eq(Order::getDelFlag, 0).ne(Order::getPayMethod, 3).last(" and after_sale_time <= now()")); List<Long> collect = list.stream().map(Order::getId).collect(Collectors.toList()); - if(collect.size() == 0){ + if(collect.isEmpty()){ return; } for (Order order : list) { - List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>() - .eq(OrderGood::getOrderId, order.getId())); - AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); - if(null == appUser){ - return; - } - //直推上级分佣金额 - 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(); - if(StringUtils.isNotEmpty(orderGood.getSuperiorPriceType())){ - String[] split = orderGood.getSuperiorPriceType().split(","); - for (String s : split) { - //直推上级 - if("1".equals(s)){ - ztsj_price = ztsj_price.add(superiorSubcommission); - } - //直帮上级 - if("2".equals(s)){ - zbsj_price = zbsj_price.add(superiorSubcommission); + //添加用户的分佣数据 + List<AppUserGiveawayTemporary> data = appUserGiveawayTemporaryClient.getAppUserGiveawayTemporary(order.getId()).getData(); + if(null != data){ + Set<Long> appUserIds = data.stream().map(AppUserGiveawayTemporary::getAppUserId).collect(Collectors.toSet()); + for (Long appUserId : appUserIds) { + Integer sharePoint = 0; + BigDecimal balance = BigDecimal.ZERO; + BigDecimal withdrawableAmount = BigDecimal.ZERO; + BigDecimal totalDistributionAmount = BigDecimal.ZERO; + Integer lowerLevelSharePoint = 0; + Integer shopSharePoint = 0; + Integer shopAchievementPoint = 0; + BigDecimal shopServiceFee = BigDecimal.ZERO; + BigDecimal shopCommission = BigDecimal.ZERO; + Integer totalPerformancePoint = 0; + Integer totalPoint = 0; + Integer lavePoint = 0; + Integer availablePoint = 0; + Integer totalAvailablePoint = 0; + Integer transferablePoint = 0; + for (AppUserGiveawayTemporary datum : data) { + if(datum.getAppUserId().longValue() == appUserId){ + sharePoint += datum.getSharePoint(); + balance = balance.add(datum.getBalance()); + withdrawableAmount = withdrawableAmount.add(datum.getWithdrawableAmount()); + totalDistributionAmount = totalDistributionAmount.add(datum.getTotalDistributionAmount()); + lowerLevelSharePoint += datum.getLowerLevelSharePoint(); + shopSharePoint += datum.getShopSharePoint(); + shopAchievementPoint += datum.getShopAchievementPoint(); + shopServiceFee = shopServiceFee.add(datum.getShopServiceFee()); + shopCommission = shopCommission.add(datum.getShopCommission()); + totalPerformancePoint += datum.getTotalPerformancePoint(); + totalPoint += datum.getTotalPoint(); + lavePoint += datum.getLavePoint(); + availablePoint += datum.getAvailablePoint(); + totalAvailablePoint += datum.getTotalAvailablePoint(); + transferablePoint += datum.getTransferablePoint(); } } - } - if(StringUtils.isNotEmpty(orderGood.getSuperiorType())){ - String[] split = orderGood.getSuperiorType().split(","); - for (String s : split) { - //直推上级 - if("1".equals(s)){ - ztsj_point += superiorRebatePoints; - } - //直帮上级 - if("2".equals(s)){ - 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(); - } - //直推上级 - if(null != appUser.getInviteUserId()){ - 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){ - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getSharePointOpen()){ - earnPoint1 = new BigDecimal(ztsj_point).multiply(pointSetting.getSharePoint().divide(new BigDecimal(100))).intValue(); - } - inviteUser.setSharePoint(inviteUser.getSharePoint() + ztsj_point); - inviteUser.setLavePoint(inviteUser.getLavePoint() + ztsj_point); - inviteUser.setAvailablePoint(inviteUser.getAvailablePoint() + earnPoint1); - inviteUser.setTotalAvailablePoint(inviteUser.getTotalAvailablePoint() + earnPoint1); - if(null != pointSetting && 1 == pointSetting.getSharePointGift()){ - inviteUser.setTransferablePoint(inviteUser.getTransferablePoint() + earnPoint1); - } - inviteUser.setTotalPoint(inviteUser.getTotalPoint() + ztsj_point); - } - appUserClient.editAppUserById(inviteUser); - //添加明细记录 - if(!inviteUser.getBalance().equals(balance)){ - BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); - balanceChangeRecord.setAppUserId(inviteUser.getId()); - balanceChangeRecord.setVipId(inviteUser.getVipId()); - 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); - //变更等级 - appUserClient.vipUpgrade(inviteUser.getId()); - } - } - } - - //直帮上级 - 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){ - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getSharePointOpen()){ - earnPoint1 = new BigDecimal(zbsj_point).multiply(pointSetting.getSharePoint().divide(new BigDecimal(100))).intValue(); - } - superiorLeader.setSharePoint(superiorLeader.getSharePoint() + zbsj_point); - superiorLeader.setLavePoint(superiorLeader.getLavePoint() + zbsj_point); - superiorLeader.setAvailablePoint(superiorLeader.getAvailablePoint() + earnPoint1); - superiorLeader.setTotalAvailablePoint(superiorLeader.getTotalAvailablePoint() + earnPoint1); - if(null != pointSetting && 1 == pointSetting.getSharePointGift()){ - superiorLeader.setTransferablePoint(superiorLeader.getTransferablePoint() + earnPoint1); - } - superiorLeader.setTotalPoint(superiorLeader.getTotalPoint() + zbsj_point); - } - appUserClient.editAppUserById(superiorLeader); - //添加明细记录 - if(!superiorLeader.getBalance().equals(balance)){ - BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); - balanceChangeRecord.setAppUserId(superiorLeader.getId()); - balanceChangeRecord.setVipId(superiorLeader.getVipId()); - 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); + + AppUser appUser = appUserClient.getAppUserById(appUserId); + appUser.setSharePoint(appUser.getSharePoint() + sharePoint); + appUser.setBalance(appUser.getBalance().add(balance).setScale(2, BigDecimal.ROUND_HALF_UP)); + appUser.setWithdrawableAmount(appUser.getWithdrawableAmount().add(withdrawableAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); + appUser.setTotalDistributionAmount(appUser.getTotalDistributionAmount().add(totalDistributionAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); + appUser.setLowerLevelSharePoint(appUser.getLowerLevelSharePoint() + lowerLevelSharePoint); + appUser.setShopSharePoint(appUser.getShopSharePoint() + shopSharePoint); + appUser.setShopAchievementPoint(appUser.getShopAchievementPoint() + shopAchievementPoint); + appUser.setShopServiceFee(appUser.getShopServiceFee().add(shopServiceFee).setScale(2, BigDecimal.ROUND_HALF_UP)); + appUser.setShopCommission(appUser.getShopCommission().add(shopCommission).setScale(2, BigDecimal.ROUND_HALF_UP)); + appUser.setTotalPerformancePoint(appUser.getTotalPerformancePoint() + totalPerformancePoint); + appUser.setTotalPoint(appUser.getTotalPoint() + totalPoint); + appUser.setLavePoint(appUser.getLavePoint() + lavePoint); + appUser.setAvailablePoint(appUser.getAvailablePoint() + availablePoint); + appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + totalAvailablePoint); + appUser.setTransferablePoint(appUser.getTransferablePoint() + transferablePoint); + appUserClient.editAppUserById(appUser); //变更等级 - appUserClient.vipUpgrade(superiorLeader.getId()); + appUserClient.vipUpgrade(appUserId); } } - //核销门店 - Shop shop = shopClient.getShopById(order.getShopId()).getData(); - AppUser shopAppUser = appUserClient.getAppUserById(shop.getAppUserId()); - if(null != shopAppUser){ - BigDecimal shopBalance = shop.getBalance(); - Integer lavePoint = shopAppUser.getLavePoint(); - Integer shopLavePoint = shop.getLavePoint(); - if(hxmd_price.compareTo(BigDecimal.ZERO) > 0){ - //门店返佣 - 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){ - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getShopPointOpen()){ - earnPoint1 = new BigDecimal(hxmd_point).multiply(pointSetting.getShopPoint().divide(new BigDecimal(100))).intValue(); + //添加店铺的分佣数据 + List<ShopGiveawayTemporary> data1 = shopGiveawayTemporaryClient.getShopGiveawayTemporary(order.getId()).getData(); + if(null != data1){ + Set<Integer> collect1 = data1.stream().map(ShopGiveawayTemporary::getShopId).collect(Collectors.toSet()); + for (Integer shopId : collect1) { + Integer shopAllPoint = 0; + Integer lowerLevelSharePoint = 0; + Integer sharePoint = 0; + Integer serverPoint = 0; + Integer lavePoint = 0; + BigDecimal giveawayAllMoney = BigDecimal.ZERO; + BigDecimal giveawayMoney = BigDecimal.ZERO; + BigDecimal lowerLevelGiveawayMoney = BigDecimal.ZERO; + BigDecimal serverGiveawayMoney = BigDecimal.ZERO; + BigDecimal canWithdrawMoney = BigDecimal.ZERO; + BigDecimal balance = BigDecimal.ZERO; + for (ShopGiveawayTemporary datum : data1) { + if(datum.getShopId().equals(shopId)){ + shopAllPoint += datum.getShopAllPoint(); + lowerLevelSharePoint += datum.getLowerLevelSharePoint(); + sharePoint += datum.getSharePoint(); + serverPoint += datum.getServerPoint(); + lavePoint += datum.getLavePoint(); + giveawayAllMoney = giveawayAllMoney.add(datum.getGiveawayAllMoney()); + giveawayMoney = giveawayMoney.add(datum.getGiveawayMoney()); + lowerLevelGiveawayMoney = lowerLevelGiveawayMoney.add(datum.getLowerLevelGiveawayMoney()); + serverGiveawayMoney = serverGiveawayMoney.add(datum.getServerGiveawayMoney()); + canWithdrawMoney = canWithdrawMoney.add(datum.getCanWithdrawMoney()); + balance = balance.add(datum.getBalance()); + } } - shopAppUser.setLavePoint(shopAppUser.getLavePoint() + hxmd_point); - shopAppUser.setAvailablePoint(shopAppUser.getAvailablePoint() + earnPoint1); - shopAppUser.setTotalAvailablePoint(shopAppUser.getTotalAvailablePoint() + earnPoint1); - if(null != pointSetting && 1 == pointSetting.getShopPointGift()){ - shopAppUser.setTransferablePoint(shopAppUser.getTransferablePoint() + earnPoint1); - } - shopAppUser.setTotalPoint(shopAppUser.getTotalPoint() + hxmd_point); - shopAppUser.setShopAchievementPoint(shopAppUser.getShopAchievementPoint() + hxmd_point); - //门店返佣 - shop.setShopAllPoint(shop.getShopAllPoint() + hxmd_point); - shop.setServerPoint(shop.getServerPoint() + hxmd_point); - shop.setLavePoint(shop.getLavePoint() + hxmd_point); + Shop shop = shopClient.getShopById(shopId).getData(); + shop.setShopAllPoint(shop.getShopAllPoint() + shopAllPoint); + shop.setLowerLevelSharePoint(shop.getLowerLevelSharePoint() + lowerLevelSharePoint); + shop.setSharePoint(shop.getSharePoint() + sharePoint); + shop.setServerPoint(shop.getServerPoint() + serverPoint); + shop.setLavePoint(shop.getLavePoint() + lavePoint); + shop.setGiveawayAllMoney(shop.getGiveawayAllMoney().add(giveawayAllMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); + shop.setGiveawayMoney(shop.getGiveawayMoney().add(giveawayMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); + shop.setLowerLevelGiveawayMoney(shop.getLowerLevelGiveawayMoney().add(lowerLevelGiveawayMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); + shop.setServerGiveawayMoney(shop.getServerGiveawayMoney().add(serverGiveawayMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); + shop.setCanWithdrawMoney(shop.getCanWithdrawMoney().add(canWithdrawMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); + shop.setBalance(shop.getBalance().add(balance).setScale(2, BigDecimal.ROUND_HALF_UP)); + shopClient.updateShop(shop); } - appUserClient.editAppUserById(shopAppUser); - shopClient.updateShop(shop); - //添加明细记录 - if(!shop.getBalance().equals(shopBalance)){ + } + + //开始处理明细流水 + List<BalanceChangeRecordCopy> data2 = balanceChangeRecordClient.getBalanceChangeRecordCopy(order.getId(), Arrays.asList(4)).getData(); + if(null != data2){ + for(BalanceChangeRecordCopy item : data2){ + BalanceChangeRecord changeRecord = new BalanceChangeRecord(); + BeanUtil.copyProperties(item, changeRecord); + changeRecord.setId(null); + balanceChangeRecordClient.saveBalanceChangeRecord(changeRecord); + } + if(data2.size() > 0){ + List<Long> ids = data2.stream().map(BalanceChangeRecordCopy::getId).collect(Collectors.toList()); + balanceChangeRecordClient.deleteBalanceChangeRecordCopyByIds(ids); + } + } + + List<UserPointCopy> data3 = userPointClient.getUserPointCopy(order.getId(), Arrays.asList(2,8,9,10,14)).getData(); + if(null != data3){ + for(UserPointCopy item : data3){ + UserPoint userPoint = new UserPoint(); + BeanUtil.copyProperties(item, userPoint); + userPoint.setId(null); + userPointClient.saveUserPoint(userPoint); + } + if(data3.size() > 0){ + List<Long> ids = data3.stream().map(UserPointCopy::getId).collect(Collectors.toList()); + userPointClient.deleteUserPointCopyByIds(ids); + } + } + + + List<ShopBalanceStatementCopy> data4 = shopBalanceStatementClient.getShopBalanceStatementCopy(order.getId(), Arrays.asList(1,2,3)).getData(); + if(null != data4){ + for(ShopBalanceStatementCopy item : data4){ 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()); + BeanUtil.copyProperties(item, shopBalanceStatement); + shopBalanceStatement.setId(null); shopBalanceStatementClient.saveShopBalanceStatement(shopBalanceStatement); } - //添加积分明细 - if(!shopAppUser.getLavePoint().equals(lavePoint)){ - UserPoint userPoint = new UserPoint(); - userPoint.setType(8); - 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); - //变更等级 - appUserClient.vipUpgrade(shopAppUser.getId()); - } - - if(!shop.getLavePoint().equals(shopLavePoint)){ - ShopPoint shopPoint = new ShopPoint(); - shopPoint.setShopId(shop.getId()); - shopPoint.setType(1); - 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(data4.size() > 0){ + List<Long> ids = data4.stream().map(ShopBalanceStatementCopy::getId).collect(Collectors.toList()); + shopBalanceStatementClient.deleteShopBalanceStatementCopyByIds(ids); } } + + List<ShopPointCopy> data5 = shopPointClient.getShopPointCopy(order.getId(), Arrays.asList(1,2,3)).getData(); + if(null != data5){ + for(ShopPointCopy item : data5){ + ShopPoint shopPoint = new ShopPoint(); + BeanUtil.copyProperties(item, shopPoint); + shopPoint.setId(null); + shopPointClient.saveShopPoint(shopPoint); + } + if(data5.size() > 0){ + List<Long> ids = data5.stream().map(ShopPointCopy::getId).collect(Collectors.toList()); + shopPointClient.deleteShopPointCopyByIds(ids); + } + } + order.setIsCommission(3); + orderService.updateById(order); - //技师服务积分 + appUserGiveawayTemporaryClient.delAppUserGiveawayTemporary(order.getId()); + shopGiveawayTemporaryClient.delShopGiveawayTemporary(order.getId()); + } + + } + + + + @Override + @Transactional(rollbackFor = Exception.class) + public void calculationCommissionUser(Long orderId) { + Order order = orderService.getById(orderId); + List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>() + .eq(OrderGood::getOrderId, order.getId())); + AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); + if(null == appUser){ + log.error("无效的用户数据"); + return; + } + //指导老师分佣金额 + BigDecimal zdls_price = BigDecimal.ZERO; + //指导老师分佣积分 + Integer zdls_point = 0; + //服务商分佣金额 + BigDecimal fws_price = BigDecimal.ZERO; + //服务商分佣积分 + Integer fws_point = 0; + //高级服务商分佣金额 + BigDecimal gjfws_price = BigDecimal.ZERO; + //高级服务商分佣积分 + Integer gjfws_point = 0; + for (OrderGood orderGood : orderGoods) { + //上级获得分佣金额(直推上级|直帮上级) + BigDecimal superiorSubcommission = orderGood.getSuperiorSubcommission(); + //上级获得分佣积分(直推上级|直帮上级) + Integer superiorRebatePoints = orderGood.getSuperiorRebatePoints(); + zdls_price = zdls_price.add(superiorSubcommission); + zdls_point += superiorRebatePoints; + + //绑定门店分佣金额 + fws_price = fws_price.add(orderGood.getBoundShopCharges()); + //绑定门店分佣积分 + fws_point += orderGood.getBoundShopPoints(); + //绑定门店上级门店分佣金额 + gjfws_price = gjfws_price.add(orderGood.getBoundShopSuperiorsCharges()); + //绑定门店上级门店分佣积分 + gjfws_point += orderGood.getBoundShopSuperiorsPoints(); + } + + //直帮上级 + AppUser superiorLeader = appUserClient.getSuperiorLeader(appUser.getId()).getData(); + if(null == superiorLeader){ + log.error("指导老师查询失败"); + } + if(null != superiorLeader){ + BigDecimal balance = superiorLeader.getBalance(); + Integer lavePoint = superiorLeader.getLavePoint(); + if(zdls_price.compareTo(BigDecimal.ZERO) > 0){ +// superiorLeader.setTotalDistributionAmount(superiorLeader.getTotalDistributionAmount().add(zdls_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// superiorLeader.setBalance(superiorLeader.getBalance().add(zdls_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// superiorLeader.setWithdrawableAmount(superiorLeader.getWithdrawableAmount().add(zdls_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); + + //添加临时分佣数据 + AppUserGiveawayTemporary appUserGiveawayTemporary = new AppUserGiveawayTemporary(); + appUserGiveawayTemporary.setOrderId(order.getId()); + appUserGiveawayTemporary.setAppUserId(superiorLeader.getId()); + appUserGiveawayTemporary.setTotalDistributionAmount(zdls_price); + appUserGiveawayTemporary.setBalance(zdls_price); + appUserGiveawayTemporary.setWithdrawableAmount(zdls_price); + appUserGiveawayTemporaryClient.saveAppUserGiveawayTemporary(appUserGiveawayTemporary); + } + if(zdls_point > 0){ + PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); + int earnPoint1 = 0; + //计算可用积分比例 + if(null != pointSetting && 1 == pointSetting.getSharePointOpen()){ + earnPoint1 = new BigDecimal(zdls_point).multiply(pointSetting.getSharePoint().divide(new BigDecimal(100))).intValue(); + } +// superiorLeader.setSharePoint(superiorLeader.getSharePoint() + zdls_point); +// superiorLeader.setLavePoint(superiorLeader.getLavePoint() + zdls_point); +// superiorLeader.setAvailablePoint(superiorLeader.getAvailablePoint() + earnPoint1); +// superiorLeader.setTotalAvailablePoint(superiorLeader.getTotalAvailablePoint() + earnPoint1); +// if(null != pointSetting && 1 == pointSetting.getSharePointGift()){ +// superiorLeader.setTransferablePoint(superiorLeader.getTransferablePoint() + earnPoint1); +// } +// superiorLeader.setTotalPoint(superiorLeader.getTotalPoint() + zdls_point); + + //添加临时分佣数据 + AppUserGiveawayTemporary appUserGiveawayTemporary = new AppUserGiveawayTemporary(); + appUserGiveawayTemporary.setOrderId(order.getId()); + appUserGiveawayTemporary.setAppUserId(superiorLeader.getId()); + appUserGiveawayTemporary.setSharePoint(zdls_point); + appUserGiveawayTemporary.setLavePoint(zdls_point); + appUserGiveawayTemporary.setAvailablePoint(earnPoint1); + appUserGiveawayTemporary.setTotalAvailablePoint(earnPoint1); + if(null != pointSetting && 1 == pointSetting.getSharePointGift()){ + appUserGiveawayTemporary.setTransferablePoint(earnPoint1); + } + appUserGiveawayTemporary.setTotalPoint(zdls_point); + appUserGiveawayTemporaryClient.saveAppUserGiveawayTemporary(appUserGiveawayTemporary); + + } +// appUserClient.editAppUserById(superiorLeader); + //添加明细记录 + if(zdls_price.compareTo(BigDecimal.ZERO) > 0){ + //添加临时明细记录数据 + BalanceChangeRecordCopy balanceChangeRecordCopy = new BalanceChangeRecordCopy(); + balanceChangeRecordCopy.setAppUserId(superiorLeader.getId()); + balanceChangeRecordCopy.setVipId(superiorLeader.getVipId()); + balanceChangeRecordCopy.setOrderId(order.getId()); + balanceChangeRecordCopy.setChangeType(4); + balanceChangeRecordCopy.setChangeAmount(zdls_price); + balanceChangeRecordCopy.setDelFlag(0); + balanceChangeRecordCopy.setCreateTime(LocalDateTime.now()); + balanceChangeRecordCopy.setChangeDirection(1); + balanceChangeRecordClient.saveBalanceChangeRecordCopy(balanceChangeRecordCopy); + } + //添加积分明细 + if(zdls_point > 0){ + UserPointCopy userPointCopy = new UserPointCopy(); + userPointCopy.setType(2); + userPointCopy.setVariablePoint(zdls_point); + userPointCopy.setCreateTime(LocalDateTime.now()); + userPointCopy.setAppUserId(superiorLeader.getId()); + userPointCopy.setObjectId(order.getId()); + userPointCopy.setExtention(order.getOrderNumber()); + userPointCopy.setChangeDirection(1); + userPointClient.saveUserPointCopy(userPointCopy); + //变更等级 +// appUserClient.vipUpgrade(superiorLeader.getId()); + } + } + + //服务商分佣 + Shop shop1 = shopClient.getServiceProvider(appUser.getId()).getData(); + if(null == shop1){ + log.error("服务商查询失败"); + } + if(null != shop1){ + AppUser bdShopAppUser = appUserClient.getAppUserById(shop1.getAppUserId()); + if(null == bdShopAppUser){ + log.error("服务商用户查询失败"); + } + if(null != bdShopAppUser){ + BigDecimal shopBalance = shop1.getBalance(); + Integer lavePoint = bdShopAppUser.getLavePoint(); + Integer shopLavePoint = shop1.getLavePoint(); + if(fws_price.compareTo(BigDecimal.ZERO) > 0){ + //门店返佣 +// shop1.setGiveawayAllMoney(shop1.getGiveawayAllMoney().add(fws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// shop1.setGiveawayMoney(shop1.getGiveawayMoney().add(fws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// shop1.setCanWithdrawMoney(shop1.getCanWithdrawMoney().add(fws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// shop1.setBalance(shop1.getBalance().add(fws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); + + //添加临时数据 + ShopGiveawayTemporary shopGiveawayTemporary = new ShopGiveawayTemporary(); + shopGiveawayTemporary.setShopId(shop1.getId()); + shopGiveawayTemporary.setOrderId(order.getId()); + shopGiveawayTemporary.setGiveawayAllMoney(fws_price); + shopGiveawayTemporary.setGiveawayMoney(fws_price); + shopGiveawayTemporary.setCanWithdrawMoney(fws_price); + shopGiveawayTemporary.setBalance(fws_price); + shopGiveawayTemporaryClient.saveShopGiveawayTemporary(shopGiveawayTemporary); + } + if(fws_point > 0){ + PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); + int earnPoint1 = 0; + //计算可用积分比例 + if(null != pointSetting && 1 == pointSetting.getShopSharePointOpen()){ + earnPoint1 = new BigDecimal(fws_point).multiply(pointSetting.getShopSharePoint().divide(new BigDecimal(100))).intValue(); + } +// bdShopAppUser.setLavePoint(bdShopAppUser.getLavePoint() + fws_point); +// bdShopAppUser.setAvailablePoint(bdShopAppUser.getAvailablePoint() + earnPoint1); +// bdShopAppUser.setTotalAvailablePoint(bdShopAppUser.getTotalAvailablePoint() + earnPoint1); +// if(null != pointSetting && 1 == pointSetting.getShopSharePointGift()){ +// bdShopAppUser.setTransferablePoint(bdShopAppUser.getTransferablePoint() + earnPoint1); +// } +// bdShopAppUser.setTotalPoint(bdShopAppUser.getTotalPoint() + fws_point); +// bdShopAppUser.setShopSharePoint(bdShopAppUser.getShopSharePoint() + fws_point); + + //添加临时分佣数据 + AppUserGiveawayTemporary appUserGiveawayTemporary = new AppUserGiveawayTemporary(); + appUserGiveawayTemporary.setOrderId(order.getId()); + appUserGiveawayTemporary.setAppUserId(bdShopAppUser.getId()); + appUserGiveawayTemporary.setLavePoint(fws_point); + appUserGiveawayTemporary.setAvailablePoint(earnPoint1); + appUserGiveawayTemporary.setTotalAvailablePoint(earnPoint1); + if(null != pointSetting && 1 == pointSetting.getShopSharePointGift()){ + appUserGiveawayTemporary.setTransferablePoint(earnPoint1); + } + appUserGiveawayTemporary.setTotalPoint(fws_point); + appUserGiveawayTemporary.setShopSharePoint(fws_point); + appUserGiveawayTemporaryClient.saveAppUserGiveawayTemporary(appUserGiveawayTemporary); + + //门店返佣 +// shop1.setShopAllPoint(shop1.getShopAllPoint() + fws_point); +// shop1.setSharePoint(shop1.getSharePoint() + fws_point); +// shop1.setLavePoint(shop1.getLavePoint() + fws_point); + //添加临时分佣数据 + ShopGiveawayTemporary shopGiveawayTemporary = new ShopGiveawayTemporary(); + shopGiveawayTemporary.setShopId(shop1.getId()); + shopGiveawayTemporary.setOrderId(order.getId()); + shopGiveawayTemporary.setShopAllPoint(fws_point); + shopGiveawayTemporary.setSharePoint(fws_point); + shopGiveawayTemporary.setLavePoint(fws_point); + shopGiveawayTemporaryClient.saveShopGiveawayTemporary(shopGiveawayTemporary); + } +// appUserClient.editAppUserById(bdShopAppUser); +// shopClient.updateShop(shop1); + //添加明细记录 + if(fws_price.compareTo(BigDecimal.ZERO) > 0){ + ShopBalanceStatementCopy shopBalanceStatementCopy = new ShopBalanceStatementCopy(); + shopBalanceStatementCopy.setShopId(shop1.getId()); + shopBalanceStatementCopy.setType(1); + shopBalanceStatementCopy.setVariableAmount(fws_price); + shopBalanceStatementCopy.setCreateTime(LocalDateTime.now()); + shopBalanceStatementCopy.setCreateUserId(order.getAppUserId()); + shopBalanceStatementCopy.setObjectId(order.getId()); + shopBalanceStatementCopy.setExtension(order.getOrderNumber()); + shopBalanceStatementCopy.setChangeDirection(1); + shopBalanceStatementClient.saveShopBalanceStatementCopy(shopBalanceStatementCopy); + } + //添加积分明细 + if(fws_point > 0){ + UserPointCopy userPointCopy = new UserPointCopy(); + userPointCopy.setType(9); + userPointCopy.setVariablePoint(fws_point); + userPointCopy.setCreateTime(LocalDateTime.now()); + userPointCopy.setAppUserId(bdShopAppUser.getId()); + userPointCopy.setObjectId(order.getId()); + userPointCopy.setExtention(order.getOrderNumber()); + userPointCopy.setChangeDirection(1); + userPointClient.saveUserPointCopy(userPointCopy); + //变更等级 +// appUserClient.vipUpgrade(bdShopAppUser.getId()); + } + + if(fws_point > 0){ + ShopPointCopy shopPointCopy = new ShopPointCopy(); + shopPointCopy.setShopId(shop1.getId()); + shopPointCopy.setType(2); + shopPointCopy.setVariablePoint(fws_point); + shopPointCopy.setCreateTime(LocalDateTime.now()); + shopPointCopy.setCreateUserId(order.getAppUserId()); + shopPointCopy.setObjectId(order.getId()); + shopPointCopy.setOrderNum(order.getOrderNumber()); + shopPointCopy.setChangeDirection(1); + shopPointClient.saveShopPointCopy(shopPointCopy); + } + } + } + + //高级服务商 + Shop shop2 = shopClient.getSuperiorServiceProvider(order.getAppUserId()).getData(); + if(null == shop2){ + log.error("高级服务商查询失败"); + } + if(null != shop2){ + AppUser sjShopAppUser = appUserClient.getAppUserById(shop2.getAppUserId()); + if(null == sjShopAppUser){ + log.error("高级服务商用户查询失败"); + } + if(null != sjShopAppUser){ + BigDecimal shopBalance = shop2.getBalance(); + Integer lavePoint = sjShopAppUser.getLavePoint(); + Integer shopLavePoint = shop2.getLavePoint(); + if(gjfws_price.compareTo(BigDecimal.ZERO) > 0){ + //门店返佣 +// shop2.setGiveawayAllMoney(shop2.getGiveawayAllMoney().add(gjfws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// shop2.setLowerLevelGiveawayMoney(shop2.getLowerLevelGiveawayMoney().add(gjfws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// shop2.setCanWithdrawMoney(shop2.getCanWithdrawMoney().add(gjfws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); +// shop2.setBalance(shop2.getBalance().add(gjfws_price).setScale(2, BigDecimal.ROUND_HALF_EVEN)); + + //添加临时分佣数据 + ShopGiveawayTemporary shopGiveawayTemporary = new ShopGiveawayTemporary(); + shopGiveawayTemporary.setShopId(shop2.getId()); + shopGiveawayTemporary.setOrderId(order.getId()); + shopGiveawayTemporary.setGiveawayAllMoney(gjfws_price); + shopGiveawayTemporary.setLowerLevelGiveawayMoney(gjfws_price); + shopGiveawayTemporary.setCanWithdrawMoney(gjfws_price); + shopGiveawayTemporary.setBalance(gjfws_price); + shopGiveawayTemporaryClient.saveShopGiveawayTemporary(shopGiveawayTemporary); + + } + if(gjfws_point > 0){ + PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); + int earnPoint1 = 0; + //计算可用积分比例 + if(null != pointSetting && 1 == pointSetting.getShopSharePointOpen()){ + earnPoint1 = new BigDecimal(gjfws_point).multiply(pointSetting.getShopSharePoint().divide(new BigDecimal(100))).intValue(); + } +// sjShopAppUser.setLavePoint(sjShopAppUser.getLavePoint() + gjfws_point); +// sjShopAppUser.setAvailablePoint(sjShopAppUser.getAvailablePoint() + earnPoint1); +// sjShopAppUser.setTotalAvailablePoint(sjShopAppUser.getTotalAvailablePoint() + earnPoint1); +// if(null != pointSetting && 1 == pointSetting.getShopSharePointGift()){ +// sjShopAppUser.setTransferablePoint(sjShopAppUser.getTransferablePoint() + earnPoint1); +// } +// sjShopAppUser.setTotalPoint(sjShopAppUser.getTotalPoint() + gjfws_point); +// sjShopAppUser.setLowerLevelSharePoint(sjShopAppUser.getLowerLevelSharePoint() + gjfws_point); + + //添加临时分佣数据 + AppUserGiveawayTemporary appUserGiveawayTemporary = new AppUserGiveawayTemporary(); + appUserGiveawayTemporary.setOrderId(order.getId()); + appUserGiveawayTemporary.setAppUserId(sjShopAppUser.getId()); + appUserGiveawayTemporary.setLavePoint(gjfws_point); + appUserGiveawayTemporary.setAvailablePoint(earnPoint1); + appUserGiveawayTemporary.setTotalAvailablePoint(earnPoint1); + if(null != pointSetting && 1 == pointSetting.getShopSharePointGift()){ + appUserGiveawayTemporary.setTransferablePoint(earnPoint1); + } + appUserGiveawayTemporary.setTotalPoint(gjfws_point); + appUserGiveawayTemporary.setLowerLevelSharePoint(gjfws_point); + appUserGiveawayTemporaryClient.saveAppUserGiveawayTemporary(appUserGiveawayTemporary); + + + //门店返佣 +// shop2.setShopAllPoint(shop2.getShopAllPoint() + gjfws_point); +// shop2.setLowerLevelSharePoint(shop2.getLowerLevelSharePoint() + gjfws_point); +// shop2.setLavePoint(shop2.getLavePoint() + gjfws_point); + + //添加临时分佣数据 + ShopGiveawayTemporary shopGiveawayTemporary = new ShopGiveawayTemporary(); + shopGiveawayTemporary.setShopId(shop2.getId()); + shopGiveawayTemporary.setOrderId(order.getId()); + shopGiveawayTemporary.setShopAllPoint(gjfws_point); + shopGiveawayTemporary.setLowerLevelSharePoint(gjfws_point); + shopGiveawayTemporary.setLavePoint(gjfws_point); + shopGiveawayTemporaryClient.saveShopGiveawayTemporary(shopGiveawayTemporary); + + } +// appUserClient.editAppUserById(sjShopAppUser); +// shopClient.updateShop(shop2); + //添加明细记录 + if(gjfws_price.compareTo(BigDecimal.ZERO) > 0){ + ShopBalanceStatementCopy shopBalanceStatementCopy = new ShopBalanceStatementCopy(); + shopBalanceStatementCopy.setShopId(shop2.getId()); + shopBalanceStatementCopy.setType(2); + shopBalanceStatementCopy.setVariableAmount(gjfws_price); + shopBalanceStatementCopy.setCreateTime(LocalDateTime.now()); + shopBalanceStatementCopy.setCreateUserId(order.getAppUserId()); + shopBalanceStatementCopy.setObjectId(order.getId()); + shopBalanceStatementCopy.setExtension(order.getOrderNumber()); + shopBalanceStatementCopy.setChangeDirection(1); + shopBalanceStatementClient.saveShopBalanceStatementCopy(shopBalanceStatementCopy); + } + //添加积分明细 + if(gjfws_point > 0){ + UserPointCopy userPointCopy = new UserPointCopy(); + userPointCopy.setType(14); + userPointCopy.setVariablePoint(gjfws_point); + userPointCopy.setCreateTime(LocalDateTime.now()); + userPointCopy.setAppUserId(sjShopAppUser.getId()); + userPointCopy.setObjectId(order.getId()); + userPointCopy.setExtention(order.getOrderNumber()); + userPointCopy.setChangeDirection(1); + userPointClient.saveUserPointCopy(userPointCopy); + //变更等级 +// appUserClient.vipUpgrade(sjShopAppUser.getId()); + } + + if(gjfws_point > 0){ + ShopPointCopy shopPointCopy = new ShopPointCopy(); + shopPointCopy.setShopId(shop2.getId()); + shopPointCopy.setType(3); + shopPointCopy.setVariablePoint(gjfws_point); + shopPointCopy.setCreateTime(LocalDateTime.now()); + shopPointCopy.setCreateUserId(order.getAppUserId()); + shopPointCopy.setObjectId(order.getId()); + shopPointCopy.setOrderNum(order.getOrderNumber()); + shopPointCopy.setChangeDirection(1); + shopPointClient.saveShopPointCopy(shopPointCopy); + } + } + } + + //自提单品和服务需要走线下核销流程 + if(order.getOrderType() == 2 && order.getDistributionMode() == 2){ + order.setIsCommission(2); + }else{ + order.setIsCommission(1); + } + orderService.updateById(order); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public void calculationCommissionShop(Long orderId) { + Order order = orderService.getById(orderId); + //快递单品不进行分佣 + if(order.getOrderType() == 2 && order.getDistributionMode() == 2){ + return; + } + List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>() + .eq(OrderGood::getOrderId, order.getId())); + AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); + if(null == appUser){ + return; + } + //核销门店分佣金额 + BigDecimal hxmd_price = BigDecimal.ZERO; + //核销门店分佣积分 + Integer hxmd_point = 0; + //技师分佣积分 + Integer js_point = 0; + for (OrderGood orderGood : orderGoods) { + //核销门店获取服务费 + hxmd_price = hxmd_price.add(orderGood.getServuceShopCharges()); + //核销门店可获得积分 + hxmd_point += orderGood.getServuceShopPoints(); + //技师分佣金额 if(order.getOrderType() == 1){ - Technician technician = technicianClient.shopdetail(order.getTechnicianId()).getData(); - if(null != technician){ - AppUser technicianAppUser = appUserClient.getAppUserById(technician.getAppUserId()); + js_point += orderGood.getTechnicianPoints(); + } + } + + //核销门店 + Shop shop = shopClient.getShopById(order.getShopId()).getData(); + AppUser shopAppUser = appUserClient.getAppUserById(shop.getAppUserId()); + if(null == shopAppUser){ + log.error("核销门店用户查询失败"); + } + if(null != shopAppUser){ + BigDecimal shopBalance = shop.getBalance(); + Integer lavePoint = shopAppUser.getLavePoint(); + Integer shopLavePoint = shop.getLavePoint(); + if(hxmd_price.compareTo(BigDecimal.ZERO) > 0){ + //门店返佣 +// 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)); + + //添加临时分佣数据 + ShopGiveawayTemporary shopGiveawayTemporary = new ShopGiveawayTemporary(); + shopGiveawayTemporary.setShopId(shop.getId()); + shopGiveawayTemporary.setOrderId(order.getId()); + shopGiveawayTemporary.setGiveawayAllMoney(hxmd_price); + shopGiveawayTemporary.setServerGiveawayMoney(hxmd_price); + shopGiveawayTemporary.setCanWithdrawMoney(hxmd_price); + shopGiveawayTemporary.setBalance(hxmd_price); + shopGiveawayTemporaryClient.saveShopGiveawayTemporary(shopGiveawayTemporary); + } + if(hxmd_point > 0){ + PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); + int earnPoint1 = 0; + //计算可用积分比例 + if(null != pointSetting && 1 == pointSetting.getShopPointOpen()){ + earnPoint1 = new BigDecimal(hxmd_point).multiply(pointSetting.getShopPoint().divide(new BigDecimal(100))).intValue(); + } +// shopAppUser.setLavePoint(shopAppUser.getLavePoint() + hxmd_point); +// shopAppUser.setAvailablePoint(shopAppUser.getAvailablePoint() + earnPoint1); +// shopAppUser.setTotalAvailablePoint(shopAppUser.getTotalAvailablePoint() + earnPoint1); +// if(null != pointSetting && 1 == pointSetting.getShopPointGift()){ +// shopAppUser.setTransferablePoint(shopAppUser.getTransferablePoint() + earnPoint1); +// } +// shopAppUser.setTotalPoint(shopAppUser.getTotalPoint() + hxmd_point); +// shopAppUser.setShopAchievementPoint(shopAppUser.getShopAchievementPoint() + hxmd_point); + + //添加临时分佣数据 + AppUserGiveawayTemporary appUserGiveawayTemporary = new AppUserGiveawayTemporary(); + appUserGiveawayTemporary.setOrderId(order.getId()); + appUserGiveawayTemporary.setAppUserId(shopAppUser.getId()); + appUserGiveawayTemporary.setLavePoint(hxmd_point); + appUserGiveawayTemporary.setAvailablePoint(earnPoint1); + appUserGiveawayTemporary.setTotalAvailablePoint(earnPoint1); + if(null != pointSetting && 1 == pointSetting.getShopPointGift()){ + appUserGiveawayTemporary.setTransferablePoint(earnPoint1); + } + appUserGiveawayTemporary.setTotalPoint(hxmd_point); + appUserGiveawayTemporary.setShopAchievementPoint(hxmd_point); + appUserGiveawayTemporaryClient.saveAppUserGiveawayTemporary(appUserGiveawayTemporary); + + + //门店返佣 +// shop.setShopAllPoint(shop.getShopAllPoint() + hxmd_point); +// shop.setServerPoint(shop.getServerPoint() + hxmd_point); +// shop.setLavePoint(shop.getLavePoint() + hxmd_point); + + //添加临时分佣数据 + ShopGiveawayTemporary shopGiveawayTemporary = new ShopGiveawayTemporary(); + shopGiveawayTemporary.setShopId(shop.getId()); + shopGiveawayTemporary.setOrderId(order.getId()); + shopGiveawayTemporary.setShopAllPoint(hxmd_point); + shopGiveawayTemporary.setServerPoint(hxmd_point); + shopGiveawayTemporary.setLavePoint(hxmd_point); + shopGiveawayTemporaryClient.saveShopGiveawayTemporary(shopGiveawayTemporary); + } +// appUserClient.editAppUserById(shopAppUser); +// shopClient.updateShop(shop); + //添加明细记录 + if(hxmd_price.compareTo(BigDecimal.ZERO) > 0){ + ShopBalanceStatementCopy shopBalanceStatementCopy = new ShopBalanceStatementCopy(); + shopBalanceStatementCopy.setShopId(shop.getId()); + shopBalanceStatementCopy.setType(3); + shopBalanceStatementCopy.setVariableAmount(hxmd_price); + shopBalanceStatementCopy.setCreateTime(LocalDateTime.now()); + shopBalanceStatementCopy.setCreateUserId(order.getAppUserId()); + shopBalanceStatementCopy.setObjectId(order.getId()); + shopBalanceStatementCopy.setExtension(order.getOrderNumber()); + shopBalanceStatementCopy.setChangeDirection(1); + shopBalanceStatementClient.saveShopBalanceStatementCopy(shopBalanceStatementCopy); + } + //添加积分明细 + if(hxmd_point > 0){ + UserPointCopy userPointCopy = new UserPointCopy(); + userPointCopy.setType(8); + userPointCopy.setVariablePoint(hxmd_point); + userPointCopy.setCreateTime(LocalDateTime.now()); + userPointCopy.setAppUserId(shopAppUser.getId()); + userPointCopy.setObjectId(order.getId()); + userPointCopy.setExtention(order.getOrderNumber()); + userPointCopy.setChangeDirection(1); + userPointClient.saveUserPointCopy(userPointCopy); + //变更等级 +// appUserClient.vipUpgrade(shopAppUser.getId()); + } + + if(hxmd_point > 0){ + ShopPointCopy shopPointCopy = new ShopPointCopy(); + shopPointCopy.setShopId(shop.getId()); + shopPointCopy.setType(1); + shopPointCopy.setVariablePoint(hxmd_point); + shopPointCopy.setCreateTime(LocalDateTime.now()); + shopPointCopy.setCreateUserId(order.getAppUserId()); + shopPointCopy.setObjectId(order.getId()); + shopPointCopy.setOrderNum(order.getOrderNumber()); + shopPointCopy.setChangeDirection(1); + shopPointClient.saveShopPointCopy(shopPointCopy); + } + } + + //技师服务积分 + if(order.getOrderType() == 1){ + Technician technician = technicianClient.shopdetail(order.getTechnicianId()).getData(); + if(null == technician){ + log.error("技师查询失败"); + } + if(null != technician){ + AppUser technicianAppUser = appUserClient.getAppUserById(technician.getAppUserId()); + if(null != technicianAppUser){ Integer lavePoint = technicianAppUser.getLavePoint(); if(js_point > 0){ PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); @@ -354,205 +785,54 @@ if(null != pointSetting && 1 == pointSetting.getPersonPointOpen()){ earnPoint1 = new BigDecimal(js_point).multiply(pointSetting.getPersonPoint().divide(new BigDecimal(100))).intValue(); } - technicianAppUser.setLavePoint(technicianAppUser.getLavePoint() + js_point); - technicianAppUser.setAvailablePoint(technicianAppUser.getAvailablePoint() + earnPoint1); - technicianAppUser.setTotalAvailablePoint(technicianAppUser.getTotalAvailablePoint() + earnPoint1); +// technicianAppUser.setLavePoint(technicianAppUser.getLavePoint() + js_point); +// technicianAppUser.setAvailablePoint(technicianAppUser.getAvailablePoint() + earnPoint1); +// technicianAppUser.setTotalAvailablePoint(technicianAppUser.getTotalAvailablePoint() + earnPoint1); +// if(null != pointSetting && 1 == pointSetting.getPersonPointGift()){ +// technicianAppUser.setTransferablePoint(technicianAppUser.getTransferablePoint() + earnPoint1); +// } +// technicianAppUser.setTotalPoint(technicianAppUser.getTotalPoint() + js_point); +// technicianAppUser.setTotalPerformancePoint(technicianAppUser.getTotalPerformancePoint() + js_point); + + //添加临时分佣数据 + AppUserGiveawayTemporary appUserGiveawayTemporary = new AppUserGiveawayTemporary(); + appUserGiveawayTemporary.setOrderId(order.getId()); + appUserGiveawayTemporary.setAppUserId(technicianAppUser.getId()); + appUserGiveawayTemporary.setLavePoint(js_point); + appUserGiveawayTemporary.setAvailablePoint(earnPoint1); + appUserGiveawayTemporary.setTotalAvailablePoint(earnPoint1); if(null != pointSetting && 1 == pointSetting.getPersonPointGift()){ - technicianAppUser.setTransferablePoint(technicianAppUser.getTransferablePoint() + earnPoint1); + appUserGiveawayTemporary.setTransferablePoint(earnPoint1); } - technicianAppUser.setTotalPoint(technicianAppUser.getTotalPoint() + js_point); - technicianAppUser.setTotalPerformancePoint(technicianAppUser.getTotalPerformancePoint() + js_point); + appUserGiveawayTemporary.setTotalPoint(js_point); + appUserGiveawayTemporary.setTotalPerformancePoint(js_point); + appUserGiveawayTemporaryClient.saveAppUserGiveawayTemporary(appUserGiveawayTemporary); + } - appUserClient.editAppUserById(technicianAppUser); +// 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); + if(js_point > 0){ + UserPointCopy userPointCopy = new UserPointCopy(); + userPointCopy.setType(10); + userPointCopy.setVariablePoint(js_point); + userPointCopy.setCreateTime(LocalDateTime.now()); + userPointCopy.setAppUserId(technicianAppUser.getId()); + userPointCopy.setObjectId(order.getId()); + userPointCopy.setExtention(order.getOrderNumber()); + userPointCopy.setChangeDirection(1); + userPointClient.saveUserPointCopy(userPointCopy); //变更等级 - appUserClient.vipUpgrade(technicianAppUser.getId()); +// appUserClient.vipUpgrade(technicianAppUser.getId()); } } - } - //绑定门店分佣 - Shop shop1 = shopClient.getShopById(appUser.getShopId()).getData(); - if(null != shop1){ - AppUser bdShopAppUser = appUserClient.getAppUserById(shop1.getAppUserId()); - if(null != bdShopAppUser){ - BigDecimal shopBalance = shop1.getBalance(); - Integer lavePoint = bdShopAppUser.getLavePoint(); - Integer shopLavePoint = shop1.getLavePoint(); - if(bdmd_price.compareTo(BigDecimal.ZERO) > 0){ - //门店返佣 - 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){ - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getShopSharePointOpen()){ - earnPoint1 = new BigDecimal(bdmd_point).multiply(pointSetting.getShopSharePoint().divide(new BigDecimal(100))).intValue(); - } - bdShopAppUser.setLavePoint(bdShopAppUser.getLavePoint() + bdmd_point); - bdShopAppUser.setAvailablePoint(bdShopAppUser.getAvailablePoint() + earnPoint1); - bdShopAppUser.setTotalAvailablePoint(bdShopAppUser.getTotalAvailablePoint() + earnPoint1); - if(null != pointSetting && 1 == pointSetting.getShopSharePointGift()){ - bdShopAppUser.setTransferablePoint(bdShopAppUser.getTransferablePoint() + earnPoint1); - } - bdShopAppUser.setTotalPoint(bdShopAppUser.getTotalPoint() + bdmd_point); - bdShopAppUser.setShopSharePoint(bdShopAppUser.getShopSharePoint() + 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(!shop1.getBalance().equals(shopBalance)){ - ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement(); - shopBalanceStatement.setShopId(shop1.getId()); - shopBalanceStatement.setType(1); - 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); - //变更等级 - appUserClient.vipUpgrade(bdShopAppUser.getId()); - } - - 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); - } - } } - - //上级门店分佣 - if(null != shop1){ - Integer pid = shop1.getPid(); - Shop shop2 = shopClient.getShopById(pid).getData(); - if(null != shop2){ - AppUser sjShopAppUser = appUserClient.getAppUserById(shop2.getAppUserId()); - if(null != sjShopAppUser){ - BigDecimal shopBalance = shop2.getBalance(); - Integer lavePoint = sjShopAppUser.getLavePoint(); - Integer shopLavePoint = shop2.getLavePoint(); - if(bdmdsj_price.compareTo(BigDecimal.ZERO) > 0){ - //门店返佣 - 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){ - PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); - int earnPoint1 = 0; - //计算可用积分比例 - if(null != pointSetting && 1 == pointSetting.getShopSharePointOpen()){ - earnPoint1 = new BigDecimal(bdmdsj_point).multiply(pointSetting.getShopSharePoint().divide(new BigDecimal(100))).intValue(); - } - sjShopAppUser.setLavePoint(sjShopAppUser.getLavePoint() + bdmdsj_point); - sjShopAppUser.setAvailablePoint(sjShopAppUser.getAvailablePoint() + earnPoint1); - sjShopAppUser.setTotalAvailablePoint(sjShopAppUser.getTotalAvailablePoint() + earnPoint1); - if(null != pointSetting && 1 == pointSetting.getShopSharePointGift()){ - sjShopAppUser.setTransferablePoint(sjShopAppUser.getTransferablePoint() + earnPoint1); - } - sjShopAppUser.setTotalPoint(sjShopAppUser.getTotalPoint() + bdmdsj_point); - sjShopAppUser.setLowerLevelSharePoint(sjShopAppUser.getLowerLevelSharePoint() + bdmdsj_point); - //门店返佣 - shop2.setShopAllPoint(shop2.getShopAllPoint() + bdmdsj_point); - shop2.setLowerLevelSharePoint(shop2.getLowerLevelSharePoint() + bdmdsj_point); - shop2.setLavePoint(shop2.getLavePoint() + bdmdsj_point); - } - appUserClient.editAppUserById(sjShopAppUser); - shopClient.updateShop(shop2); - //添加明细记录 - 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); - //变更等级 - appUserClient.vipUpgrade(sjShopAppUser.getId()); - } - - 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); - } - } - } - } - - order.setIsCommission(1); - orderService.updateById(order); } + + order.setIsCommission(2); + orderService.updateById(order); } + + + } -- Gitblit v1.7.1