|
|
@@ -31,8 +31,6 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 第三方支付
|
|
|
@@ -135,7 +133,6 @@ public class IposFeignController extends BaseFeignController {
|
|
|
BigDecimal supplierOneAmount = BigDecimal.ZERO;
|
|
|
BigDecimal supplierTwoAmount = BigDecimal.ZERO;
|
|
|
BigDecimal supplierAmount = BigDecimal.ZERO;
|
|
|
-
|
|
|
/**
|
|
|
* 0.平台自留金额
|
|
|
*/
|
|
|
@@ -157,177 +154,187 @@ public class IposFeignController extends BaseFeignController {
|
|
|
//平台自留金额
|
|
|
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)).distinct().collect(Collectors.groupingBy(SplitDetail::getSupplierOneMerchantId));
|
|
|
-
|
|
|
- for (String s : oneMaps.keySet()) {
|
|
|
- SplitRecordsDetail supplierOne = new SplitRecordsDetail();
|
|
|
- supplierOne.setSplitId(records.getSplitId());
|
|
|
- supplierOne.setSourceId(3);
|
|
|
- supplierOne.setMerchantId(s);
|
|
|
- for (SplitDetail detail : oneMaps.get(s)) {
|
|
|
+ /**
|
|
|
+ * 2.供应价/结算价 的分账(包含区域运营商/一级供应商/二级供应商/服务站)
|
|
|
+ */
|
|
|
+ //一级供应商
|
|
|
+ if(StringUtils.isNotEmpty(detail.getSupplierOneMerchantId()) && detail.getBelong().equals(1)){
|
|
|
+ SplitRecordsDetail supplierOne = new SplitRecordsDetail();
|
|
|
+ supplierOne.setSplitId(records.getSplitId());
|
|
|
+ supplierOne.setSourceId(3);
|
|
|
+ supplierOne.setMerchantId(detail.getSupplierOneMerchantId());
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getSupplierOneMerchantId())){
|
|
|
+ supplierOne = splitRecordsDetail;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail.setPrice(detail.getPrice()-detail.getConsignmentPrice());
|
|
|
supplierOneAmount = supplierOneAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
- detail.setPrice(new BigDecimal(detail.getPrice()).subtract(new BigDecimal(detail.getConsignmentPrice())).longValue());
|
|
|
- }
|
|
|
-
|
|
|
- if (supplierOneAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- supplierOne.setDivAmt(String.valueOf(supplierOneAmount.longValue()));
|
|
|
- details.add(supplierOne);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //二级供应商
|
|
|
- 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(4);
|
|
|
- supplierTwo.setMerchantId(s);
|
|
|
- for (SplitDetail detail : twoMaps.get(s)) {
|
|
|
- supplierTwoAmount = supplierTwoAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
+ if (supplierOneAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplierOne.setDivAmt(supplierOneAmount.toString());
|
|
|
+ details.add(supplierOne);
|
|
|
+ }
|
|
|
+ }else if(StringUtils.isNotEmpty(detail.getServiceStationMerchantId()) && detail.getBelong().equals(2)){
|
|
|
+ //二级供应商
|
|
|
+ SplitRecordsDetail supplierTwo = new SplitRecordsDetail();
|
|
|
+ supplierTwo.setSplitId(records.getSplitId());
|
|
|
+ supplierTwo.setSourceId(4);
|
|
|
+ supplierTwo.setMerchantId(detail.getServiceStationMerchantId());
|
|
|
+ boolean is_have = false;
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getServiceStationMerchantId())){
|
|
|
+ supplierTwo = splitRecordsDetail;
|
|
|
+ is_have = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
detail.setPrice(detail.getPrice() - detail.getConsignmentPrice());
|
|
|
- }
|
|
|
-
|
|
|
- if (supplierTwoAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- supplierTwo.setDivAmt(String.valueOf(supplierTwoAmount.longValue()));
|
|
|
- details.add(supplierTwo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //服务站
|
|
|
- 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)).distinct().collect(Collectors.groupingBy(SplitDetail::getSupplierMerchantId));
|
|
|
-
|
|
|
- for (String s : maps.keySet()) {
|
|
|
- SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
- supplier.setSplitId(records.getSplitId());
|
|
|
- supplier.setSourceId(2);
|
|
|
- supplier.setMerchantId(s);
|
|
|
- for (SplitDetail detail : maps.get(s)) {
|
|
|
- supplierAmount = supplierAmount.add(new BigDecimal(detail.getSettlementPrice()));
|
|
|
- detail.setPrice(new BigDecimal(detail.getPrice()).subtract(new BigDecimal(detail.getSettlementPrice())).longValue());
|
|
|
- }
|
|
|
-
|
|
|
- if (supplierAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- supplier.setDivAmt(String.valueOf(supplierAmount.longValue()));
|
|
|
- details.add(supplier);
|
|
|
- }
|
|
|
- }
|
|
|
+ supplierTwoAmount = supplierTwoAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
|
|
|
- /**
|
|
|
- * 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()).setScale(0, RoundingMode.HALF_UP).longValue();
|
|
|
- supplierAmount = supplierAmount.add(new BigDecimal(supplierPrice));
|
|
|
- detail.setPrice(new BigDecimal(detail.getPrice()).subtract(new BigDecimal(supplierPrice)).longValue());
|
|
|
- }
|
|
|
+ if (supplierTwoAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplierTwo.setDivAmt(supplierTwoAmount.toString());
|
|
|
+ if(!is_have){
|
|
|
+ details.add(supplierTwo);
|
|
|
+ }
|
|
|
|
|
|
- Boolean supplierNotHave = true;
|
|
|
- for (SplitRecordsDetail detail : details) {
|
|
|
- if(detail.getMerchantId()!= null &&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()).setScale(0, RoundingMode.HALF_UP).longValue();
|
|
|
- tzAmount = tzAmount.add(new BigDecimal(tzPrice));
|
|
|
- }
|
|
|
-
|
|
|
- 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()).setScale(0, RoundingMode.HALF_UP).longValue();
|
|
|
- stationAmount = stationAmount.add(new BigDecimal(stationPrice));
|
|
|
- }
|
|
|
+ }else if(detail.getBelong().equals(0)){
|
|
|
+ //服务站
|
|
|
+ if(StringUtils.isNotEmpty(detail.getServiceStationMerchantId()) && detail.getOrderType().equals(2)){
|
|
|
+ SplitRecordsDetail serviceStation = new SplitRecordsDetail();
|
|
|
+ serviceStation.setSplitId(records.getSplitId());
|
|
|
+ serviceStation.setSourceId(5);
|
|
|
+ serviceStation.setMerchantId(detail.getServiceStationMerchantId());
|
|
|
+ boolean is_have = false;
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getServiceStationMerchantId())){
|
|
|
+ serviceStation = splitRecordsDetail;
|
|
|
+ is_have=true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stationAmount = stationAmount.add(new BigDecimal(detail.getSettlementPrice()));
|
|
|
+ detail.setPrice(detail.getPrice() - detail.getSettlementPrice());
|
|
|
+ if (stationAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ serviceStation.setDivAmt(stationAmount.toString());
|
|
|
+ if(!is_have){
|
|
|
+ details.add(serviceStation);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }else if(StringUtils.isNotEmpty(detail.getSupplierMerchantId()) && detail.getOrderType().equals(1)){
|
|
|
+ //供应商
|
|
|
+ boolean is_have = false;
|
|
|
+ SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
+ supplier.setSplitId(records.getSplitId());
|
|
|
+ supplier.setSourceId(2);
|
|
|
+ supplier.setMerchantId(detail.getSupplierMerchantId());
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getSupplierMerchantId())){
|
|
|
+ supplier = splitRecordsDetail;
|
|
|
+ is_have =true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ supplierAmount = supplierAmount.add(new BigDecimal(detail.getSettlementPrice()));
|
|
|
+ detail.setPrice(detail.getPrice()-detail.getSettlementPrice());
|
|
|
+ if (supplierAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplier.setDivAmt(supplierAmount.toString());
|
|
|
+ if(!is_have){
|
|
|
+ details.add(supplier);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 3.分成
|
|
|
+ */
|
|
|
+ //区域运营商
|
|
|
+ if(detail.getSupplierMoney()!= null && detail.getSupplierMoney()>0L){
|
|
|
+ SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
+ supplier.setSplitId(records.getSplitId());
|
|
|
+ supplier.setSourceId(2);
|
|
|
+ supplier.setMerchantId(detail.getSupplierMerchantId());
|
|
|
+ boolean is_have = false;
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getSupplierMerchantId())){
|
|
|
+ supplier = splitRecordsDetail;
|
|
|
+ is_have =true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ supplierAmount = supplierAmount.add(new BigDecimal(detail.getSupplierMoney()));
|
|
|
+ detail.setPrice(detail.getPrice()-detail.getSupplierMoney());
|
|
|
+ if (supplierAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplier.setDivAmt(supplierAmount.toString());
|
|
|
+ if(!is_have){
|
|
|
+ details.add(supplier);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- Boolean stationNotHave = true;
|
|
|
- for (SplitRecordsDetail detail : details) {
|
|
|
- if(detail.getMerchantId()!= null && detail.getMerchantId().equals(s)){
|
|
|
- station = detail;
|
|
|
- station.setDivAmt(String.valueOf(stationAmount.longValue()));
|
|
|
- stationNotHave = false;
|
|
|
- break;
|
|
|
+ //团长
|
|
|
+ if(detail.getGroupCommissionMoney() != null && detail.getGroupCommissionMoney()>0L){
|
|
|
+ SplitRecordsDetail tz = new SplitRecordsDetail();
|
|
|
+ tz.setSplitId(records.getSplitId());
|
|
|
+ tz.setSourceId(6);
|
|
|
+ tz.setMerchantId(detail.getGroupLeaderMerchantId());
|
|
|
+ boolean is_have = false;
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getGroupLeaderMerchantId())){
|
|
|
+ tz = splitRecordsDetail;
|
|
|
+ is_have =true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tzAmount = tzAmount.add(new BigDecimal(detail.getGroupCommissionMoney()));
|
|
|
+ detail.setPrice(detail.getPrice()-detail.getGroupCommissionMoney());
|
|
|
+ if (tzAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ tz.setDivAmt(tzAmount.toString());
|
|
|
+ if(!is_have){
|
|
|
+ details.add(tz);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //站长
|
|
|
+ if(detail.getStationmasterCommissionMoney() != null && detail.getStationmasterCommissionMoney()>0L){
|
|
|
+ SplitRecordsDetail station = new SplitRecordsDetail();
|
|
|
+ station.setSplitId(records.getSplitId());
|
|
|
+ station.setSourceId(5);
|
|
|
+ station.setMerchantId(detail.getStationmasterMerchantId());
|
|
|
+ boolean is_have = false;
|
|
|
+ for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
+ if(splitRecordsDetail.getMerchantId().equals(detail.getStationmasterMerchantId())){
|
|
|
+ station = splitRecordsDetail;
|
|
|
+ is_have =true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stationAmount = stationAmount.add(new BigDecimal(detail.getStationmasterCommissionMoney()));
|
|
|
+ detail.setPrice(detail.getPrice()-detail.getStationmasterCommissionMoney());
|
|
|
+ if (stationAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ station.setDivAmt(stationAmount.toString());
|
|
|
+ if(!is_have){
|
|
|
+ details.add(station);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (stationAmount.compareTo(BigDecimal.ZERO) == 1 && stationNotHave) {
|
|
|
- station.setDivAmt(String.valueOf(stationAmount.longValue()));
|
|
|
- details.add(station);
|
|
|
+ if(detail.getPrice()>0L){
|
|
|
+ ptyysAmount = ptyysAmount.add(new BigDecimal(detail.getPrice()).subtract(tzAmount).subtract(stationAmount));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ pt.setDivAmt(String.valueOf(ptAmount.longValue()));
|
|
|
+ details.add(pt);
|
|
|
|
|
|
//平台运营商
|
|
|
SplitRecordsDetail ptyys = new SplitRecordsDetail();
|
|
|
ptyys.setSplitId(records.getSplitId());
|
|
|
ptyys.setSourceId(1);
|
|
|
- for (SplitDetail detail : splitInfo.getDetails()) {
|
|
|
- ptyysAmount = ptyysAmount.add(new BigDecimal(detail.getPrice()).subtract(tzAmount).subtract(stationAmount));
|
|
|
- }
|
|
|
ptyys.setMerchantId(splitInfo.getOperatorMerchantId());
|
|
|
- ptyys.setDivAmt(String.valueOf(ptyysAmount.longValue()));
|
|
|
+ ptyys.setDivAmt(ptyysAmount.toString());
|
|
|
details.add(ptyys);
|
|
|
/*VaultsResponse vaultsResponse = splitService.delayConfirm(records,details);
|
|
|
if(!vaultsResponse.validate()){
|