238 lines
7.9 KiB
C#
238 lines
7.9 KiB
C#
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;
|
|
private readonly IGameEquService _equService;
|
|
private readonly IUnitUserWeight _weightService;
|
|
|
|
public SettingController(IUnitUserService userService,IGameGoodsService goodsService,IGameEquService equService,IUnitUserWeight weightService)
|
|
{
|
|
_userService = userService;
|
|
_goodsService = goodsService;
|
|
_equService = equService;
|
|
_weightService = weightService;
|
|
}
|
|
|
|
/// <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("暂无法设置!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新/重置设置
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> RefreshSetting(int type)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
if (type == 0)//刷新负重
|
|
{
|
|
var equWeight = await _equService.GetUserEquWeightSum(userId);
|
|
var goodsWeight = await _goodsService.GetUserGoodWeightSum(userId,0);
|
|
int onWeight = equWeight + goodsWeight;//当前总占用负重
|
|
var weightLog = await _weightService.GetUserWeightLog(userId);
|
|
int maxWeight = weightLog.Sum(it => (int)it.sum);
|
|
var weightInfo = await _weightService.GetUserWeightInfo(userId);
|
|
weightInfo.onWeight = onWeight;
|
|
weightInfo.maxWeight = maxWeight;
|
|
|
|
var shipWeight = await _goodsService.GetUserGoodWeightSum(userId,1);
|
|
weightInfo.shipOnWeight = shipWeight;
|
|
if (await _weightService.UpdateUserWeight(weightInfo))
|
|
{
|
|
return PoAction.Ok(true,"负重数据已刷新成功!");
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("负重刷新失败,请稍后尝试!");
|
|
}
|
|
}
|
|
else if (type == 1)//刷新图标
|
|
{
|
|
return PoAction.Ok(true, "图标刷新成功!");
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("无效的操作!");
|
|
}
|
|
}
|
|
} |