yujian
2019-08-16 e97b71caed03d1f1aa3ae21b1ea0deac4dd9ffe0
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java
@@ -21,6 +21,7 @@
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
import com.yeshi.fanli.service.inter.integral.CodePublishRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
@@ -58,6 +59,9 @@
   
   @Resource
   private CodePublishRecordService codePublishRecordService;
   @Resource
   private IntegralExchangeRecordService integralExchangeRecordService;
   
   
@@ -99,6 +103,14 @@
         exchangeTip.setType(type.name());
         return exchangeTip;
      }
      int upperLimit = exchange.getUpperLimit();
      // 今日兑换情况
      long exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid);
      if (exchangeCount >= upperLimit) {
         throw new IntegralExchangeException(1, "今日兑换已达上限");
      }
      
      Integer goldCoinHas = extraVO.getGoldCoin();
      if (goldCoin.intValue() > goldCoinHas.intValue()) {
@@ -150,6 +162,13 @@
      if (exchange == null)
         throw new IntegralExchangeException(1, "兑换方式不存在");
      int upperLimit = exchange.getUpperLimit();
      // 今日兑换情况
      long exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid);
      if (exchangeCount >= upperLimit) {
         throw new IntegralExchangeException(1, "今日兑换已达上限");
      }
      Integer goldCoin = exchange.getGoldCoin();
      Integer goldCoinHas = extraVO.getGoldCoin();
      if (goldCoin.intValue() > goldCoinHas.intValue()) {
@@ -158,16 +177,12 @@
      
      try {
         ExchangeTypeEnum type = exchange.getType();
         if (ExchangeTypeEnum.freeCouponBuy == type) {
            // 自购免单券
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, false, null);
         } else if (ExchangeTypeEnum.freeCouponGive == type) {
            // 赠送免单券
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, true, null);
         if (ExchangeTypeEnum.freeCouponBuy == type || ExchangeTypeEnum.freeCouponGive == type) {
            // 自购免单券、赠送免单券
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
         } else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
            // 奖励免单券
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, true,
                  new BigDecimal(10));
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, new BigDecimal(10));
         } else if (ExchangeTypeEnum.inviteCodePublish == type) {
            // 邀请码发布
            if(codePublishRecordService.countValidRecord(uid) > 0)
@@ -201,9 +216,10 @@
            throw new IntegralExchangeException(1, "兑换方式不存在");
         }
         
         exchangeCount ++;
         String progress = exchange.getProgress();
         if (!StringUtil.isNullOrEmpty(progress))
            progress = progress.replace("{已兑换}", 1 + "").replace("{上限数}", exchange.getUpperLimit() + "");
            progress = progress.replace("{已兑换}",exchangeCount + "").replace("{上限数}", exchange.getUpperLimit() + "");
         exchange.setProgress(progress);
         
         // 更新金币
@@ -211,6 +227,9 @@
         extraUpdate.setId(extraVO.getId());
         extraUpdate.setGoldCoin(goldCoinHas.intValue() - goldCoin.intValue());
         userInfoExtraService.saveUserInfoExtra(extraUpdate);
         exchange.setUserGoldCoin(extraUpdate.getGoldCoin() + "枚");
         return exchange;
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);