admin
2020-02-18 ddf5db7d31af51fcf697eac0cee7dd46ff73bcc1
fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
@@ -53,6 +53,7 @@
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.exception.ExtractException;
import com.yeshi.fanli.exception.NotExistObjectException;
import com.yeshi.fanli.exception.ObjectStateException;
@@ -172,12 +173,23 @@
      updateExtract.setId(id);
      updateExtract.setState(Extract.STATE_PROCESSING);
      extractMapper.updateByPrimaryKeySelective(updateExtract);
      // TODO 新版部署后删除
      // 改变资金记录状态
      UserMoneyDetail detail = userMoneyDetailService.selectByTypeAndUidAndIdentifyCode(
            UserMoneyDetailTypeEnum.extract, find.getUserInfo().getId(), find.getId());
      if (detail != null) {
         UserMoneyDetail update = new UserMoneyDetail(detail.getId());
         update.setShow(true);
         update.setUpdateTime(new Date());
         userMoneyDetailMapper.updateByPrimaryKeySelective(update);
      }
      transfer(find, admin); // 提现通过,支付宝转账
      return null;
   }
   @Transactional
   @Transactional(rollbackFor = Exception.class)
   public synchronized void rejectExtract(long id, String reason, AdminUser admin)
         throws ObjectStateException, NotExistObjectException {
      Extract find = extractMapper.selectByPrimaryKey(id);
@@ -257,9 +269,9 @@
            && (System.currentTimeMillis() - history.getCreateTime().getTime()) < 1000 * 60 * 60 * 24 * 7L)
         return 111;
      final String autoExtract = configService.get("extract_way"); // 是否自动转账
      final String maxCount = configService.get("extract_count_day");
      final String maxMoney = configService.get("extract_money_day");
      final String autoExtract = configService.get(ConfigKeyEnum.extractWay.getKey()); // 是否自动转账
      final String maxCount = configService.get(ConfigKeyEnum.extractDayCount.getKey());
      final String maxMoney = configService.get(ConfigKeyEnum.extractMoneyDay.getKey());
      UserInfo user = userInfoMapper.selectByPrimaryKeyForUpdate(extract.getUserInfo().getId());
      // 余额不足
@@ -317,7 +329,6 @@
         LogHelper.userInfo("uid=" + user.getId() + ",提交转账申请!");
      } else {// 暂时不自动提现
         // transfer(extract, null);
         ;
      }
      return null;
   }
@@ -416,7 +427,7 @@
         response = alipayClient.execute(request);
         LogHelper.userErrorInfo("提现:支付宝通过提现成功-" + extract.getId());
      } catch (AlipayApiException e) {
         e.printStackTrace();
         LogHelper.errorDetailInfo(e, "支付宝转账异常:" + extract.getId(), "");
         LogHelper.userErrorInfo("提现:支付宝提现异常:" + response + ",提现信息" + GsonUtil.toJson(extract));
      }
@@ -531,7 +542,7 @@
      return extractMapper.selectByPrimaryKey(id);
   }
   @Transactional
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void checkExtract(Long uid) throws ExtractException {
      BigDecimal compensateMoney = extractMapper.computeCompensateByUid(uid);
@@ -1077,6 +1088,111 @@
      return listOpendIDs;
   }
   @Override
   public List<UserInfo> preAutoUserTo1212() throws Exception {
      int page = 0;
      int pageSize = 100;
      int maxSize = 300;
      Date nowDate = new Date();
      // 条件3:距离上一次成功领取微信红包已经超过了30天时间,可在第31天再次下发;
      String receivedDate = DateUtil.reduceDayTostring(30, nowDate);
      // 条件4:距离上一次未成功领取微信红包已经超过了15天时间,可在第16天再次下发;
      String refundDate = DateUtil.reduceDayTostring(15, nowDate);
      // 余额最低限制
      List<UserInfo> list = new ArrayList<UserInfo>();
      while (true) {
         // 查询满足条件 1、2 的uid
         List<UserInfo> listUser = userInfoService.getAutoExtractUserTo1212(page * pageSize, pageSize);
         if (listUser == null || listUser.isEmpty())
            break;
         List<Long> listId = new ArrayList<Long>();
         for (UserInfo userInfo : listUser) {
            listId.add(userInfo.getId());
         }
         // 查询记录是否满足
         List<Long> listValid = extractWeiXinRecordService.getValidUsers(listId, receivedDate, refundDate);
         if (listValid == null || listValid.isEmpty()) {
            page++;
            continue;
         }
         for (Long uid : listValid) {
            if (list.size() >= maxSize)
               break;
            for (UserInfo userInfo : listUser) {
               if (list.size() >= maxSize)
                  break;
               if (userInfo.getId().longValue() == uid.longValue()) {
                  list.add(userInfo);
                  break;
               }
            }
         }
         if (list.size() >= maxSize)
            break;
         page++;
      }
      return list;
   }
   @Override
   public List<String> getAutoExtractOpenIdsTo1212() throws Exception {
      int page = 0;
      int pageSize = 100;
      int maxSize = 301; // appId + 实际openid300个
      Date nowDate = new Date();
      // 条件3:距离上一次成功领取微信红包已经超过了30天时间,可在第31天再次下发;
      String receivedDate = DateUtil.reduceDayTostring(30, nowDate);
      // 条件4:距离上一次未成功领取微信红包已经超过了15天时间,可在第16天再次下发;
      String refundDate = DateUtil.reduceDayTostring(15, nowDate);
      // 提现金额
      BigDecimal money = BigDecimal.valueOf(1);
      List<String> listOpendIDs = new ArrayList<String>();
      // 首行appID
      listOpendIDs.add(Constant.getWXAccount(null, null).getAppId());
      while (true) {
         // 查询满足条件 1、2 的uid
         List<UserInfo> listUser = userInfoService.getAutoExtractUserTo1212(page * pageSize, pageSize);
         if (listUser == null || listUser.isEmpty())
            break;
         List<Long> listId = new ArrayList<Long>();
         for (UserInfo userInfo : listUser) {
            listId.add(userInfo.getId());
         }
         // 查询记录是否满足
         List<Long> listValid = extractWeiXinRecordService.getValidUsers(listId, receivedDate, refundDate);
         if (listValid == null || listValid.isEmpty()) {
            page++;
            continue;
         }
         for (Long uid : listValid) {
            UserInfo userInfo = subHongBaoByUid(uid, money, money);
            if (userInfo != null) {
               listOpendIDs.add(userInfo.getWxOpenId());
               if (listOpendIDs.size() >= maxSize)
                  break;
            }
         }
         if (listOpendIDs.size() >= maxSize)
            break;
         page++;
      }
      return listOpendIDs;
   }
   @Transactional(rollbackFor = Exception.class)
   private UserInfo subHongBaoByUid(Long uid, BigDecimal money, BigDecimal minSurplus) {
      UserInfo userInfo = userInfoMapper.selectByPrimaryKeyForUpdate(uid);