admin
2019-08-19 9c09cead959dbeef292628f345e5f80c30fc3d17
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -198,8 +198,8 @@
      }
      SystemCoupon coupon = null;
      if (couponType.equals(CouponTypeEnum.welfareFreeCoupon.name())) {
         // 福利免单券
      if (couponType.equals(CouponTypeEnum.welfareFreeCoupon.name()) || couponType.equals(CouponTypeEnum.freeCoupon.name())) {
         // 免单券
         coupon = systemCouponService.getCouponByType(couponType);
      } else if (couponType.equals(CouponTypeEnum.rebatePercentCoupon.name())) {
         // 随机奖励券
@@ -219,6 +219,8 @@
         if (countSuccess == 0) {
            stateActivated = 0;
         }
      } else if (coupon.getType() == CouponTypeEnum.freeCoupon) {
         stateActivated = 0;
      }
      // 结束日期
@@ -1892,14 +1894,18 @@
               long num = 10000 + (long) (Math.random() * 10000);
               token = UserUtil.getInviteCode(num);
               
               String endDay = DateUtil.plusDay(Constant.TOKEN_DAYS - 1,nowDate);
               SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
               Date endTime = format.parse(endDay);
               TokenRecord tokenRecord = new TokenRecord();
               tokenRecord.setUid(uid);
               tokenRecord.setIdentify(id+"");
               tokenRecord.setType(tokenTypeEnum);
               tokenRecord.setStartTime(nowDate);
               tokenRecord.setEndTime(DateUtil.plusDayDate(3, nowDate));
               tokenRecord.setEndTime(endTime);
               tokenRecord.setToken(token);
               tokenRecord.setState(state);
               tokenRecord.setState(0);
               tokenRecordService.insertSelective(tokenRecord);
            } catch (Exception e) {
               LogHelper.errorDetailInfo(e);
@@ -1915,24 +1921,61 @@
            throw new UserSystemCouponException(1, "口令生成失败");
         
         // 插入赠送记录
         UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
         giveRecord.setCouponId(id);
         giveRecord.setGiveUid(uid);
         giveRecord.setGiveTime(nowDate);
         userSystemCouponGiveRecordService.insertSelective(giveRecord);
         try {
            String endDay = DateUtil.plusDay(Constant.GIVE_DAYS - 1, new Date());
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date endTime = format.parse(endDay);
            UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
            giveRecord.setCouponId(id);
            giveRecord.setGiveUid(uid);
            giveRecord.setGiveTime(nowDate);
            giveRecord.setEndTime(endTime);
            userSystemCouponGiveRecordService.insertSelective(giveRecord);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            throw new UserSystemCouponException(1, "赠送记录创建失败");
         }
      }
      
      if(StringUtil.isNullOrEmpty(token))
         throw new UserSystemCouponException(1, "口令生成失败");
      userSystemCoupon.setState(UserSystemCoupon.STATE_IN_USE);
      userSystemCoupon.setGive(true);
      userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
      String tips = "送给你一张返利奖励券快去领取吧,复制本条消息[&%s&],打开[返利券]App领取,使用后可让返利加倍。\r\n" 
            +"----------------------------\r\n" 
            + "下载[返利券]App链接:http://t.cn/2H7AXAH\r\n"
            + "下载[返利券]App链接:%s\r\n"
            + "PS:口令将会24小时内失效,请及时领取。";
      
      tips = String.format(tips, token);
      tips = String.format(tips, token, configService.get("app_down_link"));
      
      return tips;
   }
   @Override
   public void updateGiveRecord(Long uid, Long id, String couponType) {
      Date date = new Date();
      // 更新券状态:已使用
      UserSystemCoupon userCoupon = new UserSystemCoupon();
      userCoupon.setId(id);
      userCoupon.setState(UserSystemCoupon.STATE_END_USE);
      userCoupon.setUseTime(date);
      userCoupon.setUpdateTime(date);
      userSystemCouponMapper.updateByPrimaryKeySelective(userCoupon);
      // 插入使用券记录
      UserSystemCouponRecord couponRecord = new UserSystemCouponRecord();
      couponRecord.setState(UserSystemCouponRecord.STATE_SUCCESS);
      couponRecord.setUserSystemCoupon(userCoupon);
      couponRecord.setCouponType(couponType);
      couponRecord.setCreateTime(date);
      couponRecord.setUpdateTime(date);
      userSystemCouponRecordService.insertSelective(couponRecord);
   }
}