做市商 bug fix

master
fengyu.wang 4 years ago
parent 9467cc4823
commit 3306fb2473
  1. 2
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/entity/Ad.java
  2. 15
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/AdServiceImpl.java
  3. 52
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/OrderServiceImpl.java
  4. 28
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/UserPayInfoServiceImpl.java

@ -52,6 +52,8 @@ public class Ad extends BaseModel {
private String adStatus;
@Column(name = "ad_remark")
private String adRemark;
@Column(name = "built_in")
private Boolean builtIn;
@Column(name = "create_time")
private java.util.Date createTime;
@Column(name = "modify_time")

@ -63,7 +63,7 @@ public class AdServiceImpl implements AdService, ITxTransaction {
//广告手续费率
BigDecimal serviceCharge = checkAdServiceCharge(coin.getCoinServiceCharge(), param.getUserId());
//新建广告数据,返回广告流水号
String adNumber = insertAd(param, CommonConstans.BUY, serviceCharge);
String adNumber = insertAd(param, CommonConstans.BUY, serviceCharge, false);
//新增用户交易数据表
dealStatsService.insertIsNotExist(param.getUserId());
//记录用户操作
@ -85,12 +85,12 @@ public class AdServiceImpl implements AdService, ITxTransaction {
//判断是否开启广告手续费
BigDecimal chargeRatio = checkAdServiceCharge(coin.getCoinServiceCharge(), param.getUserId());
//新建广告数据,返回广告流水号
adNumber = insertAd(param, CommonConstans.SELL, chargeRatio);
adNumber = insertAd(param, CommonConstans.SELL, chargeRatio, false);
//更新钱包并记录资金变动
publishSellAdHandleWallet(param, adNumber, chargeRatio);
} else {
//新建广告数据,返回广告流水号
adNumber = insertAd(param, CommonConstans.SELL, BigDecimal.ZERO);
adNumber = insertAd(param, CommonConstans.SELL, BigDecimal.ZERO, true);
}
//新增用户交易数据表
dealStatsService.insertIsNotExist(param.getUserId());
@ -223,11 +223,11 @@ public class AdServiceImpl implements AdService, ITxTransaction {
//检查发布参数
checkPublishParam(param);
//判断用户是否可以发布广告
if (!BooleanUtils.isTrue(param.getIsTeacher())) {
if (BooleanUtils.isFalse(param.getIsTeacher())) {
marketUserService.checkMarketUser(param.getUserId());
//检查密码
walletService.isPassword(param.getPass());
}
//检查密码
walletService.isPassword(param.getPass());
//检查币对
Coin coin = checkCoinIsNull(param.getCoinName(), param.getUnitName());
//检查发布数量、单价小数长度、单价下限是否合法
@ -461,7 +461,7 @@ public class AdServiceImpl implements AdService, ITxTransaction {
* @param coinChargeRaito
* @return adNumber
*/
private String insertAd(PublishAdParamDTO param, String adType, BigDecimal coinChargeRaito) {
private String insertAd(PublishAdParamDTO param, String adType, BigDecimal coinChargeRaito, boolean buildIn) {
//检查发布支付类型与枚举是否正确,并返回支付信息字符串
String pays = checkPaysTypeIsRealAndGeneratePayStr(param.getPayType());
@ -481,6 +481,7 @@ public class AdServiceImpl implements AdService, ITxTransaction {
ad.setUnitName(param.getUnitName());
ad.setCoinName(param.getCoinName());
ad.setAdPay(pays);
ad.setBuiltIn(buildIn);
ad.setAdStatus(AdConstants.DEFAULT);
ad.setAdType(adType);
ad.setAdRemark(param.getRemark());

@ -6,13 +6,17 @@ import com.blockchain.common.base.dto.YyyfUserDto;
import com.blockchain.common.base.enums.PushEnums;
import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.otc.common.constant.*;
import com.blockchain.server.otc.common.enums.*;
import com.blockchain.server.otc.common.enums.JgMsgEnums;
import com.blockchain.server.otc.common.enums.OtcEnums;
import com.blockchain.server.otc.common.exception.OtcException;
import com.blockchain.server.otc.common.util.CheckDecimalUtil;
import com.blockchain.server.otc.common.util.ImUtil;
import com.blockchain.server.otc.dto.order.OrderDTO;
import com.blockchain.server.otc.dto.user.UserBaseDTO;
import com.blockchain.server.otc.entity.*;
import com.blockchain.server.otc.entity.Ad;
import com.blockchain.server.otc.entity.Coin;
import com.blockchain.server.otc.entity.Order;
import com.blockchain.server.otc.entity.UserPayInfo;
import com.blockchain.server.otc.feign.PushFeign;
import com.blockchain.server.otc.feign.UserFeign;
import com.blockchain.server.otc.feign.YyyyfMoneyFeign;
@ -21,15 +25,21 @@ import com.blockchain.server.otc.redis.OrderCache;
import com.blockchain.server.otc.service.*;
import com.codingapi.tx.annotation.ITxTransaction;
import com.codingapi.tx.annotation.TxTransaction;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Service
public class OrderServiceImpl implements OrderService, ITxTransaction {
@ -68,8 +78,11 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
private YyyyfMoneyFeign yyyyfMoneyFeign;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private ApplicationContext applicationContext;
private static final BigDecimal DECIMAL_DISH = new BigDecimal("0.1"); //下单金额计算的偏差值
private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(5, 10, 0, TimeUnit.MINUTES, new PriorityBlockingQueue<>());
@Override
public List<Order> selectByAdIdAndStatus(String adId, String... status) {
@ -264,7 +277,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
}
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void pay(String userId, String orderId, String payType) {
//订单id判空
checkOrderIdNull(orderId);
@ -292,7 +305,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), payType,BigDecimal.ZERO.subtract(order.getTurnover()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()) {
if(resultDTO.getCode()==200 && resultDTO.getData()) {
//更新订单状态
receiptOrPayUpdateOrder(order, UserHandleConstants.PAY);
//记录用户操作
@ -306,7 +319,9 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
throw new OtcException(OtcEnums.FREEBALANCE_NOT_ENOUGH);
}
if (BooleanUtils.isTrue(ad.getBuiltIn())) {
EXECUTOR_SERVICE.execute(() -> applicationContext.getBean(OrderService.class).receipt(userId, orderId, "123456"));
}
}
@Override
@ -315,20 +330,21 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
public void receipt(String userId, String orderId, String pass) {
//订单id判空
checkOrderIdNull(orderId);
//校验密码
walletService.isPassword(pass);
//排他锁查询订单
Order order = orderMapper.selectByIdForUpdate(orderId);
//订单是否存在
checkOrderNull(order);
//校验密码
Ad ad = adService.selectById(order.getAdId());
if (BooleanUtils.isFalse(ad.getBuiltIn())) {
walletService.isPassword(pass);
}
//检查订单能否确认收款
checkOrderCanHandle(order, userId, UserHandleConstants.RECEIPT);
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(),order.getOrderPayType(),order.getTurnover());
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()) {
if(resultDTO.getCode()==200 && resultDTO.getData()) {
//更新订单状态
@ -408,7 +424,9 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
//判断广告类型是否正确
checkAdType(ad.getAdType(), adType);
//检查下单用户是不是广告发布用户
checkAdUserAndOrderUserEquals(ad.getUserId(), userId);
if (!ad.getBuiltIn()) {
checkAdUserAndOrderUserEquals(ad.getUserId(), userId);
}
//检查检查下单数量、单价是否合法
checkAmountAndPrice(ad, amount, price);
@ -1042,10 +1060,12 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
walletService.handleRealBalance(order.getBuyUserId(), order.getOrderNumber(), order.getCoinName(), order.getUnitName(), realAmount, BigDecimal.ZERO, serviceCharge);
//记录资金变动
billService.insertBill(order.getBuyUserId(), order.getOrderNumber(), realAmount, BigDecimal.ZERO, BillConstants.MARK, order.getCoinName());
//卖家解冻
walletService.handleRealBalance(order.getSellUserId(), order.getOrderNumber(), order.getCoinName(), order.getUnitName(), BigDecimal.ZERO, minusAmount, BigDecimal.ZERO);
//记录资金变动
billService.insertBill(order.getSellUserId(), order.getOrderNumber(), BigDecimal.ZERO, minusAmount, BillConstants.MARK, order.getCoinName());
if (BooleanUtils.isFalse(ad.getBuiltIn())) {
//卖家解冻
walletService.handleRealBalance(order.getSellUserId(), order.getOrderNumber(), order.getCoinName(), order.getUnitName(), BigDecimal.ZERO, minusAmount, BigDecimal.ZERO);
//记录资金变动
billService.insertBill(order.getSellUserId(), order.getOrderNumber(), BigDecimal.ZERO, minusAmount, BillConstants.MARK, order.getCoinName());
}
}
/***
@ -1068,7 +1088,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
//falge为卖
boolean flag = checkBuyOrSell(ad.getAdType());
//广告是卖出类型时 并且 有剩余数量时,解冻余额
if (!flag && ad.getLastNum().compareTo(BigDecimal.ZERO) > 0) {
if (!flag && BooleanUtils.isFalse(ad.getBuiltIn()) && ad.getLastNum().compareTo(BigDecimal.ZERO) > 0) {
//广告手续费
BigDecimal serviceCharge = ad.getLastNum().multiply(ad.getChargeRatio());
//增加可用

@ -17,10 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
@Service
public class UserPayInfoServiceImpl implements UserPayInfoService {
@ -55,14 +52,23 @@ public class UserPayInfoServiceImpl implements UserPayInfoService {
Ad ad = adService.selectById(order.getAdId());
//获取广告设置的支付信息
String[] pays = ad.getAdPay().split(",");
//遍历查询支付信息,添加到集合中
for (String pay : pays) {
UserPayInfo userPayInfo = selectByUserIdAndPayType(order.getSellUserId(), pay);
//防空
if (userPayInfo == null) {
continue;
if (ad.getBuiltIn()) {
Arrays.stream(pays).forEach(pay -> {
UserPayInfo userPayInfo = new UserPayInfo();
userPayInfo.setUserId(order.getSellUserId());
userPayInfo.setPayType(pay);
userPayInfos.add(userPayInfo);
});
} else {
//遍历查询支付信息,添加到集合中
for (String pay : pays) {
UserPayInfo userPayInfo = selectByUserIdAndPayType(order.getSellUserId(), pay);
//防空
if (userPayInfo == null) {
continue;
}
userPayInfos.add(userPayInfo);
}
userPayInfos.add(userPayInfo);
}
} else {
//其他状态时,查询确认付款后选择的支付方式

Loading…
Cancel
Save