分销员使用 shopUser主键ID
This commit is contained in:
parent
0d2a930ae8
commit
9b4354ae70
|
|
@ -104,9 +104,9 @@ public class UDistributionController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/bindInviteUser")
|
@PostMapping("/bindInviteUser")
|
||||||
public CzgResult<Map<String, Object>> bindInviteUser(@RequestBody MkDistributionUserDTO param) {
|
public CzgResult<Map<String, Object>> bindInviteUser(@RequestBody MkDistributionUserDTO param) {
|
||||||
|
AssertUtil.isNull(param.getId(), "店铺用户ID不能为空");
|
||||||
AssertUtil.isNull(param.getShopId(), "店铺ID不能为空");
|
AssertUtil.isNull(param.getShopId(), "店铺ID不能为空");
|
||||||
AssertUtil.isNull(param.getParentId(), "店铺用户ID不能为空");
|
AssertUtil.isNull(param.getInviteCode(), "邀请码不能为空");
|
||||||
AssertUtil.isNull(param.getDistributionLevelId(), "分销等级ID不能为空");
|
|
||||||
distributionUserService.bindInviteUser(param);
|
distributionUserService.bindInviteUser(param);
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,6 @@ public class MkDistributionUserDTO extends TimeQueryParam implements Serializabl
|
||||||
*/
|
*/
|
||||||
private Long shopId;
|
private Long shopId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 店铺用户Id
|
|
||||||
*/
|
|
||||||
private Long shopUserId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分销等级
|
* 分销等级
|
||||||
*/
|
*/
|
||||||
|
|
@ -120,4 +115,9 @@ public class MkDistributionUserDTO extends TimeQueryParam implements Serializabl
|
||||||
*/
|
*/
|
||||||
private String shopUserPhone;
|
private String shopUserPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请码
|
||||||
|
*/
|
||||||
|
private String inviteCode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,8 @@ public class MkDistributionUser implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分销员ID,主键自增
|
* 分销员ID 使用ShopUserId
|
||||||
*/
|
*/
|
||||||
@Id(keyType = KeyType.Auto)
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,11 +48,6 @@ public class MkDistributionUser implements Serializable {
|
||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 店铺用户Id
|
|
||||||
*/
|
|
||||||
private Long shopUserId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分销等级
|
* 分销等级
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -158,12 +158,12 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
if (shopUser.getDistributionUserId() != null) {
|
if (shopUser.getDistributionUserId() != null) {
|
||||||
MkDistributionUser mkDistributionUser = this.getById(shopUser.getDistributionUserId());
|
MkDistributionUser mkDistributionUser = this.getById(shopUser.getDistributionUserId());
|
||||||
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
|
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
|
||||||
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getShopUserId());
|
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
|
||||||
result.put("parentName", shopUserParent.getNickName());
|
result.put("parentName", shopUserParent.getNickName());
|
||||||
result.put("parentPhone", shopUserParent.getPhone());
|
result.put("parentPhone", shopUserParent.getPhone());
|
||||||
}
|
}
|
||||||
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create()
|
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create()
|
||||||
.eq(MkDistributionUser::getShopUserId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
|
.eq(MkDistributionUser::getId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
|
||||||
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
|
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
|
||||||
if (mkDistributionUser != null) {
|
if (mkDistributionUser != null) {
|
||||||
Map<String, Object> distributionUser = new HashMap<>();
|
Map<String, Object> distributionUser = new HashMap<>();
|
||||||
|
|
@ -211,42 +211,92 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindInviteUser(MkDistributionUserDTO param) {
|
public void bindInviteUser(MkDistributionUserDTO param) {
|
||||||
ShopUser shopUser = shopUserService.getById(param.getShopUserId());
|
ShopUser shopUser = shopUserService.getById(param.getId());
|
||||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||||
AssertUtil.isNull(shopUser.getDistributionUserId(), "店铺用户已绑定分销员");
|
AssertUtil.isNull(shopUser.getDistributionUserId(), "店铺用户已绑定分销员");
|
||||||
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCount()));
|
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
||||||
AssertUtil.isNull(parent, "邀请人不存在");
|
AssertUtil.isNull(parent, "邀请人不存在");
|
||||||
ShopUser newShopUser = new ShopUser();
|
ShopUser newShopUser = new ShopUser();
|
||||||
newShopUser.setId(shopUser.getId());
|
newShopUser.setId(shopUser.getId());
|
||||||
newShopUser.setDistributionUserId(parent.getId());
|
newShopUser.setDistributionUserId(parent.getId());
|
||||||
newShopUser.setDistributionUserParentId(parent.getParentId());
|
newShopUser.setDistributionUserParentId(parent.getParentId());
|
||||||
shopUserService.updateById(newShopUser);
|
shopUserService.updateById(newShopUser);
|
||||||
|
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
||||||
|
newDistributionUser.setId(parent.getId());
|
||||||
|
newDistributionUser.setInviteCount(parent.getInviteCount() + 1);
|
||||||
|
if (parent.getStatus() != 9) {
|
||||||
|
MkDistributionConfig mkDistributionConfig = mkDistributionConfigService.getOne(QueryWrapper.create()
|
||||||
|
.eq(MkDistributionConfig::getShopId, parent.getShopId()));
|
||||||
|
if (mkDistributionConfig != null) {
|
||||||
|
if ("invite".equals(mkDistributionConfig.getUpgradeType())) {
|
||||||
|
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||||
|
.eq(MkDistributionLevelConfig::getShopId, parent.getShopId())
|
||||||
|
.le(MkDistributionLevelConfig::getInviteCount, parent.getInviteCount())
|
||||||
|
.gt(MkDistributionLevelConfig::getId, parent.getDistributionLevelId())
|
||||||
|
.orderBy(MkDistributionLevelConfig::getLevel).desc().limit(1));
|
||||||
|
if (levelConfig != null) {
|
||||||
|
newDistributionUser.setDistributionLevelId(levelConfig.getId());
|
||||||
|
newDistributionUser.setDistributionLevelName(levelConfig.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.updateById(newDistributionUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 按消费金额升级等级
|
||||||
|
// *
|
||||||
|
// * @param distributionUserId 分销员Id
|
||||||
|
// */
|
||||||
|
// public void costUpgradeLevel(Long distributionUserId) {
|
||||||
|
// MkDistributionUser distributionUser = getById(distributionUserId);
|
||||||
|
// if (distributionUser == null) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// MkDistributionConfig mkDistributionConfig = mkDistributionConfigService.getOne(QueryWrapper.create()
|
||||||
|
// .eq(MkDistributionConfig::getShopId, distributionUser.getShopId()));
|
||||||
|
// AssertUtil.isNull(mkDistributionConfig, "升级失败,店铺未配置分销");
|
||||||
|
// AssertUtil.isNotEqual(mkDistributionConfig.getUpgradeType(), "cost", "升级失败");
|
||||||
|
//
|
||||||
|
// MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||||
|
// .eq(MkDistributionLevelConfig::getShopId, distributionUser.getShopId())
|
||||||
|
// .le(MkDistributionLevelConfig::getInviteCount, distributionUser.getInviteCount())
|
||||||
|
// .gt(MkDistributionLevelConfig::getId, distributionUser.getDistributionLevelId())
|
||||||
|
// .orderBy(MkDistributionLevelConfig::getLevel).desc().limit(1));
|
||||||
|
// if (levelConfig != null) {
|
||||||
|
// distributionUser.setDistributionLevelId(levelConfig.getId());
|
||||||
|
// distributionUser.setDistributionLevelName(levelConfig.getName());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MkDistributionUserDTO> getDistributionUser(MkDistributionUserDTO param) {
|
public Page<MkDistributionUserDTO> getDistributionUser(MkDistributionUserDTO param) {
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.eq(MkDistributionUser::getId, param.getId());
|
||||||
queryWrapper.eq(MkDistributionUser::getShopId, param.getShopId());
|
queryWrapper.eq(MkDistributionUser::getShopId, param.getShopId());
|
||||||
queryWrapper.eq(MkDistributionUser::getParentId, param.getParentId());
|
queryWrapper.eq(MkDistributionUser::getParentId, param.getParentId());
|
||||||
queryWrapper.eq(MkDistributionUser::getShopUserId, param.getShopUserId());
|
|
||||||
queryWrapper.ge(MkDistributionUser::getCreateTime, param.getStartTime());
|
queryWrapper.ge(MkDistributionUser::getCreateTime, param.getStartTime());
|
||||||
queryWrapper.le(MkDistributionUser::getCreateTime, param.getEndTime());
|
queryWrapper.le(MkDistributionUser::getCreateTime, param.getEndTime());
|
||||||
queryWrapper.orderBy(MkDistributionUser::getCreateTime).desc();
|
queryWrapper.orderBy(MkDistributionUser::getCreateTime).desc();
|
||||||
Page<MkDistributionUserDTO> page = pageAs(new Page<>(param.getPage(), param.getSize()), queryWrapper, MkDistributionUserDTO.class);
|
Page<MkDistributionUserDTO> page = pageAs(new Page<>(param.getPage(), param.getSize()), queryWrapper, MkDistributionUserDTO.class);
|
||||||
Map<Long, ShopUser> shopUserMap = new HashMap<>();
|
Map<Long, ShopUser> shopUserMap = new HashMap<>();
|
||||||
if (CollUtil.isNotEmpty(page.getRecords())) {
|
if (CollUtil.isNotEmpty(page.getRecords())) {
|
||||||
if (param.getShopUserId() != null) {
|
if (param.getId() != null) {
|
||||||
shopUserMap.put(param.getShopUserId(), shopUserService.getById(param.getShopUserId()));
|
shopUserMap.put(param.getId(), shopUserService.getById(param.getId()));
|
||||||
} else {
|
} else {
|
||||||
Set<Long> shopUserIds = page.getRecords().stream()
|
Set<Long> shopUserIds = page.getRecords().stream()
|
||||||
.map(MkDistributionUserDTO::getShopUserId)
|
.map(MkDistributionUserDTO::getId)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
shopUserMap = shopUserService.list(QueryWrapper.create().in(ShopUser::getId, shopUserIds))
|
shopUserMap = shopUserService.list(QueryWrapper.create().in(ShopUser::getId, shopUserIds))
|
||||||
.stream().collect(Collectors.toMap(ShopUser::getId, shopUser -> shopUser));
|
.stream().collect(Collectors.toMap(ShopUser::getId, shopUser -> shopUser));
|
||||||
}
|
}
|
||||||
for (MkDistributionUserDTO record : page.getRecords()) {
|
for (MkDistributionUserDTO record : page.getRecords()) {
|
||||||
ShopUser shopUser = shopUserMap.get(record.getShopUserId());
|
ShopUser shopUser = shopUserMap.get(record.getId());
|
||||||
if (shopUser == null || shopUser.getId() == null) {
|
if (shopUser == null || shopUser.getId() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -272,26 +322,29 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
AssertUtil.isNull(param.getShopId(), "店铺ID不能为空");
|
AssertUtil.isNull(param.getShopId(), "店铺ID不能为空");
|
||||||
AssertUtil.isNull(param.getOpeningMethod(), "开通方式不能为空");
|
AssertUtil.isNull(param.getOpeningMethod(), "开通方式不能为空");
|
||||||
AssertUtil.isNull(param.getUserId(), "用户ID不能为空");
|
AssertUtil.isNull(param.getUserId(), "用户ID不能为空");
|
||||||
AssertUtil.isNull(param.getShopUserId(), "店铺用户ID不能为空");
|
AssertUtil.isNull(param.getId(), "店铺用户ID不能为空");
|
||||||
long count = count(QueryWrapper.create()
|
long count = count(QueryWrapper.create()
|
||||||
|
.eq(MkDistributionUser::getId, param.getId())
|
||||||
.eq(MkDistributionUser::getShopId, param.getShopId())
|
.eq(MkDistributionUser::getShopId, param.getShopId())
|
||||||
.eq(MkDistributionUser::getShopUserId, param.getShopUserId())
|
|
||||||
.eq(MkDistributionUser::getUserId, param.getUserId()));
|
.eq(MkDistributionUser::getUserId, param.getUserId()));
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
throw new CzgException("该用户已被添加为分销员");
|
throw new CzgException("该用户已被添加为分销员");
|
||||||
}
|
}
|
||||||
//TODO 通过不同的添加方式 增加校验
|
|
||||||
MkDistributionConfig config = mkDistributionConfigService.getOne(
|
MkDistributionConfig config = mkDistributionConfigService.getOne(
|
||||||
QueryWrapper.create().eq(MkDistributionConfig::getShopId, param.getShopId())
|
QueryWrapper.create().eq(MkDistributionConfig::getShopId, param.getShopId())
|
||||||
.eq(MkDistributionConfig::getIsEnable, 1));
|
.eq(MkDistributionConfig::getIsEnable, 1));
|
||||||
AssertUtil.isNull(config, "店铺未配置分销");
|
AssertUtil.isNull(config, "店铺未配置分销");
|
||||||
param.setStatus(1);
|
param.setStatus(0);
|
||||||
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
if (!"自主申请".equals(param.getOpeningMethod()) || (config.getInviteCount() == 0)) {
|
||||||
.eq(MkDistributionLevelConfig::getShopId, param.getShopId())
|
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||||
.eq(MkDistributionLevelConfig::getLevel, 1));
|
.eq(MkDistributionLevelConfig::getShopId, param.getShopId())
|
||||||
AssertUtil.isNull(levelConfig, "店铺未配置分销等级");
|
.orderBy(MkDistributionLevelConfig::getId).asc().limit(1));
|
||||||
param.setDistributionLevelId(levelConfig.getId());
|
param.setStatus(1);
|
||||||
param.setDistributionLevelName(levelConfig.getName());
|
AssertUtil.isNull(levelConfig, "店铺未配置分销等级");
|
||||||
|
param.setDistributionLevelId(levelConfig.getId());
|
||||||
|
param.setDistributionLevelName(levelConfig.getName());
|
||||||
|
}
|
||||||
|
param.setId(param.getId());
|
||||||
param.setInviteCode(CzgRandomUtils.randomString(10));
|
param.setInviteCode(CzgRandomUtils.randomString(10));
|
||||||
save(param);
|
save(param);
|
||||||
}
|
}
|
||||||
|
|
@ -354,7 +407,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
.setRemark("分销员购买"));
|
.setRemark("分销员购买"));
|
||||||
addDistributionUser(new MkDistributionUser().setParentId(null).setShopId(shopId)
|
addDistributionUser(new MkDistributionUser().setParentId(null).setShopId(shopId)
|
||||||
.setUserId(shopUserInfo.getUserId())
|
.setUserId(shopUserInfo.getUserId())
|
||||||
.setShopUserId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
|
.setId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -381,7 +434,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
deepReward(config, shopUserService.getById(parent.getShopUserId()), amount, sourceId, type, orderNo, ++currentLevel);
|
deepReward(config, shopUserService.getById(parent.getId()), amount, sourceId, type, orderNo, ++currentLevel);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("分销奖励失败: {}", e.getMessage());
|
log.warn("分销奖励失败: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -392,9 +445,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
|
|
||||||
if (config.getRewardCount() != null && config.getRewardCount() > 0) {
|
if (config.getRewardCount() != null && config.getRewardCount() > 0) {
|
||||||
long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, sourceShopUser.getId())
|
long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, sourceShopUser.getId())
|
||||||
.eq(MkDistributionFlow::getShopUserId, distributionUser.getShopUserId()));
|
.eq(MkDistributionFlow::getShopUserId, distributionUser.getId()));
|
||||||
if (count >= config.getRewardCount()) {
|
if (count >= config.getRewardCount()) {
|
||||||
log.info("分销员{}已达到奖励次数上限, 次数: {}", distributionUser.getShopUserId(), config.getRewardCount());
|
log.info("分销员{}已达到奖励次数上限, 次数: {}", distributionUser.getId(), config.getRewardCount());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -415,7 +468,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(distributionUser.getShopUserId())
|
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(distributionUser.getId())
|
||||||
.setShopId(distributionUser.getShopId()).setDistributionUserId(distributionUser.getId())
|
.setShopId(distributionUser.getShopId()).setDistributionUserId(distributionUser.getId())
|
||||||
.setLevelId(distributionUser.getDistributionLevelId()).setLevel(level.getLevel()).setSourceNickName(sourceShopUser.getNickName()).setOrderNo(orderNo)
|
.setLevelId(distributionUser.getDistributionLevelId()).setLevel(level.getLevel()).setSourceNickName(sourceShopUser.getNickName()).setOrderNo(orderNo)
|
||||||
.setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() :
|
.setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() :
|
||||||
|
|
@ -461,7 +514,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
||||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
|
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
|
||||||
UserInfo userInfo = userInfoService.getById(shopUserInfo.getUserId());
|
UserInfo userInfo = userInfoService.getById(shopUserInfo.getUserId());
|
||||||
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getShopUserId, shopUserInfo.getId()));
|
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getId, shopUserInfo.getId()));
|
||||||
AssertUtil.isNull(distributionUser, "分销员不存在");
|
AssertUtil.isNull(distributionUser, "分销员不存在");
|
||||||
if (distributionUser.getReceivedIncome().subtract(withdrawFlowDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
if (distributionUser.getReceivedIncome().subtract(withdrawFlowDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
||||||
throw new CzgException("可提现金额不足");
|
throw new CzgException("可提现金额不足");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue