|
@@ -6,31 +6,41 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
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.SxyNotifyParam;
|
|
|
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;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Asset;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.MerchantRelation;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.OmsWithdraw;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.OmsTransferWithdraw;
|
|
|
import com.chelvc.cloud.vehicle.server.handle.TradeHandle;
|
|
|
import com.chelvc.cloud.vehicle.server.service.*;
|
|
|
import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
import com.chelvc.framework.common.function.Executor;
|
|
|
import com.chelvc.framework.database.context.DatabaseContextHolder;
|
|
|
+import com.upay.sdk.exception.HmacVerifyException;
|
|
|
+import com.upay.sdk.exception.RequestException;
|
|
|
+import com.upay.sdk.exception.ResponseException;
|
|
|
+import com.upay.sdk.exception.UnknownException;
|
|
|
+import com.upay.sdk.executer.ResultListenerAdpater;
|
|
|
+import com.upay.sdk.transferaccount.builder.OrderBuilder;
|
|
|
+import com.upay.sdk.transferaccount.executer.TransferAccountOrderExecuter;
|
|
|
+import com.upay.sdk.wallet.builder.WithdrawBuilder;
|
|
|
+import com.upay.sdk.wallet.executer.WithdrawExecuter;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
@Service
|
|
@@ -40,7 +50,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
private final OmsOrderService orderService;
|
|
|
private final MerchantService merchantService;
|
|
|
private final MerchantRelationService merchantRelationService;
|
|
|
- private final OmsWithdrawService withdrawService;
|
|
|
+ private final OmsTransferWithdrawService transferWithdrawService;
|
|
|
|
|
|
@Override
|
|
|
public Asset queryAsset(Long userId, Integer type) {
|
|
@@ -129,7 +139,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void withdraw(WithdrawParam param) {
|
|
|
+ public void withdrawApply(WithdrawParam param) {
|
|
|
Integer type = param.getType();
|
|
|
BigDecimal amount = param.getAmount();
|
|
|
Long userId = SessionContextHolder.getId();
|
|
@@ -137,7 +147,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
throw new ResourceUnavailableException("提现类型错误");
|
|
|
}
|
|
|
if(type == 2){
|
|
|
- //商家体现
|
|
|
+ //商家提现
|
|
|
Long merchantId = param.getMerchantId();
|
|
|
MerchantDTO merchantDTO = merchantService.queryCheck(merchantId, userId);
|
|
|
if(merchantDTO == null){
|
|
@@ -157,56 +167,85 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
}
|
|
|
Long finalUserId = userId;
|
|
|
DatabaseContextHolder.transactional((Executor) () -> {
|
|
|
- Long withdrawId = null;
|
|
|
- JSONObject json = null;
|
|
|
//生成提现订单
|
|
|
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);
|
|
|
+ //商户直接提现
|
|
|
+ withdraw(finalUserId, type, amount);
|
|
|
} 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)){
|
|
|
- //提现申请失败
|
|
|
- withdrawService.updateStatusById(withdrawId, 2);
|
|
|
- return;
|
|
|
- }
|
|
|
- //冻结金额
|
|
|
- int i = baseMapper.updateFrozenAmount(amount, LocalDateTime.now(), finalUserId, type);
|
|
|
- if(i != 1){
|
|
|
- withdrawService.updateStatusById(withdrawId, 2);
|
|
|
- throw new ResourceUnavailableException("提现申请失败");
|
|
|
+ transfer(0L, finalUserId, type, amount);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void reduceFrozenAsset(BigDecimal payAmount, Long userId, Integer type) {
|
|
|
+ baseMapper.reduceFrozenAsset(payAmount, userId, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void withdraw(Long userId, Integer type, BigDecimal amount) {
|
|
|
+ Long withdrawId = transferWithdrawService.createTransferWithdraw(userId, type, amount, 1, 0);
|
|
|
+ //查询首信易商户号
|
|
|
+ MerchantRelation relation = merchantRelationService.queryByUserIdAndType(userId, type);
|
|
|
+ if(relation == null){
|
|
|
+ throw new ResourceUnavailableException("请联系管理员开通商户号");
|
|
|
+ }
|
|
|
+ String sxyMerchantId = relation.getSxyMerchantId();
|
|
|
+ //生成提现参数
|
|
|
+ WithdrawBuilder builder = new WithdrawBuilder(sxyMerchantId);
|
|
|
+ builder.setRequestId(String.valueOf(withdrawId))
|
|
|
+ .setPartnerId(TradeConstant.PARTNER_ID)
|
|
|
+ .setWithdrawAmount(String.valueOf(amount.multiply(new BigDecimal("100")).longValue()))
|
|
|
+ .setNotifyUrl(TradeConstant.WITHDRAW_NOTIFY_URL);
|
|
|
+ WithdrawExecuter executer = new WithdrawExecuter();
|
|
|
+ String cause = "";
|
|
|
+ try {
|
|
|
+ executer.bothWithdraw(builder, new ResultListenerAdpater() {
|
|
|
+ @Override
|
|
|
+ public void success(JSONObject jsonObject) {
|
|
|
+ //冻结金额
|
|
|
+ int i = frozenAmount(amount, userId, type);
|
|
|
+ if(i != 1){
|
|
|
+ transferWithdrawService.updateStatusById(withdrawId, 2, "冻结金额失败");
|
|
|
+ throw new ResourceUnavailableException("提现申请失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ } catch (ResponseException e) {
|
|
|
+ JSONObject responseData = e.getResponseData();
|
|
|
+ cause = responseData.getString("cause");
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ } catch (HmacVerifyException e) {
|
|
|
+ cause = "签名验证异常";
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ } catch (RequestException e) {
|
|
|
+ JSONObject responseData = e.getResponseData();
|
|
|
+ cause = responseData.getString("cause");
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ } catch (UnknownException e) {
|
|
|
+ cause = "未知异常";
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ }
|
|
|
+ transferWithdrawService.updateStatusById(withdrawId, 2, cause);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int frozenAmount(BigDecimal amount, Long userId, Integer type) {
|
|
|
+ Asset asset = queryAsset(userId, type);
|
|
|
+ BigDecimal total = asset.getTotal();
|
|
|
+ if(amount.compareTo(total) >= 0){
|
|
|
+ throw new ResourceUnavailableException("余额不足");
|
|
|
+ }
|
|
|
+ asset.setTotal(asset.getTotal().subtract(amount));
|
|
|
+ asset.setFrozen(asset.getFrozen().add(amount));
|
|
|
+ asset.setUpdateTime(LocalDateTime.now());
|
|
|
+ return baseMapper.updateById(asset);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 转账
|
|
|
* @param sourceUserId
|
|
@@ -216,118 +255,185 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
*/
|
|
|
@Override
|
|
|
public void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount){
|
|
|
- Long withdrawId = withdrawService.createWithdraw(targetUserId, type, amount, 1, 1);
|
|
|
+ Long transferId = transferWithdrawService.createTransferWithdraw(targetUserId, type, amount, 1, 1);
|
|
|
+ //查询首信易商户号
|
|
|
MerchantRelation relation = merchantRelationService.queryByUserIdAndType(targetUserId, type);
|
|
|
+ if(relation == null){
|
|
|
+ throw new ResourceUnavailableException("请联系管理员开通商户号");
|
|
|
+ }
|
|
|
//生成转账参数
|
|
|
- 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);
|
|
|
+ OrderBuilder builder = new OrderBuilder(TradeConstant.PARTNER_ID);
|
|
|
+ builder.setRequestId(String.valueOf(transferId))
|
|
|
+ .setAmount(String.valueOf(amount.multiply(new BigDecimal("100")).longValue()))
|
|
|
+ .setNotifyUrl(TradeConstant.TRANSFER_NOTIFY_URL)
|
|
|
+ .setCurrency("CNY")
|
|
|
+ .setReceiverId(relation.getSxyMerchantId())
|
|
|
+ .setReceiverType("MERCHANT_ACC")
|
|
|
+ .setDeputeMark("NOT_DO_DEPUTE");
|
|
|
+ TransferAccountOrderExecuter executer = new TransferAccountOrderExecuter();
|
|
|
+ String cause = "";
|
|
|
+ try {
|
|
|
+ executer.bothOrder(builder, new ResultListenerAdpater() {
|
|
|
+ /**
|
|
|
+ * 提交成功,不代表支付成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void success(JSONObject jsonObject) {
|
|
|
+ //冻结金额
|
|
|
+ int i = frozenAmount(amount, 0L, 0);
|
|
|
+ if(i != 1){
|
|
|
+ transferWithdrawService.updateStatusById(transferId, 2, "冻结金额失败");
|
|
|
+ throw new ResourceUnavailableException("转账失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
return;
|
|
|
+ } catch (ResponseException e) {
|
|
|
+ JSONObject responseData = e.getResponseData();
|
|
|
+ cause = responseData.getString("cause");
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ } catch (HmacVerifyException e) {
|
|
|
+ cause = "签名验证异常";
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ } catch (RequestException e) {
|
|
|
+ JSONObject responseData = e.getResponseData();
|
|
|
+ cause = responseData.getString("cause");
|
|
|
+ log.error("transfer order error:", e);
|
|
|
+ } catch (UnknownException e) {
|
|
|
+ cause = "未知异常";
|
|
|
+ log.error("transfer order error:", e);
|
|
|
}
|
|
|
- //冻结金额
|
|
|
- int i = baseMapper.updateFrozenAmount(amount, LocalDateTime.now(), sourceUserId, type);
|
|
|
- if(i != 1){
|
|
|
- withdrawService.updateStatusById(withdrawId, 2);
|
|
|
- throw new ResourceUnavailableException("提现申请失败");
|
|
|
+ transferWithdrawService.updateStatusById(transferId, 2, cause);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateAmount(Long userId, Integer type, Integer operate, BigDecimal amount) {
|
|
|
+ Asset asset = queryAsset(userId, type);
|
|
|
+ if(operate == 0){
|
|
|
+ return baseMapper.addAmount(userId, type, amount, LocalDateTime.now());
|
|
|
+ } else if(operate == 1){
|
|
|
+ BigDecimal total = asset.getTotal();
|
|
|
+ if(total.compareTo(amount) < 0){
|
|
|
+ throw new ResourceUnavailableException("账户余额不足");
|
|
|
+ }
|
|
|
+ return baseMapper.reduceAmount(userId, type, amount, LocalDateTime.now());
|
|
|
}
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void withdrawNotify(WithdrawNotifyParam param) {
|
|
|
- String requestId = param.getRequestId();
|
|
|
+ public void withdrawNotify(SxyNotifyParam param) {
|
|
|
+ JSONObject responseData = TradeHandle.decrypt(param);
|
|
|
+ if(responseData == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String requestId = responseData.getString("requestId");
|
|
|
Long id = Long.parseLong(requestId);
|
|
|
- OmsWithdraw withdraw = withdrawService.queryById(id);
|
|
|
+ OmsTransferWithdraw withdraw = transferWithdrawService.queryById(id);
|
|
|
if(withdraw == null){
|
|
|
return;
|
|
|
}
|
|
|
- String withdrawAmount = param.getWithdrawAmount();
|
|
|
+ Integer transferStatus = withdraw.getStatus();
|
|
|
+ if(transferStatus != 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String withdrawAmount = responseData.getString("withdrawAmount");
|
|
|
BigDecimal amount = withdraw.getAmount();
|
|
|
- if(amount.compareTo(new BigDecimal(withdrawAmount)) != 0){
|
|
|
+ if(amount.multiply(new BigDecimal("100")).compareTo(new BigDecimal(withdrawAmount)) != 0){
|
|
|
//金额不一致
|
|
|
return;
|
|
|
}
|
|
|
- String withdrawStatus = param.getWithdrawStatus();
|
|
|
- int status = 2;
|
|
|
+ String withdrawStatus = responseData.getString("withdrawStatus");
|
|
|
+ BigDecimal procedureAmount = BigDecimal.ZERO;
|
|
|
if("SUCCESS".equals(withdrawStatus)){
|
|
|
- status = 1;
|
|
|
+ transferStatus = 1;
|
|
|
+ String receivedAmount = responseData.getString("receivedAmount");
|
|
|
+ procedureAmount = amount.subtract(new BigDecimal(receivedAmount));
|
|
|
+ } else if("FAIL".equals(withdrawStatus)){
|
|
|
+ transferStatus = 2;
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
}
|
|
|
+ String errorMessage = responseData.getString("errorMessage");
|
|
|
//更新提现订单状态和外部订单号
|
|
|
- int i = withdrawService.updateByNotify(id, param.getOrderId(), status);
|
|
|
+ int i = transferWithdrawService.updateByNotify(id, "", transferStatus, errorMessage, procedureAmount);
|
|
|
if(i == 1){
|
|
|
- if(status == 2){
|
|
|
+ if(transferStatus == 2){
|
|
|
//失败解冻金额
|
|
|
baseMapper.backFrozen(amount, withdraw.getUserId(), withdraw.getType(), LocalDateTime.now());
|
|
|
} else {
|
|
|
- baseMapper.deductFrozen(amount, withdraw.getUserId(),withdraw.getType(), LocalDateTime.now());
|
|
|
+ baseMapper.deductFrozen(amount, withdraw.getUserId(), withdraw.getType(), LocalDateTime.now());
|
|
|
+ BigDecimal total = queryTotal(withdraw.getUserId(), withdraw.getType());
|
|
|
+ //记录平台抽成余额明细
|
|
|
+ balanceDetailService.recordFlow(id, withdraw.getType(), withdraw.getUserId(), amount, BigDecimal.ZERO,
|
|
|
+ amount, total, 1, 4, withdraw.getUserId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void transferNotify(TransferNotifyParam param) {
|
|
|
- String requestId = param.getRequestId();
|
|
|
+ public BigDecimal queryTotal(Long userId, Integer type){
|
|
|
+ return baseMapper.queryTotal(userId, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void transferNotify(SxyNotifyParam param) {
|
|
|
+ JSONObject responseData = TradeHandle.decrypt(param);
|
|
|
+ if(responseData == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String requestId = responseData.getString("requestId");
|
|
|
Long id = Long.parseLong(requestId);
|
|
|
- OmsWithdraw withdraw = withdrawService.queryById(id);
|
|
|
- if(withdraw == null){
|
|
|
+ OmsTransferWithdraw transfer = transferWithdrawService.queryById(id);
|
|
|
+ if(transfer == null){
|
|
|
return;
|
|
|
}
|
|
|
- String withdrawAmount = param.getAmount();
|
|
|
- BigDecimal amount = withdraw.getAmount();
|
|
|
- if(amount.compareTo(new BigDecimal(withdrawAmount)) != 0){
|
|
|
+ Integer transferStatus = transfer.getStatus();
|
|
|
+ if(transferStatus != 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String transferAmount = responseData.getString("amount");
|
|
|
+ BigDecimal amount = transfer.getAmount();
|
|
|
+ if(amount.multiply(new BigDecimal("100")).compareTo(new BigDecimal(transferAmount)) != 0){
|
|
|
//金额不一致
|
|
|
return;
|
|
|
}
|
|
|
- String transferStatus = param.getStatus();
|
|
|
- int status = 2;
|
|
|
- if("SUCCESS".equals(transferStatus)){
|
|
|
- status = 1;
|
|
|
+ String transferResultStatus = responseData.getString("status");
|
|
|
+ if("SUCCESS".equals(transferResultStatus)){
|
|
|
+ transferStatus = 1;
|
|
|
+ } else if("CANCEL".equals(transferResultStatus)){
|
|
|
+ transferStatus = 3;
|
|
|
+ } else if("FAILED".equals(transferResultStatus)){
|
|
|
+ transferStatus = 2;
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
}
|
|
|
+ String errorMessage = responseData.getString("errorMessage");
|
|
|
//更新转账订单状态和外部订单号
|
|
|
- int i = withdrawService.updateByNotify(id, null, status);
|
|
|
+ int i = transferWithdrawService.updateByNotify(id, null, transferStatus, errorMessage, BigDecimal.ZERO);
|
|
|
if(i == 1){
|
|
|
- if(status == 2){
|
|
|
- //失败解冻金额
|
|
|
- baseMapper.backFrozen(amount, withdraw.getUserId(), withdraw.getType(), LocalDateTime.now());
|
|
|
+ if(transferStatus == 2){
|
|
|
+ //失败平台解冻金额
|
|
|
+ baseMapper.backFrozen(amount, 0L, 0, LocalDateTime.now());
|
|
|
} else {
|
|
|
- Integer type = withdraw.getType();
|
|
|
+ Integer type = transfer.getType();
|
|
|
+ //平台扣除冻结金额
|
|
|
+ baseMapper.deductFrozen(amount, 0L, 0, LocalDateTime.now());
|
|
|
+ BigDecimal platformTotal = queryTotal(0L, 0);
|
|
|
+ //记录平台转账余额明细
|
|
|
+ balanceDetailService.recordFlow(id, 0, 0L, amount, BigDecimal.ZERO,
|
|
|
+ amount, platformTotal, 1, 7, transfer.getUserId());
|
|
|
if(type == 2){
|
|
|
- //商家转账-更新余额
|
|
|
- baseMapper.deductFrozen(amount, withdraw.getUserId(), withdraw.getType(), LocalDateTime.now());
|
|
|
+ //商户转账-更新余额
|
|
|
+ baseMapper.addAmount(transfer.getUserId(), transfer.getType(), amount, LocalDateTime.now());
|
|
|
+ BigDecimal merchantTotal = queryTotal(transfer.getUserId(), transfer.getType());
|
|
|
+ //记录平台转账余额明细
|
|
|
+ balanceDetailService.recordFlow(id, 0, 0L, amount, BigDecimal.ZERO,
|
|
|
+ amount, merchantTotal, 0, 7, 0L);
|
|
|
} 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);
|
|
|
- }
|
|
|
+ withdraw(transfer.getUserId(), transfer.getType(), amount);
|
|
|
}
|
|
|
}
|
|
|
}
|