/** * @param rebateModel * @return */ public int doAwardItemOwnerWithBuy(DcRebateModel rebateModel) { if (rebateModel.getItemOwnerUserId() == null || rebateModel.isPgcOwner() || rebateModel.isUserSelf()) { return 0; } int integral = (int) (rebateModel.getIntegralCount() * 0.1); integral = integral > 20 ? 20 : integral; DcUserIntegralDetailDTO integralDetail = new DcUserIntegralDetailDTO(); integralDetail.setUserId(rebateModel.getItemOwnerUserId()); integralDetail.setIntegralCount(integral); integralDetail.setSource(DcIntegralSourceEnums.BUY_UGC); DcIntegralDesc desc = new DcIntegralDesc(); desc.setFromObjId(rebateModel.getItemId()); desc.setFromObjName(rebateModel.getItemTitle()); desc.setToObjId(rebateModel.getItemOwnerUserId()); try { DcUserDTO user = dcUserService.getUser(rebateModel.getItemOwnerUserId()); if (user != null) { desc.setToObjName(user.getNick()); } } catch (Exception e) { } integralDetail.setIntegralDesc(desc); try { _doWithIntegral(integralDetail); return integral; } catch (Exception e) { logger.error(e); return 0; } }
/** * 购物返积分 * * @param userId * @param integralCount */ public boolean doBuyRebate(DcRebateModel buyModel) { DcUserIntegralDetailDTO detail = new DcUserIntegralDetailDTO(); detail.setUserId(buyModel.getUserId()); detail.setIntegralCount(buyModel.getIntegralCount()); detail.setSource(DcIntegralSourceEnums.BUY_REBATE); DcIntegralDesc integralDesc = new DcIntegralDesc(); integralDesc.setFromObjName(buyModel.getItemTitle()); integralDesc.setFromObjId(buyModel.getItemId()); integralDesc.setToObjId(buyModel.getUserId()); integralDesc.setToObjName(buyModel.getUserNick()); detail.setIntegralDesc(integralDesc); try { _doWithIntegral(detail); } catch (Exception e) { logger.error(e); return false; } doAwardItemOwnerWithBuy(buyModel); return true; }
/** * log积分兑换. * * @param exchangeModel * @return */ public int doExchangeItem(DcExchangeItemModel exchangeModel) { DcUserIntegralDetailDTO detail = new DcUserIntegralDetailDTO(); detail.setUserId(exchangeModel.getUserId()); detail.setIntegralCount(exchangeModel.getExIntegral() * -1); detail.setSource(DcIntegralSourceEnums.EXCHANGE_ITEM); DcIntegralDesc integralDesc = new DcIntegralDesc(); integralDesc.setToObjId(exchangeModel.getUserId()); integralDesc.setToObjName(exchangeModel.getUserNick()); integralDesc.setFromObjName(exchangeModel.getExItemTitle()); integralDesc.setFromObjId(exchangeModel.getExItemId()); integralDesc.setOtherInfo(exchangeModel.getOtherInfo()); detail.setIntegralDesc(integralDesc); try { _doWithIntegral(detail); return exchangeModel.getExIntegral(); } catch (Exception e) { logger.error(e); return 0; } }
private boolean _doWithIntegral(DcUserIntegralDetailDTO detail) throws IntegralNotEnoughException { if (detail == null) { return false; } int effectCount = 0; int integralCount = IntegerUtils.parseInt(detail.getIntegralCount()); // 竞拍成功前不消耗用户积分. if (detail.getSourceEnum() != DcIntegralSourceEnums.AUCTION_BID) { if (integralCount > 0) { effectCount = dcUserService.incrIntegralByUser(detail.getUserId(), Math.abs(integralCount)); } else if (integralCount < 0) { DcIntegralSourceEnums source = detail.getSourceEnum(); if (!hasEnoughIntegral(detail.getUserId(), source)) { throw new IntegralNotEnoughException(); } effectCount = dcUserService.decrIntegralByUser(detail.getUserId(), Math.abs(integralCount)); } } if (detail.getSourceEnum() != DcIntegralSourceEnums.WINNER_GANE) { dcMessageService.addIntegralMessage(detail, true); } return true; }