153 lines
5.7 KiB
Plaintext
153 lines
5.7 KiB
Plaintext
/// <summary>
|
|
/// 实名认证
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> RealAuthentication(string userName, string idCard, string deviceNumber)
|
|
{
|
|
if (string.IsNullOrEmpty(userName))
|
|
{
|
|
throw MessageBox.Show(ResonseCode.ParamError, "用户名为空");
|
|
}
|
|
if (string.IsNullOrEmpty(idCard))
|
|
{
|
|
throw MessageBox.Show(ResonseCode.ParamError, "身份证号为空");
|
|
}
|
|
var isVali = OtherExtensions.ValidateIDCard(idCard);
|
|
if (!isVali)
|
|
{
|
|
throw MessageBox.Show(ResonseCode.ParamError, "身份证号错误");
|
|
}
|
|
//判断用户是否实名认证过,并且不等于未成年人
|
|
if (UserInfo.IsRealName && !UserInfo.IsJuveniles)
|
|
{
|
|
throw MessageBox.Show(0, "此账号已实名认证成功,无需重复验证");
|
|
}
|
|
if (UserInfo.RealNameDateTimeLast != null && DateTime.Now.Subtract((UserInfo.RealNameDateTimeLast ?? DateTime.MinValue)).TotalSeconds < 10)
|
|
{
|
|
throw MessageBox.Show(ResonseCode.Error, "两次绑定身份证号时间间隔太短,请稍后再绑定~");
|
|
}
|
|
if (UserInfo.IsJuveniles && UserInfo.IdCard == idCard)
|
|
{
|
|
throw MessageBox.Show(0, "此账号已实名认证成功,无需重复验证");
|
|
}
|
|
if (UserInfo.RealAuthentCount > 10)
|
|
{
|
|
throw MessageBox.Show(0, "此账号今日实名认证次数已到达上限");
|
|
}
|
|
var (verify, age, sex, birthday) = OtherExtensions.GetIDCardBirthdayAgeSex(idCard);
|
|
var user = await Dao.DaoUser.Context.T_User.FirstOrDefaultAsync(it => it.Id == _UserId);
|
|
if (user == null)
|
|
{
|
|
throw MessageBox.Show(ResonseCode.NotFoundRecord, "用户不存在");
|
|
}
|
|
IIdCardVerify idCardVerify = this.GetIdCardVerify();
|
|
var isIdCardVerify = await idCardVerify.IdCardVerify(userName, idCard);
|
|
if (!isIdCardVerify)
|
|
{
|
|
//实名认证错误
|
|
T_User_RealAuthentication_Log t_User_RealAuthentication_Log1 = new T_User_RealAuthentication_Log()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
DeviceNumber = deviceNumber,
|
|
IdCard = idCard,
|
|
UserId = _UserId,
|
|
UserName = userName,
|
|
IsRewards = false,
|
|
RealResults = "认证失败",
|
|
Message = "认证失败"
|
|
};
|
|
await Dao.DaoExt.Context.T_User_RealAuthentication_Log.AddAsync(t_User_RealAuthentication_Log1);
|
|
await Dao.DaoExt.Context.SaveChangesAsync();
|
|
UserInfo.RealNameDateTimeLast = DateTime.Now;
|
|
UserInfo.RealAuthentCount++;
|
|
//保存用户信息缓存
|
|
await this.SaveUserInfoCacheChangesAsync();
|
|
throw MessageBox.Show(ResonseCode.NotFoundRecord, "身份证号错误");
|
|
|
|
}
|
|
//已经实名认证过了,但是认证的是未成年人
|
|
user.UserName = userName;
|
|
user.IDCard = idCard;
|
|
UserInfo.IsJuveniles = false;
|
|
if (verify)
|
|
{
|
|
if (age >= 18)
|
|
{
|
|
user.UserRealNameStatus = 1;
|
|
}
|
|
else
|
|
{
|
|
UserInfo.IsJuveniles = true;
|
|
user.UserRealNameStatus = 2;
|
|
}
|
|
}
|
|
await Dao.DaoUser.Context.SaveChangesAsync();
|
|
if (string.IsNullOrEmpty(deviceNumber))
|
|
{
|
|
deviceNumber = UserInfo.DeviceNumber;
|
|
}
|
|
var limitActionLogCount = await Dao.DaoUser.Context.T_User_LimitActionLog.CountAsync(it => it.UserId == _UserId && it.ActionType == (int)UserActionTypeEnum.ActionType.实名认证);
|
|
bool IsRewards = false;
|
|
string mes = "";
|
|
//如果之前用户未实名认证过,发放奖励
|
|
if (limitActionLogCount == 0)
|
|
{
|
|
|
|
//检查设备有没有发放过
|
|
var limitActionLogDeviceNumberCount = await Dao.DaoUser.Context.T_User_LimitActionLog.CountAsync(it => it.ActionType == (int)UserActionTypeEnum.ActionType.实名认证 && it.DeviceNumber == deviceNumber);
|
|
if (limitActionLogDeviceNumberCount == 0)
|
|
{
|
|
IsRewards = true;
|
|
var ip = HttpContextAccessor.HttpContext.GetClientIpAddress();
|
|
var day = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
|
|
//发放奖励
|
|
var limitActionLog = new T_User_LimitActionLog()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
CreateTimeDay = day,
|
|
ActionId = "",
|
|
ActionType = (int)UserActionTypeEnum.ActionType.实名认证,
|
|
DeviceNumber = deviceNumber,
|
|
Extend1 = "",
|
|
UserId = _UserId,
|
|
Ip = ip
|
|
};
|
|
await Dao.DaoUser.Context.T_User_LimitActionLog.AddAsync(limitActionLog);
|
|
await Dao.DaoUser.Context.SaveChangesAsync();
|
|
mes = $"奖励已经发送,钻石*10";
|
|
}
|
|
else
|
|
{
|
|
mes = $"用户设备号重复,不发放奖励";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mes = $"用户已经领取过奖励,不再发放奖励";
|
|
}
|
|
|
|
T_User_RealAuthentication_Log t_User_RealAuthentication_Log = new T_User_RealAuthentication_Log()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
DeviceNumber = deviceNumber,
|
|
IdCard = idCard,
|
|
UserId = _UserId,
|
|
UserName = userName,
|
|
IsRewards = IsRewards,
|
|
RealResults = "",
|
|
Message = mes
|
|
};
|
|
#region 保存缓存数据
|
|
UserInfo.UserName = userName;
|
|
UserInfo.IdCard = idCard;
|
|
UserInfo.IsRealName = true;
|
|
UserInfo.RealNameDateTimeLast = DateTime.Now;
|
|
UserInfo.RealAuthentCount++;
|
|
await this.SaveUserInfoCacheChangesAsync();
|
|
#endregion
|
|
await Dao.DaoExt.Context.T_User_RealAuthentication_Log.AddAsync(t_User_RealAuthentication_Log);
|
|
await Dao.DaoExt.Context.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|