yujian
2019-12-12 8c04d27e5cebb7e654c208533e9567c4df2c8acc
fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackExchangeServiceImpl.java
@@ -29,6 +29,7 @@
import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
import com.yeshi.fanli.service.inter.redpack.RedPackExchangeService;
import com.yeshi.fanli.service.inter.redpack.RedPackForbidService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.factory.RedPackDetailFactory;
@@ -53,6 +54,9 @@
   
   @Resource
   private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
   @Resource
   private RedPackForbidService redPackForbidService;
   
   
   @Override
@@ -86,24 +90,32 @@
   public void exchangeCash(Long uid, BigDecimal amount) throws RedPackExchangeException {
      if (uid == null || amount == null)
         throw new RedPackExchangeException(1, "参数不正确");
      String extractBanlenMin = redPackConfigService.getValueByKey("extract_banlen_min");
      
      BigDecimal balance = redPackBalanceService.getBalance(uid);
      if(redPackForbidService.verifyForbid(uid))
         throw new RedPackExchangeException(1, "红包功能已被封禁");
      String extractBanlenMin = redPackConfigService.getValueByKey("extract_banlen_min");
      BigDecimal balance =  redPackBalanceService.getBalance(uid);
      if (balance == null || balance.compareTo(new BigDecimal(extractBanlenMin)) < 0)
         throw new RedPackExchangeException(1, "余额不足" + extractBanlenMin + "元");
      
      if (balance.compareTo(amount) < 0)
         throw new RedPackExchangeException(1, "提现余额不足");
      
      String moneyMin = redPackConfigService.getValueByKey("extract_money_min");
      String moneyMax = redPackConfigService.getValueByKey("extract_money_max");
      if (amount.compareTo(new BigDecimal(moneyMin)) < 0 || amount.compareTo(new BigDecimal(moneyMax)) > 0)
         throw new RedPackExchangeException(1, "提现金额至少" + moneyMin + "元至多" + moneyMax + "元");
      
      Date nowDate = new Date();
      
      long countToday = redPackExchangeMapper.countTodayByUid(uid);
      String extractDayMax = redPackConfigService.getValueByKey("extract_day_max");
      if (!StringUtil.isNullOrEmpty(extractDayMax) && countToday >= Long.parseLong(extractDayMax))
         throw new RedPackExchangeException(1, "今日红包提现次数超限");
      Date nowDate = new Date();
      // 提现申请
      RedPackExchange exchange = new RedPackExchange();
      exchange.setUid(uid);
@@ -131,6 +143,9 @@
      if (RedPackExchange.STATE_INIT != record.getState())
         throw new RedPackExchangeException(1,"该申请已被处理,请刷新");
      if(redPackForbidService.verifyForbid(record.getUid()))
         throw new RedPackExchangeException(1, "红包功能已被封禁");
      Date nowDate = new Date();
      record.setAuditId(admin.getId());
      record.setAuditTime(nowDate);
@@ -163,6 +178,7 @@
         throw new RedPackExchangeException(1,"更新提现明细出错");
      }
      
      //消息
      SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
      String beizu = "红包提现成功后请到“我的-账户余额”中查看";
@@ -173,6 +189,7 @@
      dto.setMoney("¥" + record.getMoney().setScale(2));      
      dto.setBalance("¥" + redPackBalanceService.getBalance(record.getUid()));
      userMoneyMsgNotificationService.redPackMsg(record.getUid(), MsgTypeMoneyTypeEnum.redPackExchangePass, new Gson().toJson(dto), beizu);
   }