| | |
| | | import com.ruoyi.system.config.ICBCConfig; |
| | | import com.ruoyi.system.enums.BigGiftPackageOrderStatusEnum; |
| | | import com.ruoyi.system.enums.PhysicalGoodsOrderStatusEnum; |
| | | import com.ruoyi.system.model.TAppUser; |
| | | import com.ruoyi.system.model.TBigGiftPackageOrder; |
| | | import com.ruoyi.system.model.TPhysicalGoodsOrder; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | private final TPhysicalGoodsOrderService physicalGoodsOrderService; |
| | | |
| | | private final TCommissionTransactionFlowService commissionTransactionFlowService; |
| | | |
| | | private final TAppUserService appUserService; |
| | | |
| | | private final ISysUserService sysUserService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | order.getAppUserId() |
| | | ); |
| | | log.info("订单{}分佣计算完成", order.getCode()); |
| | | |
| | | // 处理用户推荐状态和公司关联 |
| | | processUserReferrerAndCompany(order.getAppUserId()); |
| | | } else { |
| | | log.error("尾款支付订单号{}【工商银行】大礼包尾款支付失败,错误信息:{}", finalPayOrderCode, bizContent.getString("return_msg")); |
| | | } |
| | |
| | | physicalGoodsOrderService.updateById(order); |
| | | log.info("订单{}状态更新为完成支付", orderCode); |
| | | |
| | | // 处理用户推荐状态和公司关联 |
| | | processUserReferrerAndCompany(order.getAppUserId()); |
| | | |
| | | } else { |
| | | log.error("订单{}【工商银行】实物商品支付失败,错误信息:{}", orderCode, bizContent.getString("return_msg")); |
| | | order.setStatus(PhysicalGoodsOrderStatusEnum.CANCELED.getCode()); |
| | |
| | | // 启用生效日,不计算分佣(由定时任务处理) |
| | | log.info("订单{}启用生效日,延迟计算分佣", order.getCode()); |
| | | } |
| | | |
| | | // 处理用户推荐状态和公司关联 |
| | | processUserReferrerAndCompany(order.getAppUserId()); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理用户推荐状态和公司关联 |
| | | * 支付成功后调用此方法更新用户信息 |
| | | * |
| | | * @param appUserId 下单用户ID |
| | | */ |
| | | private void processUserReferrerAndCompany(Integer appUserId) { |
| | | if (appUserId == null) { |
| | | return; |
| | | } |
| | | |
| | | TAppUser appUser = appUserService.getById(appUserId); |
| | | if (appUser == null) { |
| | | log.warn("用户{}不存在,跳过推荐状态和公司关联处理", appUserId); |
| | | return; |
| | | } |
| | | |
| | | boolean needUpdate = false; |
| | | |
| | | // 1. 更新推荐状态:如果 referrerUserId 不为空且 referrerStatus=1,则更新为 referrerStatus=2 |
| | | if (appUser.getReferrerUserId() != null && Integer.valueOf(1).equals(appUser.getReferrerStatus())) { |
| | | appUser.setReferrerStatus(2); |
| | | needUpdate = true; |
| | | log.info("用户{}推荐状态从临时(1)更新为正式(2)", appUserId); |
| | | } |
| | | |
| | | // 2. 关联公司:如果用户 companyId 为空 |
| | | if (appUser.getCompanyId() == null) { |
| | | Integer companyId = null; |
| | | |
| | | // 优先使用 referrerSysUserId 对应的 SysUser 的 companyId |
| | | if (appUser.getReferrerSysUserId() != null) { |
| | | SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appUser.getReferrerSysUserId())); |
| | | if (sysUser != null && sysUser.getCompanyId() != null) { |
| | | companyId = sysUser.getCompanyId(); |
| | | log.info("用户{}通过股东(SysUser:{})关联公司{}", appUserId, appUser.getReferrerSysUserId(), companyId); |
| | | } |
| | | } |
| | | |
| | | // 如果 referrerSysUserId 为空或对应的 SysUser 没有 companyId,则使用 referrerUserId 对应的 TAppUser 的 companyId |
| | | if (companyId == null && appUser.getReferrerUserId() != null) { |
| | | TAppUser referrerAppUser = appUserService.getById(appUser.getReferrerUserId()); |
| | | if (referrerAppUser != null && referrerAppUser.getCompanyId() != null) { |
| | | companyId = referrerAppUser.getCompanyId(); |
| | | log.info("用户{}通过推荐人(TAppUser:{})关联公司{}", appUserId, appUser.getReferrerUserId(), companyId); |
| | | } |
| | | } |
| | | |
| | | if (companyId != null) { |
| | | appUser.setCompanyId(companyId); |
| | | needUpdate = true; |
| | | } |
| | | } |
| | | |
| | | // 3. 更新用户信息 |
| | | if (needUpdate) { |
| | | appUserService.updateById(appUser); |
| | | log.info("用户{}信息更新完成,referrerStatus={},companyId={}", appUserId, appUser.getReferrerStatus(), appUser.getCompanyId()); |
| | | } |
| | | } |
| | | |
| | | } |