|
|
@@ -1,9 +1,10 @@
|
|
|
package com.poteviohealth.ym.ipos.controller.feign;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.poteviohealth.cgp.common.controller.BaseFeignController;
|
|
|
-import com.poteviohealth.cgp.common.integrated.ipos.model.RefundQuery;
|
|
|
+import com.poteviohealth.cgp.common.integrated.ipos.model.*;
|
|
|
import com.poteviohealth.cgp.common.integrated.order.model.PayBefor;
|
|
|
import com.poteviohealth.cgp.common.integrated.order.model.PayInfoAppOutDTO;
|
|
|
import com.poteviohealth.cgp.common.integrated.order.model.RefundReceive;
|
|
|
@@ -11,12 +12,16 @@ import com.poteviohealth.cgp.common.model.VaultsResponse;
|
|
|
import com.poteviohealth.cgp.common.utils.CgpTool;
|
|
|
import com.poteviohealth.cgp.common.utils.DateUtils;
|
|
|
import com.poteviohealth.ym.ipos.model.payment.PaymentRecords;
|
|
|
-import com.poteviohealth.ym.ipos.service.IPaymentRecordsService;
|
|
|
-import com.poteviohealth.ym.ipos.service.IPaymentService;
|
|
|
+import com.poteviohealth.ym.ipos.model.split.SplitRecords;
|
|
|
+import com.poteviohealth.ym.ipos.model.split.SplitRecordsDetail;
|
|
|
+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.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -24,8 +29,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 第三方支付
|
|
|
@@ -40,6 +48,15 @@ public class IposFeignController extends BaseFeignController {
|
|
|
private IPaymentRecordsService paymentRecordsService;
|
|
|
@Resource
|
|
|
private IPaymentService paymentService;
|
|
|
+ @Resource
|
|
|
+ private ISplitRecordsService splitRecordsService;
|
|
|
+ @Resource
|
|
|
+ private ISplitRecordsDetailService splitRecordsDetailService;
|
|
|
+ @Resource
|
|
|
+ private ISplitService splitService;
|
|
|
+
|
|
|
+ @Value("${pay.field.split}")
|
|
|
+ private String split;
|
|
|
|
|
|
@ApiOperation(value = "第三方支付信息")
|
|
|
@RequestMapping(value = "/returnPay", method = RequestMethod.POST)
|
|
|
@@ -80,4 +97,163 @@ public class IposFeignController extends BaseFeignController {
|
|
|
}
|
|
|
return VaultsResponse.success(returnList);
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "分账信息")
|
|
|
+ @RequestMapping(value = "/splitOrder", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public VaultsResponse<List<SplitPay>> splitOrder(@RequestBody List<SplitInfo> list) {
|
|
|
+
|
|
|
+ List<SplitPay> returnList = Lists.newArrayList();
|
|
|
+ List<SplitRecords> splitRecordsList = Lists.newArrayList();
|
|
|
+ List<SplitRecordsDetail> details = Lists.newArrayList();
|
|
|
+ for (SplitInfo splitInfo : list) {
|
|
|
+ SplitRecords records = new SplitRecords();
|
|
|
+ records.setOperatorId(splitInfo.getOperatorId());
|
|
|
+ records.setSplitId(CgpTool.generateKey());
|
|
|
+ records.setPayId(splitInfo.getPayId());
|
|
|
+ records.setPaySn(splitInfo.getPaySn());
|
|
|
+ records.setSumPrice(splitInfo.getSumPrice());
|
|
|
+ SplitPay sp = new SplitPay();
|
|
|
+ sp.setPayId(records.getPayId());
|
|
|
+ sp.setSplitId(records.getSplitId());
|
|
|
+ //平台分成
|
|
|
+ SplitRecordsDetail pt = new SplitRecordsDetail();
|
|
|
+ pt.setSplitId(records.getSplitId());
|
|
|
+ pt.setSourceId(0);
|
|
|
+
|
|
|
+ BigDecimal ptAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal tzAmount = 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());
|
|
|
+ pt.setSourceId(3);
|
|
|
+
|
|
|
+ for (SplitDetail detail : splitInfo.getDetails()) {
|
|
|
+ //运算价格
|
|
|
+ BigDecimal price = new BigDecimal(detail.getPrice());
|
|
|
+
|
|
|
+ //平台金额
|
|
|
+ BigDecimal ptDecimal = new BigDecimal(split).multiply(new BigDecimal(detail.getPrice()));
|
|
|
+ BigDecimal valDecimal = ptDecimal.longValue() == 0L ? new BigDecimal(1) : ptDecimal;
|
|
|
+ price = price.subtract(valDecimal);
|
|
|
+ ptAmount.add(valDecimal);
|
|
|
+
|
|
|
+ //团长金额
|
|
|
+ if (StringUtil.isNotEmpty(detail.getGroupLeaderMerchantId())) {
|
|
|
+ tz.setMerchantId(detail.getGroupLeaderMerchantId());
|
|
|
+ BigDecimal tbd = detail.getGroupCommission().multiply(new BigDecimal(detail.getPrice()));
|
|
|
+ price = price.subtract(tbd);
|
|
|
+ tzAmount.add(tbd);
|
|
|
+ }
|
|
|
+ detail.setPrice(price.longValue());
|
|
|
+ }
|
|
|
+ pt.setDivAmt(ptAmount.toString());
|
|
|
+ details.add(pt);
|
|
|
+ if (tzAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ tz.setDivAmt(tzAmount.toString());
|
|
|
+ details.add(tz);
|
|
|
+ }
|
|
|
+
|
|
|
+ //一级供应商
|
|
|
+ Map<String, List<SplitDetail>> oneMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierOneMerchantId()) && s.getBelong().equals(1)).collect(Collectors.groupingBy(SplitDetail::getSupplierOneMerchantId));
|
|
|
+
|
|
|
+ for (String s : oneMaps.keySet()) {
|
|
|
+ SplitRecordsDetail supplierOne = new SplitRecordsDetail();
|
|
|
+ supplierOne.setSplitId(records.getSplitId());
|
|
|
+ supplierOne.setSourceId(2);
|
|
|
+ supplierOne.setMerchantId(s);
|
|
|
+ for (SplitDetail detail : oneMaps.get(s)) {
|
|
|
+ supplierOneAmount = supplierOneAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
+ detail.setPrice(detail.getPrice() - detail.getConsignmentPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (supplierOneAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplierOne.setDivAmt(supplierOneAmount.toString());
|
|
|
+ details.add(supplierOne);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //二级供应商
|
|
|
+ Map<String, List<SplitDetail>> twoMaps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getServiceStationMerchantId()) && s.getBelong().equals(2)).collect(Collectors.groupingBy(SplitDetail::getServiceStationMerchantId));
|
|
|
+
|
|
|
+ for (String s : twoMaps.keySet()) {
|
|
|
+ SplitRecordsDetail supplierTwo = new SplitRecordsDetail();
|
|
|
+ supplierTwo.setSplitId(records.getSplitId());
|
|
|
+ supplierTwo.setSourceId(2);
|
|
|
+ supplierTwo.setMerchantId(s);
|
|
|
+ for (SplitDetail detail : oneMaps.get(s)) {
|
|
|
+ supplierTwoAmount = supplierTwoAmount.add(new BigDecimal(detail.getConsignmentPrice()));
|
|
|
+ detail.setPrice(detail.getPrice() - detail.getConsignmentPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (supplierTwoAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplierTwo.setDivAmt(supplierTwoAmount.toString());
|
|
|
+ details.add(supplierTwo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //供应商
|
|
|
+ Map<String, List<SplitDetail>> maps = splitInfo.getDetails().stream().filter(s -> StringUtils.isNotEmpty(s.getSupplierMerchantId()) && s.getBelong().equals(0)).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 : oneMaps.get(s)) {
|
|
|
+ supplierAmount = supplierAmount.add(new BigDecimal(detail.getSettlementPrice()));
|
|
|
+ detail.setPrice(detail.getPrice() - detail.getSettlementPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (supplierAmount.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ supplier.setDivAmt(supplierAmount.toString());
|
|
|
+ details.add(supplier);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //平台运营商
|
|
|
+ SplitRecordsDetail ptyys = new SplitRecordsDetail();
|
|
|
+ ptyys.setSplitId(records.getSplitId());
|
|
|
+ ptyys.setSourceId(1);
|
|
|
+ for (SplitDetail detail : splitInfo.getDetails()) {
|
|
|
+ ptyysAmount = ptyysAmount.add(new BigDecimal(detail.getPrice()));
|
|
|
+ }
|
|
|
+ ptyys.setMerchantId(splitInfo.getOperatorMerchantId());
|
|
|
+ ptyys.setDivAmt(ptyysAmount.toString());
|
|
|
+ details.add(ptyys);
|
|
|
+ VaultsResponse vaultsResponse = splitService.delayConfirm(records.getSplitId());
|
|
|
+ if(!vaultsResponse.validate()){
|
|
|
+ records.setComment(vaultsResponse.getMessage());
|
|
|
+ }
|
|
|
+ records.setStatus(2);
|
|
|
+ splitRecordsList.add(records);
|
|
|
+ splitRecordsService.saveBatch(splitRecordsList);
|
|
|
+ splitRecordsDetailService.saveBatch(details);
|
|
|
+ returnList.add(sp);
|
|
|
+ }
|
|
|
+ return VaultsResponse.success(returnList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "延时交易确认查询")
|
|
|
+ @RequestMapping(value = "/delayConfirmQuery", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public VaultsResponse<List<DelayConfirmQuery>> delayConfirmQuery(@RequestBody List<DelayConfirmQuery> list){
|
|
|
+
|
|
|
+ for (DelayConfirmQuery dcfq : list) {
|
|
|
+ VaultsResponse vaultsResponse = splitService.delayConfirmQuery(dcfq.getSplitId().toString(),dcfq.getOperatorId().toString());
|
|
|
+ if(vaultsResponse.validate()){
|
|
|
+ dcfq.setStatus(1);
|
|
|
+ }
|
|
|
+ SplitRecords splitRecords = new SplitRecords();
|
|
|
+ splitRecords.setStatus(1);
|
|
|
+ QueryWrapper<SplitRecords> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("split_id",dcfq.getSplitId());
|
|
|
+ splitRecordsService.update(splitRecords,queryWrapper);
|
|
|
+ }
|
|
|
+ return VaultsResponse.success(list);
|
|
|
+ }
|
|
|
}
|