232
This commit is contained in:
193
Service/Application.Web/Controllers/User/SettingController.cs
Normal file
193
Service/Application.Web/Controllers/User/SettingController.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.User;
|
||||
|
||||
/// <summary>
|
||||
/// 设置接口
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(GroupName = "User")]
|
||||
[Route("User/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class SettingController : ControllerBase
|
||||
{
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
|
||||
public SettingController(IUnitUserService userService,IGameGoodsService goodsService)
|
||||
{
|
||||
_userService = userService;
|
||||
_goodsService = goodsService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserConfig(int type)
|
||||
{
|
||||
int result = 0;
|
||||
string userId = StateHelper.userId;
|
||||
var data = await _userService.GetUserConfigInfo(userId);
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
result = (int)data.friendRole;
|
||||
break;
|
||||
case 1:
|
||||
result = (int)data.giveRole;
|
||||
break;
|
||||
case 2:
|
||||
result = (int)data.autoBag;
|
||||
break;
|
||||
case 3:
|
||||
result = (int)data.autoDrug;
|
||||
break;
|
||||
}
|
||||
|
||||
return PoAction.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置配置
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> UpdateUserConfig(int type, int state)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
if (type == 0)
|
||||
{
|
||||
int[] target = [0, 1, 2];
|
||||
if (target.Contains(state))
|
||||
{
|
||||
if (await _userService.UpdateUserConfigInfo(userId, nameof(UserEnum.ConfigCode.FriendRole), state))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("设置失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("无效的设置!");
|
||||
}
|
||||
}
|
||||
else if (type == 1)
|
||||
{
|
||||
int[] target = [0, 1];
|
||||
if (target.Contains(state))
|
||||
{
|
||||
if (await _userService.UpdateUserConfigInfo(userId, nameof(UserEnum.ConfigCode.GiveRole), state))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("设置失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("无效的设置!");
|
||||
}
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
int[] target = [0, 1];
|
||||
if (target.Contains(state))
|
||||
{
|
||||
var data = await _userService.GetUserConfigInfo(userId);
|
||||
if (data.autoBag == -1)//判断物品开通
|
||||
{
|
||||
var goodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameAutoBagGoodsId);
|
||||
if (goodsCount < 1)
|
||||
{
|
||||
return PoAction.Message("您暂无百宝箱,无法开启!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameAutoBagGoodsId, 1, "使用物品"))
|
||||
{
|
||||
if (await _userService.UpdateUserConfigInfo(userId, nameof(UserEnum.ConfigCode.AutoBag), state))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("开启失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("开启失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
if (await _userService.UpdateUserConfigInfo(userId, nameof(UserEnum.ConfigCode.AutoBag), state))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("设置失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("无效的设置!");
|
||||
}
|
||||
}
|
||||
else if (type == 3)
|
||||
{
|
||||
int[] target = [0, 1];
|
||||
if (target.Contains(state))
|
||||
{
|
||||
var data = await _userService.GetUserConfigInfo(userId);
|
||||
if (data.autoBag == -1)//判断物品开通
|
||||
{
|
||||
var goodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameAutoDrugGoodsId);
|
||||
if (goodsCount < 1)
|
||||
{
|
||||
return PoAction.Message("您暂无急救箱,无法开启!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameAutoDrugGoodsId, 1, "使用物品"))
|
||||
{
|
||||
if (await _userService.UpdateUserConfigInfo(userId, nameof(UserEnum.ConfigCode.AutoDrug), state))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("开启失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("开启失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
if (await _userService.UpdateUserConfigInfo(userId, nameof(UserEnum.ConfigCode.AutoDrug), state))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("设置失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("无效的设置!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("暂无法设置!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user