admin
2019-02-27 dcd5d07d5d648b48f6f04cd79b6e8c5b780dcff7
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -11,6 +11,7 @@
import javax.annotation.Resource;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
@@ -27,6 +28,7 @@
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.system.SystemCoupon;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.exception.user.UserSystemCouponException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
@@ -58,6 +60,9 @@
@Service
public class UserSystemCouponServiceImpl implements UserSystemCouponService {
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   @Resource
   private UserSystemCouponMapper userSystemCouponMapper;
@@ -185,6 +190,22 @@
      // 插入数据库
      insertSelective(userCoupon);
      
      executor.execute(new Runnable() {
         @Override
         public void run() {
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            // 添加一条消息
            if (userInfoExtra != null) {
               userInfoExtra.setCouponNews(userInfoExtra.getCouponNews() + 1);
               try {
                  userInfoExtraService.saveUserInfoExtra(userInfoExtra);
               } catch (UserInfoExtraException e) {
                  e.printStackTrace();
               }
            }
         }
      });
      
      // 消息推送
      try {
@@ -990,10 +1011,46 @@
            }
         }
      }
   }
   
   @Override
   public void updateStateByDrawback(String orderNo) throws Exception {
      if (orderNo == null || orderNo.trim().length() == 0) {
         return;
      }
      UserSystemCouponRecord record = userSystemCouponRecordService.getRecordByOrderNo(orderNo, null);
      if (record == null) {
         return;
      }
      record.setOrderNo(orderNo);
      record.setUpdateTime(new Date());
      record.setState(UserSystemCouponRecord.STATE_FAIL_DRAWBACK);
      userSystemCouponRecordService.updateByPrimaryKeySelective(record);
      // 券退回
      sendBackCoupon(record.getUserSystemCoupon());
   }
   @Override
   public void updateStateByArrivalAccount(String orderNo) throws Exception {
      if (orderNo == null || orderNo.trim().length() == 0) {
         return;
      }
      UserSystemCouponRecord record = userSystemCouponRecordService.getRecordByOrderNo(orderNo, 2);
      if (record == null) {
         return;
      }
      record.setOrderNo(orderNo);
      record.setUpdateTime(new Date());
      record.setState(UserSystemCouponRecord.STATE_SUCCESS);
      userSystemCouponRecordService.updateByPrimaryKeySelective(record);
   }
   @Override
   public void updateCounponInvalid(Long uid) {
@@ -1040,7 +1097,7 @@
   @Override
   public void  sendBackTimeOutCoupon(Long uid) {
      // 超过120秒 未被匹配的券
      List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 120);
      List<UserSystemCouponRecord> list = userSystemCouponRecordService.getCouponByUsingTimeOut(uid, 120L);
      if (list == null || list.size() == 0) {
         return;
      }
@@ -1085,10 +1142,6 @@
   @Override
   public boolean updateCouponRecordUsed(Long uid, String orderNo, BigDecimal payment,
         Long auctionId) throws  Exception{
      //只处理付款金额小于10的
      if(payment==null||payment.compareTo(new BigDecimal(10))<0)
         return false;
      
      boolean isfree = false;