Skip to content

Commit

Permalink
Merge pull request #836 from LittleFish-233/master
Browse files Browse the repository at this point in the history
支持查看G币记录,添加用户权重的抽奖
  • Loading branch information
LittleFish-233 authored Sep 17, 2024
2 parents 967eeec + b33af06 commit 1599950
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CnGalWebSite.sln
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CnGalWebSite.Kanban.ChatGPT
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "审核", "审核", "{0AD54B7F-5170-4B84-A7AA-862A95DD0EE2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CnGalWebSite.ExamineService", "CnGalWebSite\CnGalWebSite.ExamineService\CnGalWebSite.ExamineService.csproj", "{708EADA8-5513-43FD-9005-0DE03A1AD0F7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CnGalWebSite.ExamineService", "CnGalWebSite\CnGalWebSite.ExamineService\CnGalWebSite.ExamineService.csproj", "{708EADA8-5513-43FD-9005-0DE03A1AD0F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ public async Task<ActionResult<Result>> EditCodeAsync(CommodityCodeEditModel mod
{
if (model.CanRedeemed == false)
{
await _userService.TryAddGCoins(item.ApplicationUserId, UserIntegralSourceType.CommodityCode, -item.Count, $"{item.Code} 修改为不可兑换,退回G币{item.Count}");
await _userService.TryAddGCoins(item.ApplicationUserId, UserIntegralSourceType.CommodityCode, -item.Count, $"{item.Code} 修改为不可兑换,退回G币 {item.Count}");
}
else
{
await _userService.TryAddGCoins(item.ApplicationUserId, UserIntegralSourceType.CommodityCode, item.Count, $"{item.Code} 修改为可兑换,增加G币{item.Count}");
await _userService.TryAddGCoins(item.ApplicationUserId, UserIntegralSourceType.CommodityCode, item.Count, $"{item.Code} 修改为可兑换,增加G币 {item.Count}");
}
}

Expand Down Expand Up @@ -374,7 +374,7 @@ public async Task<ActionResult<Result>> RedeemedCommodityCode(RedeemedCommodityC
var msg = "";
if (code.Type == CommodityCodeType.GCoins)
{
await _userService.TryAddGCoins(user.Id, UserIntegralSourceType.CommodityCode, code.Count, $"兑换码:{code.Code}");
await _userService.TryAddGCoins(user.Id, UserIntegralSourceType.CommodityCode, code.Count, $"使用兑换码 {code.Code}");
msg = $"成功兑换 {code.Count} G币";
}
else
Expand All @@ -400,5 +400,34 @@ public async Task<ActionResult<Result>> RedeemedCommodityCode(RedeemedCommodityC

return new Result { Successful = true, Error = msg };
}

[HttpPost]
public async Task<QueryResultModel<GCoinsRecordOverviewModel>> ListGCoinsRecord(QueryParameterModel model)
{
var user = await _appHelper.GetAPICurrentUserAsync(HttpContext);
if (user == null)
{
return new QueryResultModel<GCoinsRecordOverviewModel>
{
Parameter = model
};
}

var (items, total) = await _queryService.QueryAsync<UserIntegral, long>(_userIntegralRepository.GetAll().AsSingleQuery().Where(s => s.Type == UserIntegralType.GCoins && s.ApplicationUserId == user.Id), model,
s => string.IsNullOrWhiteSpace(model.SearchText) || (s.Note.Contains(model.SearchText)));

return new QueryResultModel<GCoinsRecordOverviewModel>
{
Items = await items.Select(s => new GCoinsRecordOverviewModel
{
SourceType = s.SourceType,
Count = s.Count,
Note = string.IsNullOrWhiteSpace(s.Note) ? s.SourceType.GetDisplayName() : s.Note,
Time = s.Time,
}).ToListAsync(),
Total = total,
Parameter = model
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ public async Task<ActionResult<DrawLotteryDataModel>> GetLotteryDataAsync(long i
{
Name = lottery.Name,
Id = lottery.Id,
Type = lottery.Type,
NotWinningUsers = lottery.Users.Where(s => s.IsHidden == false).Select(s => new LotteryUserDataModel
{
Id = s.ApplicationUserId,
Name = s.ApplicationUser.UserName,
Number = s.Number,
IsHidden = s.IsHidden
IsHidden = s.IsHidden,
Priority = 2,
}).ToList()
};

Expand All @@ -128,6 +130,24 @@ public async Task<ActionResult<DrawLotteryDataModel>> GetLotteryDataAsync(long i
model.NotWinningUsers.RemoveAll(s => item.WinningUsers.Select(s => s.ApplicationUserId).Contains(s.Id));
}

// 根据用户消耗的G币数量提升权重
var gcoins = await _userRepository.GetAll().AsNoTracking().Include(s => s.Commodities)
.Where(s => model.NotWinningUsers.Select(s => s.Id).ToList().Contains(s.Id)).Select(s => new
{
s.Id,
GCoins = s.Commodities.Sum(s => s.Price)
}).ToListAsync();

foreach (var item in model.NotWinningUsers)
{
var user = gcoins.FirstOrDefault(s => s.Id == item.Id);
if (user != null)
{
item.Priority = (int)(item.Priority * (1 + user.GCoins / 20.0));
}
}


return model;
}
catch (Exception ex)
Expand Down Expand Up @@ -354,7 +374,7 @@ public async Task<ActionResult<List<LotteryCardViewModel>>> GetLotteryCardsAsync
var lotteries = await _lotteryRepository.GetAll().AsNoTracking()
.Include(s => s.Users)
.Where(s => s.IsHidden == false && string.IsNullOrWhiteSpace(s.Name) == false)
.OrderByDescending(s=>s.Priority).ThenByDescending(s => s.CreateTime)
.OrderByDescending(s => s.Priority).ThenByDescending(s => s.CreateTime)
.ToListAsync();

var model = new List<LotteryCardViewModel>();
Expand All @@ -369,7 +389,7 @@ public async Task<ActionResult<List<LotteryCardViewModel>>> GetLotteryCardsAsync
Count = item.Users.Count,
EndTime = item.EndTime,
Id = item.Id,
GameSteamId=item.GameSteamId,
GameSteamId = item.GameSteamId,
MainPicture = _appHelper.GetImagePath(item.MainPicture, "app.png"),
Thumbnail = item.Thumbnail,
Name = item.Name,
Expand Down Expand Up @@ -700,10 +720,10 @@ public async Task<ActionResult<Result>> EditLottery(EditLotteryModel model)
[HttpPost]
public async Task<ActionResult<Result>> ParticipateInLottery(ParticipateInLotteryModel model)
{
if (_userService.CheckCurrentUserRole("Admin"))
{
return new Result { Successful = false, Error = "管理员不允许参与抽奖!" };
}
//if (_userService.CheckCurrentUserRole("Admin"))
//{
// return new Result { Successful = false, Error = "管理员不允许参与抽奖!" };
//}

var time = DateTime.Now.ToCstTime();
var lottery = await _lotteryRepository.GetAll().AsNoTracking()
Expand Down
16 changes: 10 additions & 6 deletions CnGalWebSite/CnGalWebSite.Components/wwwroot/css/bundle.css
Original file line number Diff line number Diff line change
Expand Up @@ -1288,16 +1288,20 @@ html {
word-break: break-all;
}
/*分页*/
.theme--light.m-pagination .m-pagination__item--active {
color: var(--md-sys-color-on-primary) !important;
.theme--light.m-pagination .m-pagination__navigation {
background: var(--md-sys-color-background) !important;
}

.theme--light.m-pagination .m-pagination__item {
background: var(--md-sys-color-background) !important;
color: var(--md-sys-color-on-background) !important;
background: var(--md-sys-color-background);
color: var(--md-sys-color-on-background);
}
.theme--light.m-pagination .m-pagination__navigation {
background: var(--md-sys-color-background) !important;

.theme--light.m-pagination .m-pagination__item--active {
color: var(--md-sys-color-on-primary) !important;
background: var(--md-sys-color-primary) !important;
}

/*弹出菜单*/
.theme--light.m-menu__content {
background: none!important;
Expand Down

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions CnGalWebSite/CnGalWebSite.Components/wwwroot/css/cover-default.css
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,20 @@ html {
word-break: break-all;
}
/*分页*/
.theme--light.m-pagination .m-pagination__item--active {
color: var(--md-sys-color-on-primary) !important;
.theme--light.m-pagination .m-pagination__navigation {
background: var(--md-sys-color-background) !important;
}

.theme--light.m-pagination .m-pagination__item {
background: var(--md-sys-color-background) !important;
color: var(--md-sys-color-on-background) !important;
background: var(--md-sys-color-background);
color: var(--md-sys-color-on-background);
}
.theme--light.m-pagination .m-pagination__navigation {
background: var(--md-sys-color-background) !important;

.theme--light.m-pagination .m-pagination__item--active {
color: var(--md-sys-color-on-primary) !important;
background: var(--md-sys-color-primary) !important;
}

/*弹出菜单*/
.theme--light.m-menu__content {
background: none!important;
Expand Down
4 changes: 3 additions & 1 deletion CnGalWebSite/CnGalWebSite.DataModel/Model/Lottery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class Lottery
public LotteryConditionType ConditionType { get; set; }

/// <summary>
/// 游戏SteamId
/// 游戏SteamId (复用这个字段,用来保存与参与条件相关的信息)
/// </summary>
public string GameSteamId { get; set; }

Expand All @@ -124,6 +124,8 @@ public enum LotteryType
Manual,
[Display(Name = "自动")]
Automatic,
[Display(Name = "用户权重")]
UserWeights,
}

public enum LotteryConditionType
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CnGalWebSite.DataModel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CnGalWebSite.DataModel.ViewModel.Commodities
{
public class GCoinsRecordBaseModel
{
public DateTime Time { get; set; }

public int Count { get; set; }

public string Note { get; set; }

public UserIntegralSourceType SourceType { get; set; }
}

public class GCoinsRecordOverviewModel : GCoinsRecordBaseModel
{

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using CnGalWebSite.DataModel.Model;
using System.Collections.Generic;

namespace CnGalWebSite.DataModel.ViewModel.Lotteries
{
Expand All @@ -8,6 +9,8 @@ public class DrawLotteryDataModel

public string Name { get; set; }

public LotteryType Type { get; set; }

public List<LotteryUserDataModel> NotWinningUsers { get; set; } = new List<LotteryUserDataModel>();

public List<LotteryAwardDataModel> Awards { get; set; } = new List<LotteryAwardDataModel>();
Expand Down Expand Up @@ -46,6 +49,7 @@ public class LotteryUserDataModel
public string Id { get; set; }
public int Number { get; set; }
public bool IsHidden { get; set; }
public int Priority { get; set; }
}

public class ExportLotteryDataModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


<div style="display: flex; justify-content: center;">
@if (Model.Type == LotteryType.Manual && Model.IsEnd == false)
@if (Model.Type != LotteryType.Automatic && Model.IsEnd == false)
{
<CnGalWebSite.Components.Buttons.MasaButton Fab Icon="mdi-wallet-giftcard " Tooltip="抽奖" OnClick="OnDraw" Color="info" Class="me-3"/>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@inject IHttpService _httpService
@inject IPopupService PopupService
@inject NavigationManager NavigationManager

<MDCard>
<DataTableCard TModel="GCoinsRecordOverviewModel" Headers="_headers" ApiUrl="@(_baseUrl)" Title="@($"{_name}列表")" ShowAddButton="false" @ref="dataTableCard">
<ItemColContent>
@if (context.Header.Value == nameof(GCoinsRecordOverviewModel.Time))
{
@context.Item.Time.ToString("yyyy-MM-dd HH:mm")
}
else
{
@context.Value
}
</ItemColContent>
</DataTableCard>

</MDCard>

@code {
private string _baseUrl = "api/commodities/ListGCoinsRecord";
private string _name = "G币记录";

private List<DataTableHeader<GCoinsRecordOverviewModel>> _headers = new List<DataTableHeader<GCoinsRecordOverviewModel>>
{
new (){ Text= "时间", Value= nameof(GCoinsRecordOverviewModel.Time)},
new (){ Text= "G币变动", Value= nameof(GCoinsRecordOverviewModel.Count)},
new (){ Text= "备注", Value= nameof(GCoinsRecordOverviewModel.Note)},
};

DataTableCard<GCoinsRecordOverviewModel> dataTableCard;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<MTab Value="2">
G币兑换<MIcon>@IconType.Lottery.ToIconString()</MIcon>
</MTab>
<MTab Value="3">
G币记录<MIcon>@IconType.Record.ToIconString()</MIcon>
</MTab>
</MTabs>
</MDCard>

Expand All @@ -54,6 +57,9 @@
<MTabItem Value="2">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.Codes.MainCard />
</MTabItem>
<MTabItem Value="3">
<CnGalWebSite.Shared.MasaComponent.PC.Commodities.ListGCoinsRecordsCard />
</MTabItem>

</MTabsItems>
</MCol>
Expand Down Expand Up @@ -126,6 +132,7 @@
{
"Shop" => 1,
"Code" => 2,
"Record" => 3,
_ => 1
};
StateHasChanged();
Expand All @@ -152,6 +159,7 @@
{
1 => "Shop",
2 => "Code",
3 => "Record",
_ => ""
}));

Expand Down
Loading

0 comments on commit 1599950

Please sign in to comment.