@Override public BusinessResult generatePointCord(final int count, final int value) throws DataAccessException { for (int i = 0; i < count; i++) { PointCard pointCard = new PointCard(); pointCard.setCredits(value); pointCard.setUsed(false); mutableDataAccess.save(pointCard); } return new BusinessResult(BusinessResult.ResultStatus.OK, "信用值卡生成成功"); }
@Override public BusinessResult recharge(String userId, String serialNumber) throws DataAccessException { PointCard pointCard = mutableDataAccess.findById(PointCard.class, serialNumber); if (pointCard == null) { return new BusinessResult(BusinessResult.ResultStatus.FAIL, "充值失败,信用值卡序列号错误"); } if (pointCard.isUsed()) { return new BusinessResult(BusinessResult.ResultStatus.FAIL, "充值失败,该信用值卡已经使用过了"); } User user = mutableDataAccess.findById(User.class, userId); user.setCredits(user.getCredits() + pointCard.getCredits()); pointCard.setUsed(true); mutableDataAccess.save(user); mutableDataAccess.save(pointCard); // BusinessResult result = new BusinessResult( BusinessResult.ResultStatus.OK, String.format("充值成功,您成功的在账号里充值<small>%s</small>信用值", pointCard.getCredits())); return result; }