Commit df4716d5a115a527baf3d022b6f9155f90de702c
1 parent
d874346d
code review:分销
Showing
4 changed files
with
22 additions
and
12 deletions
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 { |
| 83 | 83 | ErrorCode BROKERAGE_BIND_LOOP = new ErrorCode(1_011_007_007, "下级不能绑定自己的上级"); |
| 84 | 84 | ErrorCode BROKERAGE_USER_LEVEL_NOT_SUPPORT = new ErrorCode(1_011_007_008, "目前只支持 level 小于等于 2"); |
| 85 | 85 | |
| 86 | - | |
| 87 | 86 | // ========== 分销提现 模块 1-011-008-000 ========== |
| 88 | 87 | ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1_011_008_000, "佣金提现记录不存在"); |
| 89 | 88 | ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1_011_008_001, "佣金提现记录状态不是审核中"); | ... | ... |
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<BrokerageUserDO> { |
| 151 | 151 | @Param("ids") Collection<Long> ids, |
| 152 | 152 | @Param("sortingField") SortingField sortingField); |
| 153 | 153 | |
| 154 | + /** | |
| 155 | + * 获得被 bindUserIds 推广的用户编号数组 | |
| 156 | + * | |
| 157 | + * @param bindUserIds 推广员编号数组 | |
| 158 | + * @return 用户编号数组 | |
| 159 | + */ | |
| 154 | 160 | default List<Long> selectIdListByBindUserIdIn(Collection<Long> bindUserIds) { |
| 155 | 161 | return Convert.toList(Long.class, |
| 156 | 162 | selectObjs(new LambdaQueryWrapperX<BrokerageUserDO>() |
| 157 | - .select(Collections.singletonList(BrokerageUserDO::getId)) | |
| 163 | + .select(Collections.singletonList(BrokerageUserDO::getId)) // 只查询 id 字段,加速返回速度 | |
| 158 | 164 | .in(BrokerageUserDO::getBindUserId, bindUserIds))); |
| 159 | 165 | } |
| 160 | 166 | ... | ... |
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 { |
| 231 | 231 | if (CollUtil.isEmpty(childIds)) { |
| 232 | 232 | return PageResult.empty(); |
| 233 | 233 | } |
| 234 | - | |
| 235 | 234 | // 1.2 根据昵称过滤下级用户 |
| 236 | 235 | Map<Long, MemberUserRespDTO> userMap = convertMapByFilter(memberUserApi.getUserList(childIds), |
| 237 | 236 | user -> StrUtil.contains(user.getNickname(), pageReqVO.getNickname()), |
| ... | ... | @@ -240,13 +239,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { |
| 240 | 239 | return PageResult.empty(); |
| 241 | 240 | } |
| 242 | 241 | |
| 243 | - // 2 分页查询 | |
| 242 | + // 2. 分页查询 | |
| 244 | 243 | IPage<AppBrokerageUserChildSummaryRespVO> pageResult = brokerageUserMapper.selectSummaryPageByUserId( |
| 245 | 244 | MyBatisUtils.buildPage(pageReqVO), BrokerageRecordBizTypeEnum.ORDER.getType(), |
| 246 | 245 | BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), userMap.keySet(), pageReqVO.getSortingField() |
| 247 | 246 | ); |
| 248 | 247 | |
| 249 | - // 3 拼接数据并返回 | |
| 248 | + // 3. 拼接数据并返回 | |
| 250 | 249 | BrokerageUserConvert.INSTANCE.copyTo(pageResult.getRecords(), userMap); |
| 251 | 250 | return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); |
| 252 | 251 | } | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | -import cn.hutool.core.util.BooleanUtil; | |
| 6 | 5 | import cn.hutool.core.util.IdUtil; |
| 7 | 6 | import cn.hutool.core.util.ObjectUtil; |
| 8 | 7 | import cn.hutool.core.util.StrUtil; |
| ... | ... | @@ -28,6 +27,8 @@ import lombok.extern.slf4j.Slf4j; |
| 28 | 27 | import org.springframework.security.crypto.password.PasswordEncoder; |
| 29 | 28 | import org.springframework.stereotype.Service; |
| 30 | 29 | import org.springframework.transaction.annotation.Transactional; |
| 30 | +import org.springframework.transaction.support.TransactionSynchronization; | |
| 31 | +import org.springframework.transaction.support.TransactionSynchronizationManager; | |
| 31 | 32 | import org.springframework.transaction.support.TransactionTemplate; |
| 32 | 33 | |
| 33 | 34 | import javax.annotation.Resource; |
| ... | ... | @@ -78,6 +79,7 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | @Override |
| 82 | + @Transactional(rollbackFor = Exception.class) | |
| 81 | 83 | public MemberUserDO createUserIfAbsent(String mobile, String registerIp) { |
| 82 | 84 | // 用户已经存在 |
| 83 | 85 | MemberUserDO user = memberUserMapper.selectByMobile(mobile); |
| ... | ... | @@ -85,7 +87,7 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 85 | 87 | return user; |
| 86 | 88 | } |
| 87 | 89 | // 用户不存在,则进行创建 |
| 88 | - return this.createUser(mobile, registerIp); | |
| 90 | + return createUser(mobile, registerIp); | |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | private MemberUserDO createUser(String mobile, String registerIp) { |
| ... | ... | @@ -97,13 +99,17 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 97 | 99 | user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 |
| 98 | 100 | user.setPassword(encodePassword(password)); // 加密密码 |
| 99 | 101 | user.setRegisterIp(registerIp); |
| 102 | + memberUserMapper.insert(user); | |
| 100 | 103 | |
| 101 | - Boolean success = transactionTemplate.execute(status -> memberUserMapper.insert(user) > 0); | |
| 102 | - if (BooleanUtil.isTrue(success)) { | |
| 103 | - // 发送 MQ 消息:用户创建 | |
| 104 | - registerCouponProducer.sendUserCreateMessage(user.getId()); | |
| 105 | - } | |
| 104 | + // 发送 MQ 消息:用户创建 | |
| 105 | + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public void afterCommit() { | |
| 109 | + registerCouponProducer.sendUserCreateMessage(user.getId()); | |
| 110 | + } | |
| 106 | 111 | |
| 112 | + }); | |
| 107 | 113 | return user; |
| 108 | 114 | } |
| 109 | 115 | ... | ... |