yujian
2019-08-21 352c7227fc3c3be1a4465bb57cefd5462240aea9
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -62,7 +62,7 @@
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.TokenUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
@@ -1926,52 +1926,31 @@
      }
      
      
      Long giveRecordId = null;
      Date nowDate = new Date();
      // 插入赠送记录
      try {
         UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
         giveRecord.setCouponId(id);
         giveRecord.setGiveUid(uid);
         giveRecord.setGiveTime(nowDate);
         giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, nowDate));
         userSystemCouponGiveRecordService.insertSelective(giveRecord);
         giveRecordId = giveRecord.getId();
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
         throw new UserSystemCouponException(1, "赠送记录创建失败");
      }
      UserSystemCouponGiveRecord giveRecord = new UserSystemCouponGiveRecord();
      giveRecord.setCouponId(id);
      giveRecord.setGiveUid(uid);
      giveRecord.setGiveTime(nowDate);
      giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, nowDate));
      userSystemCouponGiveRecordService.insertSelective(giveRecord);
      
      String token = null;
      for (int i = 0; i < 5; i++) {
         try {
            // TODO 口令生成规则待定
            long num = 10000 + (long) (Math.random() * 10000);
            token = UserUtil.getInviteCode(num);
            TokenRecord tokenRecord = new TokenRecord();
            tokenRecord.setUid(uid);
            tokenRecord.setIdentify(giveRecordId+"");
            tokenRecord.setType(tokenTypeEnum);
            tokenRecord.setStartTime(nowDate);
            tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, nowDate));
            tokenRecord.setToken(token);
            tokenRecord.setState(0);
            tokenRecordService.insertSelective(tokenRecord);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            token = null;
         }
      // 创建记录
      TokenRecord tokenRecord = new TokenRecord();
      tokenRecord.setUid(uid);
      tokenRecord.setIdentify(giveRecord.getId()+"");
      tokenRecord.setType(tokenTypeEnum);
      tokenRecord.setStartTime(nowDate);
      tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, nowDate));
      tokenRecord.setState(0);
      tokenRecordService.insertSelective(tokenRecord);
      // 创建口令
      String token = TokenUtil.createToken(tokenRecord.getId());
      tokenRecord.setToken(token);
      tokenRecordService.updateByPrimaryKeySelective(tokenRecord);
         
         if(!StringUtil.isNullOrEmpty(token)) {
            break;
         }
      }
      if(StringUtil.isNullOrEmpty(token))
         throw new UserSystemCouponException(1, "口令生成失败");
      // 券状态
      userSystemCoupon.setState(UserSystemCoupon.STATE_IN_USE);
      userSystemCoupon.setGive(true);
      userSystemCoupon.setUpdateTime(nowDate);