|
@@ -9,6 +9,7 @@ import com.chelvc.cloud.vehicle.client.constant.PlatformConstant;
|
|
|
import com.chelvc.cloud.vehicle.client.constant.ReserveStatus;
|
|
|
import com.chelvc.cloud.vehicle.client.constant.TradeConstant;
|
|
|
import com.chelvc.cloud.vehicle.client.dto.*;
|
|
|
+import com.chelvc.cloud.vehicle.client.param.TransferNotifyParam;
|
|
|
import com.chelvc.cloud.vehicle.client.param.WithdrawNotifyParam;
|
|
|
import com.chelvc.cloud.vehicle.client.param.WithdrawParam;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.AssetMapper;
|
|
@@ -156,19 +157,41 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
}
|
|
|
Long finalUserId = userId;
|
|
|
DatabaseContextHolder.transactional((Executor) () -> {
|
|
|
+ Long withdrawId = null;
|
|
|
+ JSONObject json = null;
|
|
|
//生成提现订单
|
|
|
- Long withdrawId = withdrawService.createWithdraw(finalUserId, type, amount, 1);
|
|
|
- String sxyMerchantId = merchantRelation.getSxyMerchantId();
|
|
|
- //生成提现参数
|
|
|
- HashMap<String, Object> map = new HashMap<>();
|
|
|
- map.put("merchantId", sxyMerchantId);
|
|
|
- map.put("requestId", withdrawId);
|
|
|
- map.put("withdrawAmount", amount.multiply(new BigDecimal("100")));
|
|
|
- map.put("notifyUrl", TradeConstant.WITHDRAW_NOTIFY_URL);
|
|
|
- map.put("remark", "");
|
|
|
- Gson gson = new Gson();
|
|
|
- JSONObject json = TradeHandle.handle(gson.toJson(map),
|
|
|
- TradeConstant.WITHDRAW_URL, sxyMerchantId, TradeConstant.PARTNER_ID);
|
|
|
+ if(type == 2){
|
|
|
+ withdrawId = withdrawService.createWithdraw(finalUserId, type, amount, 1, 0);
|
|
|
+ //商户提现操作
|
|
|
+ String sxyMerchantId = merchantRelation.getSxyMerchantId();
|
|
|
+ //生成提现参数
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("merchantId", sxyMerchantId);
|
|
|
+ map.put("requestId", withdrawId);
|
|
|
+ map.put("withdrawAmount", amount.multiply(new BigDecimal("100")));
|
|
|
+ map.put("notifyUrl", TradeConstant.WITHDRAW_NOTIFY_URL);
|
|
|
+ map.put("remark", "");
|
|
|
+ Gson gson = new Gson();
|
|
|
+ json = TradeHandle.handle(gson.toJson(map),
|
|
|
+ TradeConstant.WITHDRAW_URL, sxyMerchantId, TradeConstant.PARTNER_ID);
|
|
|
+ } else {
|
|
|
+ //用户先转账后提现
|
|
|
+ withdrawId = withdrawService.createWithdraw(finalUserId, 1, amount, 1, 1);
|
|
|
+ MerchantRelation relation = merchantRelationService.queryByUserIdAndType(finalUserId, 1);
|
|
|
+ //生成转账参数
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("merchantId", TradeConstant.PARTNER_ID);
|
|
|
+ map.put("requestId", withdrawId);
|
|
|
+ map.put("receiverId", relation.getSxyMerchantId());
|
|
|
+ map.put("receiverType", "MERCHANT_ACC");
|
|
|
+ map.put("amount", amount.multiply(new BigDecimal("100")));
|
|
|
+ map.put("currency", "CNY");
|
|
|
+ map.put("notifyUrl", TradeConstant.TRANSFER_NOTIFY_URL);
|
|
|
+ map.put("deputeMark", "NOT_DO_DEPUTE");
|
|
|
+ Gson gson = new Gson();
|
|
|
+ json = TradeHandle.handle(gson.toJson(map),
|
|
|
+ TradeConstant.TRANSFER_URL, relation.getSxyMerchantId(), TradeConstant.PARTNER_ID);
|
|
|
+ }
|
|
|
String status = json.getString("status");
|
|
|
if(!"SUCCESS".equals(status)){
|
|
|
//提现申请失败
|
|
@@ -184,6 +207,44 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 转账
|
|
|
+ * @param sourceUserId
|
|
|
+ * @param targetUserId
|
|
|
+ * @param type
|
|
|
+ * @param amount
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount){
|
|
|
+ Long withdrawId = withdrawService.createWithdraw(targetUserId, type, amount, 1, 1);
|
|
|
+ MerchantRelation relation = merchantRelationService.queryByUserIdAndType(targetUserId, type);
|
|
|
+ //生成转账参数
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("merchantId", TradeConstant.PARTNER_ID);
|
|
|
+ map.put("requestId", withdrawId);
|
|
|
+ map.put("receiverId", relation.getSxyMerchantId());
|
|
|
+ map.put("receiverType", "MERCHANT_ACC");
|
|
|
+ map.put("amount", amount.multiply(new BigDecimal("100")));
|
|
|
+ map.put("currency", "CNY");
|
|
|
+ map.put("notifyUrl", TradeConstant.TRANSFER_NOTIFY_URL);
|
|
|
+ map.put("deputeMark", "NOT_DO_DEPUTE");
|
|
|
+ Gson gson = new Gson();
|
|
|
+ JSONObject json = TradeHandle.handle(gson.toJson(map),
|
|
|
+ TradeConstant.TRANSFER_URL, relation.getSxyMerchantId(), TradeConstant.PARTNER_ID);
|
|
|
+ String status = json.getString("status");
|
|
|
+ if(!"SUCCESS".equals(status)){
|
|
|
+ //转账申请失败
|
|
|
+ withdrawService.updateStatusById(withdrawId, 2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //冻结金额
|
|
|
+ int i = baseMapper.updateFrozenAmount(amount, LocalDateTime.now(), sourceUserId, type);
|
|
|
+ if(i != 1){
|
|
|
+ withdrawService.updateStatusById(withdrawId, 2);
|
|
|
+ throw new ResourceUnavailableException("提现申请失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void withdrawNotify(WithdrawNotifyParam param) {
|
|
@@ -215,4 +276,53 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void transferNotify(TransferNotifyParam param) {
|
|
|
+ String requestId = param.getRequestId();
|
|
|
+ Long id = Long.parseLong(requestId);
|
|
|
+ OmsWithdraw withdraw = withdrawService.queryById(id);
|
|
|
+ if(withdraw == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String withdrawAmount = param.getAmount();
|
|
|
+ BigDecimal amount = withdraw.getAmount();
|
|
|
+ if(amount.compareTo(new BigDecimal(withdrawAmount)) != 0){
|
|
|
+ //金额不一致
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String transferStatus = param.getStatus();
|
|
|
+ int status = 2;
|
|
|
+ if("SUCCESS".equals(transferStatus)){
|
|
|
+ status = 1;
|
|
|
+ }
|
|
|
+ //更新转账订单状态和外部订单号
|
|
|
+ int i = withdrawService.updateByNotify(id, null, status);
|
|
|
+ if(i == 1){
|
|
|
+ if(status == 2){
|
|
|
+ //失败解冻金额
|
|
|
+ baseMapper.backFrozen(amount, withdraw.getUserId(), withdraw.getType(), LocalDateTime.now());
|
|
|
+ } else {
|
|
|
+ //用户提现
|
|
|
+ Long withdrawId = withdrawService.createWithdraw(withdraw.getUserId(), 1, amount, 1, 0);
|
|
|
+ //商户提现操作
|
|
|
+ String sxyMerchantId = param.getReceiverId();
|
|
|
+ //生成提现参数
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("merchantId", sxyMerchantId);
|
|
|
+ map.put("requestId", withdrawId);
|
|
|
+ map.put("withdrawAmount", amount.multiply(new BigDecimal("100")));
|
|
|
+ map.put("notifyUrl", TradeConstant.WITHDRAW_NOTIFY_URL);
|
|
|
+ map.put("remark", "");
|
|
|
+ Gson gson = new Gson();
|
|
|
+ JSONObject json = TradeHandle.handle(gson.toJson(map),
|
|
|
+ TradeConstant.WITHDRAW_URL, sxyMerchantId, TradeConstant.PARTNER_ID);
|
|
|
+ String result = json.getString("status");
|
|
|
+ if(!"SUCCESS".equals(result)){
|
|
|
+ //提现申请失败
|
|
|
+ withdrawService.updateStatusById(withdrawId, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|