|
@ -103,22 +103,24 @@ public class BuyerService { |
|
|
User user = userMapper.selectOneById(userId); |
|
|
User user = userMapper.selectOneById(userId); |
|
|
if(!encoder.matches(password, user.getPassword())) |
|
|
if(!encoder.matches(password, user.getPassword())) |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.PASSWORD_ERROR); |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.PASSWORD_ERROR); |
|
|
|
|
|
buyerService.updateBalanceAndOrder(orderId, user.getBalance()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
public void updateBalanceAndOrder(String orderId, BigDecimal balance) { |
|
|
Order order = orderMapper.selectById(orderId); |
|
|
Order order = orderMapper.selectById(orderId); |
|
|
if(order == null) |
|
|
if(order == null) |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.ORDER_NON_EXIST_ERROR); |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.ORDER_NON_EXIST_ERROR); |
|
|
|
|
|
|
|
|
if(!order.getStatus().equals(OrderStatus.WAIT_PAYMENT)) |
|
|
if(!order.getStatus().equals(OrderStatus.WAIT_PAYMENT)) |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.ORDER_HAS_PAID_ERROR); |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.ORDER_HAS_PAID_ERROR); |
|
|
if(order.getPrice().compareTo(user.getBalance()) > 0) |
|
|
|
|
|
|
|
|
if(order.getPrice().compareTo(balance) > 0) |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.BALANCE_ERROR); |
|
|
throw new AppException(Constants.CLIENT_ERROR, Constants.BALANCE_ERROR); |
|
|
buyerService.updateBalanceAndOrder(storeMapper.getStoreById(order.getStoreId()).getSellerId(), order); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
public void updateBalanceAndOrder(Integer sellerId, Order order) { |
|
|
|
|
|
orderMapper.updateOrderStatus(order.getOrderId(), OrderStatus.WAIT_SEND); |
|
|
orderMapper.updateOrderStatus(order.getOrderId(), OrderStatus.WAIT_SEND); |
|
|
BigDecimal price = order.getPrice(); |
|
|
BigDecimal price = order.getPrice(); |
|
|
userMapper.minusBalance(order.getBuyerId(), price); |
|
|
userMapper.minusBalance(order.getBuyerId(), price); |
|
|
userMapper.addBalance(sellerId, price); |
|
|
|
|
|
|
|
|
userMapper.addBalance(storeMapper.getStoreById(order.getStoreId()).getSellerId(), price); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void addFunds(String username, String password, BigDecimal addValue) { |
|
|
public void addFunds(String username, String password, BigDecimal addValue) { |
|
|