package com.yeshi.fanli.service.impl.user.invite;
|
|
import java.util.Date;
|
import java.util.List;
|
|
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.dto.msg.MsgOtherVIPDTO;
|
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.msg.UserOtherMsgNotificationService;
|
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.vip.UserVIPPreInfoService;
|
import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
|
import com.yeshi.fanli.util.TimeUtil;
|
|
@Service
|
public class UserInviteSeparateServiceImpl implements UserInviteSeparateService {
|
|
@Resource
|
private UserInviteSeparateMapper userInviteSeparateMapper;
|
|
@Resource
|
private UserVipConfigService userVipConfigService;
|
|
@Lazy
|
@Resource
|
private ThreeSaleSerivce threeSaleSerivce;
|
|
@Lazy
|
@Resource
|
private UserVIPPreInfoService userVIPPreInfoService;
|
|
@Lazy
|
@Resource
|
private UserInfoService userInfoService;
|
|
@Lazy
|
@Resource
|
private UserOtherMsgNotificationService userOtherMsgNotificationService;
|
|
@Override
|
public void insertSelective(UserInviteSeparate record) {
|
userInviteSeparateMapper.insertSelective(record);
|
}
|
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void addPreSeparateRecord(Long workerId, Long bossId) {
|
// 更新之前状态失效
|
userInviteSeparateMapper.updateStateByWorkerIdAndBossId(workerId, bossId, UserInviteSeparate.STATE_INVALID);
|
|
// 限制天数
|
int limitDays = Integer.parseInt(userVipConfigService.getValueByKey("invite_separate_limit_days"));
|
|
// 保存记录
|
UserInviteSeparate inviteSeparate = new UserInviteSeparate();
|
inviteSeparate.setBossId(bossId);
|
inviteSeparate.setWorkerId(workerId);
|
inviteSeparate.setState(UserInviteSeparate.STATE_INIT);
|
inviteSeparate.setEndTime(DateUtil.plusDayDate(limitDays, new Date()));
|
inviteSeparate.setCreateTime(new Date());
|
inviteSeparate.setUpdateTime(new Date());
|
userInviteSeparateMapper.insertSelective(inviteSeparate);
|
|
UserInfo userInfo = userInfoService.getUserById(workerId);
|
// 消息
|
MsgOtherVIPDTO msgboss = new MsgOtherVIPDTO();
|
msgboss.setContent1(userInfo.getNickName() + " " + workerId);
|
msgboss.setContent2("于" + TimeUtil.formatDateDot(new Date()) + "成功升级成为会员");
|
msgboss.setContent3("今日起" + limitDays + "天内,你未能成为会员将会与其脱离邀请关系 ");
|
userOtherMsgNotificationService.teamVIPCallBoss(bossId, "如有疑问请联系我的-人工客服", msgboss);
|
}
|
|
@Override
|
public void updateInvalidByBossId(Long uid) {
|
userInviteSeparateMapper.updateInvalidByBossId(uid);
|
}
|
|
@Override
|
public void updateStateByWorkerIdAndBossId(Long workerId, Long bossId, int state) {
|
userInviteSeparateMapper.updateStateByWorkerIdAndBossId(workerId, bossId, state);
|
}
|
|
@Override
|
public UserInviteSeparate selectByWorkerIdAndBossId(Long workerId, Long bossId) {
|
return userInviteSeparateMapper.selectByWorkerIdAndBossId(workerId, bossId);
|
}
|
|
@Override
|
public List<UserInviteSeparate> getHandleOverdue(int start, int count) {
|
return userInviteSeparateMapper.getHandleOverdue(start, count);
|
}
|
|
|
|
@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);
|
|
int limitDays = Integer.parseInt(userVipConfigService.getValueByKey("invite_separate_limit_days"));
|
|
// 消息 TODO
|
UserInfo userInfo = userInfoService.selectByPKey(workerId);
|
MsgOtherVIPDTO msgboss = new MsgOtherVIPDTO();
|
msgboss.setContent1(userInfo.getNickName() + workerId + "于"+ TimeUtil.formatDateDot(record.getCreateTime()) + "成功升级成为会员 ");
|
msgboss.setContent2("很遗憾,你未能在" + limitDays + "天升级为会员 ");
|
msgboss.setContent3("已与其脱离邀请关系");
|
userOtherMsgNotificationService.teamSplitCallBoss(bossId, "如有疑问请联系我的-人工客服", msgboss);
|
}
|
}
|
|
|
}
|