做市商 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. 13
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/AdServiceImpl.java
  3. 42
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/OrderServiceImpl.java
  4. 14
      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; private String adStatus;
@Column(name = "ad_remark") @Column(name = "ad_remark")
private String adRemark; private String adRemark;
@Column(name = "built_in")
private Boolean builtIn;
@Column(name = "create_time") @Column(name = "create_time")
private java.util.Date createTime; private java.util.Date createTime;
@Column(name = "modify_time") @Column(name = "modify_time")

@ -63,7 +63,7 @@ public class AdServiceImpl implements AdService, ITxTransaction {
//广告手续费率 //广告手续费率
BigDecimal serviceCharge = checkAdServiceCharge(coin.getCoinServiceCharge(), param.getUserId()); 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()); dealStatsService.insertIsNotExist(param.getUserId());
//记录用户操作 //记录用户操作
@ -85,12 +85,12 @@ public class AdServiceImpl implements AdService, ITxTransaction {
//判断是否开启广告手续费 //判断是否开启广告手续费
BigDecimal chargeRatio = checkAdServiceCharge(coin.getCoinServiceCharge(), param.getUserId()); BigDecimal chargeRatio = checkAdServiceCharge(coin.getCoinServiceCharge(), param.getUserId());
//新建广告数据,返回广告流水号 //新建广告数据,返回广告流水号
adNumber = insertAd(param, CommonConstans.SELL, chargeRatio); adNumber = insertAd(param, CommonConstans.SELL, chargeRatio, false);
//更新钱包并记录资金变动 //更新钱包并记录资金变动
publishSellAdHandleWallet(param, adNumber, chargeRatio); publishSellAdHandleWallet(param, adNumber, chargeRatio);
} else { } else {
//新建广告数据,返回广告流水号 //新建广告数据,返回广告流水号
adNumber = insertAd(param, CommonConstans.SELL, BigDecimal.ZERO); adNumber = insertAd(param, CommonConstans.SELL, BigDecimal.ZERO, true);
} }
//新增用户交易数据表 //新增用户交易数据表
dealStatsService.insertIsNotExist(param.getUserId()); dealStatsService.insertIsNotExist(param.getUserId());
@ -223,11 +223,11 @@ public class AdServiceImpl implements AdService, ITxTransaction {
//检查发布参数 //检查发布参数
checkPublishParam(param); checkPublishParam(param);
//判断用户是否可以发布广告 //判断用户是否可以发布广告
if (!BooleanUtils.isTrue(param.getIsTeacher())) { if (BooleanUtils.isFalse(param.getIsTeacher())) {
marketUserService.checkMarketUser(param.getUserId()); marketUserService.checkMarketUser(param.getUserId());
}
//检查密码 //检查密码
walletService.isPassword(param.getPass()); walletService.isPassword(param.getPass());
}
//检查币对 //检查币对
Coin coin = checkCoinIsNull(param.getCoinName(), param.getUnitName()); Coin coin = checkCoinIsNull(param.getCoinName(), param.getUnitName());
//检查发布数量、单价小数长度、单价下限是否合法 //检查发布数量、单价小数长度、单价下限是否合法
@ -461,7 +461,7 @@ public class AdServiceImpl implements AdService, ITxTransaction {
* @param coinChargeRaito * @param coinChargeRaito
* @return adNumber * @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()); String pays = checkPaysTypeIsRealAndGeneratePayStr(param.getPayType());
@ -481,6 +481,7 @@ public class AdServiceImpl implements AdService, ITxTransaction {
ad.setUnitName(param.getUnitName()); ad.setUnitName(param.getUnitName());
ad.setCoinName(param.getCoinName()); ad.setCoinName(param.getCoinName());
ad.setAdPay(pays); ad.setAdPay(pays);
ad.setBuiltIn(buildIn);
ad.setAdStatus(AdConstants.DEFAULT); ad.setAdStatus(AdConstants.DEFAULT);
ad.setAdType(adType); ad.setAdType(adType);
ad.setAdRemark(param.getRemark()); 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.enums.PushEnums;
import com.blockchain.common.base.util.YyyfUserDtoUtils; import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.otc.common.constant.*; 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.exception.OtcException;
import com.blockchain.server.otc.common.util.CheckDecimalUtil; import com.blockchain.server.otc.common.util.CheckDecimalUtil;
import com.blockchain.server.otc.common.util.ImUtil; import com.blockchain.server.otc.common.util.ImUtil;
import com.blockchain.server.otc.dto.order.OrderDTO; import com.blockchain.server.otc.dto.order.OrderDTO;
import com.blockchain.server.otc.dto.user.UserBaseDTO; 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.PushFeign;
import com.blockchain.server.otc.feign.UserFeign; import com.blockchain.server.otc.feign.UserFeign;
import com.blockchain.server.otc.feign.YyyyfMoneyFeign; 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.blockchain.server.otc.service.*;
import com.codingapi.tx.annotation.ITxTransaction; import com.codingapi.tx.annotation.ITxTransaction;
import com.codingapi.tx.annotation.TxTransaction; import com.codingapi.tx.annotation.TxTransaction;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Service @Service
public class OrderServiceImpl implements OrderService, ITxTransaction { public class OrderServiceImpl implements OrderService, ITxTransaction {
@ -68,8 +78,11 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
private YyyyfMoneyFeign yyyyfMoneyFeign; private YyyyfMoneyFeign yyyyfMoneyFeign;
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired
private ApplicationContext applicationContext;
private static final BigDecimal DECIMAL_DISH = new BigDecimal("0.1"); //下单金额计算的偏差值 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 @Override
public List<Order> selectByAdIdAndStatus(String adId, String... status) { public List<Order> selectByAdIdAndStatus(String adId, String... status) {
@ -264,7 +277,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
} }
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public void pay(String userId, String orderId, String payType) { public void pay(String userId, String orderId, String payType) {
//订单id判空 //订单id判空
checkOrderIdNull(orderId); 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())); 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); receiptOrPayUpdateOrder(order, UserHandleConstants.PAY);
//记录用户操作 //记录用户操作
@ -306,7 +319,9 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
throw new OtcException(OtcEnums.FREEBALANCE_NOT_ENOUGH); throw new OtcException(OtcEnums.FREEBALANCE_NOT_ENOUGH);
} }
if (BooleanUtils.isTrue(ad.getBuiltIn())) {
EXECUTOR_SERVICE.execute(() -> applicationContext.getBean(OrderService.class).receipt(userId, orderId, "123456"));
}
} }
@Override @Override
@ -315,20 +330,21 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
public void receipt(String userId, String orderId, String pass) { public void receipt(String userId, String orderId, String pass) {
//订单id判空 //订单id判空
checkOrderIdNull(orderId); checkOrderIdNull(orderId);
//校验密码
walletService.isPassword(pass);
//排他锁查询订单 //排他锁查询订单
Order order = orderMapper.selectByIdForUpdate(orderId); Order order = orderMapper.selectByIdForUpdate(orderId);
//订单是否存在 //订单是否存在
checkOrderNull(order); checkOrderNull(order);
//校验密码
Ad ad = adService.selectById(order.getAdId());
if (BooleanUtils.isFalse(ad.getBuiltIn())) {
walletService.isPassword(pass);
}
//检查订单能否确认收款 //检查订单能否确认收款
checkOrderCanHandle(order, userId, UserHandleConstants.RECEIPT); checkOrderCanHandle(order, userId, UserHandleConstants.RECEIPT);
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate); YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(),order.getOrderPayType(),order.getTurnover()); 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); checkAdType(ad.getAdType(), adType);
//检查下单用户是不是广告发布用户 //检查下单用户是不是广告发布用户
if (!ad.getBuiltIn()) {
checkAdUserAndOrderUserEquals(ad.getUserId(), userId); checkAdUserAndOrderUserEquals(ad.getUserId(), userId);
}
//检查检查下单数量、单价是否合法 //检查检查下单数量、单价是否合法
checkAmountAndPrice(ad, amount, price); checkAmountAndPrice(ad, amount, price);
@ -1042,11 +1060,13 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
walletService.handleRealBalance(order.getBuyUserId(), order.getOrderNumber(), order.getCoinName(), order.getUnitName(), realAmount, BigDecimal.ZERO, serviceCharge); 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()); billService.insertBill(order.getBuyUserId(), order.getOrderNumber(), realAmount, BigDecimal.ZERO, BillConstants.MARK, order.getCoinName());
if (BooleanUtils.isFalse(ad.getBuiltIn())) {
//卖家解冻 //卖家解冻
walletService.handleRealBalance(order.getSellUserId(), order.getOrderNumber(), order.getCoinName(), order.getUnitName(), BigDecimal.ZERO, minusAmount, BigDecimal.ZERO); 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()); billService.insertBill(order.getSellUserId(), order.getOrderNumber(), BigDecimal.ZERO, minusAmount, BillConstants.MARK, order.getCoinName());
} }
}
/*** /***
* 判断广告是否能结束 * 判断广告是否能结束
@ -1068,7 +1088,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
//falge为卖 //falge为卖
boolean flag = checkBuyOrSell(ad.getAdType()); 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()); 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Service @Service
public class UserPayInfoServiceImpl implements UserPayInfoService { public class UserPayInfoServiceImpl implements UserPayInfoService {
@ -55,6 +52,14 @@ public class UserPayInfoServiceImpl implements UserPayInfoService {
Ad ad = adService.selectById(order.getAdId()); Ad ad = adService.selectById(order.getAdId());
//获取广告设置的支付信息 //获取广告设置的支付信息
String[] pays = ad.getAdPay().split(","); String[] pays = ad.getAdPay().split(",");
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) { for (String pay : pays) {
UserPayInfo userPayInfo = selectByUserIdAndPayType(order.getSellUserId(), pay); UserPayInfo userPayInfo = selectByUserIdAndPayType(order.getSellUserId(), pay);
@ -64,6 +69,7 @@ public class UserPayInfoServiceImpl implements UserPayInfoService {
} }
userPayInfos.add(userPayInfo); userPayInfos.add(userPayInfo);
} }
}
} else { } else {
//其他状态时,查询确认付款后选择的支付方式 //其他状态时,查询确认付款后选择的支付方式
UserPayInfo userPayInfo = selectByUserIdAndPayType(order.getSellUserId(), order.getOrderPayType()); UserPayInfo userPayInfo = selectByUserIdAndPayType(order.getSellUserId(), order.getOrderPayType());

Loading…
Cancel
Save