增加称号跟徽章接口
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_badge
|
||||
{
|
||||
/// <summary>
|
||||
/// ubId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string ubId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// badgeId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string badgeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// img
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string img { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// show
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? show { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// showChat
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? showChat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_maxname
|
||||
{
|
||||
/// <summary>
|
||||
/// umnId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string umnId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = false)]
|
||||
public string userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// mnId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = false)]
|
||||
public string mnId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// img
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string img { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// attr
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 1000, IsNullable = true)]
|
||||
public string attr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// count
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? endTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// show
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? show { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_badge
|
||||
{
|
||||
/// <summary>
|
||||
/// badgeId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string badgeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// remark
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// img
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string img { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_maxname
|
||||
{
|
||||
/// <summary>
|
||||
/// mnId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string mnId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// img
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string img { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// attr
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 1000, IsNullable = true)]
|
||||
public string attr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// remark
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Application.Domain.Services
|
||||
{
|
||||
public interface IGameBadgeService
|
||||
{
|
||||
#region unit_user_badge
|
||||
Task<int> GetUserShowBadgeCount(string userId);
|
||||
Task<int> GetUserShowBadgeOnCount(string userId);
|
||||
Task<bool> UpdateUserBadgeShow(string ubId, int show);
|
||||
Task<unit_user_badge> GetUserBadegInfo(string ubId);
|
||||
Task<List<unit_user_badge>> GetUserBadgeList(string userId, int page, int limit, RefAsync<int> total);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,9 @@
|
||||
|
||||
public interface IGameMaxNameService
|
||||
{
|
||||
|
||||
#region unit_user_maxname
|
||||
Task<bool> UpdateUserMaxname(unit_user_maxname name);
|
||||
Task<unit_user_maxname> GetUserMaxnameInfo(string umnId);
|
||||
Task<List<unit_user_maxname>> GetUserMaxnameList(string userId, int page, int limit, RefAsync<int> total);
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Application.Domain.Services
|
||||
{
|
||||
public class GameBadgeService(ISqlSugarClient DbClient, IRedisCache redis) : IGameBadgeService, ITransient
|
||||
{
|
||||
#region unit_user_badge
|
||||
public async Task<int> GetUserShowBadgeCount(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_badge>();
|
||||
return await db.Queryable<unit_user_badge>().Where(i => i.userId == userId && i.show == 1).CountAsync();
|
||||
}
|
||||
public async Task<int> GetUserShowBadgeOnCount(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_badge>();
|
||||
return await db.Queryable<unit_user_badge>().Where(i => i.userId == userId).SumAsync(i => (int)i.showChat);
|
||||
}
|
||||
public async Task<bool> UpdateUserBadgeShow(string ubId, int show)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_badge>();
|
||||
bool isok = await db.Updateable<unit_user_badge>().SetColumns(i => i.show == show).Where(i => i.ubId == ubId)
|
||||
.ExecuteCommandAsync() > 0;
|
||||
if (isok)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "UserBadge", "BadgeInfo");
|
||||
await redis.DelHashAsync(key, ubId);
|
||||
}
|
||||
return isok;
|
||||
}
|
||||
public async Task<unit_user_badge> GetUserBadegInfo(string ubId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "UserBadge", "BadgeInfo");
|
||||
var data = await redis.GetHashAsync<unit_user_badge>(key, ubId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_badge>();
|
||||
data = await db.Queryable<unit_user_badge>().Where(i => i.ubId == ubId).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await redis.AddHashAsync(key, ubId, data);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public async Task<List<unit_user_badge>> GetUserBadgeList(string userId, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_badge>();
|
||||
return await db.Queryable<unit_user_badge>().Where(i => i.userId == userId).OrderBy(i => i.addTime)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,39 @@
|
||||
|
||||
public class GameMaxNameService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMaxNameService, ITransient
|
||||
{
|
||||
|
||||
|
||||
#region unit_user_maxname
|
||||
public async Task<bool> UpdateUserMaxname(unit_user_maxname name)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_maxname>();
|
||||
bool isok = await db.Updateable(name).ExecuteCommandAsync() > 0;
|
||||
if (isok)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "UserMaxname", "MaxnameInfo");
|
||||
await redis.DelHashAsync(key, name.umnId);
|
||||
}
|
||||
return isok;
|
||||
}
|
||||
public async Task<unit_user_maxname> GetUserMaxnameInfo(string umnId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "UserMaxname", "MaxnameInfo");
|
||||
var data = await redis.GetHashAsync<unit_user_maxname>(key, umnId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_maxname>();
|
||||
data = await db.Queryable<unit_user_maxname>().Where(i => i.umnId == umnId).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await redis.AddHashAsync(key, umnId, data);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public async Task<List<unit_user_maxname>> GetUserMaxnameList(string userId, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_maxname>();
|
||||
return await db.Queryable<unit_user_maxname>().Where(i => i.userId == userId).OrderBy(i => i.addTime)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
101
Service/Application.Web/Controllers/Pub/BadgeController.cs
Normal file
101
Service/Application.Web/Controllers/Pub/BadgeController.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using Application.Domain.Services;
|
||||
using Application.Web.Model.RequestParms.Maxname;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Pub
|
||||
{
|
||||
/// <summary>
|
||||
/// 徽章接口
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class BadgeController : ControllerBase
|
||||
{
|
||||
private readonly IGameBadgeService badgeService;
|
||||
public BadgeController(IGameBadgeService _badgeService)
|
||||
{
|
||||
badgeService = _badgeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户徽章列表
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserBadgeList(int page)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
string userId = StateHelper.userId;
|
||||
var list = await badgeService.GetUserBadgeList(userId, page, 10, total);
|
||||
return PoAction.Ok(new { list, total });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取徽章详情
|
||||
/// </summary>
|
||||
/// <param name="ubId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserBadgeInfo(string ubId)
|
||||
{
|
||||
var data = await badgeService.GetUserBadegInfo(ubId);
|
||||
if (data == null)
|
||||
{
|
||||
return PoAction.Message("徽章信息不存在!");
|
||||
}
|
||||
string userId = StateHelper.userId;
|
||||
if (data.userId != userId)
|
||||
{
|
||||
return PoAction.Message("徽章信息不存在!");
|
||||
}
|
||||
return PoAction.Ok(new { data });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改徽章展示不展示
|
||||
/// </summary>
|
||||
/// <param name="par"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> UpdateBadgeShow([FromBody] UpdateBadgeParms par)
|
||||
{
|
||||
var data = await badgeService.GetUserBadegInfo(par.ubId);
|
||||
if (data == null)
|
||||
{
|
||||
return PoAction.Message("徽章信息不存在!");
|
||||
}
|
||||
string userId = StateHelper.userId;
|
||||
if (data.userId != userId)
|
||||
{
|
||||
return PoAction.Message("徽章信息不存在!");
|
||||
}
|
||||
//int onCount = await badgeService.GetUserShowBadgeOnCount(userId);
|
||||
//int showCount = await badgeService.GetUserShowBadgeCount(userId);
|
||||
//if (onCount == 0)
|
||||
//{
|
||||
// if (showCount >= 1)
|
||||
// {
|
||||
// return PoAction.Message("您最多可以同时展示1个徽章!");
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (showCount >= onCount)
|
||||
// {
|
||||
// return PoAction.Message(string.Format("您最多可以同时展示{0}个徽章!", onCount));
|
||||
// }
|
||||
//}
|
||||
int show = data.show == 1 ? 0 : 1;
|
||||
if (await badgeService.UpdateUserBadgeShow(par.ubId, show))
|
||||
{
|
||||
return PoAction.Ok("操作成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
84
Service/Application.Web/Controllers/Pub/MaxnameController.cs
Normal file
84
Service/Application.Web/Controllers/Pub/MaxnameController.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Application.Web.Model.RequestParms.Maxname;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Pub
|
||||
{
|
||||
/// <summary>
|
||||
/// 称号接口
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class MaxnameController : ControllerBase
|
||||
{
|
||||
private readonly IGameMaxNameService maxnameService;
|
||||
public MaxnameController(IGameMaxNameService _maxnameService)
|
||||
{
|
||||
maxnameService = _maxnameService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户称号列表
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserMaxnameList(int page)
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
string userId = StateHelper.userId;
|
||||
var list = await maxnameService.GetUserMaxnameList(userId, page, 10, total);
|
||||
return PoAction.Ok(new { list, total });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取称号详情
|
||||
/// </summary>
|
||||
/// <param name="umnId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserMaxnameInfo(string umnId)
|
||||
{
|
||||
var data = await maxnameService.GetUserMaxnameInfo(umnId);
|
||||
if (data == null)
|
||||
{
|
||||
return PoAction.Message("称号信息不存在!");
|
||||
}
|
||||
string userId = StateHelper.userId;
|
||||
if (data.userId != userId)
|
||||
{
|
||||
return PoAction.Message("称号信息不存在!");
|
||||
}
|
||||
return PoAction.Ok(new { data });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改称号展示不展示
|
||||
/// </summary>
|
||||
/// <param name="par"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> UpdateMaxnameShow([FromBody] UpdateMaxnameParms par)
|
||||
{
|
||||
var data = await maxnameService.GetUserMaxnameInfo(par.umnId);
|
||||
if (data == null)
|
||||
{
|
||||
return PoAction.Message("称号信息不存在!");
|
||||
}
|
||||
string userId = StateHelper.userId;
|
||||
if (data.userId != userId)
|
||||
{
|
||||
return PoAction.Message("称号信息不存在!");
|
||||
}
|
||||
data.show = data.show == 1 ? 0 : 1;
|
||||
if (await maxnameService.UpdateUserMaxname(data))
|
||||
{
|
||||
return PoAction.Ok("操作成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Model.RequestParms.Maxname
|
||||
{
|
||||
public class UpdateBadgeParms
|
||||
{
|
||||
public string ubId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Model.RequestParms.Maxname
|
||||
{
|
||||
public class UpdateMaxnameParms
|
||||
{
|
||||
public string umnId { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user