| | |
| | | package com.yeshi.fanli.service.impl.hongbao;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.context.annotation.Lazy;
|
| | | import org.springframework.core.task.TaskExecutor;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.ThreeSaleMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserActiveLog;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.exception.ThreeSaleException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleExtraInfoSerivce;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralGetService;
|
| | | import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService;
|
| | | import com.yeshi.fanli.service.inter.msg.UserInviteMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
|
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.VersionUtil;
|
| | | import com.yeshi.fanli.util.cmq.ThreeSaleCMQManager;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | import org.hibernate.HibernateException;
|
| | | import org.hibernate.Query;
|
| | | import org.hibernate.SQLQuery;
|
| | | import org.hibernate.Session;
|
| | | import org.springframework.orm.hibernate4.HibernateCallback;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.ThreeSaleMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.user.ThreeSaleDao;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.exception.ThreeSaleException;
|
| | | import com.yeshi.fanli.service.inter.config.InviteGetMoneyService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class ThreeSaleSerivceImpl implements ThreeSaleSerivce {
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleDao dao;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private InviteGetMoneyService inviteGetMoneyService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoMapper userInfoMapper;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleMapper threeSaleMapper;
|
| | |
|
| | | @Resource
|
| | | private UserInviteMsgNotificationService userInviteMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private MsgInviteDetailService msgInviteDetailService;
|
| | |
|
| | | @Resource
|
| | | private UserTaoLiJinOriginService userTaoLiJinOriginService;
|
| | |
|
| | | @Resource
|
| | | private UserActiveLogService userActiveLogService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleExtraInfoSerivce threeSaleExtraInfoSerivce;
|
| | |
|
| | | |
| | | @Lazy
|
| | | @Resource
|
| | | private IntegralGetService integralGetService;
|
| | |
|
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | |
|
| | | public UserInfo getBoss(final long uid) {
|
| | | return (UserInfo) dao.excute(new HibernateCallback<UserInfo>() {
|
| | | public UserInfo doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createQuery("select ts.boss FROM ThreeSale ts where ts.worker.id = ?");
|
| | | query.setParameter(0, uid);
|
| | | List<UserInfo> list = query.list();
|
| | | if (list.size() > 0) {
|
| | | return list.get(0);
|
| | | }
|
| | | return null;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public int findInviteCount(final long id) {
|
| | |
|
| | | return (Integer) dao.excute(new HibernateCallback<Integer>() {
|
| | |
|
| | | public Integer doInHibernate(Session session) throws HibernateException {
|
| | | SQLQuery query = session.createSQLQuery(
|
| | | "SELECT COUNT(*) from `yeshi_ec_threesale` t1 RIGHT JOIN (SELECT t2.`worker_id` AS worker_id FROM `yeshi_ec_threesale` t2 WHERE t2.`boss_id`=? ) t3 ON t1.`boss_id`=t3.worker_id WHERE t1.`boss_id`=t3.worker_id ");
|
| | | query.setParameter(0, id);
|
| | | SQLQuery query2 = session
|
| | | .createSQLQuery("SELECT COUNT(*) from `yeshi_ec_threesale` t4 WHERE t4.`boss_id`=?");
|
| | | query2.setParameter(0, id);
|
| | | int int1 = Integer.parseInt(query.uniqueResult() + "");
|
| | | int int2 = Integer.parseInt(query2.uniqueResult() + "");
|
| | | return int1 + int2;
|
| | | }
|
| | | });
|
| | | return threeSaleMapper.selectBoss(uid);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void bind(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
|
| | | if (invitee == null || inviter == null)
|
| | | public void bind(UserInfo worker, UserInfo inviter) throws ThreeSaleException {
|
| | | if (worker == null || inviter == null)
|
| | | throw new ThreeSaleException(1, "用户信息为空");
|
| | | if (invitee.getId() == null)// 该用户还不存在
|
| | |
|
| | | if (worker.getId() == null)// 该用户还不存在
|
| | | {
|
| | | // 保存用户
|
| | | UserInfo inviteeUser = userInfoService.addUser(invitee, Constant.APPID);
|
| | | UserInfo inviteeUser = userInfoService.addUser(worker, Constant.APPID);
|
| | | if (inviteeUser == null)
|
| | | throw new ThreeSaleException(2, "创建用户失败");
|
| | | // 保存关系
|
| | |
| | | threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setWorker(inviteeUser);
|
| | | threeSaleMapper.insertSelective(threeSale);
|
| | |
|
| | | List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), inviteeUser.getId());
|
| | | if (listExpire != null && listExpire.size() > 0) {
|
| | | // 删除失效
|
| | | for (ThreeSale saleExpire : listExpire) {
|
| | | msgInviteDetailService.deleteByThreeSale(saleExpire);
|
| | | }
|
| | | // 删除已失效关系
|
| | | threeSaleMapper.deleteExpireRecord(inviter.getId(), inviteeUser.getId());
|
| | | }
|
| | |
|
| | | // 创建通知
|
| | | userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
|
| | |
|
| | | } else {// 是已经存在的用户
|
| | | if (worker.getId().longValue() == inviter.getId())
|
| | | throw new ThreeSaleException(4, "不能绑定自己");
|
| | |
|
| | | worker = userInfoService.selectByPKey(worker.getId());
|
| | |
|
| | | // 用户已经存在我们的用户库中
|
| | | if (invitee.getLastLoginTime() == null || invitee.getLastLoginTime() == 0L) {
|
| | | if (worker.getLastLoginTime() == null || worker.getLastLoginTime() == 0L) {
|
| | | // 用户未登录
|
| | | int outOfDateCount = 0;// 过期数量
|
| | | // 查询邀请关系
|
| | | List<ThreeSale> list = listByWorkerId(invitee.getId());
|
| | | List<ThreeSale> list = listByWorkerId(worker.getId());
|
| | | if (list != null && list.size() > 0) {
|
| | | for (ThreeSale ts : list) {
|
| | | if (!ts.getState() && ts.getExpire() == ThreeSale.EXPIRE_OUTOFDATE) {
|
| | |
| | | threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
|
| | | threeSale.setState(false);
|
| | | threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setWorker(invitee);
|
| | | threeSale.setWorker(worker);
|
| | | threeSaleMapper.insertSelective(threeSale);
|
| | |
|
| | | // 删除已失效关系
|
| | | threeSaleMapper.deleteExpireRecord(inviter.getId(), worker.getId());
|
| | |
|
| | | List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), worker.getId());
|
| | | if (listExpire != null && listExpire.size() > 0) {
|
| | | // 删除历史通知
|
| | | for (ThreeSale saleExpire : listExpire) {
|
| | | msgInviteDetailService.deleteByThreeSale(saleExpire);
|
| | | }
|
| | | // 删除已失效关系
|
| | | threeSaleMapper.deleteExpireRecord(inviter.getId(), worker.getId());
|
| | | }
|
| | |
|
| | | userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
|
| | | // threeSaleSerivce.bind(invitee, inviter);
|
| | |
|
| | | } else {
|
| | |
| | | // 用户未登录,又不存在邀请关系,不做处理
|
| | | }
|
| | | } else {
|
| | | // 已经登录,不做处理
|
| | | // 已经登录,而且没有上下级关系或者上下级关系未生效,则绑定关系
|
| | | List<ThreeSale> list = threeSaleMapper.listByWorkerId(worker.getId());
|
| | | // 删除无效的
|
| | | if (list != null)
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getState() != null && list.get(i).getState() == false
|
| | | && list.get(i).getExpire() == ThreeSale.EXPIRE_OUTOFDATE) {// 过期的
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | // 查询上级是否有和现在上级一样的
|
| | | if (list == null || list.size() == 0)// 尚未确立关系,建立关系
|
| | | {
|
| | | ThreeSale ts = new ThreeSale();
|
| | | ts.setBoss(inviter);
|
| | | ts.setCreateTime(System.currentTimeMillis());
|
| | | ts.setExpire(ThreeSale.EXPIRE_NORMAL);
|
| | | ts.setState(true);
|
| | | ts.setSucceedTime(System.currentTimeMillis());
|
| | | ts.setWorker(worker);
|
| | | threeSaleMapper.insertSelective(ts);
|
| | | ThreeSaleCMQManager.getInstance().addThreeSaleMsg(ts);
|
| | | userInviteMsgNotificationService.inviteSuccess(inviter.getId(), ts);
|
| | | } else {
|
| | | if (!list.get(0).getState() && list.get(0).getExpire() == ThreeSale.EXPIRE_NORMAL
|
| | | && list.get(0).getBoss().getId() == inviter.getId().longValue()) {// 未生效的上级和现在上级一样就生效
|
| | | ThreeSale update = new ThreeSale(list.get(0).getId());
|
| | | update.setState(true);
|
| | | update.setSucceedTime(System.currentTimeMillis());
|
| | | threeSaleMapper.updateByPrimaryKeySelective(update);
|
| | | ThreeSaleCMQManager.getInstance().addThreeSaleMsg(list.get(0));// 添加通知
|
| | | userInviteMsgNotificationService.inviteSuccess(inviter.getId(), list.get(0));
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void effective(UserInfo invitee) {
|
| | | List<ThreeSale> list = dao.list("from ThreeSale ts where ts.worker.id = ? and ts.state=0 and ts.expire=0",
|
| | | new Serializable[] { invitee.getId() });
|
| | | public void effective(UserInfo worker) {
|
| | | List<ThreeSale> list = threeSaleMapper.listByWorkerId(worker.getId());
|
| | | if (list != null)
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getState() != null && list.get(i).getState() == false
|
| | | && list.get(i).getExpire() == ThreeSale.EXPIRE_NORMAL) {
|
| | | ;
|
| | | } else {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | if (list.size() > 0) {
|
| | | ThreeSale threeSale = list.get(0);
|
| | | UserInfo inviter = threeSale.getBoss();
|
| | | threeSale.setState(true);
|
| | | threeSale.setSucceedTime(System.currentTimeMillis());
|
| | | dao.update(threeSale);
|
| | | if (inviter != null)
|
| | | reComputeUserRank(inviter.getId());
|
| | | // }
|
| | | // });
|
| | | ThreeSale oldSale = list.get(0);
|
| | |
|
| | | ThreeSale update = new ThreeSale(list.get(0).getId());
|
| | | update.setState(true);
|
| | | update.setSucceedTime(System.currentTimeMillis());
|
| | | threeSaleMapper.updateByPrimaryKeySelective(update);
|
| | |
|
| | | oldSale.setState(update.getState());
|
| | | oldSale.setSucceedTime(update.getSucceedTime());
|
| | |
|
| | | UserInfo inviter = list.get(0).getBoss();
|
| | | // 不以邀请人数计算等级
|
| | | // if (inviter != null)
|
| | | // reComputeUserRank(inviter.getId());
|
| | | // 添加到队列
|
| | | ThreeSaleCMQManager.getInstance().addThreeSaleMsg(oldSale);
|
| | | // 通知
|
| | | userInviteMsgNotificationService.inviteSuccess(inviter.getId(), oldSale);
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void validateTwentyFour() {
|
| | | dao.excute(new HibernateCallback() {
|
| | | @Override
|
| | | public Object doInHibernate(Session session) throws HibernateException {
|
| | | long currentTimeMillis = System.currentTimeMillis();
|
| | | Query query = session
|
| | | .createQuery("delete from ThreeSale ts where ts.state = ? and (?-ts.createTime) > 86400000");
|
| | | query.setParameter(0, false);
|
| | | query.setParameter(1, currentTimeMillis);
|
| | | query.executeUpdate();
|
| | | return null;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void validate365() {
|
| | | dao.excute(new HibernateCallback() {
|
| | | @Override
|
| | | public Object doInHibernate(Session session) throws HibernateException {
|
| | | long currentTimeMillis = System.currentTimeMillis();
|
| | | Query query = session.createQuery("delete from ThreeSale ts where (?-ts.createTime) > 31536000000");
|
| | | query.setParameter(0, currentTimeMillis);
|
| | | query.executeUpdate();
|
| | | return null;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public List<UserInfo> getFirstUsers(Long uid, int page) {
|
| | | return (List<UserInfo>) dao.excute(new HibernateCallback<List<UserInfo>>() {
|
| | |
|
| | | @Override
|
| | | public List<UserInfo> doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session
|
| | | .createSQLQuery(
|
| | | "SELECT u.* FROM `yeshi_ec_threesale` t LEFT JOIN `yeshi_ec_user` u ON u.`id`=t.`worker_id` WHERE t.`boss_id`=? ORDER BY t.`createtime` DESC")
|
| | | .addEntity(UserInfo.class);
|
| | | query.setParameter(0, uid);
|
| | | query.setFirstResult((page - 1) * Constant.PAGE_SIZE).setMaxResults(Constant.PAGE_SIZE);
|
| | | return query.list();
|
| | | }
|
| | | });
|
| | |
|
| | | }
|
| | |
|
| | | @SuppressWarnings("unchecked")
|
| | | @Override
|
| | | public List<UserInfo> getSecondUsers(Long uid, int page) {
|
| | | return (List<UserInfo>) dao.excute(new HibernateCallback<List<UserInfo>>() {
|
| | |
|
| | | @Override
|
| | | public List<UserInfo> doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session
|
| | | .createSQLQuery(
|
| | | "SELECT u.* FROM `yeshi_ec_threesale` t LEFT JOIN yeshi_ec_threesale t1 ON t1.`boss_id`=t.`worker_id` LEFT JOIN `yeshi_ec_user` u ON u.`id`=t1.`worker_id` WHERE t.`boss_id`=? AND u.`id` IS NOT NULL GROUP BY u.`id` ORDER BY t.`createtime` DESC")
|
| | | .addEntity(UserInfo.class);
|
| | | query.setParameter(0, uid);
|
| | | query.setFirstResult((page - 1) * Constant.PAGE_SIZE).setMaxResults(Constant.PAGE_SIZE);
|
| | | return query.list();
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ThreeSale> getLastestThreeSaleList(int page, String key) {
|
| | | if (NumberUtil.isNumeric(key)) {
|
| | | Long uid = Long.parseLong(key);
|
| | | int start = (page - 1) * Constant.PAGE_SIZE;
|
| | | List<ThreeSale> list = dao.list(
|
| | | "from ThreeSale ts where ts.boss.nickName like ? or ts.boss.id = ? or ts.worker.nickName like ? or ts.worker.id = ? order by ts.createTime desc",
|
| | | start, Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%", uid, "%" + key + "%", uid });
|
| | | return list;
|
| | | }
|
| | | int start = (page - 1) * Constant.PAGE_SIZE;
|
| | | List<ThreeSale> list = dao.list(
|
| | | "from ThreeSale ts where ts.boss.nickName like ? or ts.worker.nickName like ? order by ts.createTime desc",
|
| | | start, Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%", "%" + key + "%" });
|
| | | return list;
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getLastestThreeSaleCount(String key) {
|
| | | if (NumberUtil.isNumeric(key)) {
|
| | | long lk = Long.parseLong(key);
|
| | | return (int) dao.getCount(
|
| | | "select count(*) from ThreeSale ts where ts.boss.id = ? or ts.worker.id = ? or ts.boss.nickName like ? or ts.worker.nickName like ?",
|
| | | new Serializable[] { lk, lk, "%" + key + "%", "%" + key + "%" });
|
| | | }
|
| | | Long lcount = dao.getCount(
|
| | | "select count(*) from ThreeSale ts where ts.boss.nickName like ? or ts.worker.nickName like ?",
|
| | | new Serializable[] { "%" + key + "%", "%" + key + "%" });
|
| | | return lcount.intValue();
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long getFirstUsersCount(Long uid) {
|
| | | return (Long) dao.excute(new HibernateCallback<Long>() {
|
| | |
|
| | | @Override
|
| | | public Long doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createSQLQuery(
|
| | | "SELECT count(u.id) FROM `yeshi_ec_threesale` t LEFT JOIN `yeshi_ec_user` u ON u.`id`=t.`worker_id` WHERE t.`boss_id`=?");
|
| | | query.setParameter(0, uid);
|
| | | Object count = query.uniqueResult();
|
| | | return Long.parseLong(count + "");
|
| | | }
|
| | | });
|
| | | return threeSaleMapper.countFirstTeam(uid, null);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long getSecondUsersCount(Long uid) {
|
| | | return (Long) dao.excute(new HibernateCallback<Long>() {
|
| | |
|
| | | @Override
|
| | | public Long doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createSQLQuery(
|
| | | "SELECT count(1) FROM `yeshi_ec_threesale` t LEFT JOIN yeshi_ec_threesale t1 ON t1.`boss_id`=t.`worker_id` LEFT JOIN `yeshi_ec_user` u ON u.`id`=t1.`worker_id` WHERE t.`boss_id`=? AND u.`id` IS NOT NULL");
|
| | | query.setParameter(0, uid);
|
| | | Object count = query.uniqueResult();
|
| | | return Long.parseLong(count + "");
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void reComputeUserRank(Long uid) {
|
| | | int myFirstTeamCount = inviteGetMoneyService.myFirstTeamCount(uid + "");
|
| | | int mySecondTeamCount = inviteGetMoneyService.mySecondTeamCount(uid + "");
|
| | | int count = myFirstTeamCount + mySecondTeamCount;
|
| | | UserInfo user = userInfoService.getUserById(uid);
|
| | | if (user == null)
|
| | | return;
|
| | |
|
| | | Map<String, String> convertMap = hongBaoManageService.convertMap();
|
| | | int tong = Integer.parseInt(convertMap.get("sale_tong"));
|
| | | int yin = Integer.parseInt(convertMap.get("sale_yin"));
|
| | | int jin = Integer.parseInt(convertMap.get("sale_jin"));
|
| | | int rank = user.getRank();
|
| | | if (count >= jin) {
|
| | | rank = 3;
|
| | | } else if (count >= yin) {
|
| | | rank = 2;
|
| | | } else if (count >= tong) {
|
| | | rank = 1;
|
| | | }
|
| | |
|
| | | if (rank > user.getRank()) {
|
| | | // 更新Rank
|
| | | UserInfo userInfo = new UserInfo(uid);
|
| | | userInfo.setRank(rank);
|
| | | userInfoMapper.updateByPrimaryKeySelective(userInfo);
|
| | | }
|
| | |
|
| | | return threeSaleMapper.countSecondTeam(uid, null);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ThreeSale> listFirstTeam(long start, int count, Long uid) {
|
| | | return threeSaleMapper.listFirstTeam(start, count, uid);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countFirstTeam(Long uid, Integer state) {
|
| | | return threeSaleMapper.countFirstTeam(uid, state);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ThreeSale> listSecondTeam(long start, int count, Long uid) {
|
| | | return threeSaleMapper.listSecondTeam(start, count, uid);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public JSONObject getMyFirstTeam(long start, int count, Long uid) {
|
| | | public JSONObject getMyFirstTeam(long start, int count, Long uid, Integer state) {
|
| | |
|
| | | List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid);
|
| | | List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid, state);
|
| | | if (list == null) {
|
| | | list = new ArrayList<ThreeSale>();
|
| | | }
|
| | |
|
| | | long countTotal = threeSaleMapper.countFirstTeam(uid, null);
|
| | | long countTotal = threeSaleMapper.countFirstTeam(uid, state);
|
| | |
|
| | | return organizeTeam(countTotal, list);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public JSONObject getMySecondTeam(long start, int count, Long uid) {
|
| | | List<ThreeSale> list = threeSaleMapper.listSecondTeam(start, count, uid);
|
| | | public JSONObject getMySecondTeam(long start, int count, Long uid, Integer state) {
|
| | | List<ThreeSale> list = threeSaleMapper.listSecondTeam(start, count, uid, state);
|
| | | if (list == null) {
|
| | | list = new ArrayList<ThreeSale>();
|
| | | }
|
| | |
|
| | | long countTotal = threeSaleMapper.countSecondTeam(uid, null);
|
| | | long countTotal = threeSaleMapper.countSecondTeam(uid, state);
|
| | |
|
| | | return organizeTeam(countTotal, list);
|
| | | }
|
| | |
| | |
|
| | | if (formatYears.format(todayTime).equals(formatYears.format(lastLoginTime))) {
|
| | | // 本年
|
| | | contentJson.put("content", "最近登陆 " + sdf.format(lastLoginTime));
|
| | | contentJson.put("content", "最近登录 " + sdf.format(lastLoginTime));
|
| | | } else {
|
| | | // 往年
|
| | | contentJson.put("content", "最近登陆 " + format.format(lastLoginTime));
|
| | | contentJson.put("content", "最近登录 " + format.format(lastLoginTime));
|
| | | }
|
| | |
|
| | | array.add(contentJson);
|
| | |
| | | return threeSaleMapper.listByWorkerId(workerId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getSuccessRelationshipNum(Long uid) {
|
| | | return threeSaleMapper.getSuccessRelationshipNum(uid);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
|
| | |
|
| | | if (invitee == null || inviter == null)
|
| | | throw new ThreeSaleException(1, "用户信息为空");
|
| | |
|
| | | // 获取有效的邀请关系
|
| | | ThreeSale threeSale = threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId());
|
| | |
|
| | | if (threeSale != null) {
|
| | | // 有效关系--生效
|
| | | threeSale.setBoss(inviter);
|
| | | threeSale.setWorker(invitee);
|
| | | threeSale.setState(true);
|
| | | threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
|
| | | threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSaleMapper.updateByPrimaryKeySelective(threeSale);
|
| | | } else {
|
| | | // 新建立确定关系
|
| | | threeSale = new ThreeSale();
|
| | | threeSale.setBoss(inviter);
|
| | | threeSale.setWorker(invitee);
|
| | | threeSale.setState(true);
|
| | | threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
|
| | | threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setCreateTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSaleMapper.insertSelective(threeSale);
|
| | | }
|
| | |
|
| | | List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), invitee.getId());
|
| | | if (listExpire != null && listExpire.size() > 0) {
|
| | | // 删除历史通知
|
| | | for (ThreeSale saleExpire : listExpire) {
|
| | | msgInviteDetailService.deleteByThreeSale(saleExpire);
|
| | | }
|
| | | // 删除已失效关系
|
| | | threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
|
| | | }
|
| | |
|
| | | // 添加到队列
|
| | | ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale);
|
| | |
|
| | | // 邀请消息
|
| | | userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale);
|
| | |
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | |
|
| | | UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(inviter.getId());
|
| | | try {
|
| | | if (activeLog != null && !StringUtil.isNullOrEmpty(activeLog.getVersionCode())) {
|
| | | String versionCode = activeLog.getVersionCode();
|
| | | String channel = activeLog.getChannel();
|
| | |
|
| | | boolean result = false;
|
| | | // 渠道是appstore 判断为IOS
|
| | | if (!StringUtil.isNullOrEmpty(channel) && "appstore".equalsIgnoreCase(channel)) {
|
| | | result = VersionUtil.greaterThan_1_5_60("ios", versionCode);
|
| | | } else {
|
| | | result = VersionUtil.greaterThan_1_5_60("android", versionCode);
|
| | | }
|
| | |
|
| | | if (result) {
|
| | | // 被邀请名称
|
| | | String inviteName = invitee.getNickName();
|
| | | if (StringUtil.isNullOrEmpty(inviteName)) {
|
| | | UserInfo userInfo = userInfoService.selectByPKey(invitee.getId());
|
| | | if (userInfo != null) {
|
| | | inviteName = userInfo.getNickName();
|
| | | }
|
| | | }
|
| | | // 奖励邀请红包(淘礼金)
|
| | | userTaoLiJinOriginService.addInviteWinMoney(inviter.getId(), inviteName);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | // 邀请金币
|
| | | integralGetService.addInviteLevelOne(inviter.getId(), invitee.getId());
|
| | | }
|
| | | });
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void bindRelationshipByWX(UserInfo invitee, Long inviterId, ThreeSale threeSaleOld)
|
| | | throws ThreeSaleException {
|
| | |
|
| | | if (invitee == null || (inviterId == null && threeSaleOld == null))
|
| | | throw new ThreeSaleException(1, "用户信息为空");
|
| | |
|
| | | ThreeSale threeSale = null;
|
| | | if (inviterId != null) {
|
| | | // 新建立确定关系
|
| | | threeSale = new ThreeSale();
|
| | | threeSale.setBoss(new UserInfo(inviterId));
|
| | | threeSale.setWorker(invitee);
|
| | | threeSale.setState(true);
|
| | | threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
|
| | | threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setCreateTime(java.lang.System.currentTimeMillis());
|
| | | threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSaleMapper.insertSelective(threeSale);
|
| | |
|
| | | // 邀请关系失效 1.5.3 之前失效
|
| | | if (threeSaleOld != null) {
|
| | | ThreeSale three = new ThreeSale();
|
| | | three.setId(threeSaleOld.getId());
|
| | | three.setExpire(ThreeSale.EXPIRE_OUTOFDATE);
|
| | | three.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSaleMapper.updateByPrimaryKeySelective(three);
|
| | | }
|
| | | } else if (threeSaleOld != null && inviterId == null) {
|
| | | // 1.5.3 之前生效
|
| | | threeSaleOld.setState(true);
|
| | | threeSaleOld.setExpire(ThreeSale.EXPIRE_NORMAL);
|
| | | threeSaleOld.setSucceedTime(java.lang.System.currentTimeMillis());
|
| | | threeSaleOld.setUpdateTime(java.lang.System.currentTimeMillis());
|
| | | threeSaleMapper.updateByPrimaryKeySelective(threeSaleOld);
|
| | |
|
| | | threeSale = threeSaleOld;
|
| | | }
|
| | |
|
| | | if (threeSale == null) {
|
| | | throw new ThreeSaleException(1, "关系绑定失败");
|
| | | }
|
| | |
|
| | | UserInfo boss = userInfoService.selectByPKey(threeSale.getBoss().getId());
|
| | | threeSale.setBoss(boss);
|
| | | threeSale.setWorker(invitee);
|
| | |
|
| | | // 添加到队列
|
| | | ThreeSaleCMQManager.getInstance().addThreeSaleMsg(threeSale);
|
| | |
|
| | | // 邀请消息
|
| | | userInviteMsgNotificationService.inviteSuccess(threeSale.getBoss().getId(), threeSale);
|
| | |
|
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(inviterId);
|
| | | if (activeLog != null && !StringUtil.isNullOrEmpty(activeLog.getVersionCode())) {
|
| | | boolean result = false;
|
| | | String versionCode = activeLog.getVersionCode();
|
| | | String channel = activeLog.getChannel();
|
| | |
|
| | | // 渠道是appstore 判断为IOS
|
| | | if (!StringUtil.isNullOrEmpty(channel) && "appstore".equalsIgnoreCase(channel)) {
|
| | | result = VersionUtil.greaterThan_1_5_60("ios", versionCode);
|
| | | } else {
|
| | | result = VersionUtil.greaterThan_1_5_60("android", versionCode);
|
| | | }
|
| | |
|
| | | if (result) {
|
| | | // 被邀请名称
|
| | | String inviteName = invitee.getNickName();
|
| | | if (StringUtil.isNullOrEmpty(inviteName)) {
|
| | | UserInfo userInfo = userInfoService.selectByPKey(invitee.getId());
|
| | | if (userInfo != null) {
|
| | | inviteName = userInfo.getNickName();
|
| | | }
|
| | | }
|
| | | // 奖励邀请红包(淘礼金)
|
| | | userTaoLiJinOriginService.addInviteWinMoney(inviterId, inviteName);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据邀请者查询关系
|
| | | * |
| | | * @param workerId
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public ThreeSale getByWorkerId(Long workerId) {
|
| | | return threeSaleMapper.getByWorkerId(workerId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countSuccessFirstTeam(Long uid) {
|
| | | return threeSaleMapper.countFirstTeam(uid, 1);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ThreeSale selectByWorkerId(Long workerId) {
|
| | | return threeSaleMapper.selectSuccessByWorkerId(workerId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ThreeSale> getSuccessByDate(Long bossId, Long minTime, Long maxTime) {
|
| | | return threeSaleMapper.getSuccessByDate(bossId, minTime, maxTime);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ThreeSale> listFirstTeam(long start, int count, Long uid, Integer state) {
|
| | | return threeSaleMapper.listFirstTeam(start, count, uid, state);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<ThreeSale> listSecondTeam(long start, int count, Long uid, Integer state) {
|
| | | return threeSaleMapper.listSecondTeam(start, count, uid, state);
|
| | | }
|
| | |
|
| | | }
|