| | |
| | | import com.yeshi.makemoney.app.exception.money.UserMoneyBalanceException; |
| | | import com.yeshi.makemoney.app.service.inter.config.SystemConfigService; |
| | | import com.yeshi.makemoney.app.service.inter.money.ExtractService; |
| | | import com.yeshi.makemoney.app.service.inter.money.UserExtractMoneyLimitService; |
| | | import com.yeshi.makemoney.app.service.inter.money.UserMoneyRecordService; |
| | | import com.yeshi.makemoney.app.service.inter.money.UserMoneyService; |
| | | import com.yeshi.makemoney.app.service.inter.msg.UserMsgNotifyService; |
| | | import com.yeshi.makemoney.app.service.inter.user.UserInfoService; |
| | | import com.yeshi.makemoney.app.service.query.money.ExtractQuery; |
| | | import com.yeshi.makemoney.app.utils.Constant; |
| | | import com.yeshi.makemoney.app.utils.factory.UserMoneyRecordFactory; |
| | | import com.yeshi.makemoney.app.utils.factory.msg.UserMsgFactory; |
| | | import com.yeshi.makemoney.app.utils.mq.CMQManager; |
| | | import com.yeshi.makemoney.app.utils.pay.AlipayUtil; |
| | | import org.slf4j.Logger; |
| | |
| | | @Resource |
| | | private UserMoneyRecordService userMoneyRecordService; |
| | | |
| | | @Resource |
| | | private UserExtractMoneyLimitService userExtractMoneyLimitService; |
| | | |
| | | @Resource |
| | | private UserMsgNotifyService userMsgNotifyService; |
| | | |
| | | @Override |
| | | public List<Extract> list(ExtractQuery extractQuery, int page, int pageSize) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | |
| | | return extractMapper.count(daoQuery) < 1L; |
| | | } |
| | | |
| | | private ExtractConfig getExtractConfig(SystemEnum system) { |
| | | @Override |
| | | public ExtractConfig getExtractConfig(SystemEnum system) { |
| | | String value = systemConfigService.getValueCache(system, SystemConfigKey.extractConfig); |
| | | if (StringUtil.isNullOrEmpty(value)) { |
| | | return null; |
| | |
| | | throw new ExtractException(ExtractException.CODE_EXTRACT_CONFIG_ERROR, "提现配置错误"); |
| | | } |
| | | |
| | | if (isFirst(user.getId())) { |
| | | if (money.compareTo(config.getFirstMinMoney()) < 0) { |
| | | throw new ExtractException(ExtractException.CODE_MONEY_LIMIT, String.format("首次提现最低金额为%s元", config.getFirstMinMoney().toString())); |
| | | } |
| | | } else { |
| | | if (money.compareTo(config.getMinMoney()) < 0) { |
| | | throw new ExtractException(ExtractException.CODE_MONEY_LIMIT, String.format("最低提现金额为%s元", config.getMinMoney().toString())); |
| | | } |
| | | |
| | | if (money.compareTo(config.getMinMoney()) < 0) { |
| | | throw new ExtractException(ExtractException.CODE_MONEY_LIMIT, String.format("最低提现金额为%s元", config.getMinMoney().toString())); |
| | | } |
| | | |
| | | |
| | | if (money.compareTo(config.getMaxMoney()) > 0) { |
| | | throw new ExtractException(ExtractException.CODE_MONEY_LIMIT, String.format("最高提现金额为%s元", config.getMaxMoney().toString())); |
| | |
| | | throw new ExtractException(ExtractException.CODE_MONEY_LIMIT, String.format("单日累计最高提现次数为%s次", config.getMaxNumPerDay().toString())); |
| | | } |
| | | |
| | | //小金额提现限制 |
| | | if (money.compareTo(Constant.EXTRACT_LITTLE_MONEY_LIMIT) < 0) { |
| | | //是否已经用完新用户额度 |
| | | if (!canExtractLittleMoney(user.getId(), config.getNewerLittleMoneyNum(), new Date(currentTime))) { |
| | | throw new ExtractException(ExtractException.CODE_LITTLE_MONEY_LIMIT, "今日小于1元提现次数已用尽"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean canExtractLittleMoney(Long uid, int maxNewerCount, Date date) { |
| | | //判断新人 |
| | | long count = countByMaxMoney(uid, Constant.EXTRACT_LITTLE_MONEY_LIMIT, Arrays.asList(new Integer[]{Extract.STATE_NOT_PROCESS, Extract.STATE_PROCESSING, Extract.STATE_PASS}), null); |
| | | if (maxNewerCount > count) { |
| | | return true; |
| | | } |
| | | |
| | | //判断激励分配 |
| | | int limit = userExtractMoneyLimitService.getLittleMoneyLimit(uid, date); |
| | | if (limit <= 0) { |
| | | return false; |
| | | } |
| | | count = countByMaxMoney(uid, Constant.EXTRACT_LITTLE_MONEY_LIMIT, Arrays.asList(new Integer[]{Extract.STATE_NOT_PROCESS, Extract.STATE_PROCESSING, Extract.STATE_PASS}), new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(date.getTime(), "yyyyMMdd"), "yyyyMMdd"))); |
| | | if (count < limit) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getExtractingMoney(Long uid) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.state = Extract.STATE_NOT_PROCESS; |
| | | BigDecimal money = extractMapper.sumMoney(daoQuery); |
| | | |
| | | return money == null ? new BigDecimal(0) : money; |
| | | } |
| | | |
| | | |
| | |
| | | updateExtract.setState(Extract.STATE_REJECT); |
| | | updateExtract.setReason(reason); |
| | | extractMapper.updateByPrimaryKeySelective(updateExtract); |
| | | //TODO 消息 |
| | | //添加消息通知 |
| | | try { |
| | | userMsgNotifyService.notify(UserMsgFactory.createExtractFail(extract.getUser().getId(), extract.getMoney(), reason)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | extractFail(extract, noMoney, errMsg); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public long countByMaxMoney(Long uid, BigDecimal money, List<Integer> stateList, Date minCreateTime) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.maxMoney = money; |
| | | daoQuery.stateList = stateList; |
| | | daoQuery.minCreateTime = minCreateTime; |
| | | return extractMapper.count(daoQuery); |
| | | } |
| | | |
| | | /** |
| | |
| | | userMoneyRecordService.update(update); |
| | | } |
| | | } |
| | | // TODO 通知转账成功 |
| | | //添加消息通知 |
| | | try { |
| | | userMsgNotifyService.notify(UserMsgFactory.createExtractSuccess(extract.getUser().getId(), extract.getMoney())); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 新版提现 |
| | | //TODO 通知转账被拒绝 |
| | | //添加消息通知 |
| | | try { |
| | | userMsgNotifyService.notify(UserMsgFactory.createExtractFail(extract.getUser().getId(), extract.getMoney(), null)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |