diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ef5ff7273..7539aa22e 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -83,7 +83,6 @@ public interface ErrorCodeConstants { ErrorCode BROKERAGE_BIND_LOOP = new ErrorCode(1_011_007_007, "下级不能绑定自己的上级"); ErrorCode BROKERAGE_USER_LEVEL_NOT_SUPPORT = new ErrorCode(1_011_007_008, "目前只支持 level 小于等于 2"); - // ========== 分销提现 模块 1-011-008-000 ========== ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1_011_008_000, "佣金提现记录不存在"); ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1_011_008_001, "佣金提现记录状态不是审核中"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index 0e41c6124..6c24cac90 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -151,10 +151,16 @@ public interface BrokerageUserMapper extends BaseMapperX { @Param("ids") Collection ids, @Param("sortingField") SortingField sortingField); + /** + * 获得被 bindUserIds 推广的用户编号数组 + * + * @param bindUserIds 推广员编号数组 + * @return 用户编号数组 + */ default List selectIdListByBindUserIdIn(Collection bindUserIds) { return Convert.toList(Long.class, selectObjs(new LambdaQueryWrapperX() - .select(Collections.singletonList(BrokerageUserDO::getId)) + .select(Collections.singletonList(BrokerageUserDO::getId)) // 只查询 id 字段,加速返回速度 .in(BrokerageUserDO::getBindUserId, bindUserIds))); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index aa8a3a7cd..ec9832d78 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -231,7 +231,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { if (CollUtil.isEmpty(childIds)) { return PageResult.empty(); } - // 1.2 根据昵称过滤下级用户 Map userMap = convertMapByFilter(memberUserApi.getUserList(childIds), user -> StrUtil.contains(user.getNickname(), pageReqVO.getNickname()), @@ -240,13 +239,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return PageResult.empty(); } - // 2 分页查询 + // 2. 分页查询 IPage pageResult = brokerageUserMapper.selectSummaryPageByUserId( MyBatisUtils.buildPage(pageReqVO), BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), userMap.keySet(), pageReqVO.getSortingField() ); - // 3 拼接数据并返回 + // 3. 拼接数据并返回 BrokerageUserConvert.INSTANCE.copyTo(pageResult.getRecords(), userMap); return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index ee1bdf1b6..c055e24f8 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.service.user; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; -import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -28,6 +27,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionSynchronization; +import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.support.TransactionTemplate; import javax.annotation.Resource; @@ -78,6 +79,7 @@ public class MemberUserServiceImpl implements MemberUserService { } @Override + @Transactional(rollbackFor = Exception.class) public MemberUserDO createUserIfAbsent(String mobile, String registerIp) { // 用户已经存在 MemberUserDO user = memberUserMapper.selectByMobile(mobile); @@ -85,7 +87,7 @@ public class MemberUserServiceImpl implements MemberUserService { return user; } // 用户不存在,则进行创建 - return this.createUser(mobile, registerIp); + return createUser(mobile, registerIp); } private MemberUserDO createUser(String mobile, String registerIp) { @@ -97,13 +99,17 @@ public class MemberUserServiceImpl implements MemberUserService { user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 user.setPassword(encodePassword(password)); // 加密密码 user.setRegisterIp(registerIp); + memberUserMapper.insert(user); - Boolean success = transactionTemplate.execute(status -> memberUserMapper.insert(user) > 0); - if (BooleanUtil.isTrue(success)) { - // 发送 MQ 消息:用户创建 - registerCouponProducer.sendUserCreateMessage(user.getId()); - } + // 发送 MQ 消息:用户创建 + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { + @Override + public void afterCommit() { + registerCouponProducer.sendUserCreateMessage(user.getId()); + } + + }); return user; }