邀请问题
This commit is contained in:
@@ -4,8 +4,10 @@ import com.czg.account.entity.UserInfo;
|
||||
import com.czg.market.dto.MkDistributionUserDTO;
|
||||
import com.czg.market.dto.MkDistributionWithdrawFlowDTO;
|
||||
import com.czg.market.entity.MkDistributionWithdrawFlow;
|
||||
import com.czg.market.entity.ShopUserInvite;
|
||||
import com.czg.market.service.*;
|
||||
import com.czg.market.service.MkDistributionConfigService;
|
||||
import com.czg.market.service.MkDistributionFlowService;
|
||||
import com.czg.market.service.MkDistributionUserService;
|
||||
import com.czg.market.service.MkDistributionWithdrawFlowService;
|
||||
import com.czg.market.vo.DistributionCenterShopVO;
|
||||
import com.czg.market.vo.InviteUserVO;
|
||||
import com.czg.market.vo.MkDistributionConfigVO;
|
||||
@@ -14,7 +16,6 @@ import com.czg.sa.StpKit;
|
||||
import com.czg.task.DistributionTask;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import io.seata.core.exception.TransactionException;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -43,19 +44,6 @@ public class UDistributionController {
|
||||
private MkDistributionFlowService distributionFlowService;
|
||||
@Resource
|
||||
private DistributionTask distributionTask;
|
||||
@Resource
|
||||
private ShopUserInviteService shopUserInviteService;
|
||||
|
||||
|
||||
/**
|
||||
* 测试方法-清空绑定
|
||||
*/
|
||||
@GetMapping("/clean")
|
||||
public CzgResult<Boolean> task() {
|
||||
shopUserInviteService.remove(QueryWrapper.create().gt(ShopUserInvite::getId, 1));
|
||||
return CzgResult.success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试方法-分销流水入账
|
||||
|
||||
@@ -152,6 +152,23 @@ public class ShopUser implements Serializable {
|
||||
private LocalDateTime nextDeliverTime;
|
||||
// 是否分销员
|
||||
private String distributionShops;
|
||||
/**
|
||||
* 上级分销员id
|
||||
*/
|
||||
private Long parentUserId;
|
||||
/**
|
||||
* 上上级分销员id
|
||||
*/
|
||||
private Long gradeUserId;
|
||||
/**
|
||||
* 一级分销收入
|
||||
*/
|
||||
private BigDecimal oneIncome;
|
||||
/**
|
||||
* 二级分销收入
|
||||
*/
|
||||
private BigDecimal twoIncome;
|
||||
|
||||
private String memberCircleName;
|
||||
private Integer memberCircleReward;
|
||||
|
||||
|
||||
@@ -110,8 +110,10 @@ public class MkDistributionFlow implements Serializable {
|
||||
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 分成比例
|
||||
*/
|
||||
private BigDecimal commission;
|
||||
private BigDecimal parentCommission;
|
||||
private LocalDateTime deliverTime;
|
||||
private Long userId;
|
||||
}
|
||||
|
||||
@@ -62,12 +62,8 @@ public class MkDistributionLevelConfig implements Serializable {
|
||||
/**
|
||||
* 一级分销比例
|
||||
*/
|
||||
private BigDecimal levelOneCommission;
|
||||
private BigDecimal commission;
|
||||
|
||||
/**
|
||||
* 二级分销比例
|
||||
*/
|
||||
private BigDecimal levelTwoCommission;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.czg.market.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 邀请与上级关联表 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-11-06
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("tb_shop_user_invite")
|
||||
public class ShopUserInvite implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* (随机)
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 店铺用户ID
|
||||
*/
|
||||
private Long shopUserId;
|
||||
|
||||
/**
|
||||
* 邀请人ID mk_distribution_user.id
|
||||
*/
|
||||
private Long distributionUserId;
|
||||
|
||||
/**
|
||||
* 邀请人上级ID mk_distribution_user.id
|
||||
*/
|
||||
private Long distributionUserParentId;
|
||||
|
||||
/**
|
||||
* 邀请人收益/一级分润
|
||||
*/
|
||||
private BigDecimal oneIncome;
|
||||
|
||||
/**
|
||||
* 邀请人上级收益/二级分润
|
||||
*/
|
||||
private BigDecimal twoIncome;
|
||||
|
||||
/**
|
||||
* 邀请时间
|
||||
*/
|
||||
private LocalDateTime inviteTime;
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.czg.market.service;
|
||||
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.market.entity.ShopUserInvite;
|
||||
|
||||
/**
|
||||
* 邀请与上级关联表 服务层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-11-06
|
||||
*/
|
||||
public interface ShopUserInviteService extends IService<ShopUserInvite> {
|
||||
|
||||
/**
|
||||
* 根据店铺ID和店铺用户ID查询邀请记录
|
||||
*
|
||||
* @param shopId 店铺ID
|
||||
* @param shopUserId 店铺用户ID
|
||||
* @return 邀请记录
|
||||
*/
|
||||
ShopUserInvite getOneByShopIdAndShopUserId(Long shopId, Long shopUserId);
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
and amount - #{money} >= 0
|
||||
</update>
|
||||
<update id="updateOneOrTwoAmount">
|
||||
update tb_shop_user_invite
|
||||
update tb_shop_user
|
||||
<set>
|
||||
<if test="isOne != null and isOne == 1">
|
||||
one_income = one_income + #{amount}
|
||||
@@ -27,8 +27,7 @@
|
||||
two_income = two_income + #{amount}
|
||||
</if>
|
||||
</set>
|
||||
where shop_user_id = #{shopUserId}
|
||||
and shop_id = #{shopId}
|
||||
where id = #{shopUserId}
|
||||
</update>
|
||||
|
||||
|
||||
@@ -257,10 +256,10 @@
|
||||
</select>
|
||||
<select id="getInviteUser" resultType="com.czg.market.vo.InviteUserVO">
|
||||
SELECT
|
||||
u.id AS shopUserId,
|
||||
u.head_img AS headImg,
|
||||
u.nick_name AS shopUserName,
|
||||
u.phone AS shopUserPhone,
|
||||
invite.id AS shopUserId,
|
||||
invite.head_img AS headImg,
|
||||
invite.nick_name AS shopUserName,
|
||||
invite.phone AS shopUserPhone,
|
||||
invite.one_income AS oneIncome,
|
||||
invite.invite_time AS inviteTime,
|
||||
dist.total_income AS totalIncome,
|
||||
@@ -270,13 +269,12 @@
|
||||
dist.status AS status,
|
||||
dist.distribution_level_id AS levelId,
|
||||
dist.distribution_level_name AS levelName,
|
||||
u.distribution_shops AS distributionShops
|
||||
FROM tb_shop_user_invite invite
|
||||
left join tb_shop_user u on invite.shop_user_id = u.id
|
||||
invite.distribution_shops AS distributionShops
|
||||
FROM tb_shop_user invite
|
||||
left join mk_distribution_user dist on u.id = dist.id and dist.shop_id = #{shopId}
|
||||
WHERE invite.`distribution_user_id` = #{distributionUserId} and invite.shop_id = #{shopId}
|
||||
WHERE invite.`parent_user_id` = #{distributionUserId}
|
||||
<if test="distributionLevelId != null">and dist.distribution_level_id = #{distributionLevelId}</if>
|
||||
<if test="shopUserId != null">and invite.shop_user_id = #{shopUserId}</if>
|
||||
<if test="shopUserId != null">and invite.id = #{shopUserId}</if>
|
||||
ORDER BY invite.`invite_time` DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.ShopUserInvite;
|
||||
|
||||
/**
|
||||
* 邀请与上级关联表 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-11-06
|
||||
*/
|
||||
public interface ShopUserInviteMapper extends BaseMapper<ShopUserInvite> {
|
||||
|
||||
}
|
||||
@@ -73,12 +73,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
private MkDistributionWithdrawFlowService withdrawFlowService;
|
||||
@Resource
|
||||
private MkDistributionDeliverService distributionDeliverService;
|
||||
@Resource
|
||||
private ShopUserInviteService shopUserInviteService;
|
||||
|
||||
@Resource
|
||||
private AppWxServiceImpl appWxService;
|
||||
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
@@ -150,9 +146,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
||||
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
|
||||
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
|
||||
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
||||
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUserInvite.getDistributionUserId(), shopId);
|
||||
|
||||
if (shopUser.getParentUserId() != null) {
|
||||
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getParentUserId(), shopId);
|
||||
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
|
||||
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
|
||||
result.put("parentName", shopUserParent.getNickName());
|
||||
@@ -181,7 +177,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
if (levelConfig.getId().equals(mkDistributionUser.getDistributionLevelId())) {
|
||||
distributionUser.put("level", levelConfig.getLevel());
|
||||
distributionUser.put("levelName", levelConfig.getName());
|
||||
distributionUser.put("levelOneCommission", levelConfig.getLevelOneCommission());
|
||||
distributionUser.put("levelOneCommission", levelConfig.getCommission());
|
||||
isNextLevel = true;
|
||||
}
|
||||
}
|
||||
@@ -234,8 +230,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
public void bindInviteUser(MkDistributionUserDTO param) throws CzgException, ValidateException {
|
||||
ShopUser shopUser = shopUserService.getById(param.getId());
|
||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(param.getShopId(), shopUser.getId());
|
||||
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
||||
if (shopUser.getParentUserId() != null) {
|
||||
throw new CzgException("店铺用户已绑定分销员");
|
||||
}
|
||||
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
||||
@@ -251,26 +246,21 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
}
|
||||
ShopUser parentShopUser = shopUserService.getById(parent.getId());
|
||||
AssertUtil.isNull(parentShopUser, "邀请人不存在");
|
||||
ShopUserInvite parentShopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(param.getShopId(), parentShopUser.getId());
|
||||
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserId() != null && parentShopUserInvite.getDistributionUserId().equals(shopUser.getId())) {
|
||||
|
||||
if (parentShopUser.getParentUserId() != null && parentShopUser.getParentUserId().equals(shopUser.getId())) {
|
||||
throw new CzgException("存在绑定关系,不可绑定");
|
||||
}
|
||||
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserParentId() != null && parentShopUserInvite.getDistributionUserParentId().equals(shopUser.getId())) {
|
||||
if (parentShopUser.getGradeUserId() != null && parentShopUser.getGradeUserId().equals(shopUser.getId())) {
|
||||
throw new CzgException("存在绑定关系,不可绑定");
|
||||
}
|
||||
//更新自己的上级
|
||||
ShopUserInvite newShopUserInvite = new ShopUserInvite();
|
||||
newShopUserInvite.setShopId(param.getShopId());
|
||||
newShopUserInvite.setShopUserId(shopUser.getId());
|
||||
newShopUserInvite.setDistributionUserId(parentShopUser.getId());
|
||||
newShopUserInvite.setDistributionUserParentId(parentShopUserInvite == null ? null : parentShopUserInvite.getDistributionUserParentId());
|
||||
newShopUserInvite.setInviteTime(LocalDateTime.now());
|
||||
shopUserInviteService.save(newShopUserInvite);
|
||||
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserParentId() != null) {
|
||||
shopUser.setParentUserId(parentShopUser.getId());
|
||||
shopUser.setGradeUserId(parentShopUser.getParentUserId());
|
||||
if (shopUser.getParentUserId() != null) {
|
||||
//更新自己的下级 的上级的上级 为自己的上级
|
||||
ShopUserInvite childShopUserInvite = new ShopUserInvite();
|
||||
childShopUserInvite.setDistributionUserParentId(parentShopUser.getId());
|
||||
shopUserInviteService.update(childShopUserInvite, QueryWrapper.create().eq(ShopUserInvite::getDistributionUserId, shopUser.getId()));
|
||||
ShopUser upShopUser = new ShopUser();
|
||||
upShopUser.setGradeUserId(shopUser.getParentUserId());
|
||||
shopUserService.update(upShopUser, QueryWrapper.create().eq(ShopUser::getParentUserId, shopUser.getId()));
|
||||
}
|
||||
|
||||
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
||||
@@ -318,9 +308,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
public void costUpgradeLevelBefore(Long userId, Long shopId) {
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
|
||||
costUpgradeLevel(shopUser.getId(), shopId);
|
||||
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
|
||||
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
||||
costUpgradeLevel(shopUserInvite.getDistributionUserId(), shopId);
|
||||
if (shopUser.getParentUserId() != null) {
|
||||
costUpgradeLevel(shopUser.getParentUserId(), shopId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,70 +558,37 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
|
||||
|
||||
@GlobalTransactional
|
||||
protected void deepReward(ShopUser orderSourceShopUser, MkDistributionLevelConfig parentLevel, MkDistributionConfigVO config,
|
||||
MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId, String type, String orderNo, Integer currentLevel) {
|
||||
if (currentLevel > 2) {
|
||||
return;
|
||||
}
|
||||
protected boolean deepReward(ShopUser orderSourceShopUser, BigDecimal commission, MkDistributionConfigVO config,
|
||||
MkDistributionUser currentDistributionUser, BigDecimal amount, Long sourceId,
|
||||
String type, String orderNo, Integer currentLevel) {
|
||||
// 当前分销员
|
||||
AssertUtil.isNull(currentDistributionUser, "分销员不存在");
|
||||
AssertUtil.isTrue(currentDistributionUser.getStatus() != 1, "分销员未开启");
|
||||
|
||||
// ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
|
||||
ShopUserInvite currentShopUser = shopUserInviteService.getOneByShopIdAndShopUserId(config.getShopId(), currentDistributionUser.getId());
|
||||
MkDistributionLevelConfig level = levelConfigService.getById(currentDistributionUser.getDistributionLevelId());
|
||||
|
||||
// 校验剩余分成比例
|
||||
BigDecimal finalCommission = parentLevel == null ? level.getLevelOneCommission() : level.getLevelOneCommission().subtract(parentLevel.getLevelOneCommission());
|
||||
if (finalCommission.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
log.info("当前分销员: {}, 分销等级: {}, 剩余比例: {}, 不参与分销", currentDistributionUser.getId(), level.getId(), finalCommission);
|
||||
return;
|
||||
if (commission.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 上上级分销员
|
||||
if (currentShopUser != null && currentShopUser.getDistributionUserId() != null) {
|
||||
MkDistributionUser parent = getMkDistributionUserByIdAndShopId(currentShopUser.getDistributionUserId(), config.getShopId());
|
||||
try {
|
||||
deepReward(orderSourceShopUser, level, config, parent, amount, sourceId, type, orderNo, currentLevel + 1);
|
||||
} catch (Exception e) {
|
||||
log.warn("分销奖励失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
AssertUtil.isNull(level, "分销等级不存在");
|
||||
log.info("当前分销员: {}, 上级分销员: {}, 分销等级: {}", currentDistributionUser.getId(), currentShopUser == null ? null : currentShopUser.getDistributionUserId(), level.getId());
|
||||
|
||||
if (config.getRewardCount() != null && config.getRewardCount() > 0) {
|
||||
long count = distributionFlowService.count(new QueryWrapper()
|
||||
.eq(MkDistributionFlow::getShopId, config.getShopId()).eq(MkDistributionFlow::getShopUserId, currentDistributionUser.getId()));
|
||||
if (count >= config.getRewardCount()) {
|
||||
log.info("分销员{}已达到奖励次数上限, 次数: {}", currentDistributionUser.getId(), config.getRewardCount());
|
||||
return;
|
||||
} else {
|
||||
log.info("分销员奖励次数: {}", count);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 店铺信息
|
||||
BigDecimal rewardAmount;
|
||||
// if (currentLevel == 1) {
|
||||
// rewardAmount = amount.multiply(level.getLevelOneCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
// } else {
|
||||
// rewardAmount = amount.multiply(level.getLevelTwoCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
// }
|
||||
rewardAmount = amount.multiply(finalCommission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
|
||||
BigDecimal rewardAmount = amount.multiply(commission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
// 延时发放时间
|
||||
LocalDateTime delayTime = config.getSettlementDay() == null || config.getSettlementDay() == 0 ? null : DateUtil.offsetDay(DateUtil.date(), config.getSettlementDay()).toLocalDateTime();
|
||||
|
||||
// 用户分账明细
|
||||
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
|
||||
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(currentDistributionUser.getId())
|
||||
.setShopId(currentDistributionUser.getShopId()).setDistributionUserId(currentDistributionUser.getId())
|
||||
.setUserId(shopUser.getUserId())
|
||||
.setNickName(shopUser.getNickName()).setSourceShopUserId(orderSourceShopUser.getId()).setSourceNickName(orderSourceShopUser.getNickName())
|
||||
.setCommission(finalCommission).setParentCommission(parentLevel != null ? parentLevel.getLevelOneCommission() : null)
|
||||
.setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel == 1 ? 1 : 2).setOrderNo(orderNo)
|
||||
.setCommission(commission)
|
||||
.setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel).setOrderNo(orderNo)
|
||||
.setSourceId(sourceId).setAmount(amount).setType(type)
|
||||
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
|
||||
|
||||
@@ -655,6 +611,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
log.info("延时分销开始");
|
||||
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -712,19 +669,24 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
AssertUtil.isTrue(amount.compareTo(BigDecimal.ZERO) == 0, "分销金额不能为0");
|
||||
MkDistributionConfigVO config = mkDistributionConfigService.detail(shopId);
|
||||
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
||||
// 当前用户上级分销员
|
||||
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
||||
if (sourceShopUserInfo == null) {
|
||||
// 产生消费的用户
|
||||
ShopUser curUser = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
||||
if (curUser == null || curUser.getParentUserId() == null) {
|
||||
return;
|
||||
}
|
||||
ShopUserInvite sourceInviteUser = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, sourceShopUserInfo.getId());
|
||||
if (sourceInviteUser.getDistributionUserId() == null) {
|
||||
return;
|
||||
}
|
||||
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId());
|
||||
|
||||
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(sourceInviteUser.getDistributionUserId(), shopId);
|
||||
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
|
||||
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, curUser.getParentUserId());
|
||||
|
||||
MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(curUser.getParentUserId(), shopId);
|
||||
MkDistributionLevelConfig level = levelConfigService.getById(distributionUser.getDistributionLevelId());
|
||||
deepReward(curUser, level.getCommission(), config, distributionUser,
|
||||
amount, sourceId, type, orderNo, 1);
|
||||
if (curUser.getGradeUserId() != null) {
|
||||
MkDistributionUser parentDis = getMkDistributionUserByIdAndShopId(curUser.getGradeUserId(), shopId);
|
||||
MkDistributionLevelConfig parentDisLevel = levelConfigService.getById(parentDis.getDistributionLevelId());
|
||||
deepReward(curUser, parentDisLevel.getCommission().subtract(level.getCommission()), config, parentDis,
|
||||
amount, sourceId, type, orderNo, 2);
|
||||
}
|
||||
});
|
||||
distributionDeliverService.save(deliver);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.ShopUserInvite;
|
||||
import com.czg.market.service.ShopUserInviteService;
|
||||
import com.czg.service.market.mapper.ShopUserInviteMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 邀请与上级关联表 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-11-06
|
||||
*/
|
||||
@Service
|
||||
public class ShopUserInviteServiceImpl extends ServiceImpl<ShopUserInviteMapper, ShopUserInvite> implements ShopUserInviteService {
|
||||
|
||||
@Override
|
||||
public ShopUserInvite getOneByShopIdAndShopUserId(Long shopId, Long shopUserId) {
|
||||
return getOne(QueryWrapper.create()
|
||||
.eq(ShopUserInvite::getShopId, shopId)
|
||||
.eq(ShopUserInvite::getShopUserId, shopUserId));
|
||||
}
|
||||
}
|
||||
@@ -65,15 +65,13 @@
|
||||
|
||||
<select id="getOrderConsumeAmountByList" resultType="java.math.BigDecimal">
|
||||
SELECT IFNULL(SUM(ord.pay_amount), 0) AS totalAmount
|
||||
FROM tb_shop_user_invite invite
|
||||
INNER JOIN tb_shop_user su on invite.shop_user_id = su.id
|
||||
INNER JOIN tb_order_info ord ON su.user_id = ord.user_id
|
||||
and invite.shop_id = #{shopId}
|
||||
FROM tb_shop_user invite
|
||||
INNER JOIN tb_order_info ord ON invite.user_id = ord.user_id
|
||||
AND ord.shop_id = #{shopId}
|
||||
AND ord.STATUS = 'done'
|
||||
AND ord.pay_type NOT IN ('vip_pay', 'credit_pay')
|
||||
AND ord.paid_time >= invite.invite_time
|
||||
WHERE invite.distribution_user_id = #{inviterId}
|
||||
WHERE invite.parent_user_id = #{inviterId}
|
||||
</select>
|
||||
|
||||
<select id="getOrderConsumeAmountById" resultType="java.math.BigDecimal">
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.ShopUserInviteMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user