@Override public void deductCoin(long userId, String subject, int coin) throws Exception { User user = userDAOImpl.fetchByUserId(userId); if (user != null) { String IP = user.getLastLoginIP(); UserWallet userWallet = userWalletDAOImpl.fetchByUserIdAndWalletId(userId, GameConstants.WALLET_TYPE_COIN); if (userWallet != null) { int value = userWallet.getValue(); int currentValue = value - coin; if (currentValue >= 0) { userWallet.setValue(currentValue); userWalletDAOImpl.save(userWallet); UserWalletTransaction userWalletTransaction = new UserWalletTransaction(); userWalletTransaction.setTransactionId(null); userWalletTransaction.setUserWalletId(userWallet.getUserWalletId()); userWalletTransaction.setUserId(userId); userWalletTransaction.setWalletId(GameConstants.WALLET_TYPE_COIN); userWalletTransaction.setTotalSpend(-coin); userWalletTransaction.setSubject(subject); userWalletTransaction.setIp(IP); userWalletTransaction.setCreateDate(new Date()); userWalletTransactionDAOImpl.save(userWalletTransaction); } } } }
public Object clone(UserWalletTransaction inputClone) { UserWalletTransaction clone = inputClone; clone.setTransactionId(getTransactionId()); clone.setUserWalletId(getUserWalletId()); clone.setUserId(getUserId()); clone.setWalletId(getWalletId()); clone.setTotalSpend(getTotalSpend()); clone.setSubject(getSubject()); clone.setIp(getIp()); clone.setCreateDate(getCreateDate()); return clone; }
@Override public void addCash(long userId, String subject, int cash) throws Exception { User user = userDAOImpl.fetchByUserId(userId); if (user != null) { String IP = user.getLastLoginIP(); UserWallet userWallet = userWalletDAOImpl.fetchByUserIdAndWalletId(userId, GameConstants.WALLET_TYPE_CASH); if (userWallet == null) { if (cash >= 0) { userWallet = new UserWallet(); userWallet.setUserWalletId(null); userWallet.setUserId(userId); userWallet.setWalletId(GameConstants.WALLET_TYPE_CASH); userWallet.setValue(cash); userWallet.setCreateDate(new Date()); userWalletDAOImpl.save(userWallet); // userWalletDAOImpl.flush(); UserWalletTransaction userWalletTransaction = new UserWalletTransaction(); userWalletTransaction.setTransactionId(null); userWalletTransaction.setUserWalletId(userWallet.getUserWalletId()); userWalletTransaction.setUserId(userId); userWalletTransaction.setWalletId(GameConstants.WALLET_TYPE_CASH); userWalletTransaction.setTotalSpend(cash); userWalletTransaction.setSubject(subject); userWalletTransaction.setIp(IP); userWalletTransaction.setCreateDate(new Date()); userWalletTransactionDAOImpl.save(userWalletTransaction); // userWalletTransactionDAOImpl.flush(); } } else { int value = userWallet.getValue(); int currentValue = value + cash; if (currentValue >= 0) { userWallet.setValue(value + cash); userWalletDAOImpl.save(userWallet); // UserWalletDAOImpl.getDAO().flush(); UserWalletTransaction userWalletTransaction = new UserWalletTransaction(); userWalletTransaction.setTransactionId(null); userWalletTransaction.setUserWalletId(userWallet.getUserWalletId()); userWalletTransaction.setUserId(userId); userWalletTransaction.setWalletId(GameConstants.WALLET_TYPE_CASH); userWalletTransaction.setTotalSpend(cash); userWalletTransaction.setSubject(subject); userWalletTransaction.setIp(IP); userWalletTransaction.setCreateDate(new Date()); userWalletTransactionDAOImpl.save(userWalletTransaction); // UserWalletTransactionDAOImpl.getDAO().flush(); } } } }