|
|
@@ -18,7 +18,6 @@ import com.poteviohealth.ym.ipos.service.*;
|
|
|
import com.poteviohealth.ym.ipos.utils.YmUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import jodd.util.StringUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
@@ -100,10 +99,18 @@ public class IposFeignController extends BaseFeignController {
|
|
|
public VaultsResponse<List<SplitPay>> splitOrder(@RequestBody List<SplitInfo> list) {
|
|
|
|
|
|
/**
|
|
|
+ * 分成顺序:平台自留->供应价/结算价->区域运营商分成->团长分成->站长分成->平台运营商
|
|
|
+ * 手续费:0.3%(由第三方提供)
|
|
|
* 分账金额=(总价-手续费)
|
|
|
* 分账 = 分账金额*99%;平台自留: 分账金额*1%
|
|
|
+ * 可分账 = 分账-供应价(结算价)
|
|
|
+ * 区域运营商分账 = 可分账 * 分账比例
|
|
|
+ * 剩余分账 = 可分账 - 区域运营商分账
|
|
|
+ * 团长分账 = 剩余分账 * 分账比例
|
|
|
+ * 站长分账 = 剩余分账 * 分账比例
|
|
|
+ * 平台运营商分账 = 可分账 - 区域运营商分账 -团长分账 -站长分账
|
|
|
*/
|
|
|
- BigDecimal proportion = new BigDecimal(0.99);
|
|
|
+ BigDecimal proportion = new BigDecimal(0.1);
|
|
|
List<SplitPay> returnList = Lists.newArrayList();
|
|
|
for (SplitInfo splitInfo : list) {
|
|
|
//List<SplitRecords> splitRecordsList = Lists.newArrayList();
|
|
|
@@ -118,50 +125,51 @@ public class IposFeignController extends BaseFeignController {
|
|
|
records.setPayId(splitInfo.getPayId());
|
|
|
records.setPaySn(splitInfo.getPaySn());
|
|
|
records.setSumPrice(splitInfo.getSumPrice());
|
|
|
- //平台分成
|
|
|
- SplitRecordsDetail pt = new SplitRecordsDetail();
|
|
|
- pt.setSplitId(records.getSplitId());
|
|
|
- pt.setSourceId(0);
|
|
|
+ //手续费
|
|
|
BigDecimal chargeAmount = new BigDecimal(pr.getChargeAmount());
|
|
|
BigDecimal ptAmount = BigDecimal.ZERO;
|
|
|
BigDecimal tzAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal stationAmount = BigDecimal.ZERO;
|
|
|
BigDecimal ptyysAmount = BigDecimal.ZERO;
|
|
|
BigDecimal supplierOneAmount = BigDecimal.ZERO;
|
|
|
BigDecimal supplierTwoAmount = BigDecimal.ZERO;
|
|
|
BigDecimal supplierAmount = BigDecimal.ZERO;
|
|
|
- //团长分成
|
|
|
- SplitRecordsDetail tz = new SplitRecordsDetail();
|
|
|
- tz.setSplitId(records.getSplitId());
|
|
|
- tz.setSourceId(3);
|
|
|
|
|
|
+ /**
|
|
|
+ * 0.平台自留金额
|
|
|
+ */
|
|
|
+ //平台自留
|
|
|
+ SplitRecordsDetail pt = new SplitRecordsDetail();
|
|
|
+ pt.setSplitId(records.getSplitId());
|
|
|
+ pt.setSourceId(0);
|
|
|
for (SplitDetail detail : splitInfo.getDetails()) {
|
|
|
SplitPay sp = new SplitPay();
|
|
|
sp.setOrderId(detail.getOrderId());
|
|
|
sp.setSplitId(records.getSplitId());
|
|
|
- //总价格 支付价-手续费
|
|
|
+ //总分账金额 支付价-手续费
|
|
|
BigDecimal sumPrice = new BigDecimal(detail.getPrice()).subtract(chargeAmount);
|
|
|
- //运算价格 总价格*99%
|
|
|
- BigDecimal price = sumPrice.multiply(proportion);
|
|
|
+ //平台自留=总分账金额*1%
|
|
|
+ BigDecimal ptDecimal = sumPrice.multiply(proportion);
|
|
|
+ //可分金额=总分账金额-平台自留
|
|
|
+ BigDecimal price = sumPrice.subtract(ptDecimal);
|
|
|
detail.setPrice(price.longValue());
|
|
|
- //平台金额=总价格-运算价格
|
|
|
- BigDecimal ptDecimal = sumPrice.subtract(price);
|
|
|
- BigDecimal valDecimal = new BigDecimal("1");
|
|
|
- if(ptDecimal.longValue() > 0){
|
|
|
- valDecimal = new BigDecimal(ptDecimal.longValue());
|
|
|
- }
|
|
|
- ptAmount = ptAmount.add(valDecimal);
|
|
|
+ //平台自留金额
|
|
|
+ ptAmount = ptAmount.add(ptDecimal);
|
|
|
returnList.add(sp);
|
|
|
}
|
|
|
pt.setDivAmt(String.valueOf(ptAmount.longValue()));
|
|
|
details.add(pt);
|
|
|
+ /**
|
|
|
+ * 2.供应价/结算价 的分账(包含区域运营商/一级供应商/二级供应商/服务站)
|
|
|
+ */
|
|
|
|
|
|
//一级供应商
|
|
|
- Map<String, List<SplitDetail>> oneMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierOneMerchantId()) && s.getBelong().equals(1)).collect(Collectors.groupingBy(SplitDetail::getSupplierOneMerchantId));
|
|
|
+ Map<String, List<SplitDetail>> oneMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierOneMerchantId()) && s.getBelong().equals(1)).distinct().collect(Collectors.groupingBy(SplitDetail::getSupplierOneMerchantId));
|
|
|
|
|
|
for (String s : oneMaps.keySet()) {
|
|
|
SplitRecordsDetail supplierOne = new SplitRecordsDetail();
|
|
|
supplierOne.setSplitId(records.getSplitId());
|
|
|
- supplierOne.setSourceId(2);
|
|
|
+ supplierOne.setSourceId(3);
|
|
|
supplierOne.setMerchantId(s);
|
|
|
for (SplitDetail detail : oneMaps.get(s)) {
|
|
|
supplierOneAmount = supplierOneAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
@@ -175,12 +183,12 @@ public class IposFeignController extends BaseFeignController {
|
|
|
}
|
|
|
|
|
|
//二级供应商
|
|
|
- Map<String, List<SplitDetail>> twoMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getServiceStationMerchantId()) && s.getBelong().equals(2)).collect(Collectors.groupingBy(SplitDetail::getServiceStationMerchantId));
|
|
|
+ Map<String, List<SplitDetail>> twoMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getServiceStationMerchantId()) && s.getBelong().equals(2)).distinct().collect(Collectors.groupingBy(SplitDetail::getServiceStationMerchantId));
|
|
|
|
|
|
for (String s : twoMaps.keySet()) {
|
|
|
SplitRecordsDetail supplierTwo = new SplitRecordsDetail();
|
|
|
supplierTwo.setSplitId(records.getSplitId());
|
|
|
- supplierTwo.setSourceId(2);
|
|
|
+ supplierTwo.setSourceId(4);
|
|
|
supplierTwo.setMerchantId(s);
|
|
|
for (SplitDetail detail : twoMaps.get(s)) {
|
|
|
supplierTwoAmount = supplierTwoAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
@@ -193,8 +201,27 @@ public class IposFeignController extends BaseFeignController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //服务站
|
|
|
+ Map<String, List<SplitDetail>> serviceStationMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getServiceStationMerchantId()) && s.getBelong().equals(0)).distinct().collect(Collectors.groupingBy(SplitDetail::getServiceStationMerchantId));
|
|
|
+
|
|
|
+ for (String s : serviceStationMaps.keySet()) {
|
|
|
+ SplitRecordsDetail serviceStation = new SplitRecordsDetail();
|
|
|
+ serviceStation.setSplitId(records.getSplitId());
|
|
|
+ serviceStation.setSourceId(5);
|
|
|
+ serviceStation.setMerchantId(s);
|
|
|
+ for (SplitDetail detail : serviceStationMaps.get(s)) {
|
|
|
+ stationAmount = stationAmount.add(new BigDecimal(detail.getSettlementPrice()));
|
|
|
+ detail.setPrice(detail.getPrice() - detail.getSettlementPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stationAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ serviceStation.setDivAmt(String.valueOf(stationAmount.longValue()));
|
|
|
+ details.add(serviceStation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//供应商
|
|
|
- Map<String, List<SplitDetail>> maps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierMerchantId()) && s.getBelong().equals(0)).collect(Collectors.groupingBy(SplitDetail::getSupplierMerchantId));
|
|
|
+ Map<String, List<SplitDetail>> maps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierMerchantId()) && s.getBelong().equals(0)).distinct().collect(Collectors.groupingBy(SplitDetail::getSupplierMerchantId));
|
|
|
|
|
|
for (String s : maps.keySet()) {
|
|
|
SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
@@ -212,18 +239,82 @@ public class IposFeignController extends BaseFeignController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (SplitDetail detail : splitInfo.getDetails()) {
|
|
|
- //团长金额
|
|
|
- if (StringUtil.isNotEmpty(detail.getGroupLeaderMerchantId())) {
|
|
|
- tz.setMerchantId(detail.getGroupLeaderMerchantId());
|
|
|
- BigDecimal tbd = detail.getGroupCommission().multiply(new BigDecimal(detail.getPrice()));
|
|
|
- detail.setPrice(detail.getPrice()-tbd.longValue());
|
|
|
- tzAmount = tzAmount.add(tbd);
|
|
|
+ /**
|
|
|
+ * 3.分成
|
|
|
+ */
|
|
|
+ //区域运营商
|
|
|
+ Map<String, List<SplitDetail>> supplierMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierMerchantId())).distinct().collect(Collectors.groupingBy(SplitDetail::getSupplierMerchantId));
|
|
|
+ for (String s : supplierMaps.keySet()) {
|
|
|
+ SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
+ supplier.setSplitId(records.getSplitId());
|
|
|
+ supplier.setSourceId(2);
|
|
|
+ supplier.setMerchantId(s);
|
|
|
+ for (SplitDetail detail : supplierMaps.get(s)) {
|
|
|
+ Long supplierPrice = new BigDecimal(detail.getPrice()).multiply(detail.getSupplierCommission()).longValue();
|
|
|
+ supplierAmount = supplierAmount.add(new BigDecimal(supplierPrice));
|
|
|
+ detail.setPrice(new BigDecimal(detail.getPrice()).subtract(new BigDecimal(supplierPrice)).longValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean supplierNotHave = true;
|
|
|
+ for (SplitRecordsDetail detail : details) {
|
|
|
+ if(detail.getMerchantId().equals(s)){
|
|
|
+ supplier = detail;
|
|
|
+ supplier.setDivAmt(String.valueOf(supplierAmount.longValue()));
|
|
|
+ supplierNotHave = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (supplierAmount.compareTo(BigDecimal.ZERO) == 1 && supplierNotHave) {
|
|
|
+ supplier.setDivAmt(String.valueOf(supplierAmount.longValue()));
|
|
|
+ details.add(supplier);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //团长分成
|
|
|
+ Map<String, List<SplitDetail>> tzMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getGroupLeaderMerchantId())).distinct().collect(Collectors.groupingBy(SplitDetail::getGroupLeaderMerchantId));
|
|
|
+ for (String s : tzMaps.keySet()) {
|
|
|
+ SplitRecordsDetail tz = new SplitRecordsDetail();
|
|
|
+ tz.setSplitId(records.getSplitId());
|
|
|
+ tz.setSourceId(6);
|
|
|
+ tz.setMerchantId(s);
|
|
|
+ for (SplitDetail detail : tzMaps.get(s)) {
|
|
|
+ Long tzPrice = new BigDecimal(detail.getPrice()).multiply(detail.getGroupCommission()).longValue();
|
|
|
+ tzAmount = tzAmount.add(new BigDecimal(tzPrice));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tzAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ tz.setDivAmt(String.valueOf(tzAmount.longValue()));
|
|
|
+ details.add(tz);
|
|
|
}
|
|
|
}
|
|
|
- if (tzAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- tz.setDivAmt(String.valueOf(tzAmount.longValue()));
|
|
|
- details.add(tz);
|
|
|
+
|
|
|
+ //站长
|
|
|
+ Map<String, List<SplitDetail>> stationMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getStationmasterMerchantId())).distinct().collect(Collectors.groupingBy(SplitDetail::getStationmasterMerchantId));
|
|
|
+ for (String s : stationMaps.keySet()) {
|
|
|
+ SplitRecordsDetail station = new SplitRecordsDetail();
|
|
|
+ station.setSplitId(records.getSplitId());
|
|
|
+ station.setSourceId(5);
|
|
|
+ station.setMerchantId(s);
|
|
|
+ for (SplitDetail detail : stationMaps.get(s)) {
|
|
|
+ Long stationPrice = new BigDecimal(detail.getPrice()).multiply(detail.getStationmasterCommission()).longValue();
|
|
|
+ stationAmount = stationAmount.add(new BigDecimal(stationPrice));
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean stationNotHave = true;
|
|
|
+ for (SplitRecordsDetail detail : details) {
|
|
|
+ if(detail.getMerchantId().equals(s)){
|
|
|
+ station = detail;
|
|
|
+ station.setDivAmt(String.valueOf(stationAmount.longValue()));
|
|
|
+ stationNotHave = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stationAmount.compareTo(BigDecimal.ZERO) == 1 && stationNotHave) {
|
|
|
+ station.setDivAmt(String.valueOf(stationAmount.longValue()));
|
|
|
+ details.add(station);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -232,7 +323,7 @@ public class IposFeignController extends BaseFeignController {
|
|
|
ptyys.setSplitId(records.getSplitId());
|
|
|
ptyys.setSourceId(1);
|
|
|
for (SplitDetail detail : splitInfo.getDetails()) {
|
|
|
- ptyysAmount = ptyysAmount.add(new BigDecimal(detail.getPrice()));
|
|
|
+ ptyysAmount = ptyysAmount.add(new BigDecimal(detail.getPrice()).subtract(tzAmount).subtract(stationAmount));
|
|
|
}
|
|
|
ptyys.setMerchantId(splitInfo.getOperatorMerchantId());
|
|
|
ptyys.setDivAmt(String.valueOf(ptyysAmount.longValue()));
|
|
|
@@ -242,7 +333,6 @@ public class IposFeignController extends BaseFeignController {
|
|
|
records.setComment(vaultsResponse.getMessage());
|
|
|
}
|
|
|
records.setStatus(2);
|
|
|
- //splitRecordsList.add(records);
|
|
|
splitRecordsService.save(records);
|
|
|
splitRecordsDetailService.saveBatch(details);
|
|
|
}
|