添加注销功能
This commit is contained in:
parent
e9c8499fca
commit
3ee3d60539
|
|
@ -81,7 +81,7 @@ namespace HuanMeng.MiaoYu.Code.Users.UserAccount.PhoneAccount
|
|||
Key = phone,
|
||||
Remarks = "登录验证码",
|
||||
VerificationType = 0,
|
||||
// TenantId = dao.daoDbMiaoYu.context?.TenantInfo?.TenantId ?? Guid.Empty,
|
||||
// TenantId = dao.daoDbMiaoYu.context?.TenantInfo?.TenantId ?? Guid.Empty,
|
||||
};
|
||||
dao.daoDbMiaoYu.Add(t_Verification_Code);
|
||||
dao.daoDbMiaoYu.context.SaveChanges();
|
||||
|
|
@ -114,12 +114,12 @@ namespace HuanMeng.MiaoYu.Code.Users.UserAccount.PhoneAccount
|
|||
throw new ArgumentNullException("验证码已失效");
|
||||
}
|
||||
}
|
||||
var userlogin = dao.daoDbMiaoYu.context.T_User_Phone_Account.Where(it => it.PhoneNum == phoneLoginParams.PhoneNumber).FirstOrDefault();
|
||||
var userlogin = dao.daoDbMiaoYu.context.T_User_Phone_Account.Where(it => it.PhoneNum == phoneLoginParams.PhoneNumber && !it.IsLogout).FirstOrDefault();
|
||||
T_User? user = null;
|
||||
T_User_Data? userData = null;
|
||||
if (userlogin != null)
|
||||
{
|
||||
user = await dao.daoDbMiaoYu.context.T_User.FirstOrDefaultAsync(it => it.Id == userlogin.UserId);
|
||||
user = await dao.daoDbMiaoYu.context.T_User.FirstOrDefaultAsync(it => it.Id == userlogin.UserId && it.State == 0);
|
||||
userData = await dao.daoDbMiaoYu.context.T_User_Data.FirstOrDefaultAsync(it => it.UserId == userlogin.UserId);
|
||||
}
|
||||
if (user == null)
|
||||
|
|
@ -137,15 +137,16 @@ namespace HuanMeng.MiaoYu.Code.Users.UserAccount.PhoneAccount
|
|||
RegisterType = 1,
|
||||
TenantId = dao.daoDbMiaoYu.context.TenantInfo.TenantId,
|
||||
UserName = phoneLoginParams.PhoneNumber,
|
||||
State = 0,
|
||||
|
||||
};
|
||||
dao.daoDbMiaoYu.context.T_User.Add(user);
|
||||
dao.daoDbMiaoYu.context.SaveChanges();
|
||||
|
||||
//给用户添加货币
|
||||
user.ConsumeMoney(UserCurrencyType.聊天次数, 10, dao,"新用户赠送10次聊天次数");
|
||||
user.ConsumeMoney(UserCurrencyType.聊天次数, 10, dao, "新用户赠送10次聊天次数");
|
||||
}
|
||||
|
||||
|
||||
if (userData == null)
|
||||
{
|
||||
userData = new T_User_Data()
|
||||
|
|
@ -174,6 +175,7 @@ namespace HuanMeng.MiaoYu.Code.Users.UserAccount.PhoneAccount
|
|||
NikeName = user.NickName,
|
||||
TenantId = dao.daoDbMiaoYu.context.TenantInfo.TenantId,
|
||||
UpdatedAt = DateTime.Now,
|
||||
IsLogout = false
|
||||
};
|
||||
dao.daoDbMiaoYu.context.Add(userlogin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,5 +149,32 @@ namespace HuanMeng.MiaoYu.Code.Users
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 账号注销
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public async Task<BaseResponse<bool>> Logout()
|
||||
{
|
||||
if (_UserId == 0)
|
||||
{
|
||||
throw new Exception("请先登录");
|
||||
}
|
||||
//
|
||||
var user = await Dao.daoDbMiaoYu.context.T_User.Where(it => it.Id == _UserId).FirstOrDefaultAsync();
|
||||
//
|
||||
var userAccount = await Dao.daoDbMiaoYu.context.T_User_Phone_Account.Where(it => it.UserId == _UserId).FirstOrDefaultAsync();
|
||||
if (user == null || userAccount == null)
|
||||
{
|
||||
|
||||
throw new Exception("账号不存在");
|
||||
}
|
||||
user.State = 1;
|
||||
userAccount.IsLogout = true;
|
||||
Dao.daoDbMiaoYu.context.SaveChanges();
|
||||
return new BaseResponse<bool>(ResonseCode.Success, "", true);
|
||||
//userAccount.p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -707,6 +707,7 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
|
|||
.IsUnicode(false)
|
||||
.HasComment("绑定的手机号");
|
||||
entity.Property(e => e.RegisterType).HasComment("首次注册方式");
|
||||
entity.Property(e => e.State).HasComment("0正常,1注销");
|
||||
entity.Property(e => e.TenantId).HasComment("租户Id");
|
||||
entity.Property(e => e.UpdatedAt)
|
||||
.HasComment("修改时间")
|
||||
|
|
@ -887,6 +888,7 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext
|
|||
entity.Property(e => e.CreatedAt)
|
||||
.HasComment("修改时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.IsLogout).HasComment("是否注销");
|
||||
entity.Property(e => e.LastLoginAt)
|
||||
.HasComment("最后一次登录时间")
|
||||
.HasColumnType("datetime");
|
||||
|
|
|
|||
|
|
@ -68,4 +68,9 @@ public partial class T_User: MultiTenantEntity
|
|||
/// Ip地址
|
||||
/// </summary>
|
||||
public virtual string? Ip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0正常,1注销
|
||||
/// </summary>
|
||||
public virtual int State { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,4 +48,9 @@ public partial class T_User_Phone_Account: MultiTenantEntity
|
|||
/// 用户昵称
|
||||
/// </summary>
|
||||
public virtual string? NikeName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否注销
|
||||
/// </summary>
|
||||
public virtual bool IsLogout { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Numerics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
|
@ -47,7 +49,7 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
|
|||
UserBLL userBLL = new UserBLL(ServiceProvider);
|
||||
return await userBLL.SendPhoneNumber(phone.PhoneNumber);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 登录- 登录
|
||||
/// </summary>
|
||||
|
|
@ -106,5 +108,16 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
|
|||
var obj = JsonConvert.DeserializeObject<ShopInfoDto>("{\"Mall\":[{\"PropId\":1,\"PropName\":\"记忆卡1\",\"PropCount\":100,\"PropType\":0,\"Price\":10,\"PriceType\":0,\"ImgUrl\":\"https://cos.shhuanmeng.com/image/20240718110512.png\"},{\"PropId\":2,\"PropName\":\"记忆卡2\",\"PropCount\":100,\"PropType\":0,\"Price\":20,\"PriceType\":0,\"ImgUrl\":\"https://cos.shhuanmeng.com/image/20240718110518.png\"}],\"Purchased\":[{\"PropId\":2,\"PropName\":\"记忆卡2\",\"PropCount\":100,\"PropType\":0,\"Price\":20,\"PriceType\":0,\"ImgUrl\":\"https://cos.shhuanmeng.com/image/20240718110518.png\",\"BuyingTime\":\"2024-07-09 03:33:09.563\"}]}");
|
||||
return new BaseResponse<ShopInfoDto>(ResonseCode.Success, "", obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注销账号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<BaseResponse<bool>> Logout()
|
||||
{
|
||||
UserBLL userBLL = new UserBLL(ServiceProvider);
|
||||
return await userBLL.Logout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user