| | |
| | | import kernel.util.UUIDGenerator; |
| | | import kernel.web.ApplicationUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | import project.Constants; |
| | | import project.data.DataService; |
| | | import project.data.model.Realtime; |
| | |
| | | |
| | | @Override |
| | | public void update(String partyId, double amount) { |
| | | Object money = redisHandler.get("PARTY_ID_MONEY_" + partyId); |
| | | Wallet wallet = (Wallet) redisHandler.get(WalletRedisKeys.WALLET_PARTY_ID + partyId.toString()); |
| | | wallet.setMoney(Arith.add(wallet.getMoney(), amount)); |
| | | if(!ObjectUtils.isEmpty(money)){ |
| | | wallet.setMoney(Double.parseDouble(money.toString())); |
| | | } |
| | | // 确保余额不会为负数 |
| | | double newBalance = Arith.add(wallet.getMoney(), amount); |
| | | if (newBalance < 0) { |
| | | wallet.setMoney(0); |
| | | }else{ |
| | | wallet.setMoney(Arith.add(wallet.getMoney(), amount)); |
| | | } |
| | | logger.info("----------------tmd钱包的钱为什么不对"+wallet.getMoney()); |
| | | redisHandler.setSync(WalletRedisKeys.WALLET_PARTY_ID + wallet.getPartyId().toString(), wallet); |
| | | redisHandler.pushAsyn(WalletRedisKeys.WALLET_QUEUE_UPDATE, new WalletMessage(partyId, amount)); |
| | | redisHandler.pushAsyn(WalletRedisKeys.WALLET_QUEUE_UPDATE, new WalletMessage(partyId, wallet.getMoney())); |
| | | |
| | | //用于计算合约亏损 |
| | | redisHandler.setSync("PARTY_ID_MONEY_"+partyId, wallet.getMoney()); |
| | | } |
| | | |
| | | @Override |