admin
2019-08-19 9c09cead959dbeef292628f345e5f80c30fc3d17
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -1894,12 +1894,16 @@
               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(0);
               tokenRecordService.insertSelective(tokenRecord);
@@ -1917,16 +1921,30 @@
            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链接:%s\r\n"
@@ -1937,4 +1955,27 @@
      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);
   }
}