yujian
2020-04-14 c04a59775ee986f33fe19e21ae02cff9f6b002a7
fanli/src/main/java/com/yeshi/fanli/service/impl/user/invite/UserInviteSeparateServiceImpl.java
@@ -5,13 +5,21 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
import com.yeshi.fanli.dao.mybatis.user.UserInviteSeparateMapper;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserInviteSeparate;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserInviteSeparateService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.invite.UserInviteMsgNotificationService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
@Service
@@ -23,7 +31,21 @@
   @Resource
   private UserVipConfigService userVipConfigService;
   
   @Lazy
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   
   @Lazy
   @Resource
   private UserVIPPreInfoService userVIPPreInfoService;
   @Lazy
   @Resource
   private UserInfoService userInfoService;
   @Lazy
   @Resource
   private UserInviteMsgNotificationService userInviteMsgNotificationService;
   @Override
   public void insertSelective(UserInviteSeparate record) {
@@ -51,8 +73,6 @@
      userInviteSeparateMapper.insertSelective(inviteSeparate);
   }
   
   @Override
   public void updateInvalidByBossId(Long uid) {
      userInviteSeparateMapper.updateInvalidByBossId(uid);
@@ -74,6 +94,55 @@
   }
   
   
   @Override
   @Transactional(rollbackFor = Exception.class)
   public void inviteSeparate(UserInviteSeparate record) {
      if (record == null)
         return;
      Long workerId = record.getWorkerId();
      Long bossId = record.getBossId();
      ThreeSale threeSale = threeSaleSerivce.getMyBoss(workerId);
      if (threeSale == null) {
         // 成功脱离 不发消息
         userInviteSeparateMapper.updateStateByWorkerIdAndBossId(workerId, bossId, UserInviteSeparate.STATE_SUCCESS);
         return;
      }
      boolean separate = false;
      UserVIPPreInfo info = userVIPPreInfoService.getVipByProcess(bossId, UserVIPPreInfo.PROCESS_1);
      if (info == null) {
         separate = true;
      } else if (info.getCreateTime().getTime() >= record.getEndTime().getTime()) {
         separate = true;
      }
      if (!separate) {
         // 未脱离
         userInviteSeparateMapper.updateStateByWorkerIdAndBossId(workerId, bossId, UserInviteSeparate.STATE_INVALID);
      } else {
         // 脱离关系
         userInviteSeparateMapper.updateStateByWorkerIdAndBossId(workerId, bossId, UserInviteSeparate.STATE_SUCCESS);
         // 脱离邀请关系
         threeSaleSerivce.inviteSeparate(workerId, bossId);
         UserInfo worker = userInfoService.selectByPKey(workerId);
         // 提醒上级脱离
         userInviteMsgNotificationService.fansDivorced(bossId, worker.getNickName(), new Date());
         // 提醒上上级脱离
         ThreeSale threeSaleSuper = threeSaleSerivce.getMyBoss(bossId);
         if (threeSaleSuper != null) { // 粉丝升级提醒
            Long bossIdSuper = threeSaleSuper.getBoss().getId();
            UserInfo boss = userInfoService.selectByPKey(workerId);
            userInviteMsgNotificationService.fansDivorcedIndirect(bossIdSuper, worker.getNickName(),
                  boss.getNickName(), new Date());
         }
      }
   }
   
   
}