From 5054391f6b71a40b827db6c719e18a21645f7e0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com>
Date: Sun, 3 Nov 2024 01:38:12 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E8=B4=A6=E5=8F=B7?=
=?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Etos/BindAccountEto.cs | 10 ++
.../BindAccountForBbsEventHandler.cs | 47 ++++++++++
.../InvitationCodeGetOutputDto.cs | 20 ++++
.../WeChatMiniProgramAccountService.cs | 26 +++++-
.../Services/InvitationCodeService.cs | 67 ++++---------
.../CollectiblesUserExtraInfoEntity.cs | 27 ------
.../Entities/InvitationCodeAggregateRoot.cs | 37 +++++++-
.../BindAccountForCollectiblesEventHandler.cs | 93 +++++++++++++++++++
.../Managers/InvitationCodeManager.cs | 87 +++++++++++++++++
9 files changed, 329 insertions(+), 85 deletions(-)
create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/BindAccountEto.cs
create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/BindAccountForBbsEventHandler.cs
create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/InvitationCode/InvitationCodeGetOutputDto.cs
delete mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Entities/CollectiblesUserExtraInfoEntity.cs
create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/EventHandlers/BindAccountForCollectiblesEventHandler.cs
create mode 100644 Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Domain/Managers/InvitationCodeManager.cs
diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/BindAccountEto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/BindAccountEto.cs
new file mode 100644
index 00000000..0ab6ad5b
--- /dev/null
+++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain.Shared/Etos/BindAccountEto.cs
@@ -0,0 +1,10 @@
+namespace Yi.Framework.Bbs.Domain.Shared.Etos;
+
+///
+/// 临时用户绑定到正式用户
+///
+public class BindAccountEto
+{
+ public Guid NewUserId { get; set; }
+ public Guid OldUserId { get; set; }
+}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/BindAccountForBbsEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/BindAccountForBbsEventHandler.cs
new file mode 100644
index 00000000..e6fc1257
--- /dev/null
+++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/BindAccountForBbsEventHandler.cs
@@ -0,0 +1,47 @@
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.EventBus;
+using Yi.Framework.Bbs.Domain.Entities;
+using Yi.Framework.Bbs.Domain.Shared.Etos;
+using Yi.Framework.Rbac.Domain.Entities;
+using Yi.Framework.SqlSugarCore.Abstractions;
+
+namespace Yi.Framework.Bbs.Domain.EventHandlers;
+
+///
+/// 临时账号绑定到正式账号,钱钱 (累加),禁用临时账号(修改)
+///
+public class BindAccountForBbsEventHandler : ILocalEventHandler, ITransientDependency
+{
+ private readonly ISqlSugarRepository _bbsUserRepository;
+ private readonly ISqlSugarRepository _userRepository;
+
+ public BindAccountForBbsEventHandler(ISqlSugarRepository bbsUserRepository,
+ ISqlSugarRepository userRepository)
+ {
+ _bbsUserRepository = bbsUserRepository;
+ _userRepository = userRepository;
+ }
+
+ public async Task HandleEventAsync(BindAccountEto eventData)
+ {
+ //禁用临时用户
+ var oldUser = await _userRepository.GetFirstAsync(x => x.Id == eventData.OldUserId);
+ if (oldUser is null || oldUser.State == false)
+ {
+ throw new UserFriendlyException("无法将无效用户进行绑定");
+ }
+
+ oldUser.State = false;
+ await _userRepository.UpdateAsync(oldUser);
+
+
+ //账户钱转移
+ var bbsOldUser = await _bbsUserRepository.GetFirstAsync(x => x.UserId == eventData.OldUserId);
+ var bbsNewUser = await _bbsUserRepository.GetFirstAsync(x => x.UserId == eventData.NewUserId);
+ if (bbsNewUser is not null)
+ {
+ bbsNewUser.Money += bbsOldUser?.Money ?? 0;
+ await _bbsUserRepository.UpdateAsync(bbsNewUser);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/InvitationCode/InvitationCodeGetOutputDto.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/InvitationCode/InvitationCodeGetOutputDto.cs
new file mode 100644
index 00000000..ead2e169
--- /dev/null
+++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/InvitationCode/InvitationCodeGetOutputDto.cs
@@ -0,0 +1,20 @@
+namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.InvitationCode;
+
+public class InvitationCodeGetOutputDto
+{
+ ///
+ /// 是否填写了邀请码(是否被邀请)
+ ///
+ public bool IsInvited { get; set; }
+
+
+ ///
+ /// 积分-邀请数量
+ ///
+ public int PointsNumber { get; set; }
+
+ ///
+ /// 邀请码
+ ///
+ public string InvitationCode { get; set; }
+}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs
index ae8ba5bf..5e178198 100644
--- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs
+++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs
@@ -1,8 +1,13 @@
-using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
+using Volo.Abp.EventBus.Local;
+using Volo.Abp.Users;
+using Yi.Framework.Bbs.Domain.Shared.Etos;
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Account;
using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts;
using Yi.Framework.DigitalCollectibles.Domain.Shared.Enums;
+using Yi.Framework.DigitalCollectibles.Domain.Shared.Etos;
using Yi.Framework.Rbac.Application.Contracts.Dtos.Account;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Shared.Enums;
@@ -19,13 +24,14 @@ public class WeChatMiniProgramAccountService : ApplicationService
private readonly IWeChatMiniProgramManager _weChatMiniProgramManager;
private readonly IAuthService _authService;
private readonly IAccountService _accountService;
-
+ private readonly ILocalEventBus _localEventBus;
public WeChatMiniProgramAccountService(IWeChatMiniProgramManager weChatMiniProgramManager, IAuthService authService,
- IAccountService accountService)
+ IAccountService accountService, ILocalEventBus localEventBus)
{
_weChatMiniProgramManager = weChatMiniProgramManager;
_authService = authService;
_accountService = accountService;
+ _localEventBus = localEventBus;
}
///
@@ -63,8 +69,11 @@ public class WeChatMiniProgramAccountService : ApplicationService
///
///
[HttpPost("wechat/mini-program/account/bind")]
+ [Authorize]
public async Task PostBindAsync(BindInput input)
{
+ var userId = CurrentUser.GetId();
+
//验证手机号
await _accountService.ValidationPhoneCaptchaAsync(ValidationPhoneTypeEnum.Bind, input.Phone, input.Code);
//校验手机号与验证码
@@ -80,8 +89,17 @@ public class WeChatMiniProgramAccountService : ApplicationService
//验证手机号的验证码
var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(input.JsCode))).openid;
-
await PostBindToAuthAsync(userInfo.User.Id, openId, userInfo.User.UserName);
+
+ //发送账号绑定的事件,不同领域对账号数据进行迁移
+ //bbs:钱钱 (累加),禁用临时账号(修改)
+ //dc: 价值、积分 (累加)
+ await _localEventBus.PublishAsync(new BindAccountEto
+ {
+ NewUserId = userInfo.User.Id,
+ OldUserId = userId
+ },false);
+
}
private async Task PostBindToAuthAsync(Guid userId, string openId, string? name = null)
diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/InvitationCodeService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/InvitationCodeService.cs
index 1fa2be68..f76c927b 100644
--- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/InvitationCodeService.cs
+++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/InvitationCodeService.cs
@@ -2,7 +2,9 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
using Volo.Abp.Users;
+using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.InvitationCode;
using Yi.Framework.DigitalCollectibles.Domain.Entities;
+using Yi.Framework.DigitalCollectibles.Domain.Managers;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.DigitalCollectibles.Application.Services;
@@ -12,11 +14,11 @@ namespace Yi.Framework.DigitalCollectibles.Application.Services;
///
public class InvitationCodeService : ApplicationService
{
- private readonly ISqlSugarRepository _repository;
+ private readonly InvitationCodeManager _invitationCodeManager;
- public InvitationCodeService(ISqlSugarRepository repository)
+ public InvitationCodeService(InvitationCodeManager invitationCodeManager)
{
- _repository = repository;
+ _invitationCodeManager = invitationCodeManager;
}
///
@@ -24,16 +26,17 @@ public class InvitationCodeService : ApplicationService
///
///
[Authorize]
- public async Task