yujian
2019-09-17 2a99c607e5c7dc640d3608b35a20b451e42922c3
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java
@@ -20,6 +20,7 @@
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
@@ -113,6 +114,11 @@
      if (exchange == null)
         throw new IntegralExchangeException(1, "兑换方式不存在");
      
      Integer state = exchange.getState();
      if (state == null || state != 1)
         throw new IntegralExchangeException(1, "兑换活动未开启");
      Integer goldCoin = exchange.getGoldCoin();
      
      ExchangeTipVO exchangeTip = new ExchangeTipVO();
@@ -190,9 +196,12 @@
      if (exchange == null)
         throw new IntegralExchangeException(1, "兑换方式不存在");
      ExchangeTypeEnum type = exchange.getType();
      Integer state = exchange.getState();
      if (state == null || state != 1)
         throw new IntegralExchangeException(1, "兑换活动未开启");
      
      long exchangeCount = 0;
      ExchangeTypeEnum type = exchange.getType();
      if (ExchangeTypeEnum.freeCouponBuy == type) {
         exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, null);
         if (exchangeCount >= 1) {
@@ -221,21 +230,25 @@
      boolean once = false; // 兑换一次是否消失
      try {
         if (ExchangeTypeEnum.freeCouponBuy == type) {
            List<UserSystemCoupon> listCoupon = userSystemCouponService.getFreeCouponByType(uid, CouponTypeEnum.freeCouponBuy.name());
            if (listCoupon != null && listCoupon.size() > 0)
               throw new IntegralExchangeException(1, "自购免单券,仅能兑换一次");
            thing = "自购免单券";
            thingNum = "1张";
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
            userSystemCouponService.exchangeCoupon(uid, CouponTypeEnum.freeCouponBuy.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
            once = true; 
            couponNews = 1;
         } else if (ExchangeTypeEnum.freeCouponGive == type) {
            thing = "赠送免单券";
            thingNum = "1张";
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
            userSystemCouponService.exchangeCoupon(uid, CouponTypeEnum.freeCouponGive.name(), UserSystemCoupon.SOURCE_EXCHANGE, null);
            couponNews = 1;
         } else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
            thing = "返利奖励券";
            thingNum = "1张";
            String percent = configService.get("exchange_rebate_percent");
            userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, new BigDecimal(percent));
            userSystemCouponService.exchangeCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(), UserSystemCoupon.SOURCE_EXCHANGE, new BigDecimal(percent));
            couponNews = 1;
         } else if (ExchangeTypeEnum.inviteCodePublish == type) {
            thing = "邀请码发布卡";
@@ -325,6 +338,8 @@
            exchange = null;
         
         return exchange;
      } catch (IntegralExchangeException e) {
         throw new IntegralExchangeException(1, e.getMsg());
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
         throw new IntegralExchangeException(1, "兑换异常");