|
|
|
@ -1,26 +1,21 @@ |
|
|
|
|
package com.hfkj.openapi.v1.service.impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hfkj.channel.lakala.LaKaLaTradeSeparateService; |
|
|
|
|
import com.hfkj.channel.lakala.LaKaLaTradeService; |
|
|
|
|
import com.hfkj.common.exception.ErrorCode; |
|
|
|
|
import com.hfkj.common.exception.ErrorHelp; |
|
|
|
|
import com.hfkj.common.exception.SysCode; |
|
|
|
|
import com.hfkj.common.utils.DateUtil; |
|
|
|
|
import com.hfkj.dao.OpenApiTradeOrderMapper; |
|
|
|
|
import com.hfkj.entity.BsTradeOrder; |
|
|
|
|
import com.hfkj.entity.BsTradeOrderProfitSharing; |
|
|
|
|
import com.hfkj.entity.BsTradeOrderRefund; |
|
|
|
|
import com.hfkj.entity.*; |
|
|
|
|
import com.hfkj.openapi.v1.model.TradeBillsModel; |
|
|
|
|
import com.hfkj.openapi.v1.model.request.RequestRefundTradeModel; |
|
|
|
|
import com.hfkj.openapi.v1.model.request.RequestSeparateModel; |
|
|
|
|
import com.hfkj.openapi.v1.model.response.ResponseRefundTradeModel; |
|
|
|
|
import com.hfkj.openapi.v1.model.request.*; |
|
|
|
|
import com.hfkj.openapi.v1.model.response.*; |
|
|
|
|
import com.hfkj.openapi.v1.service.OpenApiTradeOrderProfitSharingService; |
|
|
|
|
import com.hfkj.openapi.v1.service.OpenApiTradeOrderService; |
|
|
|
|
import com.hfkj.openapi.v1.utils.SignatureUtil; |
|
|
|
|
import com.hfkj.service.BsMerKeyService; |
|
|
|
|
import com.hfkj.service.BsTradeOrderProfitSharingService; |
|
|
|
|
import com.hfkj.service.BsTradeOrderRefundService; |
|
|
|
|
import com.hfkj.service.BsTradeOrderService; |
|
|
|
|
import com.hfkj.service.*; |
|
|
|
|
import com.hfkj.sysenum.*; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -29,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -43,18 +39,30 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private BsTradeOrderProfitSharingService tradeOrderProfitSharingService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private BsTradeOrderProfitSharingReceiverService tradeOrderProfitSharingReceiverService; |
|
|
|
|
@Resource |
|
|
|
|
private BsMerService merService; |
|
|
|
|
@Resource |
|
|
|
|
private BsMerKeyService merKeyService; |
|
|
|
|
@Resource |
|
|
|
|
private BsMerLedgerService merLedgerService; |
|
|
|
|
@Resource |
|
|
|
|
private OpenApiTradeOrderService openApiTradeOrderService; |
|
|
|
|
@Resource |
|
|
|
|
private LaKaLaTradeSeparateService laKaLaTradeSeparateService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW, timeout = 20) |
|
|
|
|
public Map<String, Object> separate(RequestSeparateModel separateModel) { |
|
|
|
|
public ResponseSeparateModel separate(RequestSeparateModel separateModel) throws Exception { |
|
|
|
|
// 查询交易订单
|
|
|
|
|
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(separateModel.getOutTradeNo()); |
|
|
|
|
if (tradeOrder == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易单号"); |
|
|
|
|
} |
|
|
|
|
if (!tradeOrder.getMerNo().equals(separateModel.getMerchantNo())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易单号"); |
|
|
|
|
} |
|
|
|
|
if (!tradeOrder.getStatus().equals(TradeOrderStatusEnum.status3.getNumber())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "交易订单不处于已支付"); |
|
|
|
|
} |
|
|
|
@ -72,7 +80,133 @@ public class OpenApiTradeOrderProfitSharingServiceImpl implements OpenApiTradeOr |
|
|
|
|
tradeOrderProfitSharing.setPlatformAppid(tradeOrder.getPlatformAppid()); |
|
|
|
|
tradeOrderProfitSharing.setProfitSharingAmoun(new BigDecimal(separateModel.getTotalAmount())); |
|
|
|
|
tradeOrderProfitSharing.setStatus(ProfitSharingStatusEnum.status0.getNumber()); |
|
|
|
|
tradeOrderProfitSharing.setCreateType(TradeOrderProfitSharingCreateType.type2.getNumber()); |
|
|
|
|
tradeOrderProfitSharingService.editData(tradeOrderProfitSharing); |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
for (RequestSeparateModel.RequestSeparateRecvDataModel recvData : separateModel.getRecvDatas()) { |
|
|
|
|
BsMer recvMer = merService.getMer(recvData.getRecvMerchantNo()); |
|
|
|
|
BsMerLedger merLedger = merLedgerService.getMerLedger(recvMer.getId(), PlatformTypeEnum.type1); |
|
|
|
|
BsTradeOrderProfitSharingReceiver profitSharingReceiver = new BsTradeOrderProfitSharingReceiver(); |
|
|
|
|
profitSharingReceiver.setTradeOrderProfitSharingId(tradeOrderProfitSharing.getId()); |
|
|
|
|
profitSharingReceiver.setTradeOrderId(tradeOrder.getId()); |
|
|
|
|
profitSharingReceiver.setTradeOrderNo(tradeOrder.getOutTradeNo()); |
|
|
|
|
profitSharingReceiver.setProfitSharingAmount(tradeOrderProfitSharing.getProfitSharingAmoun()); |
|
|
|
|
profitSharingReceiver.setReceiverObjectType(ProfitSharingReceiverObjectType.mer.getType()); |
|
|
|
|
profitSharingReceiver.setReceiverObjectId(recvMer.getId().toString()); |
|
|
|
|
profitSharingReceiver.setReceiverAccount(merLedger.getReceiverNo()); |
|
|
|
|
profitSharingReceiver.setReceiverName(recvMer.getMerName()); |
|
|
|
|
profitSharingReceiver.setReceiverAmount(new BigDecimal(recvData.getSeparateAmount())); |
|
|
|
|
tradeOrderProfitSharingReceiverService.editData(profitSharingReceiver); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 调用第三方分账
|
|
|
|
|
BsTradeOrderProfitSharing profitSharing = laKaLaTradeSeparateService.separate(tradeOrderProfitSharing.getProfitSharingOrderNo()); |
|
|
|
|
|
|
|
|
|
ResponseSeparateModel responseSeparate = new ResponseSeparateModel(); |
|
|
|
|
responseSeparate.setMerchantNo(separateModel.getMerchantNo()); |
|
|
|
|
responseSeparate.setOutSeparateNo(separateModel.getOutSeparateNo()); |
|
|
|
|
responseSeparate.setSeparateNo(profitSharing.getPlatformProfitSharingOrderNo()); |
|
|
|
|
responseSeparate.setStatus(profitSharing.getStatus()); |
|
|
|
|
responseSeparate.setTotalAmount(separateModel.getTotalAmount()); |
|
|
|
|
responseSeparate.setSign(SignatureUtil.createSign(responseSeparate, merKeyService.getKeyByMerNo(responseSeparate.getMerchantNo()))); |
|
|
|
|
return responseSeparate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@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 tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateCancelModel.getOutSeparateNo()); |
|
|
|
|
if (tradeOrderProfitSharing == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分商户分账指令"); |
|
|
|
|
} |
|
|
|
|
/*if (tradeOrderProfitSharing.getProfitSharingAmoun()) { |
|
|
|
|
|
|
|
|
|
}*/ |
|
|
|
|
// 交易订单
|
|
|
|
|
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); |
|
|
|
|
if (tradeOrder == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户分账指令"); |
|
|
|
|
} |
|
|
|
|
if (!separateCancelModel.getMerchantNo().equals(tradeOrder.getMerNo())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的商户分账指令"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// laKaLaTradeSeparateService.cancel();
|
|
|
|
|
|
|
|
|
|
ResponseSeparateCancelModel responseSeparateCancel = new ResponseSeparateCancelModel(); |
|
|
|
|
responseSeparateCancel.setSign(SignatureUtil.createSign(separateCancelModel, merKeyService.getKeyByMerNo(separateCancelModel.getMerchantNo()))); |
|
|
|
|
return responseSeparateCancel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ResponseSeparateQueryModel query(RequestSeparateQueryModel separateQueryModel) throws Exception { |
|
|
|
|
// 查询分账
|
|
|
|
|
BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateQueryModel.getOutSeparateNo()); |
|
|
|
|
if (tradeOrderProfitSharing == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分账流水号"); |
|
|
|
|
} |
|
|
|
|
// 交易订单
|
|
|
|
|
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); |
|
|
|
|
if (tradeOrder == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易流水号"); |
|
|
|
|
} |
|
|
|
|
if (!separateQueryModel.getMerchantNo().equals(tradeOrder.getMerNo())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分账流水号"); |
|
|
|
|
}/* |
|
|
|
|
// 第三方接口查询
|
|
|
|
|
JSONObject queryProfitSharing = laKaLaTradeSeparateService.query(separateQueryModel.getOutSeparateNo());*/ |
|
|
|
|
|
|
|
|
|
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.setTotalAmount(tradeOrderProfitSharing.getProfitSharingAmoun()); |
|
|
|
|
responseSeparateQueryModel.setStatus(tradeOrderProfitSharing.getStatus()); |
|
|
|
|
// 接收方
|
|
|
|
|
List<ResponseSeparateQueryModel.ResponseSeparateRecvDataModel> recvDataList = new ArrayList<>(); |
|
|
|
|
List<BsTradeOrderProfitSharingReceiver> receiverList = tradeOrderProfitSharingReceiverService.getReceiverListByProfitSharingId(tradeOrderProfitSharing.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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ResponseSeparateQueryAmtModel queryAmt(RequestSeparateQueryAmtModel separateQueryAmtModel) throws Exception { |
|
|
|
|
// 查询分账
|
|
|
|
|
BsTradeOrderProfitSharing tradeOrderProfitSharing = tradeOrderProfitSharingService.getDetailByProfitSharingOrderNo(separateQueryAmtModel.getOutSeparateNo()); |
|
|
|
|
if (tradeOrderProfitSharing == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分账流水号"); |
|
|
|
|
} |
|
|
|
|
// 交易订单
|
|
|
|
|
BsTradeOrder tradeOrder = openApiTradeOrderService.getOrderByOutTradeNo(tradeOrderProfitSharing.getTradeOrderNo()); |
|
|
|
|
if (tradeOrder == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的交易流水号"); |
|
|
|
|
} |
|
|
|
|
if (!separateQueryAmtModel.getMerchantNo().equals(tradeOrder.getMerNo())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知的分账流水号"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 第三方查询
|
|
|
|
|
JSONObject queryAmt = laKaLaTradeSeparateService.queryAmt(separateQueryAmtModel.getOutSeparateNo()); |
|
|
|
|
ResponseSeparateQueryAmtModel responseSeparateQueryAmtModel = new ResponseSeparateQueryAmtModel(); |
|
|
|
|
responseSeparateQueryAmtModel.setMerchantNo(separateQueryAmtModel.getMerchantNo()); |
|
|
|
|
responseSeparateQueryAmtModel.setTotalSeparateAmt(queryAmt.getBigDecimal("total_separate_amt").divide(new BigDecimal("100"))); |
|
|
|
|
responseSeparateQueryAmtModel.setCanSeparateAmt(queryAmt.getBigDecimal("can_separate_amt").divide(new BigDecimal("100"))); |
|
|
|
|
responseSeparateQueryAmtModel.setSign(SignatureUtil.createSign(responseSeparateQueryAmtModel, merKeyService.getKeyByMerNo(separateQueryAmtModel.getMerchantNo()))); |
|
|
|
|
return responseSeparateQueryAmtModel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|