修复
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_message
|
||||
{
|
||||
/// <summary>
|
||||
/// msgId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long msgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sendId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? sendId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sign
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? sign { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// isRead
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? isRead { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// status
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? endTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 会话ID
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 100, IsNullable = true)]
|
||||
public string? talkId { get; set; }
|
||||
}
|
||||
}
|
||||
69
Service/Application.Domain.Entity/log/db/game_mall_log.cs
Normal file
69
Service/Application.Domain.Entity/log/db/game_mall_log.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Log")]
|
||||
public class game_mall_log
|
||||
{
|
||||
/// <summary>
|
||||
/// logId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string logId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// mallId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? mallId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// type
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// pars
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public Int32? pars { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// count
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// price
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// payType
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? payType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? endTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
[Tenant("Kg.SeaTime.Log")]
|
||||
public class unit_user_acc_log
|
||||
{
|
||||
/// <summary>
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
[Tenant("Kg.SeaTime.Log")]
|
||||
public class unit_user_weight_log
|
||||
{
|
||||
/// <summary>
|
||||
69
Service/Application.Domain.Entity/resource/game/game_mall.cs
Normal file
69
Service/Application.Domain.Entity/resource/game/game_mall.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_mall
|
||||
{
|
||||
/// <summary>
|
||||
/// mallId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string mallId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// areaId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? areaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// type
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// goodsId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? goodsId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// price
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// payType
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? payType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sort
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? endTime { get; set; }
|
||||
}
|
||||
}
|
||||
7
Service/Application.Domain.Entity/view/MessageView.cs
Normal file
7
Service/Application.Domain.Entity/view/MessageView.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class MessageView
|
||||
{
|
||||
public string sign { get; set; }
|
||||
public UserModel user { get; set;}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameMallService
|
||||
{
|
||||
Task<List<game_mall>> GetMallData(int area, string type, int page, int limit, RefAsync<int> total);
|
||||
Task<game_mall> GetMallInfo(string mallId);
|
||||
Task<bool> AddLog(game_mall mall, string userId, int count);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IMessageService
|
||||
{
|
||||
Task<int> GetNoReadCount(string userId);
|
||||
|
||||
#region 私聊消息
|
||||
|
||||
string GetTalkId(string userId, string otId);
|
||||
Task<List<unit_user_message>> GetUserNoReadData(string talkId);
|
||||
|
||||
Task<List<unit_user_message>> GetUserMessageData(string talkId, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
Task<List<MessageView>> GetUserMessage(string userId, int type, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
Task<bool> SendMsg(string sendId, string toUser, string msg);
|
||||
Task SetMsgRead(List<long> msgIds, string userId);
|
||||
Task<bool> DeleteMsgByTalkId(string talkId, string userId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMallService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMallService, ITransient
|
||||
{
|
||||
public async Task<List<game_mall>> GetMallData(int area, string type, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
DateTime onTime = DateTime.Now;
|
||||
string _area = area.ToString();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_mall>();
|
||||
return await db.Queryable<game_mall>().Where(it =>
|
||||
it.endTime > onTime && (it.areaId.Contains("0") || it.areaId.Contains(_area)))
|
||||
.WhereIF(type=="0",it=>it.payType=="cowry")
|
||||
.WhereIF(type=="1",it=>it.payType=="gold")
|
||||
.OrderBy(it=>it.sort,OrderByType.Asc)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<game_mall> GetMallInfo(string mallId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_mall>();
|
||||
return await db.Queryable<game_mall>().Where(it => it.mallId == mallId).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddLog(game_mall mall, string userId, int count)
|
||||
{
|
||||
game_mall_log log = new game_mall_log();
|
||||
log.logId = StringAssist.NewGuid;
|
||||
log.mallId = mall.mallId;
|
||||
log.type = mall.type;
|
||||
log.pars = mall.goodsId;
|
||||
log.count = count;
|
||||
log.price = mall.price;
|
||||
log.payType = mall.payType;
|
||||
log.userId = userId;
|
||||
log.addTime = DateTime.Now;
|
||||
log.endTime = DateTime.Now.AddDays(30);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_mall_log>();
|
||||
return await db.Insertable(log).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMessageService, ITransient
|
||||
{
|
||||
public async Task<int> GetNoReadCount(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
//普通消息
|
||||
int noRead = await GetUserNoReadDataCountByUserId(userId);
|
||||
result += noRead;
|
||||
//邮件详细
|
||||
//通知消息
|
||||
await redis.AddHashAsync(key, userId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearMessageCache(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
#region 私信消息
|
||||
|
||||
public string GetTalkId(string userId, string otId)
|
||||
{
|
||||
return $"{userId}_{otId}";
|
||||
}
|
||||
|
||||
private List<string> GetTalkIdToUserId(string talkId)
|
||||
{
|
||||
return talkId.Split('_').ToList();
|
||||
}
|
||||
|
||||
private async Task<int> GetUserNoReadDataCountByUserId(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
.Where(it => it.status == 1 && it.userId == userId && it.isRead == 0).CountAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_message>> GetUserNoReadData(string talkId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
.Where(it => it.status == 1 && it.talkId == talkId && it.isRead == 0)
|
||||
.OrderByDescending(it => it.addTime).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_message>> GetUserMessageData(string talkId, int page, int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
.Where(it => it.status == 1 && it.talkId == talkId)
|
||||
.OrderByDescending(it => it.addTime)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最新对话列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <param name="total"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<MessageView>> GetUserMessage(string userId, int type, int page, int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
var talkData = await db.Queryable<unit_user_message>()
|
||||
.GroupBy(it => new { it.talkId })
|
||||
.Where(it => it.userId == userId && it.status == 1)
|
||||
.WhereIF(type == 0, it => it.isRead == 0)
|
||||
.OrderByDescending(it => it.addTime)
|
||||
.Select(it => new { mgsId = SqlFunc.AggregateMax(it.msgId) })
|
||||
.ToPageListAsync(page, limit, total);
|
||||
|
||||
List<MessageView> result = new List<MessageView>();
|
||||
foreach (var item in talkData)
|
||||
{
|
||||
MessageView temp = new MessageView();
|
||||
var msgInfo = await db.Queryable<unit_user_message>().Where(it => it.msgId == item.mgsId).SingleAsync();
|
||||
temp.sign = msgInfo.sign;
|
||||
var users = GetTalkIdToUserId(msgInfo.talkId);
|
||||
temp.user = await UserModelTool.GetUserView(users[1]);
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SendMsg(string sendId, string toUser, string msg)
|
||||
{
|
||||
List<unit_user_message> adds = new List<unit_user_message>();
|
||||
unit_user_message message = new unit_user_message();
|
||||
message.msgId = SnowflakeAssist.NextId();
|
||||
message.userId = toUser;
|
||||
message.sendId = sendId;
|
||||
message.sign = msg;
|
||||
message.isRead = 0;
|
||||
message.status = 1;
|
||||
message.addTime = DateTime.Now;
|
||||
message.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(90));
|
||||
message.talkId = GetTalkId(toUser, sendId);
|
||||
adds.Add(message);
|
||||
if (sendId != "0")
|
||||
{
|
||||
message = new unit_user_message();
|
||||
message.msgId = SnowflakeAssist.NextId();
|
||||
message.userId = sendId;
|
||||
message.sendId = sendId;
|
||||
message.sign = msg;
|
||||
message.isRead = 1;
|
||||
message.status = 1;
|
||||
message.addTime = DateTime.Now;
|
||||
message.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(90));
|
||||
message.talkId = GetTalkId(sendId, toUser);
|
||||
adds.Add(message);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
bool result = await db.Insertable(adds).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMessageCache(toUser);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task SetMsgRead(List<long> msgIds, string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
bool result = await db.Updateable<unit_user_message>().SetColumns(it => it.isRead == 1)
|
||||
.Where(it => msgIds.Contains(it.msgId)).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMessageCache(userId);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteMsgByTalkId(string talkId, string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
bool result = await db.Updateable<unit_user_message>().SetColumns(it => it.status == 0)
|
||||
.Where(it => it.talkId == talkId && it.status == 1).ExecuteCommandAsync() >
|
||||
0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMessageCache(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -70,9 +70,9 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
userAccLog.name = name;
|
||||
userAccLog.amount = count;
|
||||
userAccLog.addTime = DateTime.Now;
|
||||
userAccLog.endTime = DateTime.Now.AddDays(3);
|
||||
userAccLog.endTime = DateTime.Now.AddDays(30);
|
||||
userAccLog.remark = remark;
|
||||
await db.Insertable(userAccLog).ExecuteCommandAsync();
|
||||
await AddLog(userAccLog);
|
||||
}
|
||||
|
||||
await DbClient.AsTenant().CommitTranAsync();
|
||||
@@ -102,6 +102,11 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task AddLog(unit_user_acc_log log)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_acc_log>();
|
||||
await db.Insertable(log).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user_copper> GetUserCopperInfo(string userId)
|
||||
{
|
||||
|
||||
@@ -34,8 +34,8 @@ public class GameTool
|
||||
|
||||
public static bool AreaVerify(int area, string areas)
|
||||
{
|
||||
List<string> onArea = new List<string>() { "0", area.ToString() };
|
||||
return onArea.Any(it => areas.Contains(it));
|
||||
List<string> okArea = areas.Split(',').ToList();
|
||||
return okArea.Any(it => it == "0" || it == area.ToString());
|
||||
}
|
||||
|
||||
public static string GetCurrencyName(string payCode)
|
||||
|
||||
@@ -11,22 +11,33 @@ public class UserModelTool
|
||||
public static async Task<UserModel> GetUserView(string userId,bool addIcon=false)
|
||||
{
|
||||
UserModel result = new UserModel();
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userInfo = await userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo != null)
|
||||
if (userId == "0")
|
||||
{
|
||||
result.userNo = userInfo.userNo;
|
||||
result.nick = userInfo.nick;
|
||||
result.sex = userInfo.sex;
|
||||
result.headImg = userInfo.headImg;
|
||||
result.area = (int)userInfo.areaId;
|
||||
result.userNo = "0";
|
||||
result.nick = "海精灵";
|
||||
result.sex = "女";
|
||||
result.headImg = "";
|
||||
result.area = 0;
|
||||
result.icon = "";
|
||||
if (addIcon)//获取图标信息
|
||||
}
|
||||
else
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userInfo = await userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo != null)
|
||||
{
|
||||
result.userNo = userInfo.userNo;
|
||||
result.nick = userInfo.nick;
|
||||
result.sex = userInfo.sex;
|
||||
result.headImg = userInfo.headImg;
|
||||
result.area = (int)userInfo.areaId;
|
||||
result.icon = "";
|
||||
if (addIcon)//获取图标信息
|
||||
{
|
||||
result.icon = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,16 @@ public class MapController : ControllerBase
|
||||
private readonly IGameMapService _mapService;
|
||||
private readonly IGameChatService _chatService;
|
||||
private readonly IUnitUserAttrService _attrService;
|
||||
private readonly IMessageService _messageService;
|
||||
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
|
||||
IUnitUserAttrService attrService)
|
||||
IUnitUserAttrService attrService,IMessageService messageService)
|
||||
{
|
||||
_userService = userService;
|
||||
_mapService = mapService;
|
||||
_chatService = chatService;
|
||||
_attrService = attrService;
|
||||
_messageService = messageService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,6 +81,7 @@ public class MapController : ControllerBase
|
||||
var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId); //城市信息
|
||||
var cityShow = await _mapService.GetCityShowMap(cityInfo.cityId); //城内地图
|
||||
|
||||
int noReadMsg = await _messageService.GetNoReadCount(userId);
|
||||
#region 更新在线
|
||||
|
||||
string ip = ComHelper.GetClientUserIp(HttpContext);
|
||||
@@ -86,7 +89,7 @@ public class MapController : ControllerBase
|
||||
|
||||
#endregion
|
||||
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser };
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser,noReadMsg };
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
|
||||
86
Service/Application.Web/Controllers/Pub/MallController.cs
Normal file
86
Service/Application.Web/Controllers/Pub/MallController.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Pub;
|
||||
|
||||
/// <summary>
|
||||
/// 商城接口
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class MallController : ControllerBase
|
||||
{
|
||||
private readonly IGameMallService _mallService;
|
||||
private readonly IUnitUserAccService _accService;
|
||||
|
||||
public MallController(IGameMallService mallService, IUnitUserAccService accService)
|
||||
{
|
||||
_mallService = mallService;
|
||||
_accService = accService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商城列表
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetMall(string type, int page)
|
||||
{
|
||||
int area = StateHelper.areaId;
|
||||
string userId = StateHelper.userId;
|
||||
var accInfo = await _accService.GetUserAccInfo(userId);
|
||||
RefAsync<int> total = 0;
|
||||
var data = await _mallService.GetMallData(area, type, page, 10, total);
|
||||
return PoAction.Ok(new { data, total = total.Value, accInfo.gold, accInfo.cowry });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 购买物品
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> Buy([FromBody] MallBuyParms parms)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
int area = StateHelper.areaId;
|
||||
parms.count = parms.count < 1 ? 1 : parms.count;
|
||||
var mallInfo = await _mallService.GetMallInfo(parms.id);
|
||||
if (mallInfo == null)
|
||||
{
|
||||
return PoAction.Message("商品已下架!");
|
||||
}
|
||||
|
||||
if (mallInfo.endTime < DateTime.Now)
|
||||
{
|
||||
return PoAction.Message("商品已下架!");
|
||||
}
|
||||
|
||||
if (GameTool.AreaVerify(area, mallInfo.areaId) == false)
|
||||
{
|
||||
return PoAction.Message("商品已下架!");
|
||||
}
|
||||
|
||||
var myAcc = await _accService.GetUserAccInfo(userId, mallInfo.payType);
|
||||
long need = (long)mallInfo.price * parms.count;
|
||||
if (myAcc < need)
|
||||
{
|
||||
return PoAction.Message($"您的{GameTool.GetCurrencyName(mallInfo.payType)}不足!");
|
||||
}
|
||||
|
||||
if (await _accService.UpdateUserAcc(userId, 0, mallInfo.payType, need, nameof(AccEnum.Name.系统商城), "系统商店购买"))
|
||||
{
|
||||
if (await _mallService.AddLog(mallInfo, userId, parms.count))
|
||||
{
|
||||
await GameBus.UpdateBag(userId, 1, mallInfo.type, mallInfo.goodsId.ToString(), parms.count, "系统商店购买");
|
||||
}
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("购买失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
196
Service/Application.Web/Controllers/Pub/MessageController.cs
Normal file
196
Service/Application.Web/Controllers/Pub/MessageController.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Pub;
|
||||
|
||||
/// <summary>
|
||||
/// 消息接口
|
||||
/// </summary>
|
||||
[Route("[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class MessageController : ControllerBase
|
||||
{
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly IUnitUserService _userService;
|
||||
|
||||
public MessageController(IMessageService messageService, IUnitUserService userService)
|
||||
{
|
||||
_messageService = messageService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取消息
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetMessageData(int type, int page)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
RefAsync<int> total = 0;
|
||||
if (type == 0)
|
||||
{
|
||||
var data = await _messageService.GetUserMessage(userId, 0, page, 10, total);
|
||||
return PoAction.Ok(new { data, total = total.Value });
|
||||
}
|
||||
else if (type == 1)
|
||||
{
|
||||
var data = await _messageService.GetUserMessage(userId, 1, page, 10, total);
|
||||
return PoAction.Ok(new { data, total = total.Value });
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Ok(new { data = new List<string>(), total = total.Value });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取消息界面
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetReadInfo(int no)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
UserModel user = new UserModel();
|
||||
string talkId = string.Empty;
|
||||
if (no == 0)
|
||||
{
|
||||
user = await UserModelTool.GetUserView("0");
|
||||
talkId = _messageService.GetTalkId(userId, "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no.ToString());
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
talkId = _messageService.GetTalkId(userId, userInfo.userId);
|
||||
user = await UserModelTool.GetUserView(userInfo.userId);
|
||||
}
|
||||
|
||||
|
||||
var noRead = await _messageService.GetUserNoReadData(talkId); //未读消息
|
||||
if (noRead.Count > 0)
|
||||
{
|
||||
List<long> msgIds = noRead.Select(it => it.msgId).ToList();
|
||||
await _messageService.SetMsgRead(msgIds, userId);
|
||||
}
|
||||
|
||||
RefAsync<int> total = 0;
|
||||
var logs = await _messageService.GetUserMessageData(talkId, 1, 5, total); //消息记录
|
||||
return PoAction.Ok(new { user, data = noRead, logs });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> SendMsg([FromBody] SendMsgParms parms)
|
||||
{
|
||||
if (string.IsNullOrEmpty(parms.sign))
|
||||
{
|
||||
return PoAction.Message("消息内容不能为空!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
|
||||
var toUser = await _userService.GetUserInfoByUserNo(parms.no.ToString());
|
||||
if (toUser == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 100);
|
||||
}
|
||||
|
||||
if (toUser.areaId != areaId)
|
||||
{
|
||||
return PoAction.Message("暂不支持漫游消息!");
|
||||
}
|
||||
|
||||
parms.sign = StringAssist.NoHTML(parms.sign);
|
||||
if (await _messageService.SendMsg(userId, toUser.userId, parms.sign))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("发送失败,请稍后尝试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 聊天记录
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> MessageLog(int no, int page)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
UserModel user = new UserModel();
|
||||
string talkId = string.Empty;
|
||||
if (no == 0)
|
||||
{
|
||||
user = await UserModelTool.GetUserView("0");
|
||||
talkId = _messageService.GetTalkId(userId, "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no.ToString());
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
talkId = _messageService.GetTalkId(userId, userInfo.userId);
|
||||
user = await UserModelTool.GetUserView(userInfo.userId);
|
||||
}
|
||||
|
||||
RefAsync<int> total = 0;
|
||||
var logs = await _messageService.GetUserMessageData(talkId, page, 10, total); //消息记录
|
||||
return PoAction.Ok(new { user, data = logs, total = total.Value });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除对话
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> DeleteMsg(int no)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
string talkId = string.Empty;
|
||||
if (no == 0)
|
||||
{
|
||||
talkId = _messageService.GetTalkId(userId, "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no.ToString());
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
talkId = _messageService.GetTalkId(userId, userInfo.userId);
|
||||
}
|
||||
|
||||
if (await _messageService.DeleteMsgByTalkId(talkId, userId))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("删除失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,10 @@ public class UserController : ControllerBase
|
||||
{
|
||||
return PoAction.Message("用户本身!", 101);
|
||||
}
|
||||
if (userInfo.areaId != StateHelper.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 102);
|
||||
}
|
||||
|
||||
object user = new { userInfo.userNo, userInfo.nick, userInfo.sex, userInfo.sign };
|
||||
var attrInfo = await _attrService.GetUserAttrModel(userInfo.userId); //基础属性
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class MallBuyParms
|
||||
{
|
||||
public string id { get; set; }
|
||||
public int count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class SendMsgParms
|
||||
{
|
||||
public int no { get; set; }
|
||||
public string sign { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user