修复
This commit is contained in:
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("删除失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user