Merge branch 'dev' into prod

This commit is contained in:
2025-11-06 11:05:48 +08:00
14 changed files with 265 additions and 52 deletions

View File

@@ -0,0 +1,14 @@
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> {
}

View File

@@ -74,6 +74,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
private MkDistributionWithdrawFlowService withdrawFlowService;
@Resource
private MkDistributionDeliverService distributionDeliverService;
@Resource
private ShopUserInviteService shopUserInviteService;
@Resource
private AppWxServiceImpl appWxService;
@@ -127,7 +129,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
for (DistributionCenterShopVO unActivate : unActivates) {
if (unActivate.getOrderCount() == 1) {
unActivate.setLabelContent("在本店下单过");
}else if (unActivate.getShopUser() == 1) {
} else if (unActivate.getShopUser() == 1) {
unActivate.setLabelContent("曾进入过店铺");
}
// else if("manual".equals(unActivate.getOpenType())){
@@ -151,8 +153,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());
if (shopUser.getDistributionUserId() != null) {
MkDistributionUser mkDistributionUser = this.getById(shopUser.getDistributionUserId());
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
MkDistributionUser mkDistributionUser = this.getById(shopUserInvite.getDistributionUserId());
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
result.put("parentName", shopUserParent.getNickName());
@@ -236,7 +239,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void bindInviteUser(MkDistributionUserDTO param) {
ShopUser shopUser = shopUserService.getById(param.getId());
AssertUtil.isNull(shopUser, "店铺用户不存在");
if (shopUser.getDistributionUserId() != null) {
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(param.getShopId(), shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
throw new CzgException("店铺用户已绑定分销员");
}
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
@@ -252,24 +256,26 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
}
ShopUser parentShopUser = shopUserService.getById(parent.getId());
AssertUtil.isNull(parentShopUser, "邀请人不存在");
if (parentShopUser.getDistributionUserId() != null && parentShopUser.getDistributionUserId().equals(shopUser.getId())) {
ShopUserInvite parentShopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(param.getShopId(), parentShopUser.getId());
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserId() != null && parentShopUserInvite.getDistributionUserId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
if (parentShopUser.getDistributionUserParentId() != null && parentShopUser.getDistributionUserParentId().equals(shopUser.getId())) {
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserParentId() != null && parentShopUserInvite.getDistributionUserParentId().equals(shopUser.getId())) {
throw new CzgException("存在绑定关系,不可绑定");
}
//更新自己的上级
ShopUser newShopUser = new ShopUser();
newShopUser.setId(shopUser.getId());
newShopUser.setDistributionUserId(parentShopUser.getId());
newShopUser.setDistributionUserParentId(parentShopUser.getDistributionUserId());
newShopUser.setInviteTime(LocalDateTime.now());
shopUserService.updateById(newShopUser);
if (parentShopUser.getDistributionUserParentId() != null) {
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 childShopUser = new ShopUser();
childShopUser.setDistributionUserParentId(parentShopUser.getDistributionUserParentId());
shopUserService.update(childShopUser, QueryWrapper.create().eq(ShopUser::getDistributionUserId, shopUser.getId()));
ShopUserInvite childShopUserInvite = new ShopUserInvite();
childShopUserInvite.setDistributionUserParentId(parentShopUser.getId());
shopUserInviteService.update(childShopUserInvite, QueryWrapper.create().eq(ShopUserInvite::getDistributionUserId, shopUser.getId()));
}
MkDistributionUser newDistributionUser = new MkDistributionUser();
@@ -316,8 +322,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void costUpgradeLevelBefore(Long userId, Long shopId) {
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
costUpgradeLevel(shopUser.getId(), shopId);
if (shopUser.getDistributionUserId() != null) {
costUpgradeLevel(shopUser.getDistributionUserId(), shopId);
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
costUpgradeLevel(shopUserInvite.getDistributionUserId(), shopId);
}
}
@@ -474,7 +481,6 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
}
@Override
public void initLevel(MkDistributionConfig config, MkDistributionUser distributionUser) {
MkDistributionLevelConfig levelConfig = new MkDistributionLevelConfig();
@@ -572,7 +578,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isNull(currentDistributionUser, "分销员不存在");
AssertUtil.isTrue(currentDistributionUser.getStatus() != 1, "分销员未开启");
ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
// ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
ShopUserInvite currentShopUser = shopUserInviteService.getOneByShopIdAndShopUserId(config.getShopId(), currentDistributionUser.getId());
MkDistributionLevelConfig level = levelConfigService.getById(currentDistributionUser.getDistributionLevelId());
// 校验剩余分成比例
@@ -633,10 +640,10 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
log.info("即时分销开始");
try {
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount.negate(), sourceId, TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣除");
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
} catch (Exception e) {
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
distributionFlowService.updateById(mkDistributionFlow);
}
} else {
@@ -644,7 +651,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
distributionFlowService.save(mkDistributionFlow);
log.info("延时分销开始");
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
}
}
@@ -675,11 +682,11 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel());
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
distributionFlowService.updateById(item);
} else {
// 执行扣款
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel());
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(),item.getShopUserId(), item.getShopId(), item.getLevel());
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
}
distributionFlowService.save(refundFlow);
@@ -695,12 +702,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
// 当前用户上级分销员
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
if (sourceShopUserInfo.getDistributionUserId() == null) {
ShopUserInvite sourceInviteUser = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, sourceShopUserInfo.getId());
if (sourceInviteUser.getDistributionUserId() == null) {
return;
}
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceShopUserInfo.getDistributionUserId());
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId());
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
MkDistributionUser distributionUser = getById(sourceInviteUser.getDistributionUserId());
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
});
distributionDeliverService.save(deliver);
@@ -708,9 +716,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
@Override
@Transactional(rollbackFor = Exception.class)
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long mainShopId, Integer isOne) {
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopUserId, Long shopId, Integer isOne) {
// 用户收益信息
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome, isOne);
shopUserService.updateOneOrTwoAmount(shopUserId, shopId, receivedIncome, isOne);
// 用户可提现余额
userInfoService.updateDistributionAmount(userId, receivedIncome);
//分销员余额

View File

@@ -0,0 +1,25 @@
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));
}
}

View File

@@ -0,0 +1,7 @@
<?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>