143 lines
4.7 KiB
C#
143 lines
4.7 KiB
C#
using Newtonsoft.Json;
|
|
|
|
namespace Application.Web.Controllers.User;
|
|
|
|
/// <summary>
|
|
/// 用户背包信息
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "User")]
|
|
[Route("User/[controller]/[action]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class BagController : ControllerBase
|
|
{
|
|
private readonly IUnitUserWeight _weightService;
|
|
private readonly IGameGoodsService _goodsService;
|
|
private readonly IGameEquService _equService;
|
|
private readonly IUnitUserAccService _accService;
|
|
|
|
public BagController(IUnitUserWeight weightService, IGameGoodsService goodsService, IGameEquService equService,
|
|
IUnitUserAccService accService)
|
|
{
|
|
_weightService = weightService;
|
|
_goodsService = goodsService;
|
|
_equService = equService;
|
|
_accService = accService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取背包信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserBagData()
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var accInfo = await _accService.GetUserAccInfo(userId);
|
|
long gold = (long)accInfo.gold;
|
|
long cowry = (long)accInfo.cowry;
|
|
|
|
long copper = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
|
|
var userWeight = await _weightService.GetUserWeightInfo(userId);
|
|
int onWeight = (int)userWeight.onWeight;
|
|
int maxWeight = (int)userWeight.maxWeight;
|
|
|
|
return PoAction.Ok(new { onWeight, maxWeight, cowry, gold, copper });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户道具数据
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="type"></param>
|
|
/// <param name="ch"></param>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserBagProp(int type, int ch, string? query, int page)
|
|
{
|
|
RefAsync<int> total = 0;
|
|
string userId = StateHelper.userId;
|
|
if (type == 0)
|
|
{
|
|
int _t = 0;
|
|
switch (ch)
|
|
{
|
|
case 1:
|
|
_t = 1;
|
|
break;
|
|
case 2:
|
|
_t = 2;
|
|
break;
|
|
case 3:
|
|
_t = 3;
|
|
break;
|
|
}
|
|
|
|
var data = await _equService.GetUserEquData(userId, _t, query, page, 10, total);
|
|
return PoAction.Ok(new { data, total = total.Value});
|
|
}
|
|
else if (type == 1)
|
|
{
|
|
List<string> code = new List<string>() { nameof(GoodsEnum.Code.Drug) };
|
|
var data = await _goodsService.GetUserGoodsData(userId, code, new List<string>(), query, page, 10, total);
|
|
return PoAction.Ok(new { data, total = total.Value });
|
|
}
|
|
else if (type == 2)
|
|
{
|
|
List<string> code = new List<string>();
|
|
List<string> noCode = new List<string>() { nameof(GoodsEnum.Code.Drug) };
|
|
switch (ch)
|
|
{
|
|
case 1:
|
|
code.Add(nameof(GoodsEnum.Code.Gem));
|
|
break;
|
|
case 2:
|
|
code.Add(nameof(GoodsEnum.Code.Palace));
|
|
break;
|
|
case 3:
|
|
code.Add(nameof(GoodsEnum.Code.Mark));
|
|
break;
|
|
case 4:
|
|
code.Add(nameof(GoodsEnum.Code.Pack));
|
|
break;
|
|
case 5:
|
|
code.Add(nameof(GoodsEnum.Code.Mak));
|
|
break;
|
|
case 6:
|
|
code.Add(nameof(GoodsEnum.Code.Paper));
|
|
break;
|
|
case 7:
|
|
code.Add(nameof(GoodsEnum.Code.Card));
|
|
break;
|
|
case 8:
|
|
code.Add(nameof(GoodsEnum.Code.Cargo));
|
|
break;
|
|
case 9:
|
|
code.Add(nameof(GoodsEnum.Code.Prop));
|
|
break;
|
|
}
|
|
|
|
var data = await _goodsService.GetUserGoodsData(userId, code, noCode, query, 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="parms"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IPoAction> CheckUserProp([FromBody] CheckUserPropParms parms)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
List<TowerNeeds> needs = JsonConvert.DeserializeObject<List<TowerNeeds>>(parms.needs);
|
|
var result = await GameBus.CheckNeeds(userId, needs, 1);
|
|
return PoAction.Ok(result);
|
|
}
|
|
} |