|
|
|
@ -79,6 +79,7 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
tradeOrderProfitSharing.setPlatformTradeNo(tradeOrder.getPlatformTradeNo()); |
|
|
|
|
tradeOrderProfitSharing.setPlatformAppid(tradeOrder.getPlatformAppid()); |
|
|
|
|
tradeOrderProfitSharing.setProfitSharingAmoun(new BigDecimal(separateModel.getTotalAmount())); |
|
|
|
|
tradeOrderProfitSharing.setProfitSharingTime(new Date()); |
|
|
|
|
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status0.getNumber()); |
|
|
|
|
tradeOrderProfitSharing.setCreateType(TradeOrderProfitSharingCreateType.type2.getNumber()); |
|
|
|
|
tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); |
|
|
|
@ -93,6 +94,7 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
profitSharingReceiver.setProfitSharingAmount(tradeOrderProfitSharing.getProfitSharingAmoun()); |
|
|
|
|
profitSharingReceiver.setReceiverObjectType(ProfitSharingReceiverObjectType.mer.getType()); |
|
|
|
|
profitSharingReceiver.setReceiverObjectId(recvMer.getId().toString()); |
|
|
|
|
profitSharingReceiver.setReceiverNo(recvMer.getMerNo()); |
|
|
|
|
profitSharingReceiver.setReceiverAccount(merLedger.getReceiverNo()); |
|
|
|
|
profitSharingReceiver.setReceiverName(recvMer.getMerName()); |
|
|
|
|
profitSharingReceiver.setReceiverAmount(new BigDecimal(recvData.getSeparateAmount())); |
|
|
|
@ -116,29 +118,54 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW, timeout = 20) |
|
|
|
|
public ResponseSeparateCancelModel cancel(RequestSeparateCancelModel separateCancelModel) throws Exception { |
|
|
|
|
// 查询分账流水号是否存在
|
|
|
|
|
if (tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOriginOutSeparateNo()) != null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "原分账指令流水号重复"); |
|
|
|
|
BsTradeOrderProfitSharing originOutSeparate = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOriginOutSeparateNo()); |
|
|
|
|
if (originOutSeparate == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "原分账指令流水号不存在"); |
|
|
|
|
} |
|
|
|
|
// 查询分账
|
|
|
|
|
BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()); |
|
|
|
|
if (tradeOrderProfitSharing == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分商户分账指令"); |
|
|
|
|
if (!originOutSeparate.getStatus().equals(ProfitSharingStatusEnum.status1.getNumber())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "原分账状态错误"); |
|
|
|
|
} |
|
|
|
|
if (originOutSeparate.getProfitSharingAmoun().compareTo(new BigDecimal(separateCancelModel.getTotalAmount())) != 0) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "撤销金额与分账金额不一致"); |
|
|
|
|
} |
|
|
|
|
// 查询撤销分账指令流水号
|
|
|
|
|
if (tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()) != null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "商户分账指令流水号重复"); |
|
|
|
|
} |
|
|
|
|
/*if (tradeOrderProfitSharing.getProfitSharingAmoun()) { |
|
|
|
|
|
|
|
|
|
}*/ |
|
|
|
|
// 交易订单
|
|
|
|
|
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); |
|
|
|
|
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(originOutSeparate.getTradeOrderNo()); |
|
|
|
|
if (tradeOrder == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户分账指令"); |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户指令"); |
|
|
|
|
} |
|
|
|
|
if (!separateCancelModel.getMerchantNo().equals(tradeOrder.getMerNo())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户分账指令"); |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户指令"); |
|
|
|
|
} |
|
|
|
|
BsTradeOrderProfitSharing profitSharingCmd = new BsTradeOrderProfitSharing(); |
|
|
|
|
profitSharingCmd.setCmdType(ProfitSharingCmdTypeEnum.CMD_TYPE_2.getNumber()); |
|
|
|
|
profitSharingCmd.setTradeOrderId(tradeOrder.getId()); |
|
|
|
|
profitSharingCmd.setTradeOrderNo(tradeOrder.getOutTradeNo()); |
|
|
|
|
profitSharingCmd.setOriginProfitSharingOrderNo(separateCancelModel.getOriginOutSeparateNo()); |
|
|
|
|
profitSharingCmd.setProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()); |
|
|
|
|
profitSharingCmd.setPlatformType(tradeOrder.getPlatformType()); |
|
|
|
|
profitSharingCmd.setPlatformMerNo(tradeOrder.getPlatformMerNo()); |
|
|
|
|
profitSharingCmd.setPlatformTradeNo(tradeOrder.getPlatformTradeNo()); |
|
|
|
|
profitSharingCmd.setPlatformAppid(tradeOrder.getPlatformAppid()); |
|
|
|
|
profitSharingCmd.setProfitSharingAmoun(new BigDecimal(separateCancelModel.getTotalAmount())); |
|
|
|
|
profitSharingCmd.setProfitSharingTime(new Date()); |
|
|
|
|
profitSharingCmd.setStatus(ProfitSharingStatusEnum.status2.getNumber()); |
|
|
|
|
profitSharingCmd.setCreateType(TradeOrderProfitSharingCreateType.type2.getNumber()); |
|
|
|
|
tradeOrderProfitSharingService.editData(profitSharingCmd); |
|
|
|
|
|
|
|
|
|
// laKaLaTradeSeparateService.cancel();
|
|
|
|
|
// 调用第三方
|
|
|
|
|
JSONObject responseCancel = laKaLaTradeSeparateService.cancel(separateCancelModel.getOutSeparateNo()); |
|
|
|
|
|
|
|
|
|
ResponseSeparateCancelModel responseSeparateCancel = new ResponseSeparateCancelModel(); |
|
|
|
|
responseSeparateCancel.setSeparateNo(responseCancel.getString("separate_no")); |
|
|
|
|
responseSeparateCancel.setOutSeparateNo(profitSharingCmd.getProfitSharingOrderNo()); |
|
|
|
|
responseSeparateCancel.setOriginSeparateNo(originOutSeparate.getPlatformProfitSharingOrderNo()); |
|
|
|
|
responseSeparateCancel.setOriginOutSeparateNo(originOutSeparate.getProfitSharingOrderNo()); |
|
|
|
|
responseSeparateCancel.setStatus(profitSharingCmd.getStatus()); |
|
|
|
|
responseSeparateCancel.setTotalAmount(profitSharingCmd.getProfitSharingAmoun()); |
|
|
|
|
responseSeparateCancel.setSign(SignatureUtil.createSign(separateCancelModel, merKeyService.getKeyByMerNo(separateCancelModel.getMerchantNo()))); |
|
|
|
|
return responseSeparateCancel; |
|
|
|
|
} |
|
|
|
@ -157,20 +184,44 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
} |
|
|
|
|
if (!separateQueryModel.getMerchantNo().equals(tradeOrder.getMerNo())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分账流水号"); |
|
|
|
|
}/* |
|
|
|
|
// 第三方接口查询
|
|
|
|
|
JSONObject queryProfitSharing = laKaLaTradeSeparateService.query(separateQueryModel.getOutSeparateNo());*/ |
|
|
|
|
} |
|
|
|
|
// 第三方接口查询,防止未及时更新
|
|
|
|
|
if (!tradeOrderProfitSharing.getStatus().equals(ProfitSharingStatusEnum.status1.getNumber())) { |
|
|
|
|
JSONObject queryProfitSharing = laKaLaTradeSeparateService.query(separateQueryModel.getOutSeparateNo()); |
|
|
|
|
if (queryProfitSharing.getString("status").equals("SUCCESS")) { |
|
|
|
|
tradeOrderProfitSharing.setFinishTime(new Date()); |
|
|
|
|
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status1.getNumber()); |
|
|
|
|
tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); |
|
|
|
|
|
|
|
|
|
// 修改接收方状态
|
|
|
|
|
List<BsTradeOrderProfitSharingReceiver> receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); |
|
|
|
|
for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { |
|
|
|
|
receiver.setStatus(ProfitSharingReceiverStatusEnum.status1.getNumber()); |
|
|
|
|
tradeOrderProfitSharingReceiverService.editData(receiver); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ResponseSeparateQueryModel responseSeparateQueryModel = new ResponseSeparateQueryModel(); |
|
|
|
|
responseSeparateQueryModel.setCmdType(tradeOrderProfitSharing.getCmdType()); |
|
|
|
|
responseSeparateQueryModel.setOutSeparateNo(tradeOrderProfitSharing.getProfitSharingOrderNo()); |
|
|
|
|
responseSeparateQueryModel.setSeparateNo(tradeOrderProfitSharing.getPlatformProfitSharingOrderNo()); |
|
|
|
|
responseSeparateQueryModel.setSeparateDate(tradeOrderProfitSharing.getProfitSharingTime()); |
|
|
|
|
responseSeparateQueryModel.setFinishDate(tradeOrderProfitSharing.getFinishTime()); |
|
|
|
|
|
|
|
|
|
responseSeparateQueryModel.setCreateDate( |
|
|
|
|
tradeOrderProfitSharing.getProfitSharingTime()!=null? |
|
|
|
|
DateUtil.date2String(tradeOrderProfitSharing.getProfitSharingTime(), "yyyyMMdd") |
|
|
|
|
: null); |
|
|
|
|
|
|
|
|
|
responseSeparateQueryModel.setFinishDate( |
|
|
|
|
tradeOrderProfitSharing.getFinishTime()!=null? |
|
|
|
|
DateUtil.date2String(tradeOrderProfitSharing.getFinishTime(), "yyyyMMdd") |
|
|
|
|
: null); |
|
|
|
|
|
|
|
|
|
responseSeparateQueryModel.setTotalAmount(tradeOrderProfitSharing.getProfitSharingAmoun()); |
|
|
|
|
responseSeparateQueryModel.setStatus(tradeOrderProfitSharing.getStatus()); |
|
|
|
|
// 接收方
|
|
|
|
|
List<ResponseSeparateQueryModel.ResponseSeparateRecvDataModel> recvDataList = new ArrayList<>(); |
|
|
|
|
if (tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_1.getNumber())) { |
|
|
|
|
List<BsTradeOrderProfitSharingReceiver> receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.getId()); |
|
|
|
|
for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { |
|
|
|
|
ResponseSeparateQueryModel.ResponseSeparateRecvDataModel recvData = new ResponseSeparateQueryModel.ResponseSeparateRecvDataModel(); |
|
|
|
@ -178,6 +229,21 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
recvData.setSeparateAmount(receiver.getReceiverAmount()); |
|
|
|
|
recvDataList.add(recvData); |
|
|
|
|
} |
|
|
|
|
} else if (tradeOrderProfitSharing.getCmdType().equals(ProfitSharingCmdTypeEnum.CMD_TYPE_2.getNumber())) { |
|
|
|
|
// 原分账流水
|
|
|
|
|
BsTradeOrderProfitSharing originOutSeparate = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(tradeOrderProfitSharing.getOriginProfitSharingOrderNo()); |
|
|
|
|
if (originOutSeparate == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的原分账指令流水号"); |
|
|
|
|
} |
|
|
|
|
List<BsTradeOrderProfitSharingReceiver> receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(originOutSeparate.getId()); |
|
|
|
|
for (BsTradeOrderProfitSharingReceiver receiver : receiverList) { |
|
|
|
|
ResponseSeparateQueryModel.ResponseSeparateRecvDataModel recvData = new ResponseSeparateQueryModel.ResponseSeparateRecvDataModel(); |
|
|
|
|
recvData.setRecvMerchantNo(receiver.getReceiverNo()); |
|
|
|
|
recvData.setSeparateAmount(receiver.getReceiverAmount()); |
|
|
|
|
recvDataList.add(recvData); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
responseSeparateQueryModel.setRecvDataList(recvDataList); |
|
|
|
|
responseSeparateQueryModel.setSign(SignatureUtil.createSign(responseSeparateQueryModel, merKeyService.getKeyByMerNo(separateQueryModel.getMerchantNo()))); |
|
|
|
|
return responseSeparateQueryModel; |
|
|
|
|