|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.blockchain.server.otc.service.impl; |
|
|
|
package com.blockchain.server.otc.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.blockchain.common.base.dto.ResultDTO; |
|
|
|
import com.blockchain.common.base.dto.ResultDTO; |
|
|
|
|
|
|
|
import com.blockchain.server.otc.common.constant.BillConstants; |
|
|
|
import com.blockchain.server.otc.common.constant.MarketApplyConstants; |
|
|
|
import com.blockchain.server.otc.common.constant.MarketApplyConstants; |
|
|
|
import com.blockchain.server.otc.common.constant.MarketUserConstants; |
|
|
|
import com.blockchain.server.otc.common.constant.MarketUserConstants; |
|
|
|
import com.blockchain.server.otc.common.enums.OtcEnums; |
|
|
|
import com.blockchain.server.otc.common.enums.OtcEnums; |
|
|
@ -10,10 +11,8 @@ import com.blockchain.server.otc.entity.MarketFreeze; |
|
|
|
import com.blockchain.server.otc.entity.MarketUser; |
|
|
|
import com.blockchain.server.otc.entity.MarketUser; |
|
|
|
import com.blockchain.server.otc.feign.UserFeign; |
|
|
|
import com.blockchain.server.otc.feign.UserFeign; |
|
|
|
import com.blockchain.server.otc.mapper.MarketApplyMapper; |
|
|
|
import com.blockchain.server.otc.mapper.MarketApplyMapper; |
|
|
|
import com.blockchain.server.otc.service.ConfigService; |
|
|
|
import com.blockchain.server.otc.service.*; |
|
|
|
import com.blockchain.server.otc.service.MarketApplyService; |
|
|
|
import com.codingapi.tx.annotation.TxTransaction; |
|
|
|
import com.blockchain.server.otc.service.MarketFreezeService; |
|
|
|
|
|
|
|
import com.blockchain.server.otc.service.MarketUserService; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -34,8 +33,15 @@ public class MarketApplyServiceImpl implements MarketApplyService { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ConfigService configService; |
|
|
|
private ConfigService configService; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
|
|
|
|
private WalletService walletService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private BillService billService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserFeign userFeign; |
|
|
|
private UserFeign userFeign; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保证金固定为CNY
|
|
|
|
|
|
|
|
private static final String UNIT_NAME = "CNY"; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
public void applyMarket(String userId, String applyType) { |
|
|
|
public void applyMarket(String userId, String applyType) { |
|
|
@ -51,6 +57,88 @@ public class MarketApplyServiceImpl implements MarketApplyService { |
|
|
|
insertMarketApply(userId, applyType); |
|
|
|
insertMarketApply(userId, applyType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
|
|
@TxTransaction(isStart = true) |
|
|
|
|
|
|
|
public void asMarket(String userId) { |
|
|
|
|
|
|
|
//提交市商申请时,判断用户是否通过高级认证
|
|
|
|
|
|
|
|
checkUserHighAuth(userId, MarketUserConstants.MARKET); |
|
|
|
|
|
|
|
//查询用户市商状态
|
|
|
|
|
|
|
|
MarketUser marketUser = marketUserService.getMarketUserByUserId(userId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//市商用户存在
|
|
|
|
|
|
|
|
if (marketUser != null) { |
|
|
|
|
|
|
|
//市商状态不等于未认证
|
|
|
|
|
|
|
|
if (!marketUser.getStatus().equals(MarketUserConstants.NOTMARKET)) { |
|
|
|
|
|
|
|
throw new OtcException(OtcEnums.USER_IS_MRAKET); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//更新市商用户状态为市商
|
|
|
|
|
|
|
|
marketUser.setStatus(MarketUserConstants.MARKET); |
|
|
|
|
|
|
|
marketUser.setModifyTime(new Date()); |
|
|
|
|
|
|
|
marketUserService.updateByPrimaryKeySelective(marketUser); |
|
|
|
|
|
|
|
} else {//市商用户不存在
|
|
|
|
|
|
|
|
//新建市商
|
|
|
|
|
|
|
|
marketUserService.insertMarketUser(userId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//新建市商申请
|
|
|
|
|
|
|
|
//市商申请id
|
|
|
|
|
|
|
|
String applyId = insertAgreeMarketApply(userId, MarketApplyConstants.MARKET); |
|
|
|
|
|
|
|
//市商保证金代币
|
|
|
|
|
|
|
|
String coinName = configService.selectMarketFreezeCoin(); |
|
|
|
|
|
|
|
//市商保证金数量
|
|
|
|
|
|
|
|
BigDecimal amount = configService.selectMarketFreezeAmount(); |
|
|
|
|
|
|
|
//防止保证金代币和数量为空
|
|
|
|
|
|
|
|
if (coinName != null && amount.compareTo(BigDecimal.ZERO) > 0) { |
|
|
|
|
|
|
|
//新建冻结记录
|
|
|
|
|
|
|
|
marketFreezeService.insertMarketFreeze(userId, amount, coinName); |
|
|
|
|
|
|
|
//冻结余额
|
|
|
|
|
|
|
|
walletService.handleBalance(userId, applyId, coinName, UNIT_NAME, BigDecimal.ZERO, amount); |
|
|
|
|
|
|
|
//增加余额变更记录
|
|
|
|
|
|
|
|
billService.insertBill(userId, applyId, BigDecimal.ZERO, amount, BillConstants.MARKET_USER, coinName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
|
|
@TxTransaction(isStart = true) |
|
|
|
|
|
|
|
public void cancelMarket(String userId) { |
|
|
|
|
|
|
|
//查询用户市商状态
|
|
|
|
|
|
|
|
MarketUser marketUser = marketUserService.getMarketUserByUserId(userId); |
|
|
|
|
|
|
|
//市商用户为空
|
|
|
|
|
|
|
|
if (marketUser == null) { |
|
|
|
|
|
|
|
throw new OtcException(OtcEnums.MARKET_USER_NULL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//市商用户状态不等于市商
|
|
|
|
|
|
|
|
if (!marketUser.getStatus().equals(MarketUserConstants.MARKET)) { |
|
|
|
|
|
|
|
throw new OtcException(OtcEnums.CANCEL_MARKET_USER_STATUS_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//新建市商申请
|
|
|
|
|
|
|
|
String applyId = insertAgreeMarketApply(userId, MarketApplyConstants.CANCEL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新
|
|
|
|
|
|
|
|
marketUser.setStatus(MarketUserConstants.NOTMARKET); |
|
|
|
|
|
|
|
marketUser.setModifyTime(new Date()); |
|
|
|
|
|
|
|
marketUserService.updateByPrimaryKeySelective(marketUser); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询保证金记录
|
|
|
|
|
|
|
|
MarketFreeze marketFreeze = marketFreezeService.getByUserId(userId); |
|
|
|
|
|
|
|
if (marketFreeze != null) { |
|
|
|
|
|
|
|
//删除冻结记录
|
|
|
|
|
|
|
|
marketFreezeService.deleteMarketFreeze(userId); |
|
|
|
|
|
|
|
//解冻资金
|
|
|
|
|
|
|
|
BigDecimal freeAmount = marketFreeze.getAmount(); |
|
|
|
|
|
|
|
BigDecimal freezeAmount = freeAmount.multiply(new BigDecimal("-1")); |
|
|
|
|
|
|
|
//解冻的币种
|
|
|
|
|
|
|
|
String coinName = marketFreeze.getCoinName(); |
|
|
|
|
|
|
|
//解冻余额
|
|
|
|
|
|
|
|
walletService.handleBalance(userId, applyId, coinName, UNIT_NAME, freeAmount, freezeAmount); |
|
|
|
|
|
|
|
//增加余额变更记录
|
|
|
|
|
|
|
|
billService.insertBill(userId, applyId, freeAmount, freezeAmount, BillConstants.CANCEL_MARKET_USER, coinName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MarketApply getByUserIdAndApplyTypeAndStatus(String userId, String applyType, String status) { |
|
|
|
public MarketApply getByUserIdAndApplyTypeAndStatus(String userId, String applyType, String status) { |
|
|
|
return marketApplyMapper.selectByUserIdAndApplyTypeAndStatus(userId, applyType, status); |
|
|
|
return marketApplyMapper.selectByUserIdAndApplyTypeAndStatus(userId, applyType, status); |
|
|
@ -101,6 +189,27 @@ public class MarketApplyServiceImpl implements MarketApplyService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* 新建状态为'已同意'的申请记录 |
|
|
|
|
|
|
|
* @param userId |
|
|
|
|
|
|
|
* @param applyType |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String insertAgreeMarketApply(String userId, String applyType) { |
|
|
|
|
|
|
|
MarketApply marketApply = new MarketApply(); |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
String applyId = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
marketApply.setId(applyId); |
|
|
|
|
|
|
|
marketApply.setUserId(userId); |
|
|
|
|
|
|
|
marketApply.setApplyType(applyType); |
|
|
|
|
|
|
|
marketApply.setCreateTime(now); |
|
|
|
|
|
|
|
marketApply.setModifyTime(now); |
|
|
|
|
|
|
|
marketApply.setStatus(MarketApplyConstants.AGREE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
marketApplyMapper.insertSelective(marketApply); |
|
|
|
|
|
|
|
return applyId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
|
* 新增市商申请 |
|
|
|
* 新增市商申请 |
|
|
|
* @param userId |
|
|
|
* @param userId |
|
|
|