|
@@ -1,5 +1,4 @@
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
-using Microsoft.AspNetCore.Identity;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using System;
|
|
|
using System.Diagnostics;
|
|
@@ -7,7 +6,6 @@ using System.Threading.Tasks;
|
|
|
using ZhonTai.Admin.Core.Attributes;
|
|
|
using ZhonTai.Admin.Core.Consts;
|
|
|
using ZhonTai.Admin.Core.Dto;
|
|
|
-using ZhonTai.Admin.Domain.User;
|
|
|
using ZhonTai.Admin.Services.Auth.Dto;
|
|
|
using ZhonTai.Admin.Services.DiTuiAPI.Dto;
|
|
|
using ZhonTai.Common.Helpers;
|
|
@@ -20,10 +18,8 @@ using System.Security.Claims;
|
|
|
using ZhonTai.Admin.Core.Auth;
|
|
|
using ZhonTai.Common.Extensions;
|
|
|
using System.Linq.Expressions;
|
|
|
-using ZhonTai.Admin.Domain.UserOrg;
|
|
|
-using ZhonTai.Admin.Domain.UserRole;
|
|
|
-using ZhonTai.Admin.Domain.UserStaff;
|
|
|
-using ZhonTai.Admin.Services.User.Dto;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using ZhonTai.Admin.Domain.Org;
|
|
|
|
|
|
namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
{
|
|
@@ -35,20 +31,24 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
[DynamicApi(Area = AdminConsts.DiTuiName)]
|
|
|
public class DiTuiAPIService : BaseService, IDiTuiAPIService, IDynamicApi
|
|
|
{
|
|
|
- private IPasswordHasher<PlatformUserEntity> _passwordHasher => LazyGetRequiredService<IPasswordHasher<PlatformUserEntity>>();
|
|
|
private readonly AppConfig _appConfig;
|
|
|
- private readonly IUserRepository _userRepository;
|
|
|
private readonly IPlatformUserRepository _platformUserRepository;
|
|
|
private readonly ITenantRepository _tenantRepository;
|
|
|
+ private readonly IOrgRepository _orgRepository;
|
|
|
+ private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
public DiTuiAPIService(
|
|
|
IPlatformUserRepository platformUserRepository,
|
|
|
AppConfig appConfig,
|
|
|
- ITenantRepository tenantRepository
|
|
|
+ ITenantRepository tenantRepository,
|
|
|
+ IHttpContextAccessor httpContextAccessor,
|
|
|
+ IOrgRepository orgRepository
|
|
|
)
|
|
|
{
|
|
|
_platformUserRepository = platformUserRepository;
|
|
|
_appConfig = appConfig;
|
|
|
_tenantRepository = tenantRepository;
|
|
|
+ _httpContextAccessor = httpContextAccessor;
|
|
|
+ _orgRepository = orgRepository;
|
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
@@ -162,7 +162,7 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 新增用户
|
|
|
+ /// 用户注册
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
@@ -172,12 +172,32 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
[AdminTransaction]
|
|
|
public virtual async Task<long> RegisterAsync(RegisterInput input)
|
|
|
{
|
|
|
+ var platform = _httpContextAccessor.HttpContext.Request.Headers["platform"];
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(input.InvitCode))
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception($"邀请码不可为空");
|
|
|
+ }
|
|
|
+ var org = await _orgRepository.Select.Where(a=> a.Code == platform).DisableGlobalFilter()
|
|
|
+ .FirstAsync(a => new { a.Name, a.TenantId });
|
|
|
+
|
|
|
Expression<Func<PlatformUserEntity, bool>> where = (a => a.Phone == input.Phone);
|
|
|
where = where.Or(input.Phone.NotNull(), a => a.Phone == input.Phone)
|
|
|
.Or(input.Name.NotNull(), a => a.Name == input.Name);
|
|
|
|
|
|
- var existsUser = await _platformUserRepository.Select.Where(where)
|
|
|
- .FirstAsync(a => new { a.Name, a.Phone });
|
|
|
+ var existsUser = await _platformUserRepository.Select.Where(where).DisableGlobalFilter().Where(a => a.TenantId == org.TenantId)
|
|
|
+ .FirstAsync(a => new { a.Name, a.Phone, a.TenantId });
|
|
|
+
|
|
|
+
|
|
|
+ //fsql.Select<TestAddEnum>().DisableGlobalFilter().ToList();
|
|
|
+ var parentUser = await _platformUserRepository.Select.Where(a =>a.TenantId == org.TenantId && a.InviteCode == input.InvitCode).DisableGlobalFilter()
|
|
|
+ .ToOneAsync();
|
|
|
+ //.FirstAsync(a => new { a.Name, a.Phone, a.TenantId, a.Id,a.ParentId });
|
|
|
+
|
|
|
+ if (parentUser == null)
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception($"未找到邀请人,请确认邀请码");
|
|
|
+ }
|
|
|
|
|
|
if (existsUser != null)
|
|
|
{
|
|
@@ -210,6 +230,9 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
entity.Password = MD5Encrypt.Encrypt32(input.Password);
|
|
|
// 注册口注册用户皆为下级角色
|
|
|
entity.Role = "2";
|
|
|
+ entity.ParentId = parentUser.ParentId + parentUser.Id + "_";
|
|
|
+ entity.TenantId = parentUser.TenantId;
|
|
|
+
|
|
|
var user = await _platformUserRepository.InsertAsync(entity);
|
|
|
var userId = user.Id;
|
|
|
|