|
|
@ -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()); |
|
|
|
//增加可用
|
|
|
|
//增加可用
|
|
|
|