|
|
|
@ -16,6 +16,8 @@ using Furion.DynamicApiController;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using GDZZ.Application.Help;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using GDZZ.Core.Service;
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application.Service.Auth
|
|
|
|
|
{
|
|
|
|
@ -27,7 +29,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _sysTenantRep; //租户仓储
|
|
|
|
|
private readonly SqlSugarRepository<SeIF> Self; //职业仓储
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<Company> CompanyRep;
|
|
|
|
|
private readonly SqlSugarRepository<MiniRecharge> rechargeRep; //充值仓储
|
|
|
|
|
private readonly SqlSugarRepository<MiniPayTake> payTakeRep; //支付仓储
|
|
|
|
|
#endregion
|
|
|
|
@ -51,11 +53,14 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
SqlSugarRepository<SysTenant> sysTenantRep,
|
|
|
|
|
SqlSugarRepository<SysUser> sysUserRep,
|
|
|
|
|
SqlSugarRepository<SeIF> Self,
|
|
|
|
|
SqlSugarRepository<Company> CompanyRep,
|
|
|
|
|
SqlSugarRepository<MiniPayTake> payTakeRep,
|
|
|
|
|
ICacheService cacheService,
|
|
|
|
|
WechatOAuth wechatOAuth,
|
|
|
|
|
IEventPublisher eventPublisher,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
|
|
{
|
|
|
|
|
this.CompanyRep= CompanyRep;
|
|
|
|
|
this._eventPublisher= eventPublisher;
|
|
|
|
|
this._sysUserRep = sysUserRep;
|
|
|
|
|
this._sysTenantRep = sysTenantRep;
|
|
|
|
@ -63,6 +68,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
this._httpContextAccessor = httpContextAccessor;
|
|
|
|
|
this.cacheService= cacheService;
|
|
|
|
|
this.Self = Self;
|
|
|
|
|
this.payTakeRep = payTakeRep;
|
|
|
|
|
_wechatOAuth = wechatOAuth;
|
|
|
|
|
_oauthConfig = options.Value.Wechat;
|
|
|
|
|
}
|
|
|
|
@ -76,9 +82,11 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
public async Task<AuthUserOut> SignInAsync(PhoneModel phoneModel)
|
|
|
|
|
{
|
|
|
|
|
AuthUserOut authUserOut = new AuthUserOut();
|
|
|
|
|
|
|
|
|
|
Company company = new Company();
|
|
|
|
|
|
|
|
|
|
//读取凭证
|
|
|
|
|
var tokenModel = await this._wechatOAuth.GetAccessTokenAsync(phoneModel.code);
|
|
|
|
|
|
|
|
|
|
//解析电话
|
|
|
|
|
var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.encryptedDataStr, tokenModel.SessionKey, phoneModel.iv);
|
|
|
|
|
|
|
|
|
@ -87,6 +95,14 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
|
.First(x => x.Phone == phoneInfo.PhoneNumber);
|
|
|
|
|
|
|
|
|
|
var wxUser = await this.Baseuser.AsQueryable()
|
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
|
.Where(x => x.OpenID == tokenModel.OpenId).SingleAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//账号不存在 生成系统账号
|
|
|
|
|
if (sysUser.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser()
|
|
|
|
@ -111,10 +127,9 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var wxUser = await this.Baseuser.AsQueryable()
|
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
|
.Where(x => x.OpenID == tokenModel.OpenId).SingleAsync();
|
|
|
|
|
|
|
|
|
|
//区分不同类型账号
|
|
|
|
|
if (phoneModel.logInType ==(int)UserEnum.JOB)
|
|
|
|
|
{
|
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
wxUser = await this.Baseuser.InsertReturnEntityAsync(new BaseUser()
|
|
|
|
@ -124,17 +139,31 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
CreatedUserName = sysUser.Name,
|
|
|
|
|
AvatarUrl = "https://gdzongzhi.com/assets/img/logo.png",
|
|
|
|
|
Status = CommonStatus.ENABLE,
|
|
|
|
|
Status =(int)CommonStatus.ENABLE,
|
|
|
|
|
OpenID = tokenModel.OpenId,
|
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
|
Type = UserEnum.JOB,
|
|
|
|
|
Type = (int)UserEnum.JOB,
|
|
|
|
|
UserName = phoneInfo.PhoneNumber,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//如果是企业账号,应该是绑定了企业租户信息
|
|
|
|
|
if (wxUser.IsEmpty()|| wxUser.CompanyID.IsNullOrZero())
|
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
|
|
|
|
|
|
//获取公司信息
|
|
|
|
|
company = await this.CompanyRep.SingleAsync(x=>x.Id == wxUser.CompanyID);
|
|
|
|
|
authUserOut.companyDto = company.Adapt<CompanyDto>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (wxUser.IsEmpty() || sysUser.IsEmpty())
|
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id);
|
|
|
|
|
|
|
|
|
|
// 获取加密后的密码
|
|
|
|
@ -143,13 +172,13 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
// 验证账号是否被冻结
|
|
|
|
|
if (sysUser.Status == CommonStatus.DISABLE)
|
|
|
|
|
throw Oops.Oh(ErrorCode.D1017);
|
|
|
|
|
|
|
|
|
|
//获取对应租户
|
|
|
|
|
var tenant = this._sysTenantRep.Single(sysUser.TenantId);
|
|
|
|
|
|
|
|
|
|
if (tenant.IsNullOrZero())
|
|
|
|
|
throw Oops.Oh(ErrorCode.F1001);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 生成Token令牌
|
|
|
|
|
authUserOut.Token = JWTEncryption.Encrypt(new Dictionary<string, object>
|
|
|
|
|
{
|
|
|
|
@ -180,9 +209,11 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
authUserOut.Sex = sysUser.Sex;
|
|
|
|
|
authUserOut.UserId = sysUser.Id;
|
|
|
|
|
authUserOut.UserName = sysUser.Name;
|
|
|
|
|
authUserOut.Self = Self.IsEmpty() ? "未填写" : Self.Name;
|
|
|
|
|
authUserOut.Type = UserEnum.JOB;
|
|
|
|
|
authUserOut.Self = Self.IsEmpty() ? null : Self.Name;
|
|
|
|
|
authUserOut.Type = (UserEnum)wxUser.Type;
|
|
|
|
|
authUserOut.OpenID = tokenModel.OpenId;
|
|
|
|
|
authUserOut.Tenant = tenant.Adapt<TenantOutput>();
|
|
|
|
|
authUserOut.Describe = wxUser.Describe;
|
|
|
|
|
|
|
|
|
|
await this.cacheService.SetUserInfoAsync(authUserOut, authUserOut.UserId);
|
|
|
|
|
return authUserOut;
|
|
|
|
@ -200,17 +231,11 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
return await this.cacheService.GetUserInfoAsync(UserManager.UserId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 微信支付
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="productId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("Mini/WxPay")]
|
|
|
|
|
public async Task<dynamic> WxPay(AuthUserInput authUserInput)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|