diff --git a/ghy-order/pom.xml b/ghy-order/pom.xml
index 7c5a6c76..b9e2a413 100644
--- a/ghy-order/pom.xml
+++ b/ghy-order/pom.xml
@@ -33,6 +33,11 @@
ghy-worker
+
+ com.ghy
+ ghy-custom
+
+
com.ghy
ghy-payment
diff --git a/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java b/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java
index 9950a90b..323f9601 100644
--- a/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java
+++ b/ghy-order/src/main/java/com/ghy/order/service/impl/OrderDetailServiceImpl.java
@@ -13,9 +13,14 @@ import com.ghy.common.exception.base.BaseException;
import com.ghy.common.utils.AdapayUtils;
import com.ghy.common.utils.MoneyUtil;
import com.ghy.common.utils.ObjectUtils;
+import com.ghy.common.utils.StringUtils;
+import com.ghy.customer.domain.Customer;
+import com.ghy.customer.service.CustomerService;
import com.ghy.goods.domain.DeptGoodsCategory;
+import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.domain.GoodsStandard;
import com.ghy.goods.service.DeptGoodsCategoryService;
+import com.ghy.goods.service.GoodsCategoryService;
import com.ghy.goods.service.GoodsStandardService;
import com.ghy.order.domain.*;
import com.ghy.order.mapper.OrderAddSubtractMapper;
@@ -100,6 +105,9 @@ public class OrderDetailServiceImpl implements OrderDetailService {
@Resource
private DeptGoodsCategoryService deptGoodsCategoryService;
+ @Resource
+ private CustomerService customerService;
+
// Adapay 手续费率 默认0.008
@Value("${adapay.fee_rate:0.008}")
private String feeRate;
@@ -478,7 +486,10 @@ public class OrderDetailServiceImpl implements OrderDetailService {
Long goodsStandardId = orderGoods.get(0).getGoodsStandardId();
GoodsStandard goodsStandard = goodsStandardService.selectById(goodsStandardId);
- DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId());
+ // 第四级规格
+ DeptGoodsCategory childCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId());
+ // 需要找第三级规格
+ DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(childCategory.getParentCategoryId());
// 修改子订单状态为完成
updateStatus(orderDetailId, OrderStatus.FINISH.code());
@@ -493,6 +504,31 @@ public class OrderDetailServiceImpl implements OrderDetailService {
// 子单收款人的memberId
String memberId = AdapayUtils.getWorkerMemberId(financialDetail.getPayeeId(), deptId);
String masterMemberId = AdapayUtils.getWorkerMemberId(workerMaster.getWorkerId(), deptId);
+ String placeId = null;
+ String parentPlaceId = null;
+
+
+ // 一级分销追加扣点
+ BigDecimal saleRateOne = new BigDecimal(deptGoodsCategory.getOneRate());
+ saleRateOne = MoneyUtil.lt0(saleRateOne) ? BigDecimal.ZERO : saleRateOne;
+
+ // 二级分销追加扣点
+ BigDecimal saleRateTwo = new BigDecimal(deptGoodsCategory.getTwoRate());
+ saleRateTwo = MoneyUtil.lt0(saleRateTwo) ? BigDecimal.ZERO : saleRateTwo;
+
+ // 三级分销追加扣点
+ BigDecimal saleRateThree = new BigDecimal(deptGoodsCategory.getThreeRate());
+ saleRateThree = MoneyUtil.lt0(saleRateThree) ? BigDecimal.ZERO : saleRateThree;
+
+ Customer customer = customerService.selectByCustomerId(orderMaster.getCustomerId());
+ // 一级分销售
+ if(customer.getCustomerPlace() != null && customer.getParentCustomerPlace() == null){
+ placeId = AdapayUtils.getCustomerMemberId(customer.getCustomerPlace(), deptId);
+ saleRateOne = saleRateOne.add(saleRateTwo).add(saleRateThree);
+ }else if(customer.getCustomerPlace() != null && customer.getParentCustomerPlace() != null){
+ parentPlaceId = AdapayUtils.getCustomerMemberId(customer.getParentCustomerPlace(), deptId);
+ saleRateTwo = saleRateTwo.add(saleRateThree);
+ }
// 大师傅提成
BigDecimal teamRete = new BigDecimal(workerMaster.getLeaderTeamRate());
@@ -513,7 +549,7 @@ public class OrderDetailServiceImpl implements OrderDetailService {
BigDecimal dtx = BigDecimal.ZERO;
// 追加金额分账
- BigDecimal dtx1 = addPaymentConfirm(orderDetailId, deptId, memberId, masterMemberId, teamRete, teamMoney, pcDeptRate, pcDeptMoney);
+ BigDecimal dtx1 = this.addPaymentConfirm(orderDetailId, deptId, memberId, masterMemberId, teamRete, teamMoney, pcDeptRate, pcDeptMoney, placeId, saleRateOne, parentPlaceId, saleRateTwo);
dtx = dtx.add(dtx1);
// 改价单分账
@@ -709,12 +745,16 @@ public class OrderDetailServiceImpl implements OrderDetailService {
* @throws BaseAdaPayException AdaPay分账接口可能抛出的异常
*/
private BigDecimal addPaymentConfirm(Long orderDetailId, Long deptId, String memberId, String masterMemberId,
- BigDecimal teamRete, BigDecimal teamMoney, BigDecimal pcDeptRate, BigDecimal pcDeptMoney) throws BaseAdaPayException {
+ BigDecimal teamRete, BigDecimal teamMoney, BigDecimal pcDeptRate, BigDecimal pcDeptMoney,
+ BigDecimal oneRate, String placeOne, BigDecimal twoRate, String placeTwo) throws BaseAdaPayException {
BigDecimal dtx = BigDecimal.ZERO;
List oasList = orderAddSubtractMapper.select(new OrderAddSubtract()
.setOrderDetailId(orderDetailId).setPayStatus(PayStatus.PAID.getCode()));
List adds = oasList.stream().filter(oas -> MoneyUtil.gt0(oas.getMoney())).collect(Collectors.toList());
for (OrderAddSubtract oas : adds) {
+ BigDecimal placeOneMoney = BigDecimal.ZERO;
+ BigDecimal placeTwoMoney = BigDecimal.ZERO;
+
BigDecimal oasMoney = oas.getMoney();
// 平台抽成
BigDecimal platformFee = oasMoney.multiply(pcDeptRate).add(pcDeptMoney).setScale(2, RoundingMode.UP);
@@ -725,6 +765,17 @@ public class OrderDetailServiceImpl implements OrderDetailService {
platformFee = oasMoney.multiply(pcDeptRate).setScale(2, RoundingMode.UP);
masterFee = oasMoney.multiply(teamRete).setScale(2, RoundingMode.UP);
}
+ // 分销抽成
+ // 1级分销
+ if (MoneyUtil.lt(oneRate, oasMoney)) {
+ placeOneMoney = oasMoney.multiply(oneRate).setScale(2, RoundingMode.UP);
+ }
+ // 2级分销
+ if (MoneyUtil.lt(twoRate, oasMoney)) {
+ placeTwoMoney = oasMoney.multiply(twoRate).setScale(2, RoundingMode.UP);
+ }
+
+
// 上门师傅的报酬
BigDecimal workerFee = oasMoney.subtract(platformFee).subtract(masterFee);
// 分账信息
@@ -743,6 +794,14 @@ public class OrderDetailServiceImpl implements OrderDetailService {
divMembers.add(new DivMember(memberId, MoneyUtil.toS(workerFee), !feeFlag));
dtx = dtx.add(workerFee);
}
+ if (StringUtils.isNotEmpty(placeOne)) {
+ divMembers.add(new DivMember(placeOne, MoneyUtil.toS(placeOneMoney), !feeFlag));
+ dtx = dtx.add(placeOneMoney);
+ }
+ if (StringUtils.isNotEmpty(placeTwo)) {
+ divMembers.add(new DivMember(placeTwo, MoneyUtil.toS(placeTwoMoney), !feeFlag));
+ dtx = dtx.add(placeTwoMoney);
+ }
String orderNo = "OAS_" + oas.getId() + "_" + System.currentTimeMillis();
//调用分账
logger.info("子订单[{}]的追加单[{}]发起分账: {}", orderDetailId, oas.getId(), JSON.toJSONString(divMembers));