|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.message.sdk.utils.DateUtils;
|
|
|
import com.yoho.service.model.social.response.UserInfoRspBO;
|
|
|
import com.yohobuy.ufo.model.order.resp.InviteInfoResp;
|
|
|
import com.yohoufo.common.ApiResponse;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.*;
|
...
|
...
|
@@ -13,15 +18,20 @@ import com.yohoufo.order.common.InviterStatus; |
|
|
import com.yohoufo.order.common.InviterType;
|
|
|
import com.yohoufo.order.service.IInviteService;
|
|
|
import com.yohoufo.order.service.IStoredSellerService;
|
|
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -47,6 +57,12 @@ public class InviteServiceImpl implements IInviteService { |
|
|
@Autowired
|
|
|
InviteSettlementItemMapper inviteSettlementItemMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ServiceCaller serviceCaller;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
UserProxyService userProxyService;
|
|
|
/**
|
|
|
* 是否需要跳转到入驻页面
|
|
|
* @param uid
|
...
|
...
|
@@ -101,6 +117,7 @@ public class InviteServiceImpl implements IInviteService { |
|
|
|
|
|
// 校验邀请码的合法性
|
|
|
if (StringUtils.isEmpty(showInviteCode)){
|
|
|
LOGGER.info("enter shop uid[{}] has no inviteCode", uid);
|
|
|
return;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -131,10 +148,16 @@ public class InviteServiceImpl implements IInviteService { |
|
|
throw new ServiceException(ServiceError.INVITE_CODE_NOT_EXIST);
|
|
|
}
|
|
|
|
|
|
// 不能自己邀请自己
|
|
|
if (inviter.getUid() == uid){
|
|
|
LOGGER.info("can not invite self, uid is {}, showInviteCode is {}", uid, showInviteCode);
|
|
|
throw new ServiceException(ServiceError.INVITE_CODE_NOT_EXIST);
|
|
|
}
|
|
|
|
|
|
// 校验是否已经有绑定关系
|
|
|
InviteRecord inviteRecord = inviteRecordMapper.selectByInviterAndInviteeUid(inviter.getUid(), uid);
|
|
|
InviteRecord inviteRecord = inviteRecordMapper.selectByInviteeUid(uid);
|
|
|
if (inviteRecord != null){
|
|
|
LOGGER.warn("has invite bind. showInviteCode is {}, uid is {}", showInviteCode, uid);
|
|
|
LOGGER.warn("has invite bind. showInviteCode is {}, invitee is {}, inviter is {}", showInviteCode, uid, inviteRecord.getInviterUid());
|
|
|
throw new ServiceException(ServiceError.INVITE_HAS_BIND);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -150,6 +173,9 @@ public class InviteServiceImpl implements IInviteService { |
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取邀请码信息
|
|
|
* @param uid
|
...
|
...
|
@@ -166,7 +192,8 @@ public class InviteServiceImpl implements IInviteService { |
|
|
String showInviteCode = getShowInviteCode(uid);
|
|
|
|
|
|
if (StringUtils.isEmpty(showInviteCode)){
|
|
|
return null;
|
|
|
LOGGER.warn("has no showInviteCode. uid is {}", uid);
|
|
|
throw new ServiceException(ServiceError.HAS_NO_ENTER);
|
|
|
}
|
|
|
|
|
|
// 有邀请码的场合,获取邀请的好友
|
...
|
...
|
@@ -176,22 +203,22 @@ public class InviteServiceImpl implements IInviteService { |
|
|
List<Integer> inviteeUidList = inviteRecords.stream().map(InviteRecord::getInviteeUid).collect(Collectors.toList());
|
|
|
|
|
|
// 批量查询昵称
|
|
|
Map<Integer, String> nickNameMap = userProxyService.getNickNameByUids(inviteeUidList);
|
|
|
|
|
|
// 批量查询入驻时间
|
|
|
List<StoredSeller> storedSellerList = storedSellerService.batchGetStoredSeller(inviteeUidList);
|
|
|
Map<Integer, Long> storedSellerMap = storedSellerList.stream().collect(Collectors.toMap(StoredSeller::getUid, StoredSeller::getEnterTime));
|
|
|
|
|
|
// 批量查询订单数目
|
|
|
List<InviteSettlementItem> orderNumList = inviteSettlementItemMapper.selectByInviterUid(uid);
|
|
|
List<InviteSettlementItem> orderNumList = inviteSettlementItemMapper.selectOrderNumByInviterUid(uid);
|
|
|
Map<Integer, Integer> orderNumMap = orderNumList.stream().collect(Collectors.toMap(InviteSettlementItem::getSellerUid, InviteSettlementItem::getOrderNum));
|
|
|
|
|
|
|
|
|
return InviteInfoResp.builder()
|
|
|
.uid(uid)
|
|
|
.showInviteCode(showInviteCode)
|
|
|
.inviteeUidNum(inviteeUidList.size())
|
|
|
.finishedOrderNum(orderNumMap.keySet().stream().collect(Collectors.summingInt(Integer::intValue)))
|
|
|
.inviteRecordList(getInviteRecordList(inviteRecords, storedSellerMap, orderNumMap))
|
|
|
.inviteRecordList(getInviteRecordList(inviteRecords, storedSellerMap, orderNumMap, nickNameMap))
|
|
|
.build();
|
|
|
|
|
|
}
|
...
|
...
|
@@ -200,13 +227,16 @@ public class InviteServiceImpl implements IInviteService { |
|
|
|
|
|
}
|
|
|
|
|
|
private List<InviteInfoResp.InviteRecord> getInviteRecordList(List<InviteRecord> inviteRecords, Map<Integer, Long> storedSellerMap, Map<Integer, Integer> orderNumMap) {
|
|
|
private List<InviteInfoResp.InviteRecord> getInviteRecordList(List<InviteRecord> inviteRecords,
|
|
|
Map<Integer, Long> storedSellerMap,
|
|
|
Map<Integer, Integer> orderNumMap,
|
|
|
Map<Integer, String> nickNameMap) {
|
|
|
return inviteRecords.stream().map(x ->{
|
|
|
return InviteInfoResp.InviteRecord.builder()
|
|
|
.inviteeUid(x.getInviteeUid())
|
|
|
.nikeName(null)
|
|
|
.nikeName(Objects.isNull(nickNameMap.get(x.getInviteeUid())) ? "" : nickNameMap.get(x.getInviteeUid()))
|
|
|
.enterTime(storedSellerMap.get(x.getInviteeUid()) == null ? "" : DateUtil.getDateFormatLong(storedSellerMap.get(x.getInviteeUid())))
|
|
|
.orderNum(orderNumMap.get(x.getInviteeUid()))
|
|
|
.orderNum(Objects.isNull(orderNumMap.get(x.getInviteeUid())) ? 0 : orderNumMap.get(x.getInviteeUid()))
|
|
|
.build();
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
...
|
...
|
@@ -231,7 +261,7 @@ public class InviteServiceImpl implements IInviteService { |
|
|
*/
|
|
|
Integer bClassInviteCode = null;
|
|
|
if (!CollectionUtils.isEmpty(inviters)){
|
|
|
bClassInviteCode = getInviteCode(inviters, InviterType.STORED_SELLER);
|
|
|
bClassInviteCode = getInviteCode(inviters, InviterType.CLASS_B_AGENT);
|
|
|
}
|
|
|
|
|
|
boolean storedSeller = storedSellerService.isStoredSeller(uid);
|
...
|
...
|
@@ -270,9 +300,10 @@ public class InviteServiceImpl implements IInviteService { |
|
|
|
|
|
|
|
|
private Integer getInviteCode(List<Inviter> inviters, InviterType inviterType){
|
|
|
return inviters.stream()
|
|
|
Optional<Inviter> inviter = inviters.stream()
|
|
|
.filter(x -> x.getType().intValue() == inviterType.getType() && x.getStatus().intValue() == InviterStatus.VALID.getCode())
|
|
|
.findAny().get().getInviteCode();
|
|
|
.findAny();
|
|
|
return inviter.isPresent() ? inviter.get().getInviteCode() : null;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -375,7 +406,7 @@ public class InviteServiceImpl implements IInviteService { |
|
|
}
|
|
|
|
|
|
// 首次入驻才可以输入邀请码,如果之前有绑定关系了,则本次无效
|
|
|
InviteRecord inviteRecord = inviteRecordMapper.selectByInviterAndInviteeUid(inviter.getUid(), uid);
|
|
|
InviteRecord inviteRecord = inviteRecordMapper.selectByInviteeUid(uid);
|
|
|
if (inviteRecord!=null){
|
|
|
LOGGER.warn("[{}] [{}] [{}]. has bind. inviter uid is {}", showInviteCode, uid, orderCode, inviter.getUid());
|
|
|
return 0;
|
...
|
...
|
|