|
|
@@ -1,7 +1,6 @@
|
|
|
package com.poteviohealth.ym.ipos.controller.feign;
|
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.poteviohealth.cgp.common.controller.BaseFeignController;
|
|
|
@@ -19,7 +18,6 @@ import com.poteviohealth.ym.ipos.utils.YmUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -27,8 +25,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -98,280 +94,129 @@ public class IposFeignController extends BaseFeignController {
|
|
|
public VaultsResponse<List<SplitPay>> splitOrder(@RequestBody List<SplitInfo> list) {
|
|
|
|
|
|
/**
|
|
|
- * 分成顺序:平台自留->供应价/结算价->区域运营商分成->团长分成->站长分成->平台运营商
|
|
|
+ * 分成顺序:平台自留->供应价/结算价->平台运营商分成->区域运营商分成->团长分成/站长分成
|
|
|
* 手续费:0.3%(由第三方提供)
|
|
|
- * 分账金额=(总价-手续费)
|
|
|
- * 分账 = 分账金额*99%;平台自留: 分账金额*1%
|
|
|
- * 可分账 = 分账-供应价(结算价)
|
|
|
- * 区域运营商分账 = 可分账 * 分账比例
|
|
|
- * 剩余分账 = 可分账 - 区域运营商分账
|
|
|
- * 团长分账 = 剩余分账 * 分账比例
|
|
|
- * 站长分账 = 剩余分账 * 分账比例
|
|
|
- * 平台运营商分账 = 可分账 - 区域运营商分账 -团长分账 -站长分账
|
|
|
+ * 分账总金额 = 支付金额-手续费
|
|
|
+ * 平台自留金额 = 分账总金额 * 平台自留分成比例
|
|
|
+ * 可分账金额 = 分账总金额 - 平台自留金额
|
|
|
+ * 应分账金额 = 可分账金额 - 供应商成本价
|
|
|
+ * 平台运营商分成金额 = 应分账金额 * 平台运营商分成比例
|
|
|
+ * 区域运营商分成金额 = 应分账金额 * 区域运营商分成比例
|
|
|
+ * 剩余分成金额 = 应分账金额 - 平台运营商分成金额 - 区域运营商分成金额
|
|
|
+ * 团长分成金额 = 剩余分成金额 * 团长分成比例
|
|
|
+ * 站长分成金额 = 剩余分成金额 * 站长分成比例
|
|
|
+ * 剩余未分账部分则归属到平台自留金额中
|
|
|
*/
|
|
|
- log.info(JSON.toJSONString(list));
|
|
|
-
|
|
|
List<SplitPay> returnList = Lists.newArrayList();
|
|
|
for (SplitInfo splitInfo : list) {
|
|
|
- BigDecimal proportion = BigDecimal.ONE.subtract(splitInfo.getOperatorSplitProportion());
|
|
|
- List<SplitRecords> splitRecordsList = Lists.newArrayList();
|
|
|
- //TODO 三方支付相关
|
|
|
- //YJ:一级供应商;FS:二级供应商,服务商;QY:供应商,区域运营商;TZ:团长;ZZ:站长;PT:平台
|
|
|
PaymentRecords pr = paymentRecordsService.getPaymentRecords(splitInfo.getPayId());
|
|
|
if(pr == null){
|
|
|
continue;
|
|
|
}
|
|
|
+ Long id = CgpTool.generateKey();
|
|
|
List<SplitRecordsDetail> details = Lists.newArrayList();
|
|
|
SplitRecords records = new SplitRecords();
|
|
|
records.setOperatorId(splitInfo.getOperatorId());
|
|
|
- records.setSplitId(CgpTool.generateKey());
|
|
|
+ records.setSplitId(id);
|
|
|
records.setPayId(splitInfo.getPayId());
|
|
|
records.setPaySn(splitInfo.getPaySn());
|
|
|
records.setSumPrice(splitInfo.getSumPrice());
|
|
|
- //手续费
|
|
|
- BigDecimal chargeAmount = new BigDecimal(splitInfo.getCommissionMoney());
|
|
|
- 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;
|
|
|
- /**
|
|
|
- * 0.平台自留金额
|
|
|
- */
|
|
|
- //平台自留
|
|
|
+ //平台自留金额
|
|
|
SplitRecordsDetail pt = new SplitRecordsDetail();
|
|
|
- pt.setSplitId(records.getSplitId());
|
|
|
+ pt.setSplitId(id);
|
|
|
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);
|
|
|
- //平台自留=总分账金额*1%
|
|
|
- BigDecimal ptDecimal = sumPrice.multiply(proportion).setScale(0, RoundingMode.HALF_UP);
|
|
|
- //可分金额=总分账金额-平台自留
|
|
|
- BigDecimal price = sumPrice.subtract(ptDecimal);
|
|
|
- detail.setPrice(price.longValue());
|
|
|
- //平台自留金额
|
|
|
- ptAmount = ptAmount.add(ptDecimal);
|
|
|
- returnList.add(sp);
|
|
|
- /**
|
|
|
- * 2.供应价/结算价 的分账(包含区域运营商/一级供应商/二级供应商/服务站)
|
|
|
- */
|
|
|
+ pt.setDivAmt(String.valueOf(splitInfo.getSelfCommissionMoney()));
|
|
|
+ details.add(pt);
|
|
|
+ //平台运营商
|
|
|
+ if(splitInfo.getIsSplitOperator()){
|
|
|
+ SplitRecordsDetail ptyys = new SplitRecordsDetail();
|
|
|
+ ptyys.setSplitId(id);
|
|
|
+ ptyys.setSourceId(1);
|
|
|
+ ptyys.setMerchantId(splitInfo.getOperatorMerchantId());
|
|
|
+ ptyys.setDivAmt(splitInfo.getOperatorCommissionMoney().toString());
|
|
|
+ details.add(ptyys);
|
|
|
+ }
|
|
|
+
|
|
|
+ SplitDetail detail = splitInfo.getDetails().get(0);
|
|
|
+ //回写
|
|
|
+ SplitPay sp = new SplitPay();
|
|
|
+ sp.setOrderId(detail.getOrderId());
|
|
|
+ sp.setSplitId(id);
|
|
|
+ returnList.add(sp);
|
|
|
+ //区域运营商
|
|
|
+ if(detail.getIsSplitSupplier()){
|
|
|
+ if(detail.getSupplierMoney()>0L){
|
|
|
+ SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
+ supplier.setSplitId(id);
|
|
|
+ supplier.setSourceId(2);
|
|
|
+ supplier.setMerchantId(detail.getSupplierMerchantId());
|
|
|
+ supplier.setDivAmt(detail.getSupplierMoney().toString());
|
|
|
+ details.add(supplier);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //供应商
|
|
|
+ if(detail.getBelong().equals(1)){
|
|
|
//一级供应商
|
|
|
- //TODO 三方支付相关
|
|
|
- //if(detail.getBelong().equals(1)){
|
|
|
- if(StringUtils.isNotEmpty(detail.getSupplierOneMerchantId()) && detail.getBelong().equals(1)){
|
|
|
+ if(detail.getIsSplitSupplierOne()){
|
|
|
SplitRecordsDetail supplierOne = new SplitRecordsDetail();
|
|
|
- supplierOne.setSplitId(records.getSplitId());
|
|
|
+ supplierOne.setSplitId(id);
|
|
|
supplierOne.setSourceId(3);
|
|
|
- //TODO 三方支付相关
|
|
|
supplierOne.setMerchantId(detail.getSupplierOneMerchantId());
|
|
|
- //supplierOne.setMerchantId("YJ"+detail.getSupplierOneId().toString());
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(supplierOne.getMerchantId())){
|
|
|
- supplierOne = splitRecordsDetail;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- detail.setPrice(detail.getPrice()-detail.getConsignmentPrice());
|
|
|
- supplierOneAmount = supplierOneAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
- if (supplierOneAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- supplierOne.setDivAmt(supplierOneAmount.toString());
|
|
|
- details.add(supplierOne);
|
|
|
- }
|
|
|
- //TODO 三方支付相关
|
|
|
- //}else if(detail.getBelong().equals(2)){
|
|
|
- }else if(StringUtils.isNotEmpty(detail.getServiceStationMerchantId()) && detail.getBelong().equals(2)){
|
|
|
- //二级供应商
|
|
|
+ supplierOne.setDivAmt(detail.getConsignmentPrice().toString());
|
|
|
+ details.add(supplierOne);
|
|
|
+ }
|
|
|
+ }else if(detail.getBelong().equals(2)){
|
|
|
+ //二级供应商
|
|
|
+ if(detail.getIsSplitServiceStation()){
|
|
|
SplitRecordsDetail supplierTwo = new SplitRecordsDetail();
|
|
|
- supplierTwo.setSplitId(records.getSplitId());
|
|
|
+ supplierTwo.setSplitId(id);
|
|
|
supplierTwo.setSourceId(4);
|
|
|
- //TODO 三方支付相关
|
|
|
- //supplierTwo.setMerchantId("FS"+detail.getServiceStationId().toString());
|
|
|
supplierTwo.setMerchantId(detail.getServiceStationMerchantId());
|
|
|
- boolean is_have = false;
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
-
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(supplierTwo.getMerchantId())){
|
|
|
- supplierTwo = splitRecordsDetail;
|
|
|
- is_have = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- detail.setPrice(detail.getPrice() - detail.getConsignmentPrice());
|
|
|
- supplierTwoAmount = supplierTwoAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
-
|
|
|
- if (supplierTwoAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
- supplierTwo.setDivAmt(supplierTwoAmount.toString());
|
|
|
- if(!is_have){
|
|
|
- details.add(supplierTwo);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }else if(detail.getBelong().equals(0)){
|
|
|
- //服务商
|
|
|
- //TODO 三方支付相关
|
|
|
- //if(detail.getOrderType().equals(2) && !detail.getServiceStationId().equals(detail.getStationId())){
|
|
|
- if(StringUtils.isNotEmpty(detail.getServiceStationMerchantId()) && detail.getOrderType().equals(2) && !detail.getServiceStationId().equals(detail.getStationId())){
|
|
|
+ supplierTwo.setDivAmt(detail.getConsignmentPrice().toString());
|
|
|
+ details.add(supplierTwo);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //服务商
|
|
|
+ if(detail.getOrderType().equals(2) && !detail.getServiceStationId().equals(detail.getStationId())){
|
|
|
+ if(detail.getIsSplitServiceStation()){
|
|
|
SplitRecordsDetail serviceStation = new SplitRecordsDetail();
|
|
|
- serviceStation.setSplitId(records.getSplitId());
|
|
|
+ serviceStation.setSplitId(id);
|
|
|
serviceStation.setSourceId(5);
|
|
|
- //TODO 三方支付相关
|
|
|
- //serviceStation.setMerchantId("FS"+detail.getServiceStationId().toString());
|
|
|
serviceStation.setMerchantId(detail.getServiceStationMerchantId());
|
|
|
- boolean is_have = false;
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(serviceStation.getMerchantId())){
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- //TODO 三方支付相关
|
|
|
- //}else{
|
|
|
- }else if(StringUtils.isNotEmpty(detail.getSupplierMerchantId())){
|
|
|
- //供应商
|
|
|
- if(detail.getOrderType().equals(1) ||(detail.getOrderType().equals(2)&&detail.getStationId().equals(detail.getServiceStationId()))){
|
|
|
- boolean is_have = false;
|
|
|
- SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
- supplier.setSplitId(records.getSplitId());
|
|
|
- supplier.setSourceId(2);
|
|
|
- //TODO 三方支付相关
|
|
|
- //supplier.setMerchantId("QY"+detail.getSupplierId().toString());
|
|
|
- supplier.setMerchantId(detail.getSupplierMerchantId());
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(supplier.getMerchantId())){
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ serviceStation.setDivAmt(detail.getSettlementPrice().toString());
|
|
|
+ details.add(serviceStation);
|
|
|
}
|
|
|
+ }else{
|
|
|
+ //供应商
|
|
|
+ SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
+ supplier.setSplitId(id);
|
|
|
+ supplier.setSourceId(2);
|
|
|
+ supplier.setMerchantId(detail.getSupplierMerchantId());
|
|
|
+ supplier.setDivAmt(detail.getSettlementPrice().toString());
|
|
|
+ details.add(supplier);
|
|
|
}
|
|
|
- /**
|
|
|
- * 3.分成
|
|
|
- */
|
|
|
- //区域运营商
|
|
|
- if(detail.getSupplierMoney()!= null && detail.getSupplierMoney()>0L){
|
|
|
- SplitRecordsDetail supplier = new SplitRecordsDetail();
|
|
|
- supplier.setSplitId(records.getSplitId());
|
|
|
- supplier.setSourceId(2);
|
|
|
- //TODO 三方支付相关
|
|
|
- //supplier.setMerchantId("QY"+detail.getSupplierId().toString());
|
|
|
- supplier.setMerchantId(detail.getSupplierMerchantId());
|
|
|
- boolean is_have = false;
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(supplier.getMerchantId())){
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //团长
|
|
|
- //TODO 三方支付相关
|
|
|
- //if(detail.getGroupCommissionMoney() != null && detail.getGroupCommissionMoney()>0L){
|
|
|
- if(detail.getGroupCommissionMoney() != null && detail.getGroupCommissionMoney()>0L &&StringUtils.isNotBlank(detail.getGroupLeaderMerchantId())){
|
|
|
- SplitRecordsDetail tz = new SplitRecordsDetail();
|
|
|
- tz.setSplitId(records.getSplitId());
|
|
|
- tz.setSourceId(6);
|
|
|
- //TODO 三方支付相关
|
|
|
- //tz.setMerchantId("TZ"+detail.getGroupLeaderId().toString());
|
|
|
- tz.setMerchantId(detail.getGroupLeaderMerchantId());
|
|
|
- boolean is_have = false;
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(tz.getMerchantId())){
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //站长
|
|
|
- //TODO 三方支付相关
|
|
|
- //if(detail.getStationmasterCommissionMoney() != null && detail.getStationmasterCommissionMoney()>0L){
|
|
|
- if(detail.getStationmasterCommissionMoney() != null && detail.getStationmasterCommissionMoney()>0L&&StringUtils.isNotBlank(detail.getStationmasterMerchantId())){
|
|
|
- SplitRecordsDetail station = new SplitRecordsDetail();
|
|
|
- station.setSplitId(records.getSplitId());
|
|
|
- station.setSourceId(5);
|
|
|
- //TODO 三方支付相关
|
|
|
- //station.setMerchantId("ZZ"+detail.getStationId().toString());
|
|
|
- station.setMerchantId(detail.getStationmasterMerchantId());
|
|
|
- Boolean is_have = false;
|
|
|
- for (SplitRecordsDetail splitRecordsDetail : details) {
|
|
|
- if(splitRecordsDetail.getMerchantId().equals(station.getMerchantId())){
|
|
|
- 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(detail.getPrice()>0L){
|
|
|
- ptyysAmount = ptyysAmount.add(new BigDecimal(detail.getPrice()));
|
|
|
- }
|
|
|
- }
|
|
|
- pt.setDivAmt(String.valueOf(ptAmount.longValue()));
|
|
|
- details.add(pt);
|
|
|
+ //团长
|
|
|
+ if(detail.getIsSplitGroupLeader()){
|
|
|
+ SplitRecordsDetail tz = new SplitRecordsDetail();
|
|
|
+ tz.setSplitId(id);
|
|
|
+ tz.setSourceId(6);
|
|
|
+ tz.setMerchantId(detail.getGroupLeaderMerchantId());
|
|
|
+ tz.setDivAmt(detail.getGroupCommissionMoney().toString());
|
|
|
+ details.add(tz);
|
|
|
+ }
|
|
|
+ //站长
|
|
|
+ if(detail.getIsSplitStation()){
|
|
|
+ SplitRecordsDetail station = new SplitRecordsDetail();
|
|
|
+ station.setSplitId(id);
|
|
|
+ station.setSourceId(5);
|
|
|
+ station.setMerchantId(detail.getStationmasterMerchantId());
|
|
|
+ station.setDivAmt(detail.getStationmasterCommissionMoney().toString());
|
|
|
+ details.add(station);
|
|
|
+ }
|
|
|
|
|
|
- //平台运营商
|
|
|
- SplitRecordsDetail ptyys = new SplitRecordsDetail();
|
|
|
- ptyys.setSplitId(records.getSplitId());
|
|
|
- ptyys.setSourceId(1);
|
|
|
- //TODO 三方支付相关
|
|
|
- //ptyys.setMerchantId("PT"+splitInfo.getOperatorId().toString());
|
|
|
- ptyys.setMerchantId(splitInfo.getOperatorMerchantId());
|
|
|
- ptyys.setDivAmt(ptyysAmount.toString());
|
|
|
- details.add(ptyys);
|
|
|
- //TODO 三方支付相关
|
|
|
VaultsResponse vaultsResponse = splitService.delayConfirm(records,details);
|
|
|
if(!vaultsResponse.validate()){
|
|
|
records.setComment(vaultsResponse.getMessage());
|