yujian
2019-08-23 659ecb86b75e24c95ab2edc9a056fdd6f7d90a91
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -191,7 +191,7 @@
   @Override
   @Transactional
   public void insertUserCoupon(Long uid, String couponType, String source)
   public void insertUserCoupon(Long uid, String couponType, String source, BigDecimal percent)
         throws UserSystemCouponException, Exception {
      if (couponType == null || uid == null) {
@@ -204,8 +204,12 @@
         coupon = systemCouponService.getCouponByType(couponType);
      } else if (couponType.equals(CouponTypeEnum.rebatePercentCoupon.name())) {
         // 随机奖励券
         randomRewardCoupon(1, uid, source);
         return;
         if (percent == null || percent.compareTo(new BigDecimal(0)) > 0) {
            randomRewardCoupon(1, uid, source);
            return;
         }  else {
            coupon = systemCouponService.getCouponByTypeAndPercent(couponType, percent);
         }
      }
      
      if (coupon == null) {
@@ -1809,6 +1813,7 @@
            }
         } else if (UserSystemCoupon.STATE_IN_USE == state && give) {
            userCouponVO.setCouponEffect("赠送中");
            userCouponVO.setCouponRule(systemCoupon.getRemark());
            String tips = null;
            if (CouponTypeEnum.freeCouponGive == type) {
               userCouponVO.setState(UserSystemCoupon.STATE_GIVE_IN);
@@ -1830,6 +1835,7 @@
                        tips = tips.replace("{APP名称}", projectChineseName);
                     }
                     tips = tips.replace("{口令}", tokenRecord.getToken()).replace("{下载链接}", configService.get("app_down_link"));
                     userCouponVO.setGiveTips(tips);
                  }
                  
                  Date endTimeGive = record.getEndTime();
@@ -1839,19 +1845,20 @@
                     remainDays.put("fontColor", "#F14242");
                     userCouponVO.setRemainDays(remainDays);
                  }
               }
            } else {
               tips = "";
            }
            userCouponVO.setGiveTips(tips);
         } else if (UserSystemCoupon.STATE_END_USE == state) {
            if (give && CouponTypeEnum.freeCouponGive == type) {
               }
            }
         } else if (give && UserSystemCoupon.STATE_END_USE == state) {
            userCouponVO.setCouponRule(systemCoupon.getRemark());
            if (CouponTypeEnum.freeCouponGive == type) {
               userCouponVO.setState(UserSystemCoupon.STATE_GIVE_END);
            }
            
            if (give && CouponTypeEnum.rebatePercentCoupon == type) {
            if (CouponTypeEnum.rebatePercentCoupon == type) {
               userCouponVO.setState(UserSystemCoupon.STATE_GIVE_END);
            }
         }else if (give && UserSystemCoupon.STATE_OVERDUE == state) {
            userCouponVO.setCouponRule(systemCoupon.getRemark());
         }
         userCouponVO.setJumpBtn(jumpBtn);
      }
@@ -1861,7 +1868,7 @@
   
   @Transactional
   @Override
   public String giveCoupon(Long uid, Long id) throws UserSystemCouponException {
   public UserSystemCouponVO giveCoupon(Long uid, Long id) throws UserSystemCouponException {
      UserSystemCoupon userSystemCoupon = userSystemCouponMapper.selectByPrimaryKey(id);
      if (userSystemCoupon == null)
         throw new UserSystemCouponException(1, "该券已不存在");
@@ -1875,11 +1882,8 @@
         throw new UserSystemCouponException(1, "该券已失效");
      
      Integer state = userSystemCoupon.getState();
      if (state == UserSystemCoupon.STATE_OVERDUE)
         throw new UserSystemCouponException(1, "该券已过期");
      if (state == UserSystemCoupon.STATE_END_USE)
         throw new UserSystemCouponException(1, "该券使用/赠送成功");
      if (state != UserSystemCoupon.STATE_CAN_USE)
         throw new UserSystemCouponException(1, "该券已被使用或赠送");
      
      CouponTypeEnum type = systemCoupon.getType();
      if (type != CouponTypeEnum.freeCouponGive && type != CouponTypeEnum.rebatePercentCoupon )
@@ -1911,7 +1915,8 @@
               tips = tips.replace("{APP名称}", projectChineseName);
            }
            tips = tips.replace("{口令}", tokenRecord.getToken()).replace("{下载链接}", configService.get("app_down_link"));
            return tips;
            return createUserCouponVOo(userSystemCoupon, systemCoupon, record, tips);
         }
      }
      
@@ -1960,7 +1965,44 @@
         tips = tips.replace("{APP名称}", projectChineseName);
      }
      tips = tips.replace("{口令}", token).replace("{下载链接}", configService.get("app_down_link"));
      return tips;
      return createUserCouponVOo(userSystemCoupon, systemCoupon, giveRecord, tips);
   }
   private UserSystemCouponVO createUserCouponVOo(UserSystemCoupon userSystemCoupon, SystemCoupon systemCoupon,
         UserSystemCouponGiveRecord record, String tips) {
      UserSystemCouponVO userCouponVO = new UserSystemCouponVO();
      userCouponVO.setId(userSystemCoupon.getId());
      userCouponVO.setUid(userSystemCoupon.getUid());
      userCouponVO.setSource("来源:" + userSystemCoupon.getSource());
      userCouponVO.setCouponName(systemCoupon.getName());
      userCouponVO.setCouponEffect("赠送中");
      userCouponVO.setState(UserSystemCoupon.STATE_GIVE_IN);
      userCouponVO.setCouponRule(systemCoupon.getRemark());
      userCouponVO.setCouponRuleLink(systemCoupon.getRuleLink());
      userCouponVO.setCouponPicture(systemCoupon.getPicture());
      userCouponVO.setGiveTips(tips);
      String couponTerm = "有效期:";
      Date startTime = userCouponVO.getStartTime();
      Date endTime = userCouponVO.getEndTime();
      if (endTime != null && startTime != null) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
         couponTerm = couponTerm + sdf.format(startTime) + "-" + sdf.format(endTime);
      }
      userCouponVO.setCouponTerm(couponTerm);
      Map<String, Object> remainDays = new HashMap<String, Object>();
      try {
         remainDays.put("content", "剩余" + DateUtil.dateDiff2(new Date(), record.getGiveTime()) + "过期");
      } catch (Exception e) {
      }
      remainDays.put("fontColor", "#F14242");
      userCouponVO.setRemainDays(remainDays);
      return userCouponVO;
   }
   
@@ -2025,7 +2067,7 @@
         
         // 退回消息
         String beiZhu = "请到我的-福利中心查看";
         SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH.mm");
         SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
         MsgOtherGiveContentDTO msgOther = new MsgOtherGiveContentDTO();
         msgOther.setType(MsgOtherGiveContentDTO.TYEP_COUPON);
         msgOther.setTitle("赠送" + systemCoupon.getName() + "退回");