| | |
| | | import com.yeshi.fanli.dao.mongodb.redpack.RedPackWinNewUserDao;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.redpack.RedPackWinNewUser;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
|
| | |
| | | private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
|
| | |
|
| | |
|
| | | @Override
|
| | | public boolean verifyHasReward(Long uid) {
|
| | | try {
|
| | | if (uid == null || uid <= 0) |
| | | return true; // 未登录弹出
|
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null) |
| | | return false;
|
| | | |
| | | Date nowTime = new Date();
|
| | | Date firstLoginTime = userInfoExtra.getFirstLoginTime();
|
| | | int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
|
| | | if (days > Constant.RED_PACK_NEW_USER_DAYS)
|
| | | return false; // 已经超出设置天数
|
| | | |
| | | RedPackWinNewUser redPackWin = redPackWinNewUserDao.getByUid(uid);
|
| | | if (redPackWin != null) {
|
| | | if (redPackWin.getMoney().compareTo(Constant.RED_PACK_NEW_USER_MONEY) >= 0)
|
| | | return false; // 已领取完
|
| | | |
| | | Date updateTime = redPackWin.getUpdateTime();
|
| | | int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
|
| | | if (daysNum == 0) |
| | | return false; // 今日已领取
|
| | | |
| | | Integer num = redPackWin.getNum();
|
| | | if (num >= Constant.RED_PACK_NEW_USER_DAYS) |
| | | return false; // 领取次数超限
|
| | | }
|
| | | return true;
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | |
| | | |
| | | |
| | | @RequestSerializableByKeyService(key = "#uid")
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public RedPackWinDetailVO receiveReward(Long uid) throws Exception {
|
| | | if (uid == null || uid <= 0) |
| | | return null; // 未登录弹出
|
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
|
| | | return null;
|
| | |
| | | Date nowTime = new Date();
|
| | | Date firstLoginTime = userInfoExtra.getFirstLoginTime();
|
| | | int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
|
| | | if (days > Constant.RED_PACK_NEW_USER_DAYS)
|
| | | if (days >= Constant.RED_PACK_NEW_USER_DAYS)
|
| | | return null; // 已经超出设置天数
|
| | |
|
| | | RedPackWinNewUser redPackWin = redPackWinNewUserDao.getByUid(uid);
|
| | |
| | |
|
| | | BigDecimal money = null;
|
| | | if (redPackWin == null) { // 第一次
|
| | | if (days == Constant.RED_PACK_NEW_USER_DAYS) { // 最后一天
|
| | | if (days == Constant.RED_PACK_NEW_USER_DAYS - 1) { // 最后一天
|
| | | money = Constant.RED_PACK_NEW_USER_MONEY;
|
| | | } else { // 计算随机奖励
|
| | | double randomNum = Constant.RED_PACK_NEW_USER_MIN + Math.random() * (Constant.RED_PACK_NEW_USER_MAX - Constant.RED_PACK_NEW_USER_MIN);
|
| | | BigDecimal rate = new BigDecimal(randomNum/100).setScale(2);
|
| | | randomNum = randomNum/100;
|
| | | BigDecimal rate = new BigDecimal(randomNum).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | money = MoneyBigDecimalUtil.mul(Constant.RED_PACK_NEW_USER_MONEY,rate);
|
| | | }
|
| | | } else if (days == Constant.RED_PACK_NEW_USER_DAYS) { // 最后一天
|
| | | } else if (days == Constant.RED_PACK_NEW_USER_DAYS - 1) { // 最后一天
|
| | | money = MoneyBigDecimalUtil.sub(Constant.RED_PACK_NEW_USER_MONEY, redPackWin.getMoney());
|
| | | } else { // 计算剩余随机奖励 10%-25%
|
| | | double randomNum = 10 + Math.random() * (20 - 10);
|
| | | BigDecimal rate = new BigDecimal(randomNum/100).setScale(2);
|
| | | BigDecimal rate = new BigDecimal(randomNum/100).setScale(2, BigDecimal.ROUND_DOWN);
|
| | | money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.sub(Constant.RED_PACK_NEW_USER_MONEY,redPackWin.getMoney()),rate);
|
| | | }
|
| | |
|
| | | int num = 1;
|
| | | money = money.setScale(2);
|
| | | // 4、增加红包
|
| | | redPackBalanceService.addRedPack(uid, money, RedPackDetailFactory.createNewUserReward(uid, days, money));
|
| | | |
| | | // 插入领取记录
|
| | | int num = 1;
|
| | | if (redPackWin == null) {
|
| | | redPackWin = new RedPackWinNewUser();
|
| | | redPackWin.setNum(1);
|
| | |
| | | redPackWin.setUpdateTime(nowTime);
|
| | | } else {
|
| | | num = redPackWin.getNum() + 1;
|
| | | redPackWin = new RedPackWinNewUser();
|
| | | redPackWin.setUid(uid.toString());
|
| | | redPackWin.setNum(num);
|
| | | redPackWin.setMoney(MoneyBigDecimalUtil.add(money, redPackWin.getMoney()));
|
| | | redPackWin.setUpdateTime(nowTime);
|
| | | }
|
| | | redPackWinNewUserDao.save(redPackWin);
|
| | | |
| | | // 4、增加红包
|
| | | redPackBalanceService.addRedPack(uid, money, RedPackDetailFactory.createNewUserReward(uid,num, money));
|
| | |
|
| | | RedPackWinDetailVO winDetailVO = new RedPackWinDetailVO();
|
| | | winDetailVO.setTitle("新人红包");
|