| 
					
				 | 
			
			
				@@ -11,6 +11,7 @@ import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPerce 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofit.PtProfitDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.newfeifan.mall.module.distri.enums.CaclEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.newfeifan.mall.module.distri.enums.SocialStatusEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.newfeifan.mall.module.distri.mq.message.order.OrderCalcMessage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.newfeifan.mall.module.distri.mq.message.order.OrderItemMessage; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -198,13 +199,14 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 计算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 计算利润: (价格 - 成本价格) * 产品数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            final BigDecimal[] profit = {new BigDecimal("0")}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            final BigDecimal[] profit = {new BigDecimal("0"),new BigDecimal("0")};      //用户自得不用要计算,从orderItem里面获取 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             k.getOrderItemMessages().forEach(j -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 BigDecimal onePrice = new BigDecimal(j.getPrice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 BigDecimal oneCostPrice = new BigDecimal(j.getCostPrice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 BigDecimal productCount = new BigDecimal(j.getCount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 profit[0] = profit[0].add(oneGrossProfit);  // 注意这里的改动 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                profit[1] = profit[1].add(new BigDecimal(j.getIncreaseIntegral()));     //自得积分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -219,7 +221,7 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 用户所得: 毛利 * 0.35 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            BigDecimal descendantQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitUserQuotaPerc())).setScale(4, RoundingMode.DOWN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal descendantQuota = profit[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 直推奖: 毛利 * 0.35 (上一级) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal ancestorQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc())).setScale(4, RoundingMode.DOWN); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -237,7 +239,7 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 乘以 10000 并转换为整数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Long grossProfitInt = grossProfit.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Long ancestorQuotaInt = ancestorQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Long descendantQuotaInt = descendantQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long descendantQuotaInt = descendantQuota.longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Long bonusQuotaInt = bonusQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Long highQuotaInt = highQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Long grossProfitAfterBonusInt = grossProfitAfterBonus.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -250,6 +252,20 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             IntegralDO ptIntegral = integralService.selectByUser(1L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // ========== 身价计算 ============== 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //推荐人身价计算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal orderAncestorSocialStatus = new BigDecimal(orderPercentageDO.getOrderAncestorSocialStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long ancestorSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderAncestorSocialStatus.longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            duserService.updateDuserSocial(integralDOAncestor.getUserId(), ancestorSocial, SocialStatusEnum.SHOPPING_ANCESTOR_SOCIAL.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //自得身价计算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal orderUserSocialStatus = new BigDecimal(orderPercentageDO.getOrderUserSocialStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long descendantSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderUserSocialStatus.longValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            duserService.updateDuserSocial(integralDOAncestor.getUserId(), descendantSocial, SocialStatusEnum.SHOPPING_SOCIAL.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // ========== 汇总计算 ================= 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             OrderCalcSaveReqVO orderCalcSaveReqVO = OrderCalcSaveReqVO.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .userId(k.getUserId()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -267,7 +283,8 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .percentTemplate(percentTemplate).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             saveList.add(orderCalcSaveReqVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // ========== 修改用户钱包 ================= 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt, descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // ========== 修改平台信息 ================= 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 每个订单计算的过程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 增加平台收益 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -303,6 +320,9 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 直推人记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).amount(descendantQuotaInt).afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt).percentTemplate(percentTemplate).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 直推人冻结积分转化成可用记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            PtProfitLogSaveReqVO freezeLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.FREEZE_CHANGE_INTEGRAL.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).freezeAmount(descendantQuotaInt).afterFreezeAmount(integralDO.getCurrentQuota() - descendantQuotaInt).percentTemplate(percentTemplate).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             PtProfitLogSaveReqVO highQuotaLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.HIGH_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).amount(highQuotaInt).afterAmount(integralDO.getHighQuota() + highQuotaInt).percentTemplate(percentTemplate).build(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 合赢奖记录 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -314,6 +334,7 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ptProfitLogSaveReqVOS.add(ptAddLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ptProfitLogSaveReqVOS.add(tjrLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ptProfitLogSaveReqVOS.add(ztrLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ptProfitLogSaveReqVOS.add(freezeLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ptProfitLogSaveReqVOS.add(hyjLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ptProfitLogSaveReqVOS.add(highQuotaLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -386,6 +407,7 @@ public class OrderCalcServiceImpl implements OrderCalcService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // todo 增加累计额度 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        integralDO.setFreezeQuota(integralDO.getFreezeQuota() - descendantQuota); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 增加推荐人额度 
			 |