This commit is contained in:
Putoo
2026-05-18 18:12:21 +08:00
parent 571877970b
commit 2037d1e577
20 changed files with 555 additions and 77 deletions

View File

@@ -10,4 +10,8 @@
<ProjectReference Include="..\Application.Service.Pub\Application.Service.Pub.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="game\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,93 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class unit_user
{
/// <summary>
/// userId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string userId { get; set; }
/// <summary>
/// 账号ID
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? accId { get; set; }
/// <summary>
/// 区服
/// </summary>
[SugarColumn(IsNullable = true)]
public int? areaId { get; set; }
/// <summary>
/// userNo
/// </summary>
[SugarColumn(Length = 12, IsNullable = false)]
public string userNo { get; set; }
/// <summary>
/// 名称
/// </summary>
[SugarColumn(IsNullable = true)]
public string? nick { get; set; }
/// <summary>
/// 头像
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? headImg { get; set; }
/// <summary>
/// 性别
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? sex { get; set; }
/// <summary>
/// 简介
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? sign { get; set; }
/// <summary>
/// 状态
/// </summary>
[SugarColumn(IsNullable = true)]
public int? status { get; set; }
/// <summary>
/// 注册状态
/// </summary>
[SugarColumn(IsNullable = true)]
public int? regOk { get; set; }
/// <summary>
/// token
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? token { get; set; }
/// <summary>
/// 是否系统账号
/// </summary>
[SugarColumn(IsNullable = true)]
public int? isSystem { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? addTime { get; set; }
/// <summary>
/// 最后更新时间
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? upTime { get; set; }
}
}

View File

@@ -4,4 +4,5 @@ public interface INoticeService
{
Task<List<game_notice>> GetNoticeDataByTake(int take);
Task<List<game_notice>> GetNoticeData(int page, int limit, RefAsync<int> total);
Task<game_notice> GetNoticeInfo(string id);
}

View File

@@ -0,0 +1,22 @@
namespace Application.Domain;
public interface IUnitUserService
{
#region
Task<List<unit_user>> GetUserDataByAccId(string accId);
#endregion
#region
/// <summary>
/// 注册游戏角色
/// </summary>
/// <param name="areaId"></param>
/// <param name="accId"></param>
/// <returns></returns>
Task<unit_user> Register(int areaId, string accId);
#endregion
}

View File

@@ -22,4 +22,10 @@ public class NoticeService:INoticeService,ITransient
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
return await db.Queryable<game_notice>().OrderByDescending(it=>it.addTime).ToPageListAsync(page, limit, total);
}
public async Task<game_notice> GetNoticeInfo(string id)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
return await db.Queryable<game_notice>().Where(it => it.noticeId == id).SingleAsync();
}
}

View File

@@ -0,0 +1,135 @@
using Photon.Core.Assist;
namespace Application.Domain;
public class UnitUserService : IUnitUserService, ITransient
{
private readonly ISqlSugarClient _dbClient;
private readonly IRedisCache _redisClient;
public UnitUserService(ISqlSugarClient dbClient, IRedisCache redisClient)
{
_dbClient = dbClient;
_redisClient = redisClient;
}
#region
public async Task<List<unit_user>> GetUserDataByAccId(string accId)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
}
public async Task<unit_user> GetUserInfoByUserNo(string userNo)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo");
var data = await _redisClient.GetHashAsync<unit_user>(key, userNo);
if (data == null)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
data = await db.Queryable<unit_user>().Where(it => it.userNo == userNo).SingleAsync();
if (data != null)
{
await _redisClient.AddHashAsync(key, userNo, data);
}
}
return data;
}
public async Task<unit_user> GetUserInfoBySid(string token)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid");
var data = await _redisClient.GetHashAsync<unit_user>(key, token);
if (data == null)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
data = await db.Queryable<unit_user>().Where(it => it.token == token).SingleAsync();
if (data != null)
{
await _redisClient.AddHashAsync(key, token, data);
}
}
return data;
}
#endregion
#region
public async Task<unit_user> Register(int areaId, string accId)
{
unit_user result = new unit_user();
try
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
await _dbClient.AsTenant().BeginTranAsync();
string userId = StringAssist.NewGuid;
result.userId = userId;
result.areaId = areaId;
result.accId = accId;
result.nick = "四海虾米";
result.headImg = "";
int no = await GetUserNo();
result.userNo = no.ToString();
string token = await GetToken();
result.token = token;
result.sign = "这个小家伙儿很懒,什么也没留下.";
result.status = 1;
result.regOk = 0;
result.isSystem = 0;
result.addTime = DateTime.Now;
result.upTime = DateTime.Now;
bool isok = db.Insertable(result).ExecuteCommand() > 0;
if (!isok)
{
result = null;
}
await _dbClient.AsTenant().CommitTranAsync();
}
catch
{
result = null;
await _dbClient.AsTenant().RollbackTranAsync();
}
return result;
}
public async Task<int> GetUserNo()
{
int No = 0;
bool ok = true;
while (ok)
{
No = RandomAssist.GetFormatedNumeric(11012585, 97521695);
if (await GetUserInfoByUserNo(No.ToString()) == null)
{
ok = false;
}
}
return No;
}
private async Task<string> GetToken()
{
string sid = string.Empty;
bool ok = true;
while (ok)
{
sid = StringAssist.RandomString(32);
if (await GetUserInfoBySid(sid) == null)
{
ok = false;
}
}
return sid;
}
#endregion
}

View File

@@ -0,0 +1,21 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Application.Web;
public class DateTimeJsonConverter: JsonConverter<DateTime>
{
public override DateTime Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
{
return DateTime.ParseExact(reader.GetString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
}
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
}
}

View File

@@ -14,9 +14,15 @@ namespace Application.Web.Controllers.Login
public class LoginController : ControllerBase
{
private readonly IGameAccountService _accountService;
public LoginController(IGameAccountService accountService)
private readonly IAreaService _areaService;
private readonly IUnitUserService _userService;
public LoginController(IGameAccountService accountService, IAreaService areaService,
IUnitUserService userService)
{
_accountService = accountService;
_areaService = areaService;
_userService = userService;
}
/// <summary>
@@ -27,8 +33,6 @@ namespace Application.Web.Controllers.Login
[HttpPost]
public async Task<IPoAction> Login([FromBody] LoginParms parms)
{
return PoAction.Ok(parms.code);
}
@@ -38,12 +42,13 @@ namespace Application.Web.Controllers.Login
/// <param name="code"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> TwLogin( string code)
public async Task<IPoAction> TwLogin(string code)
{
if (string.IsNullOrEmpty(code))
{
return PoAction.Message("code值错误!");
}
AutoLogin login = new AutoLogin();
var loginInfo = await login.TwLogin(code);
if (loginInfo.code == 0)
@@ -61,7 +66,7 @@ namespace Application.Web.Controllers.Login
}
else
{
object ret =new { token = userData.token };
object ret = new { token = userData.token };
return PoAction.Ok(ret);
}
}
@@ -73,7 +78,7 @@ namespace Application.Web.Controllers.Login
}
else
{
object ret =new { token = accInfo.token };
object ret = new { token = accInfo.token };
return PoAction.Ok(ret);
}
}
@@ -112,5 +117,60 @@ namespace Application.Web.Controllers.Login
return PoAction.Message("退出失败,请稍后尝试!");
}
}
/// <summary>
/// 注册基础账号信息
/// </summary>
/// <param name="sid"></param>
/// <param name="area"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> Register(string sid, int area)
{
if (string.IsNullOrEmpty(sid))
{
return PoAction.Message("未登录账号!");
}
var accInfo = await _accountService.GetAccInfoByToken(sid);
if (accInfo == null)
{
return PoAction.Message("未登录账号!");
}
var areaInfo = await _areaService.GetAreaInfo(area);
if (areaInfo == null)
{
return PoAction.Message("区服不存在!");
}
if (areaInfo.status != 1)
{
return PoAction.Message("当前区繁忙,无法进入!");
}
//判断是否已经注册
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
if (userData.Any(it => it.areaId == area))
{
return PoAction.Message("该区已存在角色!");
}
var userInfo = await _userService.Register(areaInfo.areaId, accInfo.accId);
if (userInfo == null)
{
return PoAction.Message("注册失败,请稍后尝试!");
}
Dictionary<string, object> loadData = new Dictionary<string, object>();
loadData.Add("userId", userInfo.userId);
loadData.Add("accId", userInfo.accId);
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
string token = JwtHelper.CreateToken(Key, Issuer, Audience, loadData, 300);
return PoAction.Ok(new { token = token, refToken = userInfo.token, userId = userInfo.userId });
}
}
}

View File

@@ -13,12 +13,14 @@ namespace Application.Web.Controllers.Pub
private readonly IAreaService _areaService;
private readonly INoticeService _noticeService;
private readonly IGameAccountService _accountService;
private readonly IUnitUserService _userService;
public PubController(IAreaService areaService, INoticeService noticeService,IGameAccountService accountService)
public PubController(IAreaService areaService, INoticeService noticeService, IGameAccountService accountService,IUnitUserService userService)
{
_areaService = areaService;
_noticeService = noticeService;
_accountService = accountService;
_userService = userService;
}
/// <summary>
@@ -31,20 +33,27 @@ namespace Application.Web.Controllers.Pub
{
bool isOnline = false;
game_account account = new game_account();
List<unit_user> userData = new List<unit_user>();
if (!string.IsNullOrEmpty(sid))
{
account = await _accountService.GetAccInfoByToken(sid);
if (account != null)
{
isOnline = true;
userData = await _userService.GetUserDataByAccId(account.accId);
}
}
var areaData = await _areaService.GetAreaData();
foreach (var _user in userData)
{
areaData.RemoveAll(it => it.areaId == _user.areaId);
}
var notice = await _noticeService.GetNoticeDataByTake(5);
int OnCount = 100;
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount,account });
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount, account,userData });
}
/// <summary>
@@ -54,11 +63,28 @@ namespace Application.Web.Controllers.Pub
/// <param name="limit"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetNoticeData(int page,int limit)
public async Task<IPoAction> GetNoticeData(int page, int limit)
{
RefAsync<int> total = 0;
var data = await _noticeService.GetNoticeData(page, limit, total);
return PoAction.Ok(new { data, total=total.Value });
return PoAction.Ok(new { data, total = total.Value });
}
/// <summary>
/// 获取公告详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetNoticeInfo(string id)
{
var data = await _noticeService.GetNoticeInfo(id);
if (data == null)
{
return PoAction.Message("公告不存在!");
}
data.sign = data.sign.Replace("[Br]", "<br />");
return PoAction.Ok(data);
}
}
}

View File

@@ -53,8 +53,13 @@ builder.Services.InjectTimer(services =>
builder.Logging.InjectLog();
// Add services to the container.
builder.Services.AddControllers().AddJsonOptions(option =>
{
option.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
option.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
option.JsonSerializerOptions.MaxDepth =int.MaxValue;
});
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
#region

View File

@@ -16,20 +16,22 @@ export class StateHelper {
static get userId() {
return this.userStore.userId;
}
static SetToken(userId: string, token: string, refToken: string) {
this.userStore.setToken(userId, token, refToken);
}
static SetSid(sid: string) {
this.userStore.setSid(sid);
}
static OffOnline()
{
static OffOnline() {
this.userStore.offOnline();
}
static get IsAccLogin(){
static get IsAccLogin() {
return this.userStore.isLoginAccount;
}
static get IsLogin(){
static get IsLogin() {
return this.userStore.isLogin;
}

View File

@@ -4,7 +4,11 @@
export class MessageExtend {
// 消息通知
static Notify(message: any, type?: 'primary' | 'success' | 'danger' | 'warning') {
showNotify({ type, message })
showNotify({
type: type,
message: message,
duration: 1500,
});
}
// 提示弹窗
@@ -12,6 +16,16 @@ export class MessageExtend {
showDialog({ title: title, message: message })
}
static ShowDialogEvent(title: string, message: string, onConfirm?: () => void, confirmButtonText?: string) {
showDialog({
title: title,
message: message,
confirmButtonText: confirmButtonText || '确认'
}).then(() => {
onConfirm?.()
});
}
// 确认提示弹窗
static ShowConfirmDialog(title: string, message: string, onConfirm?: () => void, onCancel?: () => void, confirmButtonText?: string) {
showConfirmDialog({

View File

@@ -14,10 +14,10 @@
</div>
<div style="margin-top:5px;">
<div>
<a :href='"http://m.twbar.cn/Regain/ToMain?openid=" + AccountInfo.openId'>返回探玩驿站</a>
<a :href='"https://3g.fan/Regain/ToMain?openid=" + AccountInfo.openId'>返回探玩驿站</a>
</div>
<div>
<a :href='"http://m.twbar.cn/Regain/ToBbs?openid=" + AccountInfo.openId + "&bbs=1146"'>游戏论坛</a>&nbsp;&nbsp;
<a :href='"https://3g.fan/Regain/ToBbs?openid=" + AccountInfo.openId + "&bbs=1146"'>游戏论坛</a>&nbsp;&nbsp;
<a @click.stop="offOnline">退出游戏</a>
</div>
</div>
@@ -30,8 +30,8 @@
=====<Abar href="/area/my">我的区服</Abar>=====
</div>
<div class="content">
<div class="item">
<Abar href="/">&#x2727;&#x3010;1&#x3011;新手村&#x2730;村长()</Abar>
<div class="item" v-for="(item, index) in userData" :key="index">
<a @click="loginGame(item.userId)">{{ item.areaId }}{{ item.nick }}({{ (item.sex == null||item.sex=='') ? "未知" : item.sex }})</a>
</div>
</div>
</div>
@@ -41,7 +41,7 @@
</div>
<div class="content">
<div class="item" v-for="(item, index) in areaData" :key="index">
<Abar :href='"/login/register?id=" + item.areaId'>({{ item.areaId }}){{ item.name }}</Abar>
<a @click="registerGame(item.areaId)">({{ item.areaId }}){{ item.name }}</a>
{{ item.status == 1 ? "(推荐)" : "(繁忙)" }}
</div>
<span v-if="areaData.length == 0">暂无区服.</span>
@@ -85,50 +85,7 @@ const noticeData = ref<Array<any>>([]);
const isOnline = ref(false);
const OnCount = ref(0);
const AccountInfo = ref<any>();
const Initialize = async (): Promise<void> => {
var result = await PubService.GetMain(StateHelper.Sid);
if (result.code == 0) {
isOnline.value = result.data.isOnline;
if (isOnline.value == false) {
StateHelper.OffOnline();
}
areaData.value = result.data?.area;
noticeData.value = result.data.notice;
OnCount.value = result.data.onCount;
AccountInfo.value = result.data.account;
}
else {
MessageExtend.ShowToast(result.msg, "fail");
}
};
//退出登录
const offOnline = async () => {
MessageExtend.ShowConfirmDialog("退出游戏", "您确定要退出游戏吗?", async () => {
var result = await PubService.GetMain(StateHelper.Sid);
if (result.code == 0) {
StateHelper.OffOnline();
isOnline.value = false;
MessageExtend.ShowToast("退出成功!", "success");
}
else {
MessageExtend.ShowToast(result.msg, "fail");
}
});
}
const login = async (code: string): Promise<void> => {
var result = await LoginService.TwLogin(code);
console.log(result);
if (result.code == 0) {
StateHelper.SetSid(result.data.token);
await Initialize();
}
else {
MessageExtend.ShowToast(result.msg, "default");
}
}
const userData = ref<Array<any>>([]);
onMounted(async () => {
try {
@@ -146,4 +103,72 @@ onMounted(async () => {
PageLoading.Close();
}
})
/**初始化数据 */
const Initialize = async (): Promise<void> => {
let result = await PubService.GetMain(StateHelper.Sid);
if (result.code == 0) {
isOnline.value = result.data.isOnline;
if (isOnline.value == false) {
StateHelper.OffOnline();
}
areaData.value = result.data?.area;
noticeData.value = result.data.notice;
OnCount.value = result.data.onCount;
AccountInfo.value = result.data.account;
userData.value = result.data.userData;
}
else {
MessageExtend.ShowToast(result.msg, "fail");
}
};
/**自动登录 */
const login = async (code: string): Promise<void> => {
let result = await LoginService.TwLogin(code);
console.log(result);
if (result.code == 0) {
StateHelper.SetSid(result.data.token);
await Initialize();
}
else {
MessageExtend.ShowToast(result.msg, "default");
}
}
/**退出登录 */
const offOnline = async () => {
MessageExtend.ShowConfirmDialog("退出游戏", "您确定要退出游戏吗?", async () => {
let result = await PubService.GetMain(StateHelper.Sid);
if (result.code == 0) {
StateHelper.OffOnline();
isOnline.value = false;
MessageExtend.ShowToast("退出成功!", "success");
}
else {
MessageExtend.ShowToast(result.msg, "fail");
}
});
}
/**登录到游戏 */
const loginGame = async (gameId: string): Promise<void> => {
alert(gameId)
};
/**注册游戏 */
const registerGame = async (area: number): Promise<void> => {
let result = await LoginService.Register(StateHelper.Sid, area);
if (result.code == 0) {
StateHelper.SetToken(result.data.userId, result.data.token, result.data.refToken);
PageExtend.Redirect("/login/register");
}
else {
MessageExtend.ShowDialog("注册角色", result.msg);
}
}
/**辅助方法 */
</script>

View File

@@ -27,12 +27,10 @@ const data = ref<Array<any>>([]);
const handlePageChange = async (page: number): Promise<void> => {
currentPage.value = page;
await BindData();
console.log('跳转到第', page, '页');
};
const BindData = async (): Promise<void> => {
var result = await PubService.GetNoticeData(currentPage.value, 10);
console.log(result);
if (result.code == 0) {
data.value = result.data.data;
totalPages.value = result.data.total;

View File

@@ -1 +1,51 @@
<template></template>
<template>
<div class="content">
<Abar href="/news/">官方公告</Abar>&gt;详情
</div>
<div class="content">
<div class="common">
[标题]:<strong>{{ noticeData.title }}</strong>
</div>
<div class="common">
[时间]: {{noticeData.addTime}}
</div>
<div class="common" v-html="noticeData.sign"></div>
</div>
<div class="content">
<Abar href="/news/">返回公告列表</Abar>
</div>
<Abar href="/">返回游戏首页</Abar>
</template>
<script setup lang="ts">
definePageMeta({
layout: layout.empty,
middleware: 'page-loading'
})
let noticeData = ref<any>({});
const BindData = async (): Promise<void> => {
var noticeId = PageExtend.QueryString("id");
var result = await PubService.GetNoticeInfo(noticeId);
if (result.code == 0) {
noticeData.value = result.data;
}
else {
MessageExtend.ShowDialogEvent("提示", "公告不存在!", () => {
PageExtend.Redirect("/news/");
}, "我知道了");
}
};
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
</script>

View File

@@ -8,10 +8,18 @@ export class PubService {
}
/**
* GetNoticeData
* 获取公告列表
* GET /Pub/GetNoticeData
*/
static async GetNoticeData(page: number, limit: number) {
return await ApiService.Request("get", "/Pub/GetNoticeData", { page, limit });
}
/**
* 获取公告详情
* GET /Pub/GetNoticeInfo
*/
static async GetNoticeInfo(id: string) {
return await ApiService.Request("get", "/Pub/GetNoticeInfo", { id });
}
}

View File

@@ -26,4 +26,12 @@ export class LoginService {
static async LoginOut(sid: string) {
return await ApiService.Request("get", "/Login/LoginOut", { sid });
}
/**
* 注册基础账号信息
* GET /Login/Regist
*/
static async Register(sid: string, area: number) {
return await ApiService.Request("get", "/Login/Register", { sid, area });
}
}