|
|
@@ -36,6 +36,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
|
@@ -69,14 +70,23 @@ public class GiftOrderService {
|
|
|
private GeneralProperties generalProperties;
|
|
|
private SnowflakeIdWorker snowflakeIdWorker;
|
|
|
private ErrorOrderRepo errorOrderRepo;
|
|
|
+ private PasswordEncoder passwordEncoder;
|
|
|
|
|
|
@Transactional
|
|
|
- public GiftOrder giftWithoutGasFee(Long userId, Long assetId, Long toUserId) {
|
|
|
+ public GiftOrder giftWithoutGasFee(Long userId, Long assetId, Long toUserId, String tradeCode) {
|
|
|
+ if (BigDecimal.ZERO.compareTo(sysConfigService.getBigDecimal("gift_gas_fee")) != 0) {
|
|
|
+ throw new BusinessException("需支付gas费");
|
|
|
+ }
|
|
|
Asset asset = assetRepo.findById(assetId).orElseThrow(new BusinessException("资产不存在"));
|
|
|
if (!asset.getUserId().equals(userId)) {
|
|
|
throw new BusinessException("无权限");
|
|
|
}
|
|
|
|
|
|
+ User user = userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ if (!passwordEncoder.matches(tradeCode, user.getTradeCode())) {
|
|
|
+ throw new BusinessException("交易密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
int holdDays;
|
|
|
if (ObjectUtils.isEmpty(asset.getHoldDays())) {
|
|
|
holdDays = sysConfigService.getInt("hold_days");
|
|
|
@@ -123,15 +133,20 @@ public class GiftOrderService {
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public GiftOrder gift(Long userId, Long assetId, Long toUserId) {
|
|
|
+ public GiftOrder gift(Long userId, Long assetId, Long toUserId, String tradeCode) {
|
|
|
if (BigDecimal.ZERO.compareTo(sysConfigService.getBigDecimal("gift_gas_fee")) == 0) {
|
|
|
- return giftWithoutGasFee(userId, assetId, toUserId);
|
|
|
+ return giftWithoutGasFee(userId, assetId, toUserId, tradeCode);
|
|
|
}
|
|
|
Asset asset = assetRepo.findById(assetId).orElseThrow(new BusinessException("资产不存在"));
|
|
|
if (!asset.getUserId().equals(userId)) {
|
|
|
throw new BusinessException("无权限");
|
|
|
}
|
|
|
|
|
|
+ User user = userRepo.findById(asset.getUserId()).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ if (!passwordEncoder.matches(tradeCode, user.getTradeCode())) {
|
|
|
+ throw new BusinessException("交易密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
int holdDays;
|
|
|
if (ObjectUtils.isEmpty(asset.getHoldDays())) {
|
|
|
holdDays = sysConfigService.getInt("hold_days");
|