yujian
2019-08-30 ffbd3afe3806bfdbb13487f6031b938cb1ebcf9b
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -10,7 +10,9 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
@@ -105,6 +107,7 @@
   private UserSystemCouponRecordService userSystemCouponRecordService;
   @Resource
   @Lazy
   private HongBaoV2Service hongBaoV2Service;
   @Resource
@@ -141,6 +144,7 @@
   private CommonOrderCountService commonOrderCountService;
   
   @Resource
   @Lazy
   private PushCouponService pushCouponService;
   
   @Resource
@@ -910,7 +914,7 @@
      userRecordVO.setCouponEffect("返利¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN) + "已返" + percent + "%");
      // 资金明细
      JumpDetailV2 welfareCore = jumpDetailV2Service.getByTypeCache("capitalDetails");
      JumpDetailV2 welfareCore = jumpDetailV2Service.getByTypeCache("moneyDetails");
      Map<String, Object> jumpWelfare = new HashMap<String, Object>();
      jumpWelfare.put("jumpDetail", welfareCore);
      Map<String, Object> jumpparms = new HashMap<String, Object>();
@@ -1754,9 +1758,11 @@
               // 可使用、 可赠送
               userCouponVO.setState(UserSystemCoupon.STATE_USE_GIVE);
               // 返利奖励券- 跳转至已到账-已收货
               jumpLink.put("state", "2");
               jumpLink.put("type", "1");
               // 订单列表
               jumpLink.put("state", "2"); // 已收货
               jumpLink.put("type", "1");  // 返利订单
               jumpLink.put("title", "返利订单"); // 标题名
               jumpLink.put("goodsType", "0"); // 订单来源
               jumpBtn = new HashMap<String, Object>();
               jumpBtn.put("params", jumpLink);
               jumpBtn.put("jumpDetail", jumpDetailV2Service.getByTypeCache("order_screen_list"));
@@ -2145,16 +2151,10 @@
      userSystemCoupon.setUseTime(null);
      userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
      userSystemCoupon.setUpdateTime(new Date());
      userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
      userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
      
      // 使用记录
      if  (record != null) {
         UserSystemCouponRecord useRecordUpdate = new UserSystemCouponRecord();
         useRecordUpdate.setId(record.getId());
         useRecordUpdate.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
         useRecordUpdate.setUpdateTime(new Date());
         userSystemCouponRecordService.updateByPrimaryKeySelective(useRecordUpdate);
         if (CouponTypeEnum.welfareFreeCoupon.name().equals(record.getCouponType())) {
            userOtherMsgNotificationService.welfareCouponDrawBack(userSystemCoupon, record.getOrderNo());
         } else if (CouponTypeEnum.freeCoupon.name().equals(record.getCouponType())) {
@@ -2166,27 +2166,44 @@
   }
   
   
   @Async()
   @Transactional
   @Override
   public void sendBackTimeOutCoupon(Long uid) {
      // 超过10分钟   未被匹配的券
      List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 600L);
      if (list == null || list.size() == 0) {
      // 商品相关的券
      List<SystemCoupon> couponList = systemCouponService.getGoodsCouponList();
      if (couponList == null || couponList.size() == 0) {
         return;
      }
      for (UserSystemCouponRecord couponRecord : list) {
         // 更新状态:匹配超时
         couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
         couponRecord.setUpdateTime(new Date());
         userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
      List<Long> list = new ArrayList<Long>();
      for (SystemCoupon systemCoupon: couponList) {
         list.add(systemCoupon.getId());
      }
      // 超过10分钟   未被匹配的免单券
      List<UserSystemCoupon> listUserCoupon = userSystemCouponMapper.getCouponByUsingTimeOut(uid, list, 600L);
      if (listUserCoupon == null || listUserCoupon.size() == 0) {
         return;
      }
      for (UserSystemCoupon userCoupon : listUserCoupon) {
         // 状态初始化
         UserSystemCoupon userSystemCoupon = couponRecord.getUserSystemCoupon();
         UserSystemCoupon userSystemCoupon = new UserSystemCoupon();
         userSystemCoupon.setId(userCoupon.getId());
         userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
         userSystemCoupon.setUseTime(null);
         userSystemCoupon.setUpdateTime(new Date());
         userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
         userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
         UserSystemCouponRecord record = userSystemCouponRecordService.getNearByUserCouponId(userCoupon.getId());
         if (record != null) {
            UserSystemCouponRecord couponRecord = new UserSystemCouponRecord();
            couponRecord.setId(record.getId());
            couponRecord.setUpdateTime(new Date());
            couponRecord.setState(UserSystemCouponRecord.STATE_WAIT_TIME_OUT);
            userSystemCouponRecordService.updateByPrimaryKeySelective(couponRecord);
         }
      }
   }
@@ -2241,7 +2258,7 @@
         userSystemCoupon.setUseTime(null);
         userSystemCoupon.setState(UserSystemCoupon.STATE_CAN_USE);
         userSystemCoupon.setUpdateTime(new Date());
         userSystemCouponMapper.updateByPrimaryKey(userSystemCoupon);
         userSystemCouponMapper.updateByPrimaryKeySelective(userSystemCoupon);
         
         // 使用记录
         UserSystemCouponRecord useRecord = userSystemCouponRecordService.getNearByUserCouponId(couponId);