|
@@ -1,7 +1,6 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -9,8 +8,6 @@ import com.chelvc.cloud.vehicle.client.constant.PlatformConstant;
|
|
|
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;
|
|
@@ -32,17 +29,15 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
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.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor = @__({@Autowired,@Lazy}))
|
|
|
public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements AssetService {
|
|
@@ -182,6 +177,9 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
*/
|
|
|
@Override
|
|
|
public void withdraw(Long userId, Integer type, BigDecimal amount) {
|
|
|
+ if(amount.compareTo(new BigDecimal("1.00")) <= 0){
|
|
|
+ throw new ResourceUnavailableException("提现金额不能少于1元");
|
|
|
+ }
|
|
|
Long withdrawId = transferWithdrawService.createTransferWithdraw(userId, type, amount, 1, 0);
|
|
|
//查询首信易商户号
|
|
|
MerchantRelation relation = merchantRelationService.queryByUserIdAndType(userId, type);
|
|
@@ -228,12 +226,13 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
log.error("transfer order error:", e);
|
|
|
}
|
|
|
transferWithdrawService.updateStatusById(withdrawId, 2, cause);
|
|
|
+ throw new ResourceUnavailableException(cause);
|
|
|
}
|
|
|
|
|
|
public int frozenAmount(BigDecimal amount, Long userId, Integer type) {
|
|
|
Asset asset = queryAsset(userId, type);
|
|
|
BigDecimal total = asset.getTotal();
|
|
|
- if(amount.compareTo(total) >= 0){
|
|
|
+ if(amount.compareTo(total) > 0){
|
|
|
throw new ResourceUnavailableException("余额不足");
|
|
|
}
|
|
|
asset.setTotal(asset.getTotal().subtract(amount));
|
|
@@ -301,6 +300,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
log.error("transfer order error:", e);
|
|
|
}
|
|
|
transferWithdrawService.updateStatusById(transferId, 2, cause);
|
|
|
+ throw new ResourceUnavailableException(cause);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -324,6 +324,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
if(responseData == null){
|
|
|
return;
|
|
|
}
|
|
|
+ log.info("提现回调参数:{}", responseData);
|
|
|
String requestId = responseData.getString("requestId");
|
|
|
Long id = Long.parseLong(requestId);
|
|
|
OmsTransferWithdraw withdraw = transferWithdrawService.queryById(id);
|
|
@@ -342,10 +343,12 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
}
|
|
|
String withdrawStatus = responseData.getString("withdrawStatus");
|
|
|
BigDecimal procedureAmount = BigDecimal.ZERO;
|
|
|
+ String receivedAmount = responseData.getString("receivedAmount");
|
|
|
+ BigDecimal realAmount = new BigDecimal(receivedAmount == null ? "0" : receivedAmount)
|
|
|
+ .divide(new BigDecimal("100"), 2, RoundingMode.UP);
|
|
|
if("SUCCESS".equals(withdrawStatus)){
|
|
|
transferStatus = 1;
|
|
|
- String receivedAmount = responseData.getString("receivedAmount");
|
|
|
- procedureAmount = amount.subtract(new BigDecimal(receivedAmount));
|
|
|
+ procedureAmount = amount.subtract(realAmount);
|
|
|
} else if("FAIL".equals(withdrawStatus)){
|
|
|
transferStatus = 2;
|
|
|
} else {
|
|
@@ -362,8 +365,8 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
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());
|
|
|
+ balanceDetailService.recordFlow(id, withdraw.getType(), withdraw.getUserId(), amount, procedureAmount,
|
|
|
+ realAmount, total, 1, 4, withdraw.getUserId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -376,6 +379,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
@Override
|
|
|
public void transferNotify(SxyNotifyParam param) {
|
|
|
JSONObject responseData = TradeHandle.decrypt(param);
|
|
|
+ log.info("转账回调参数:{}", responseData);
|
|
|
if(responseData == null){
|
|
|
return;
|
|
|
}
|