Commit af7d161c authored by unset's avatar unset

Merge remote-tracking branch 'origin/dev' into dev

parents 4c37c88d 0d96146f
......@@ -61,12 +61,6 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
@Autowired
private AppUserAlipayBiz appUserAlipayBiz;
@Autowired
private AppUserRelationBiz appUserRelationBiz;
@Autowired
private AppUserSellingWaterBiz appUserSellingWaterBiz;
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
@Override
......@@ -413,22 +407,6 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
public List<Integer> findAppuser(String phone, String leaderPhone, String name) {
List<Integer> memberIds = null;
//1.根据leader手机号查询userid
boolean isNoNullLeaderPhone = StringUtils.isNotEmpty(leaderPhone) && leaderPhone.trim().length() > 0;
if (isNoNullLeaderPhone) {
List<AppUserLogin> appUserLogins = mapper.selectbyPhones(Arrays.asList(leaderPhone));
Integer leaderId = null;
if (CollectionUtils.isEmpty(appUserLogins)) {
return Collections.EMPTY_LIST;
}
leaderId = appUserLogins.get(0).getId();
//2.根据leader userId查询下级 userid
if (Objects.nonNull(leaderId)) {
memberIds = appUserSellingWaterBiz.findMemberIdByLeaderIdAndOrdreType(leaderId, 3);
if (CollectionUtils.isEmpty(memberIds)) {
return Collections.EMPTY_LIST;
}
}
}
List<Integer> userIds = mapper.findAppUser(phone, name, memberIds);
return userIds == null ? Collections.EMPTY_LIST : userIds;
}
......@@ -437,14 +415,10 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
Map<String, Integer> userIdAndFacilitateIdMap = userBos.stream().filter(x -> Objects.nonNull(x.getFacilitateId())).collect(Collectors.toMap(UserBo::getOrderNo, UserBo::getFacilitateId));
List<Integer> userIdList = userBos.stream().map(UserBo::getUserId).distinct().collect(Collectors.toList());
//查询上级人
List<AppUserRelation> appUserRelationList = appUserRelationBiz.findLeaderByUserIds(userIdList);
Map<Integer, Integer> memberIdAndParentMap = appUserRelationList.stream().collect(Collectors.toMap(AppUserRelation::getUserId, AppUserRelation::getParentId));
List<Integer> uids = new ArrayList<>();
uids.addAll(userIdAndFacilitateIdMap == null ? Collections.EMPTY_LIST : userIdList);
uids.addAll(userIdAndFacilitateIdMap == null ? Collections.EMPTY_LIST : userIdAndFacilitateIdMap.values());
uids.addAll(memberIdAndParentMap == null ? Collections.EMPTY_LIST : memberIdAndParentMap.values());
List<UserBo> userBoList = mapper.selectByUserIds(uids);
Map<Integer, UserBo> userMap = userBoList == null ? Collections.EMPTY_MAP : userBoList.stream().collect(Collectors.toMap(UserBo::getUserId, Function.identity()));
......@@ -458,12 +432,6 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
userBo.setPhone(bo.getPhone());
userBo.setName(bo.getName());
}
Integer leaderId = memberIdAndParentMap.get(userBo.getUserId());
UserBo leader = userMap.get(leaderId);
if (Objects.nonNull(leader)) {
userBo.setLeaderName(leader.getName());
userBo.setLeaderPhone(leader.getPhone());
}
UserBo facilitate = userMap.get(userBo.getFacilitateId());
if (Objects.nonNull(facilitate)) {
userBo.setFacilitateName(facilitate.getName());
......
package com.github.wxiaoqi.security.admin.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.wxiaoqi.security.admin.dto.UserRelationDTO;
import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.admin.bo.InviteMemberBO;
import com.github.wxiaoqi.security.admin.vo.InviteMemberVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.github.wxiaoqi.security.admin.mapper.AppUserRelationMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.*;
import java.util.stream.Collectors;
/**
* 用户关系表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
@Service
@Slf4j
public class AppUserRelationBiz extends BaseBiz<AppUserRelationMapper, AppUserRelation> {
@Autowired
AppUserRelationTempBiz relationTempBiz;
@Autowired
AppUserDetailBiz userDetailBiz;
@Autowired
private AppUserLoginBiz appUserLoginBiz;
@Value("${temamember.failureTime:60}")
private Long failureTime;
@Autowired
private AppUserDetailBiz appUserDetailBiz;
@Value("${admin.validTime}")
private Long validTime;
private static final HashMap<Integer, Boolean> map = new HashMap<>();
private static final HashMap<Integer, Boolean> parentMap = new HashMap<>();
private static final Object obj = new Object();
private static final Object parentObj = new Object();
private boolean lock(Integer userId) {
synchronized (obj) {
if (map.get(userId) == null) {
map.put(userId, true);
return true;
}
}
return false;
}
private boolean parentLock(Integer userId) {
log.info("---进锁前---parentId===="+userId);
synchronized (parentObj) {
log.info("---进锁---parentId===="+userId);
if (parentMap.get(userId) == null) {
log.info("---进锁处理---parentId===="+userId);
parentMap.put(userId, true);
return true;
}
}
return false;
}
private void unParentLock(Integer userId) {
log.info("---解锁处理---parentId===="+userId);
synchronized (parentObj) {
parentMap.remove(userId);
}
}
private void unLock(Integer userId) {
synchronized (obj) {
map.remove(userId);
}
}
/**
* 关系绑定
* 规则A->B (B无有效上线+无有效下线)
*
* @param userId
* @param parentId
*/
public void bindRelation(Integer userId,Integer parentId,Integer type){
try {
if (userId.equals(parentId)){
log.info("----userId==="+userId+"----parentId===="+parentId+"----自己不能成为自己的上线");
return;
}
/* AppUserVo appUserVo=userDetailBiz.getUserInfoById(userId);
if (appUserVo==null){
log.info("----userId==="+userId+"----parentId===="+parentId+"----该用户不存在");
return;
}*/
AppUserVo appUserVo=userDetailBiz.getUserInfoById(parentId);
if (appUserVo==null){
log.info("----userId==="+userId+"----parentId===="+parentId+"----该上线用户不存在");
return;
}
if (lock(userId)) {
AppUserRelation relation = getMyBiz().getRelationByUserId(parentId);
Long time = System.currentTimeMillis();
if (relation == null) {
insertLock(parentId, type);
}
Long bindTime = time - validTime;
//判断用户是否有有效的下线
if (getCountByParentId(userId, bindTime) == 0L) {
relation = getMyBiz().getRelationByUserId(userId);
if (relation == null) {
relation = new AppUserRelation();
relation.setUserId(userId);
relation.setParentId(parentId);
relation.setBindType(type);
relation.setBindTime(time);
insertSelective(relation);
AppStaffUserDTO staffUserDTO = new AppStaffUserDTO();
staffUserDTO.setSuId(relation.getParentId());
staffUserDTO.setUid(relation.getUserId());
} else {
//判断用户是否有有效的上线
log.info("----userId===" + userId + "----bindTime====" + bindTime + "----relation.getBindTime()===" + relation.getBindTime());
if (relation.getParentId() == null || relation.getParentId() == 0 || (relation.getIsForever() != 1 && validTime > 0 && relation.getBindTime() < bindTime)) {
relation.setParentId(parentId);
relation.setBindType(type);
relation.setBindTime(time);
getMyBiz().updRelation(relation);
}
}
}
}
}catch (Exception e){
log.info("网络异常===" + e.getMessage());
}finally {
unLock(userId);
}
}
private void insertLock(Integer userId, Integer type) {
try {
if (parentLock(userId)) {
AppUserRelation relation = getMyBiz().getRelationByUserId(userId);
if (relation == null) {
log.info("insertLock----parentId===" +userId);
relation = new AppUserRelation();
relation.setUserId(userId);
relation.setBindType(type);
insertSelective(relation);
}
}
}catch (Exception e){
}finally {
unParentLock(userId);
}
}
//首页关系绑定
public ObjectRestResponse appBindRelation(Integer userId, String code) {
Integer parentId = 0;
if (StringUtils.isNotBlank(code)) {
//判断处理活动关键字
String[] codes = code.split("_");
if (codes.length > 1) {
code = codes[0];
}
parentId = appUserDetailBiz.getUserByCode(code);
}
if (parentId != null && parentId > 0 && userId != null && userId > 0) {
getMyBiz().bindRelation(userId, parentId, 1);
}
return ObjectRestResponse.succ();
}
//后台关系绑定
public ObjectRestResponse adminBindRelation(UserRelationDTO relationDTO) {
String phone = relationDTO.getPhone();
Integer userId = relationDTO.getUserId();
if (StringUtils.isBlank(phone) || userId == null || userId == 0) {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数不能为空");
}
AppUserLogin userLogin = appUserLoginBiz.checkeUserLogin(phone);
if (userLogin == null) {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "该上级不存在");
}
Integer parentId = userLogin.getId();
getMyBiz().bindRelation(userId, parentId, 1);
return ObjectRestResponse.succ();
}
//永久稳定关系
public void foreverBind(Integer user_id) {
AppUserRelation relation = getMyBiz().getRelationByUserId(user_id);
if (relation != null && relation.getIsForever() == 0 && relation.getParentId() != null && relation.getParentId() > 0) {
relation.setIsForever(1);
getMyBiz().updRelation(relation);
}
}
/**
* 小程序分享上下线绑定
*
* @param userid 当前人小程序id
* @param pid 分享人id
* @param platform_userid 当前人统一平台id
*/
public ObjectRestResponse shareParentByUserId(Integer userid, Integer pid, Integer platform_userid) {
if (pid == null || pid == 0 || ((platform_userid == null || platform_userid == 0) && (userid == 0 || userid == null))) {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
if (platform_userid == null || platform_userid == 0) {
upRelationTemp(pid, userid);
} else {
AppUserVo userVo = userDetailBiz.getUserInfoById(platform_userid);
if (userVo == null) {
upRelationTemp(pid, userid);
} else {
bindRelation(platform_userid, pid, 2);
}
}
return ObjectRestResponse.succ();
}
/**
* 新增临时关系
*
* @param pid
* @param userid
*/
public void upRelationTemp(Integer pid, Integer userid) {
AppUserRelationTemp relationTemp = new AppUserRelationTemp();
relationTemp.setTempId(userid);
relationTemp.setIsDel(0);
relationTemp.setType(1);
AppUserRelationTemp relationTemp1 = relationTempBiz.selectOne(relationTemp);
if (relationTemp1 == null) {
relationTemp.setUserId(pid);
relationTempBiz.insertSelective(relationTemp);
}
}
/**
* 小程序上下线绑定
*
* @param platform_userid 当前人统一平台id
* @param userid 当前人小程序id
*/
public void bindByUserId(Integer platform_userid, Integer userid) {
if (platform_userid == null || platform_userid == 0 || userid == null || userid == 0) {
return;
}
AppUserRelationTemp relationTemp = new AppUserRelationTemp();
relationTemp.setTempId(userid);
relationTemp.setIsValid(0);
relationTemp.setType(1);
relationTemp.setIsDel(0);
relationTemp=relationTempBiz.selectOne(relationTemp);
if(relationTemp==null){
return;
}
Integer parentId = relationTemp.getUserId();
bindRelation(platform_userid, parentId, 2);
}
/**
* 获取用户的上线关系
*
* @param userId
* @return
*/
@Cache(key = "user:relation{1}")
public AppUserRelation getRelationByUserId(Integer userId) {
/* AppUserRelation relation = new AppUserRelation();
relation.setUserId(userId);*/
Example example=new Example(AppUserRelation.class);
example.createCriteria().andEqualTo("userId",userId);
List<AppUserRelation> list=selectByExample(example);
if (list.size()>0){
return list.get(0);
}
return null;
}
//获取有效的上线
public AppUserRelation getRelationByIdUserIdAndTime(Integer userId) {
AppUserRelation userRelation = getMyBiz().getRelationByUserId(userId);
if (userRelation == null) {
return null;
}
log.info("---userId===" + userId + "-----isForever===" + userRelation.getIsForever());
if (validTime == null || validTime == 0) {
return userRelation;
}
Long time = System.currentTimeMillis() - validTime;
if (userRelation.getIsForever() == 1 || userRelation.getBindTime() > time) {
return userRelation;
}
log.info("---userId===" + userId + "-----time===" + time + "----userRelation.getBindTime()===" + userRelation.getBindTime());
return null;
}
//获取用户的下线总数
public int getCountByParentId(Integer parentId, Long time) {
if (validTime <= 0) {
time = validTime;
}
return mapper.countByParentId(parentId, time);
}
@CacheClear(key = "user:relation{1.userId}")
public int updRelation(AppUserRelation appUserRelation) {
return super.updateSelectiveByIdRe(appUserRelation);
}
private AppUserRelationBiz getMyBiz() {
return AopContext.currentProxy() != null ? (AppUserRelationBiz) AopContext.currentProxy() : this;
}
public List<AppUserRelation> findMemberPageByLeaderId(Integer leaderId) {
return mapper.selectByLeaderId(leaderId);
}
public InviteMemberVo findInviteMemberByActivitState(Integer leaderId, Integer state, Integer page, Integer limit) {
InviteMemberVo inviteMemberVo = new InviteMemberVo();
inviteMemberVo.setPage(page);
inviteMemberVo.setLimit(limit);
inviteMemberVo.setFailureTime(failureTime * 24 * 60 * 60);
Example example = new Example(AppUserRelation.class);
Example.Criteria criteria = example.createCriteria();
if (state != null) {
criteria.andEqualTo("isForever", state);
}
criteria.andEqualTo("parentId", leaderId);
PageDataVO<AppUserRelation> pageDataVO = PageDataVO.pageInfo(page, limit, () -> mapper.selectByExample(example));
List<AppUserRelation> appUserRelations = pageDataVO.getData();
if (CollectionUtils.isEmpty(appUserRelations)) {
inviteMemberVo.setInviteMembers(Collections.EMPTY_LIST);
return inviteMemberVo;
}
List<Integer> memberIds = appUserRelations.stream().map(AppUserRelation::getUserId).collect(Collectors.toList());
Map<Integer, AppUserLogin> userIdAndUserLoginMap = appUserLoginBiz.findUserIdAndUserLoginMapByMemberIds(memberIds);
Map<Integer, AppUserDetail> userIdAndUserDetailMap = userDetailBiz.findUserIdAndUserDetailMapByMemberIds(memberIds);
List<InviteMemberBO> inviteMemberBOS = new ArrayList<>();
InviteMemberBO inviteMemberBO;
for (AppUserRelation appUserRelation : appUserRelations) {
if (userIdAndUserLoginMap == null || userIdAndUserDetailMap == null) {
continue;
}
inviteMemberBO = new InviteMemberBO();
inviteMemberBO.setUserId(appUserRelation.getUserId());
inviteMemberBO.setParentId(appUserRelation.getParentId());
inviteMemberBO.setBindTime(appUserRelation.getBindTime());
inviteMemberBO.setJoinTime(appUserRelation.getBindTime());
inviteMemberBO.setUsername(userIdAndUserLoginMap == null ? "" : userIdAndUserLoginMap.get(appUserRelation.getUserId()) == null ? "" : userIdAndUserLoginMap.get(appUserRelation.getUserId()).getUsername());
inviteMemberBO.setHeadUrl(userIdAndUserDetailMap == null ? "" : userIdAndUserDetailMap.get(appUserRelation.getUserId()) == null ? "" : userIdAndUserDetailMap.get(appUserRelation.getUserId()).getHeadimgurl());
inviteMemberBOS.add(inviteMemberBO);
}
inviteMemberVo.setTotalCount(pageDataVO.getTotalCount().intValue());
inviteMemberVo.setTotalPage(pageDataVO.getTotalPage());
inviteMemberVo.setInviteMembers(inviteMemberBOS);
return inviteMemberVo;
}
public Integer findLeaderIdByMemberId(Integer userId) {
Example example = new Example(AppUserRelation.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("userId", userId);
List<AppUserRelation> appUserRelations = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(appUserRelations)) {
return 0;
}
return appUserRelations.get(0).getParentId();
}
public Map<Integer, Integer> findMemberSateAndCountMapByLeaderId(Integer userId) {
Map<Integer, Integer> memberSateAndCountMap = new HashMap<>();
List<AppUserRelation> appUserRelationList = mapper.selectCountByLeaderId(userId);
if (CollectionUtils.isEmpty(appUserRelationList)){
memberSateAndCountMap.put(0, 0);
memberSateAndCountMap.put(1, 0);
}
Map<Boolean, Long> resultMap = appUserRelationList.stream().collect(Collectors.partitioningBy(x -> x.getIsForever() == 0, Collectors.counting()));
memberSateAndCountMap.put(0, resultMap.get(Boolean.TRUE)==null?0:resultMap.get(Boolean.TRUE).intValue());
memberSateAndCountMap.put(1, resultMap.get(Boolean.FALSE)==null?0:resultMap.get(Boolean.FALSE).intValue());
return memberSateAndCountMap;
}
public void deleteByMemberIds(Collection<Integer> userIds) {
Example example = new Example(AppUserRelation.class);
Example.Criteria criteria = example.createCriteria();
criteria.andIn("parentId", userIds);
List<AppUserRelation> list = mapper.selectByExample(example);
for (AppUserRelation appUserRelation : list) {
getMyBiz().delRelation(appUserRelation.getUserId());
}
mapper.deleteByExample(example);
Example example2 = new Example(AppUserRelation.class);
Example.Criteria criteria1 = example2.createCriteria();
criteria1.andIn("userId", userIds);
mapper.deleteByExample(example2);
for (Integer userId : userIds) {
getMyBiz().delRelation(userId);
}
}
@CacheClear(key = "user:relation{1}")
public void delRelation(Integer userId) {
}
public List<AppUserRelation> findLeaderByUserIds(List<Integer> userIds) {
List<AppUserRelation> appUserRelationList = mapper.selectByUserIds(userIds);
return appUserRelationList == null ? Collections.EMPTY_LIST : appUserRelationList;
}
public void initParentId(AppUserDTO userDTO, Integer userid) {
AppUserRelation relation = getRelationByIdUserIdAndTime(userid);
Integer parentId = 0;
if (relation != null) {
parentId = relation.getParentId();
}
userDTO.setParentId(parentId);
}
}
package com.github.wxiaoqi.security.admin.biz;
import com.github.wxiaoqi.security.admin.bo.UserIncomeBo;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.*;
import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import com.github.wxiaoqi.security.admin.vo.SellingWalletVo;
import com.github.wxiaoqi.security.admin.vo.SellingWalletPagVo;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.wxiaoqi.security.admin.mapper.AppUserSellingWaterMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 拥金明细表
*
* @author zjw
* @email 18178966185@163.com
* @date 2019-07-11 14:14:54
*/
@Service
@Slf4j
public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, AppUserSellingWater> {
@Autowired
AppUserRelationBiz relationBiz;
@Autowired
BaseGoodCommissionBiz commissionBiz;
@Autowired
AppUserPositionBiz positionBiz;
@Autowired
AppUserDetailBiz detailBiz;
@Autowired
private AppUserLoginBiz appUserLoginBiz;
@Autowired
private AppUserDetailBiz appUserDetailBiz;
@Autowired
MyWaterBiz myWaterBiz;
//计算用户拥金
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public void orderWater(OrderWaterDTO orderWaterDTO) {
if (orderWaterDTO == null) {
log.info("计算用户拥金----orderWater----次数不能为空----");
return;
}
//订单状态
Integer status = orderWaterDTO.getStatus();
if (status == null || status == 0) {
log.info("购买计算用户拥金----payOrderWater----参数不能为空----status===" + status);
return;
}
if (status == 1) {
payOrderWater(orderWaterDTO);
} else if (status == 2) {
finishOrderWater(orderWaterDTO);
} else {
refundOrderWater(orderWaterDTO);
}
}
//购买计算用户拥金
public void payOrderWater(OrderWaterDTO orderWaterDTO) {
//订单id
Integer orderId = orderWaterDTO.getOrderId();
//订单号
String orderNo = orderWaterDTO.getOrderNo();
//用户id
Integer userId = orderWaterDTO.getUserId();
List<OrderGoodsDTO> goodsDTOList = orderWaterDTO.getGoodsDTOList();
log.info("购买计算用户拥金----payOrderWater----userId====" + userId + "---orderId===" + orderId + "---orderNo===" + orderNo);
if (orderId == null || orderId == 0 || userId == null || userId == 0 | CollectionUtils.isEmpty(goodsDTOList)) {
log.info("购买计算用户拥金----payOrderWater----参数不能为空----orderId===" + orderId);
return;
}
AppUserRelation relation = relationBiz.getRelationByIdUserIdAndTime(userId);
if (relation == null || relation.getParentId() == null || relation.getParentId() == 0) {
log.info("购买计算用户拥金----payOrderWater--------userId===" + userId + "---无有效上线");
return;
}
Integer parentId = relation.getParentId();
log.info("购买计算用户拥金----payOrderWater--------userId===" + userId + "---parentId===" + parentId);
Integer positionId = 6;
Integer level = 0;
AppUserPosition position = positionBiz.getExtract(parentId);
if (position != null) {
positionId = position.getId();
}
AppUserPosition position1 = positionBiz.getExtract(userId);
if (position != null) {
level = position1.getLevel();
}
log.info("购买计算用户拥金----payOrderWater--------userId===" + userId + "---positionId===" + positionId + "---level===" + level);
if (level != 0) {
log.info("购买计算用户拥金----payOrderWater--------userId===" + userId + "----无法享受拥金");
return;
}
BigDecimal amount = new BigDecimal("0.00");
//商品类型
Integer orderType = 0;
for (OrderGoodsDTO goodsDto : goodsDTOList) {
//商品id
Integer goodId = goodsDto.getGoodId();
//商品价格
BigDecimal price = goodsDto.getPrice();
orderType = goodsDto.getType();
//商品比例
Integer extract = commissionBiz.getExtract(orderType, goodId);
if (extract == null || extract == 0) {
extract = position.getExtract();
}
log.info("购买计算用户拥金----payOrderWater--------userId===" + userId + "---extract===" + extract);
if (extract != null && extract > 0) {
AppUserSellingWater sellingWater = new AppUserSellingWater();
sellingWater.setOrderId(orderId);
sellingWater.setGoodId(goodId);
sellingWater = selectOne(sellingWater);
if (sellingWater != null) {
continue;
}
BigDecimal commission = price.multiply(new BigDecimal(extract + "")).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
log.info("购买计算用户拥金----payOrderWater--------userId===" + userId + "---commission===" + commission);
sellingWater = new AppUserSellingWater();
sellingWater.setUserId(parentId);
sellingWater.setSourceId(userId);
sellingWater.setPositionId(positionId);
sellingWater.setOrderId(orderId);
sellingWater.setOrderNo(orderNo);
sellingWater.setOrderType(orderType);
sellingWater.setGoodId(goodId);
sellingWater.setTitle(goodsDto.getTitle());
sellingWater.setImg(goodsDto.getImg());
sellingWater.setPrice(price);
sellingWater.setExtract(extract);
sellingWater.setGoodNumber(goodsDto.getGoodNumber());
sellingWater.setCommission(commission);
insertSelective(sellingWater);
log.info("购买计算用户拥成功----payOrderWater--------userId===" + userId);
amount = amount.add(commission);
}
}
log.info("购买计算用户未入账----payOrderWater--------userId===" + parentId + "----amount====" + amount + "--orderType===" + orderType);
if (orderType == 3) {
finishOrderWater(orderWaterDTO);
} else if (orderType == 1 || orderType == 2) {
myWaterBiz.updMyWalletUnbooked(parentId, amount, 1);
}
}
//订单完成计算用户拥金
public void finishOrderWater(OrderWaterDTO orderWaterDTO) {
//订单id
Integer orderId = orderWaterDTO.getOrderId();
log.info("订单完成计算用户拥金----finishOrderWater----orderId====" + orderId);
if (orderId == null || orderId == 0) {
return;
}
List<AppUserSellingWater> list = getWaterList(orderId);
BigDecimal amount = new BigDecimal("0.00");
Integer userId = 0;
Integer orderType = 0;
String orderNo = "";
if (list.size() > 0) {
orderNo = list.get(0).getOrderNo();
for (AppUserSellingWater sellingWater : list) {
Integer id = sellingWater.getId();
orderType = sellingWater.getOrderType();
userId = sellingWater.getUserId();
sellingWater.setWaiting(1);
updateById(sellingWater);
BigDecimal commission = sellingWater.getCommission();
log.info("订单完成计算用户拥金----finishOrderWater----id====" + id + "---commission==" + commission + "----orderType===" + orderType);
amount = amount.add(commission);
}
BigDecimal unbooked = amount;
log.info("订单完成计算用户拥金----finishOrderWater----orderId====" + orderId + "---amount==" + amount + "---unbooked==" + unbooked);
if (orderType == 1) {
List<OrderGoodsDTO> goodsDTOList = orderWaterDTO.getGoodsDTOList();
log.info("租车订单完成-----goodsDTOList===" + goodsDTOList);
if (CollectionUtils.isNotEmpty(goodsDTOList)) {
for (OrderGoodsDTO goodsDto : goodsDTOList) {
//商品id
Integer goodId = goodsDto.getGoodId();
//商品价格
BigDecimal price = goodsDto.getPrice();
AppUserSellingWater sellingWater = new AppUserSellingWater();
sellingWater.setOrderId(orderId);
sellingWater.setGoodId(goodId);
sellingWater = selectOne(sellingWater);
if (sellingWater == null || sellingWater.getExtract() == null || sellingWater.getExtract() == 0) {
log.info("租车订单完成-----sellingWater---不存在或extract---为空");
continue;
}
if (price.compareTo(sellingWater.getPrice()) >= 0) {
log.info("租车订单完成-----完成价格大于支付价格");
continue;
}
price = sellingWater.getPrice().subtract(price);
Integer extract = sellingWater.getExtract();
log.info("租车订单完成-----price=====" + price + "---extract====" + extract);
BigDecimal commission = price.multiply(new BigDecimal(extract + "")).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
log.info("租车订单完成--------userId===" + userId + "---commission===" + commission);
sellingWater.setWaiting(1);
sellingWater.setStatus(1);
sellingWater.setCommission(commission);
sellingWater.setId(null);
insertSelective(sellingWater);
log.info("租车订单完成计算用户拥成功----payOrderWater--------userId===" + userId);
amount = amount.subtract(commission);
}
}
}
log.info("订单完成计算用户拥金----finishOrderWater--------orderId===" + orderId + "----amount====" + amount + "--orderType===" + orderType);
int r = amount.compareTo(BigDecimal.ZERO);
//更新钱包
if (r == 1 && userId > 0) {
MyWalletDetail detail = new MyWalletDetail();
detail.setUserId(userId);
detail.setAmount(amount);
detail.setCono(orderId);
detail.setWithDrawOrderNo(orderNo);
detail.setSource(1);
myWaterBiz.updMyWater(detail);
}
if ((orderType == 1 || orderType == 2) && unbooked.compareTo(BigDecimal.ZERO) == 1) {
myWaterBiz.updMyWalletUnbooked(userId, unbooked, 2);
}
}
}
//订单退款计算用户拥金
public void refundOrderWater(OrderWaterDTO orderWaterDTO) {
//订单id
Integer orderId = orderWaterDTO.getOrderId();
log.info("订单完成计算用户拥金----refundOrderWater----orderId====" + orderId);
if (orderId == null || orderId == 0) {
return;
}
List<AppUserSellingWater> list = getWaterList(orderId);
BigDecimal amount = new BigDecimal("0.00");
BigDecimal unbooked = new BigDecimal("0.00");
Integer userId = 0;
Integer orderType = 0;
String orderNo = "";
if (list.size() > 0) {
orderNo = list.get(0).getOrderNo();
for (AppUserSellingWater sellingWater : list) {
Integer id = sellingWater.getId();
orderType = sellingWater.getOrderType();
userId = sellingWater.getUserId();
sellingWater.setWaiting(1);
updateById(sellingWater);
sellingWater.setId(null);
sellingWater.setStatus(1);
insertSelective(sellingWater);
BigDecimal commission = sellingWater.getCommission();
log.info("订单完成计算用户拥金----refundOrderWater----id====" + id + "---commission==" + commission + "---orderType====" + orderType);
unbooked = unbooked.add(commission);
}
log.info("订单完成计算用户拥金----refundOrderWater----orderId====" + orderId + "---amount==" + amount + "---unbooked===" + unbooked);
int r = amount.compareTo(BigDecimal.ZERO);
//更新钱包
if (r == 1 && userId > 0) {
MyWalletDetail detail = new MyWalletDetail();
detail.setUserId(userId);
detail.setAmount(amount);
detail.setCono(orderId);
detail.setWithDrawOrderNo(orderNo);
detail.setSource(1);
myWaterBiz.updMyWater(detail);
}
if (orderType == 1 || orderType == 2) {
myWaterBiz.updMyWalletUnbooked(userId, unbooked, 2);
}
}
}
//获取拥金列表
public List<AppUserSellingWater> getWaterList(Integer orderId) {
Example example = new Example(AppUserSellingWater.class);
example.createCriteria().andEqualTo("orderId", orderId).andEqualTo("waiting", 0).andEqualTo("status", 0);
return mapper.selectByExample(example);
}
public PageDataVO<UserIncomeBo> findMemberIdAndIncomeMapByMemberIds(Integer parentId, Integer pageNo, Integer pageSize) {
return PageDataVO.pageInfo(pageNo, pageSize, () -> mapper.accquireIncomeByMemberIds(parentId));
}
public SellingWalletPagVo findSellingWaterPageByWaiting(Integer waiting, Integer userId, Integer pageNo, Integer pageSize) {
SellingWalletPagVo sellingWalletPagVo = new SellingWalletPagVo();
Example example = new Example(AppUserSellingWater.class);
example.setOrderByClause("crt_time DESC");
Example.Criteria criteria = example.createCriteria();
if (waiting != null) {
criteria.andEqualTo("waiting", waiting);
}
criteria.andEqualTo("userId", userId);
PageDataVO<AppUserSellingWater> appUserSellingWaterPageDataVO = PageDataVO.pageInfo(pageNo, pageSize, () -> mapper.selectByExample(example));
List<AppUserSellingWater> appUserSellingWaters = appUserSellingWaterPageDataVO.getData();
if (CollectionUtils.isEmpty(appUserSellingWaters)) {
sellingWalletPagVo.setPageNum(pageNo);
sellingWalletPagVo.setPageSize(pageSize);
sellingWalletPagVo.setTotalCount(0);
sellingWalletPagVo.setTotalPage(0);
sellingWalletPagVo.setTotalIncome(new BigDecimal(0));
sellingWalletPagVo.setSellingWaters(Collections.EMPTY_LIST);
return sellingWalletPagVo;
}
List<Integer> memberIds = appUserSellingWaters.stream().map(AppUserSellingWater::getSourceId).distinct().collect(Collectors.toList());
Map<Integer, AppUserLogin> userIdAndAppUserLoginMap = appUserLoginBiz.findUserIdAndUserLoginMapByMemberIds(memberIds);
Map<Integer, AppUserDetail> userIdAndAppUserDetailMap = appUserDetailBiz.findUserIdAndUserDetailMapByMemberIds(memberIds);
List<SellingWalletVo> sellingWaterVos = new ArrayList<>();
SellingWalletVo sellingWaterVo;
BigDecimal totalIncome = new BigDecimal(0);
for (AppUserSellingWater appUserSellingWater : appUserSellingWaters) {
sellingWaterVo = new SellingWalletVo();
BeanUtils.copyProperties(appUserSellingWater, sellingWaterVo);
sellingWaterVo.setUsername(userIdAndAppUserLoginMap.get(appUserSellingWater.getSourceId()).getUsername());
if (userIdAndAppUserDetailMap != null) {
AppUserDetail appUserDetail = userIdAndAppUserDetailMap.get(appUserSellingWater.getSourceId());
sellingWaterVo.setNickName(appUserDetail == null ? "" : appUserDetail.getNickname());
sellingWaterVo.setHeadUrl(appUserDetail == null ? "" : appUserDetail.getHeadimgurl());
}
totalIncome = totalIncome.add(sellingWaterVo.getCommission());
sellingWaterVos.add(sellingWaterVo);
}
if (waiting == null) {
Supplier<Stream<AppUserSellingWater>> commissionStream = () -> appUserSellingWaters.stream();
BigDecimal total = commissionStream.get().filter(x -> x.getStatus() == 0).map(AppUserSellingWater::getCommission).reduce(new BigDecimal(0), (x, y) -> x.add(y));
BigDecimal refund = commissionStream.get().filter(x -> x.getStatus() == 1).map(AppUserSellingWater::getCommission).reduce(new BigDecimal(0), (x, y) -> x.add(y));
totalIncome = total.subtract(refund);
}
sellingWaterVos.sort(Comparator.comparing(SellingWalletVo::getCrtTime).reversed());
sellingWalletPagVo.setPageNum(pageNo);
sellingWalletPagVo.setPageSize(pageSize);
sellingWalletPagVo.setTotalCount(appUserSellingWaterPageDataVO.getTotalCount().intValue());
sellingWalletPagVo.setTotalPage(appUserSellingWaterPageDataVO.getTotalPage());
sellingWalletPagVo.setTotalIncome(totalIncome);
sellingWalletPagVo.setSellingWaters(sellingWaterVos);
return sellingWalletPagVo;
}
public BigDecimal selectTotalIncomeByUserId(Integer userId) {
return mapper.selectTotalIncomeByUserId(userId);
}
public void deleteByMemberIds(Collection<Integer> userIds) {
Example example = new Example(AppUserSellingWater.class);
Example.Criteria criteria = example.createCriteria();
criteria.orIn("sourceId", userIds);
criteria.orIn("userId", userIds);
mapper.deleteByExample(example);
}
public SellingWalletPagVo findSellingWaterPageForAppByWaiting(Integer wating, Integer userId, Integer pageNo, Integer pageSize) {
SellingWalletPagVo sellingWalletPagVo = new SellingWalletPagVo();
PageDataVO<SellingWalletVo> pageDataVO = PageDataVO.pageInfo(pageNo, pageSize, () -> mapper.selectSellerWalterByUserIdAndWating(userId, wating));
List<SellingWalletVo> data = pageDataVO.getData();
if (CollectionUtils.isEmpty(data)) {
sellingWalletPagVo.setPageNum(pageNo);
sellingWalletPagVo.setPageSize(pageSize);
sellingWalletPagVo.setSellingWaters(Collections.EMPTY_LIST);
sellingWalletPagVo.setTotalCount(0);
sellingWalletPagVo.setTotalPage(0);
return sellingWalletPagVo;
}
List<Integer> memberIds = data.stream().map(SellingWalletVo::getSourceId).distinct().collect(Collectors.toList());
Map<Integer, AppUserLogin> userIdAndAppUserLoginMap = appUserLoginBiz.findUserIdAndUserLoginMapByMemberIds(memberIds);
Map<Integer, AppUserDetail> userIdAndAppUserDetailMap = appUserDetailBiz.findUserIdAndUserDetailMapByMemberIds(memberIds);
for (SellingWalletVo sellingWalletVo : data) {
String username = userIdAndAppUserLoginMap.get(sellingWalletVo.getSourceId()).getUsername();
sellingWalletVo.setUsername(username);
if (userIdAndAppUserDetailMap != null) {
AppUserDetail appUserDetail = userIdAndAppUserDetailMap.get(sellingWalletVo.getSourceId());
sellingWalletVo.setNickName(appUserDetail == null ? "" : appUserDetail.getRealname());
sellingWalletVo.setHeadUrl(appUserDetail == null ? "" : appUserDetail.getHeadimgurl());
}
//取消单
if (sellingWalletVo.getSellerStatus() == 1) {
sellingWalletVo.setSellerStatus(SellerWallterStatus.CANCEL.getCode());
sellingWalletVo.setStatusText(SellerWallterStatus.CANCEL.getText());
sellingWalletVo.setIsShow(true);
} else {
if (sellingWalletVo.getWaiting() == SellerWallterStatus.POST.getCode()) {
sellingWalletVo.setSellerStatus(SellerWallterStatus.POST.getCode());
sellingWalletVo.setStatusText(SellerWallterStatus.POST.getText());
sellingWalletVo.setIsShow(false);
}
if (sellingWalletVo.getWaiting() == SellerWallterStatus.NO_POST.getCode()) {
sellingWalletVo.setSellerStatus(SellerWallterStatus.NO_POST.getCode());
sellingWalletVo.setStatusText(SellerWallterStatus.NO_POST.getText());
sellingWalletVo.setIsShow(false);
}
}
}
sellingWalletPagVo.setPageNum(pageNo);
sellingWalletPagVo.setPageSize(pageSize);
sellingWalletPagVo.setSellingWaters(data);
sellingWalletPagVo.setTotalCount(pageDataVO.getTotalCount().intValue());
sellingWalletPagVo.setTotalPage(pageDataVO.getTotalPage());
return sellingWalletPagVo;
}
public List<Integer> findMemberIdByLeaderIdAndOrdreType(Integer leaderId, int orderType) {
Example example = new Example(AppUserSellingWater.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("userId", leaderId);
criteria.andEqualTo("orderType", orderType);
List<AppUserSellingWater> appUserSellingWaters = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(appUserSellingWaters)) {
return Collections.EMPTY_LIST;
}
return appUserSellingWaters.stream().map(AppUserSellingWater::getSourceId).collect(Collectors.toList());
}
public PageDataVO<UserSellingWaterAdminDTO> findSellingWaterWithPage(UserSellingWaterFindDTO userSellingWaterFindDTO) {
PageDataVO<UserSellingWaterAdminDTO> pageDataVO = PageDataVO.pageInfo(userSellingWaterFindDTO.getPage(),
userSellingWaterFindDTO.getLimit(),
() -> mapper.selectSellingWaterPage(userSellingWaterFindDTO));
return pageDataVO;
}
public List<AppUserSellingWaterDTO> findStatffSellerWaterByUserIdsAndTime(List<Integer> userIds, Date startDate, Date endDate) {
/* List<UserStaffBo> userStaffBos = mapper.statisticsStatffSellerWaterByUserIdsAndTime(userIds,startDate.getTime(),endDate.getTime());
return CollectionUtils.isEmpty(userStaffBos)?Collections.EMPTY_LIST:userStaffBos;*/
List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = new ArrayList<>();
Example example = new Example(AppUserSellingWater.class);
Example.Criteria criteria = example.createCriteria();
criteria.andIn("userId", userIds);
if(startDate!=null && endDate!=null){
criteria.andBetween("crtTime", startDate.getTime(), endDate.getTime());
}
if (startDate!=null && endDate==null){
criteria.andGreaterThanOrEqualTo("crtTime",startDate.getTime());
}
if(startDate==null && endDate!=null){
criteria.andLessThanOrEqualTo("crtTime",endDate.getTime());
}
criteria.andNotEqualTo("positionId", 6);
List<AppUserSellingWater> appUserSellingWaters = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(appUserSellingWaters)) {
return appUserSellingWaterDTOS;
}
AppUserSellingWaterDTO appUserSellingWaterDTO = null;
for (AppUserSellingWater appUserSellingWater : appUserSellingWaters) {
appUserSellingWaterDTO = new AppUserSellingWaterDTO();
BeanUtils.copyProperties(appUserSellingWater, appUserSellingWaterDTO);
appUserSellingWaterDTOS.add(appUserSellingWaterDTO);
}
return appUserSellingWaterDTOS;
}
private enum SellerWallterStatus {
CANCEL(2, "取消订单"),
POST(1, "已入账"),
NO_POST(0, "未入账");
private int code;
private String text;
SellerWallterStatus(int code, String text) {
this.code = code;
this.text = text;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.biz;
import com.github.wxiaoqi.security.admin.bo.PromoteBO;
import com.github.wxiaoqi.security.admin.bo.UserIncomeBo;
import com.github.wxiaoqi.security.admin.bo.UserTeamMemberBo;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.entity.AppUserLogin;
import com.github.wxiaoqi.security.admin.vo.UserTeamMemberVo;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/11 14:44
*/
@Transactional
@Service
public class UserBusinessBiz {
@Autowired
private AppUserRelationBiz appUserRelationBiz;
@Autowired
private AppUserSellingWaterBiz appUserSellingWaterBiz;
@Autowired
private AppUserLoginBiz appUserLoginBiz;
@Autowired
private AppUserDetailBiz appUserDetailBiz;
public UserTeamMemberVo findTeamMemberPageByUserId(Integer userId, Integer pageNo, Integer pageSize) {
UserTeamMemberVo userTeamMemberVo = new UserTeamMemberVo();
PageDataVO<UserIncomeBo> dataVO = appUserSellingWaterBiz.findMemberIdAndIncomeMapByMemberIds(userId, pageNo, pageSize);
List<UserIncomeBo> data = dataVO.getData();
if (CollectionUtils.isEmpty(data)) {
userTeamMemberVo.setPageNum(pageNo);
userTeamMemberVo.setPageSize(pageSize);
userTeamMemberVo.setTotalCount(0);
userTeamMemberVo.setTotalPage(0);
userTeamMemberVo.setTotalIncome(new BigDecimal(0));
userTeamMemberVo.setUserTeamMemberBos(Collections.EMPTY_LIST);
return userTeamMemberVo;
}
Map<Integer, UserIncomeBo> userIdAndIncomMap = data.stream().collect(Collectors.toMap(UserIncomeBo::getUserId, Function.identity()));
List<Integer> memberIds = data.stream().map(UserIncomeBo::getUserId).collect(Collectors.toList());
Map<Integer, AppUserLogin> userIdAndAppUserLoginMap = appUserLoginBiz.findUserIdAndUserLoginMapByMemberIds(memberIds);
Map<Integer, AppUserDetail> userIdAndAppUserDetailMap = appUserDetailBiz.findUserIdAndUserDetailMapByMemberIds(memberIds);
List<UserTeamMemberBo> userTeamMemberBos = new ArrayList<>();
UserTeamMemberBo userTeamMemberBo;
BigDecimal totalIncome = new BigDecimal(0);
for (Integer memberId : memberIds) {
userTeamMemberBo = new UserTeamMemberBo();
userTeamMemberBo.setLeagueTime(userIdAndIncomMap.get(memberId).getLeagueTime());
userTeamMemberBo.setUserId(memberId);
if (userIdAndAppUserLoginMap != null) {
AppUserLogin appUserLogin = userIdAndAppUserLoginMap.get(memberId);
if (appUserLogin == null) {
continue;
}
userTeamMemberBo.setUserName(appUserLogin.getUsername());
}
if (userIdAndAppUserDetailMap != null) {
AppUserDetail appUserDetail = userIdAndAppUserDetailMap.get(memberId);
userTeamMemberBo.setHeadUrl(appUserDetail == null ? "" : appUserDetail.getHeadimgurl());
userTeamMemberBo.setNickName(appUserDetail == null ? "" : appUserDetail.getNickname());
userTeamMemberBo.setRealName(appUserDetail == null ? "" : appUserDetail.getRealname());
}
BigDecimal income = userIdAndIncomMap.get(memberId).getIncome() == null ? new BigDecimal(0) : userIdAndIncomMap.get(memberId).getIncome();
userTeamMemberBo.setIncome(income);
totalIncome = totalIncome.add(income);
userTeamMemberBos.add(userTeamMemberBo);
}
userTeamMemberBos.sort(Comparator.comparing(UserTeamMemberBo::getIncome).reversed());
userTeamMemberVo.setPageNum(dataVO.getPageNum());
userTeamMemberVo.setPageSize(dataVO.getPageSize());
userTeamMemberVo.setTotalCount(dataVO.getTotalCount().intValue());
userTeamMemberVo.setTotalPage(dataVO.getTotalPage());
userTeamMemberVo.setUserTeamMemberBos(userTeamMemberBos);
userTeamMemberVo.setTotalIncome(totalIncome);
return userTeamMemberVo;
}
public PromoteBO getPromoteBoByUserId(Integer userId) {
PromoteBO promoteBO = new PromoteBO();
Integer leaderId = appUserRelationBiz.findLeaderIdByMemberId(userId);
Map<Integer, Integer> memberStateAndCountMap = appUserRelationBiz.findMemberSateAndCountMapByLeaderId(userId);
if (leaderId != 0) {
Map<Integer, AppUserLogin> userIdAndUserLoginMap = appUserLoginBiz.findUserIdAndUserLoginMapByMemberIds(Arrays.asList(leaderId));
Map<Integer, AppUserDetail> userIdAndUserDetailMap = appUserDetailBiz.findUserIdAndUserDetailMapByMemberIds(Arrays.asList(leaderId));
if (!userIdAndUserLoginMap.isEmpty()) {
promoteBO.setLeaderUsername(userIdAndUserLoginMap.get(leaderId).getUsername());
}
if (!userIdAndUserDetailMap.isEmpty()) {
AppUserDetail appUserDetail = userIdAndUserDetailMap.get(leaderId);
promoteBO.setLeaderHeadUrl(StringUtils.isEmpty(appUserDetail.getHeadimgurl()) ? "" : appUserDetail.getHeadimgurl());
promoteBO.setLeaderUsername(StringUtils.isEmpty(appUserDetail.getRealname()) ? promoteBO.getLeaderUsername() : appUserDetail.getRealname());
}
}
promoteBO.setInviteNumber(memberStateAndCountMap.get(0));
promoteBO.setActivatedNumber(memberStateAndCountMap.get(1));
BigDecimal totalIncome = appUserSellingWaterBiz.selectTotalIncomeByUserId(userId);
promoteBO.setTotalIncome(totalIncome == null ? new BigDecimal(0) : totalIncome);
return promoteBO;
}
}
package com.github.wxiaoqi.security.admin.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* xxl-job config
*
* @author xuxueli 2017-04-28
*/
@Slf4j
@Configuration
public class XxlJobConfig {
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.executor.appname}")
private String appName;
@Value("${xxl.job.executor.ip}")
private String ip;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppName(appName);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
/**
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
*
* 1、引入依赖:
* <dependency>
* <groupId>org.springframework.cloud</groupId>
* <artifactId>spring-cloud-commons</artifactId>
* <version>${version}</version>
* </dependency>
*
* 2、配置文件,或者容器启动变量
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
*
* 3、获取IP
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
*/
}
\ No newline at end of file
......@@ -74,9 +74,6 @@ public class AppUserController extends CommonBaseController{
@Autowired
private AppUserAlipayBiz appUserAlipayBiz;
@Autowired
private AppUserRelationBiz relationBiz;
@GetMapping("page")
......@@ -154,7 +151,6 @@ public class AppUserController extends CommonBaseController{
if (userPosition!=null&&userPosition.getLevel()>0){
userDTO.setPositionName(userPosition.getName());
}
relationBiz.initParentId(userDTO, userid);
List<AppUserAlipay> appUserAlipays = appUserAlipayBiz.getByUserId(request);
long count = appUserAlipays.stream().filter(appUserAlipay -> appUserAlipay.getType() == 1).count();
userDTO.setIsBindAliPay(count>0);
......
......@@ -32,10 +32,6 @@ public class DataController {
private final AppUserDetailBiz appUserDetailBiz;
private final AppUserRelationBiz appUserRelationBiz;
private final AppUserSellingWaterBiz appUserSellingWaterBiz;
private final MyWalletCathBiz walletCathBiz;
private final BaseUserMemberBiz userMemberBiz;
......@@ -51,14 +47,10 @@ public class DataController {
appUserLoginBiz.deleteByPhones(phons);
//2.删除用户详情信息
appUserDetailBiz.deleteByUserIds(userIds);
//3.删除用户关系表信息
appUserRelationBiz.deleteByMemberIds(userIds);
//5.删除用户提现记录
walletCathBiz.deleteByUserIds(userIds);
//6.删除会员信息
userMemberBiz.deleteByUserIds(userIds);
//7.删除佣金数据
appUserSellingWaterBiz.deleteByMemberIds(userIds);
}
return ObjectRestResponse.succ();
}
......@@ -69,8 +61,6 @@ public class DataController {
Map<String, Integer> phoneAndUserIdMapByPhones = appUserLoginBiz.findPhoneAndUserIdMapByPhones(phons);
if (Objects.nonNull(phoneAndUserIdMapByPhones)) {
Collection<Integer> userIds = phoneAndUserIdMapByPhones.values();
appUserRelationBiz.deleteByMemberIds(userIds);
appUserSellingWaterBiz.deleteByMemberIds(userIds);
}
return ObjectRestResponse.succ();
......
......@@ -48,9 +48,6 @@ public class PublicController {
@Autowired
AppUserPositionBiz positionBiz;
@Autowired
private AppUserRelationBiz relationBiz;
@RequestMapping(value = "/userinfo-by-token", method = RequestMethod.GET)
public @ResponseBody
ObjectRestResponse userinfoByToken(String token) throws Exception {
......@@ -125,8 +122,6 @@ public class PublicController {
userDTO.setId(id);
//设置上级
relationBiz.initParentId(userDTO, userid);
return userDTO;
}
......
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.UserBusinessBiz;
import com.github.wxiaoqi.security.admin.bo.PromoteBO;
import com.github.wxiaoqi.security.admin.vo.UserTeamMemberVo;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil;
import com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/11 17:48
*/
@RestController
@RequestMapping("/team")
public class UserBussinessController {
@Autowired
private UserAuthUtil userAuthUtil;
@Autowired
private UserAuthConfig userAuthConfig;
@Autowired
private UserBusinessBiz businessBiz;
@GetMapping("/teams")
public ObjectRestResponse<UserTeamMemberVo> findTeamPage(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, HttpServletRequest request){
try {
IJWTInfo infoFromToken = userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request));
UserTeamMemberVo userTeamMemberVo = businessBiz.findTeamMemberPageByUserId(Integer.valueOf(infoFromToken.getId()), pageNo, pageSize);
return ObjectRestResponse.succ(userTeamMemberVo);
} catch (Exception e) {
throw new BaseException(e);
}
}
@GetMapping("/promote")
public ObjectRestResponse<PromoteBO> findPromoteBo(HttpServletRequest request){
try {
IJWTInfo infoFromToken = userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request));
PromoteBO promoteBO = businessBiz.getPromoteBoByUserId(Integer.valueOf(infoFromToken.getId()));
return ObjectRestResponse.succ(promoteBO);
} catch (Exception e) {
throw new BaseException(e);
}
}
}
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.AppUserSellingWaterBiz;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO;
import com.github.wxiaoqi.security.admin.dto.OrderWaterDTO;
import com.github.wxiaoqi.security.admin.vo.SellingWalletPagVo;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil;
import com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/7/12 11:35
*/
@RestController
@RequestMapping("/sellingwater")
public class UserSellingWaterController {
@Autowired
private AppUserSellingWaterBiz appUserSellingWaterBiz;
@Autowired
private UserAuthUtil userAuthUtil;
@Autowired
private UserAuthConfig userAuthConfig;
@Autowired
private AppUserSellingWaterBiz waterBiz;
@GetMapping("/page")
public ObjectRestResponse<SellingWalletPagVo> findSellingWaterPage(@RequestParam(required = false,value = "type") Integer wating,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
HttpServletRequest request) {
try {
IJWTInfo infoFromToken = userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request));
SellingWalletPagVo sellingWalletPagVo = appUserSellingWaterBiz.findSellingWaterPageByWaiting(wating, Integer.valueOf(infoFromToken.getId()), pageNo, pageSize);
return ObjectRestResponse.succ(sellingWalletPagVo);
} catch (Exception e) {
throw new BaseException(e);
}
}
@GetMapping("/pagea")
public ObjectRestResponse<SellingWalletPagVo> findSellingWaterPagea(@RequestParam(required = false,value = "type") Integer wating,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
HttpServletRequest request) {
try {
IJWTInfo infoFromToken = userAuthUtil.getInfoFromToken(userAuthConfig.getToken(request));
SellingWalletPagVo sellingWalletPagVo = appUserSellingWaterBiz.findSellingWaterPageForAppByWaiting(wating, Integer.valueOf(infoFromToken.getId()), pageNo, pageSize);
return ObjectRestResponse.succ(sellingWalletPagVo);
} catch (Exception e) {
throw new BaseException(e);
}
}
@PostMapping("app/unauth/order")
public ObjectRestResponse order(@RequestBody OrderWaterDTO orderWaterDTO) {
try {
waterBiz.orderWater(orderWaterDTO);
return ObjectRestResponse.succ();
} catch (Exception e) {
throw new BaseException(e);
}
}
@ApiOperation("员工佣金")
@GetMapping("/list_staff_sellerwater")
public List<AppUserSellingWaterDTO> findStaffSellerWater(@RequestParam(value = "userIds",required = false) List<Integer> userIds,
@RequestParam(value = "startDate") Date startDate,
@RequestParam(value = "endDate") Date endDate){
return appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds,startDate,endDate);
}
}
package com.github.wxiaoqi.security.admin.rest.admin;
import com.github.wxiaoqi.security.admin.biz.AppUserRelationBiz;
import com.github.wxiaoqi.security.admin.dto.UserRelationDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("relation/admin")
public class AdminUserRelationController extends BaseController<AppUserRelationBiz,AppUserRelation> {
@RequestMapping(value = "/bind",method = RequestMethod.POST)
@ApiModelProperty("后台绑定")
public ObjectRestResponse bind(@RequestBody UserRelationDTO relationDTO){
try {
return baseBiz.adminBindRelation(relationDTO);
} catch (Exception e) {
e.printStackTrace();
throw new BaseException(e);
}
}
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.rest.admin;
import com.github.wxiaoqi.security.admin.biz.AppUserSellingWaterBiz;
import com.github.wxiaoqi.security.admin.dto.UserSellingWaterAdminDTO;
import com.github.wxiaoqi.security.admin.dto.UserSellingWaterFindDTO;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/10/21 10:10
*/
@RestController
@RequestMapping("/sellingwater/admin")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserSellingWaterAdminController {
private final AppUserSellingWaterBiz appUserSellingWaterBiz;
@PostMapping("/page")
public ObjectRestResponse<PageDataVO<UserSellingWaterAdminDTO>> findSellingWaterWithPage(@RequestBody UserSellingWaterFindDTO userSellingWaterFindDTO){
PageDataVO<UserSellingWaterAdminDTO> pageDataVO = appUserSellingWaterBiz.findSellingWaterWithPage(userSellingWaterFindDTO);
return ObjectRestResponse.succ(pageDataVO);
}
}
......@@ -68,9 +68,6 @@ public class AppPermissionService {
@Autowired
MQSenderFeign mqSenderFeign;
@Autowired
AppUserRelationBiz relationBiz;
@Resource
private RegionFeign regionFeign;
......@@ -94,8 +91,8 @@ public class AppPermissionService {
@Autowired
private BaseUserMemberBiz baseUserMemberBiz;
@Value("${admin.smallName}")
private String smallName;
// @Value("${admin.smallName}")
// private String smallName;
@Autowired
private AppUserPhoneNotesBiz notesBiz;
......@@ -1057,23 +1054,6 @@ public class AppPermissionService {
log.info("注册:解析地址后: " + userid+"---time===="+System.currentTimeMillis()/1000L);
//邀请人id关系绑定
Integer parentId=0;
if (StringUtils.isNotBlank(code)){
//判断处理活动关键字
String[] codes = code.split("_");
if(codes.length > 1) {
code = codes[0];
activityCode = codes[1];
}
parentId=appUserDetailBiz.getUserByCode(code);
}
if(parentId!=null&&parentId>0){
rsUserDetail.setSource(1);
relationBiz.bindRelation(userid, parentId, 1);
if(StringUtils.isNotBlank(activityCode)){
rsUserDetail.setInviterAccount(parentId);
}
}
//生成邀请码 长度改为8 不然重复率太高
rsUserDetail.setCode(ReferralCodeUtil.encode(userid));
rsUserDetail.setChannel(channel);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment