|
|
@ -43,6 +43,8 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
private readonly WechatOAuth _wechatOAuth; //微信权限服务
|
|
|
|
private readonly WechatOAuth _wechatOAuth; //微信权限服务
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor; //http服务
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor; //http服务
|
|
|
|
private readonly IEventPublisher _eventPublisher; //事件写入服务
|
|
|
|
private readonly IEventPublisher _eventPublisher; //事件写入服务
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<InviteUserPos> invitaitionRey;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<MiniRecharge> rechargeRep; //充值仓储
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取配置文件
|
|
|
|
/// 获取配置文件
|
|
|
@ -60,6 +62,8 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
SqlSugarRepository<Company> CompanyRep,
|
|
|
|
SqlSugarRepository<Company> CompanyRep,
|
|
|
|
SqlSugarRepository<MiniPayTake> payTakeRep,
|
|
|
|
SqlSugarRepository<MiniPayTake> payTakeRep,
|
|
|
|
SqlSugarRepository<SysConfig> sysConfigRep,
|
|
|
|
SqlSugarRepository<SysConfig> sysConfigRep,
|
|
|
|
|
|
|
|
SqlSugarRepository<InviteUserPos> invitaitionRey,
|
|
|
|
|
|
|
|
SqlSugarRepository<MiniRecharge> rechargeRep,
|
|
|
|
ISysCacheService sysCacheService,
|
|
|
|
ISysCacheService sysCacheService,
|
|
|
|
ICacheService cacheService,
|
|
|
|
ICacheService cacheService,
|
|
|
|
WechatOAuth wechatOAuth,
|
|
|
|
WechatOAuth wechatOAuth,
|
|
|
@ -77,6 +81,8 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
this.payTakeRep = payTakeRep;
|
|
|
|
this.payTakeRep = payTakeRep;
|
|
|
|
this._sysCacheService= sysCacheService;
|
|
|
|
this._sysCacheService= sysCacheService;
|
|
|
|
this._sysConfigRep= sysConfigRep;
|
|
|
|
this._sysConfigRep= sysConfigRep;
|
|
|
|
|
|
|
|
this.invitaitionRey = invitaitionRey;
|
|
|
|
|
|
|
|
this.rechargeRep= rechargeRep;
|
|
|
|
_wechatOAuth = wechatOAuth;
|
|
|
|
_wechatOAuth = wechatOAuth;
|
|
|
|
_oauthConfig = options.Value.Wechat;
|
|
|
|
_oauthConfig = options.Value.Wechat;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -94,9 +100,9 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
Company company = new Company();
|
|
|
|
Company company = new Company();
|
|
|
|
|
|
|
|
|
|
|
|
//读取凭证
|
|
|
|
//读取凭证
|
|
|
|
var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.code);
|
|
|
|
var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.Code);
|
|
|
|
//解析电话
|
|
|
|
//解析电话
|
|
|
|
var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.encryptedDataStr, tokenModel.SessionKey, phoneModel.iv);
|
|
|
|
var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.EncryptedDataStr, tokenModel.SessionKey, phoneModel.Iv);
|
|
|
|
|
|
|
|
|
|
|
|
//查询系统用户
|
|
|
|
//查询系统用户
|
|
|
|
var sysUser = this._sysUserRep.AsQueryable()
|
|
|
|
var sysUser = this._sysUserRep.AsQueryable()
|
|
|
@ -136,7 +142,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//区分不同类型账号
|
|
|
|
//区分不同类型账号
|
|
|
|
if (phoneModel.logInType ==(int)UserEnum.JOB)
|
|
|
|
if (phoneModel.LogInType ==(int)UserEnum.JOB)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -178,8 +184,31 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wxUser.IsEmpty() || sysUser.IsEmpty())
|
|
|
|
if (wxUser.IsEmpty() || sysUser.IsEmpty())
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
throw Oops.Oh(ErrorCode.xg1002);
|
|
|
|
|
|
|
|
//判断是否存在邀请
|
|
|
|
|
|
|
|
if(phoneModel.Scene != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//判断当前用户是否被邀请过
|
|
|
|
|
|
|
|
var invi = await this.invitaitionRey.FirstOrDefaultAsync(x => x.UserID == UserManager.UserId);
|
|
|
|
|
|
|
|
if (invi.IsNullOrZero())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var invres = await this.invitaitionRey.FirstOrDefaultAsync(x => x.InviteID == phoneModel.Scene);
|
|
|
|
|
|
|
|
//未被邀请
|
|
|
|
|
|
|
|
var invrey = await this.invitaitionRey.InsertAsync(new InviteUserPos()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UserID = UserManager.UserId,
|
|
|
|
|
|
|
|
InviteUserID = (long)phoneModel.Scene,
|
|
|
|
|
|
|
|
InviteID = invres.InviteID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (invrey > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//附加奖励给邀请人
|
|
|
|
|
|
|
|
UtilService utilService = new UtilService(this.rechargeRep);
|
|
|
|
|
|
|
|
utilService.Reward((long)phoneModel.Scene, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id);
|
|
|
|
var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id);
|
|
|
|
|
|
|
|
|
|
|
@ -249,14 +278,14 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
Company company = new Company();
|
|
|
|
Company company = new Company();
|
|
|
|
AuthUserOut authUserOut = new AuthUserOut();
|
|
|
|
AuthUserOut authUserOut = new AuthUserOut();
|
|
|
|
//验证电话和验证码一致
|
|
|
|
//验证电话和验证码一致
|
|
|
|
var verIfy = await this.cacheService.GetVerifyCode(phoneModel.phone);
|
|
|
|
var verIfy = await this.cacheService.GetVerifyCode(phoneModel.Phone);
|
|
|
|
if (verIfy != phoneModel.checkingCode)
|
|
|
|
if (verIfy != phoneModel.CheckingCode)
|
|
|
|
throw new Exception("验证码错误");
|
|
|
|
throw new Exception("验证码错误");
|
|
|
|
|
|
|
|
|
|
|
|
//查询系统用户
|
|
|
|
//查询系统用户
|
|
|
|
var sysUser = this._sysUserRep.AsQueryable()
|
|
|
|
var sysUser = this._sysUserRep.AsQueryable()
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
.First(x => x.Phone == phoneModel.phone.ToString());
|
|
|
|
.First(x => x.Phone == phoneModel.Phone.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//账号不存在 生成系统账号
|
|
|
|
//账号不存在 生成系统账号
|
|
|
@ -264,7 +293,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser()
|
|
|
|
sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Account = phoneModel.phone.ToString(),
|
|
|
|
Account = phoneModel.Phone.ToString(),
|
|
|
|
AdminType = AdminType.None,
|
|
|
|
AdminType = AdminType.None,
|
|
|
|
Avatar = "https://gdzongzhi.com/assets/img/logo.png",
|
|
|
|
Avatar = "https://gdzongzhi.com/assets/img/logo.png",
|
|
|
|
Birthday = DateTime.Now,
|
|
|
|
Birthday = DateTime.Now,
|
|
|
@ -275,10 +304,10 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
Status = CommonStatus.ENABLE,
|
|
|
|
Status = CommonStatus.ENABLE,
|
|
|
|
Email = null,
|
|
|
|
Email = null,
|
|
|
|
IsDeleted = false,
|
|
|
|
IsDeleted = false,
|
|
|
|
Name = phoneModel.phone.ToString(),
|
|
|
|
Name = phoneModel.Phone.ToString(),
|
|
|
|
Password = MD5Encryption.Encrypt("123456"),
|
|
|
|
Password = MD5Encryption.Encrypt("123456"),
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
Phone = phoneModel.phone.ToString(),
|
|
|
|
Phone = phoneModel.Phone.ToString(),
|
|
|
|
NickName = "",
|
|
|
|
NickName = "",
|
|
|
|
Tel = null,
|
|
|
|
Tel = null,
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -286,7 +315,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//读取凭证
|
|
|
|
//读取凭证
|
|
|
|
var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.code);
|
|
|
|
var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.Code);
|
|
|
|
|
|
|
|
|
|
|
|
var wxUser = await this.Baseuser.AsQueryable()
|
|
|
|
var wxUser = await this.Baseuser.AsQueryable()
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
.Filter("TenantId", true)
|
|
|
@ -294,7 +323,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//区分不同类型账号
|
|
|
|
//区分不同类型账号
|
|
|
|
if (phoneModel.logInType == (int)UserEnum.JOB)
|
|
|
|
if (phoneModel.LogInType == (int)UserEnum.JOB)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
if (wxUser.IsEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -309,7 +338,7 @@ namespace GDZZ.Application.Service.Auth
|
|
|
|
OpenID = tokenModel.OpenId,
|
|
|
|
OpenID = tokenModel.OpenId,
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
TenantId = 392820661919813,
|
|
|
|
Type = (int)UserEnum.JOB,
|
|
|
|
Type = (int)UserEnum.JOB,
|
|
|
|
UserName = phoneModel.phone.ToString(),
|
|
|
|
UserName = phoneModel.Phone.ToString(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|