feat: 完善积分明细功能

pull/1/head
Yosheng 2023-07-30 16:15:15 +08:00
parent 63f7abe3ba
commit 9a437352d6
5 changed files with 41 additions and 9 deletions

View File

@ -11,6 +11,8 @@ public interface IUserPointService
Task<PageResultDto<UserPointDto>> GetUserPoints(GetUserPointDto req);
Task CreateUserPoint(CreateUserPointDto input);
Task DeletePoint(long userPointId);
}
public class UserPointService : IUserPointService
@ -36,6 +38,8 @@ public class UserPointService : IUserPointService
CreateTime = userPoint.CreateTime
};
queryable = queryable.Where(x => x.UserId == req.UserId, req.UserId.HasValue);
var count = queryable.Count();
var data = await queryable.OrderByDescending(x => x.CreateTime).Paging(req).ToListAsync().ConfigureAwait(false);
@ -52,4 +56,14 @@ public class UserPointService : IUserPointService
_userPointManagementDbContext.UserPoints.Add(new UserPoint(input.UserId, input.Point));
await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false);
}
public async Task DeletePoint(long userPointId)
{
await using var _userPointManagementDbContext = await _dbContextFactory.CreateDbContextAsync();
var userPoint = await _userPointManagementDbContext.UserPoints.FirstOrDefaultAsync(x => x.Id == userPointId)
.ConfigureAwait(false);
_userPointManagementDbContext.Remove(userPoint);
await _userPointManagementDbContext.SaveChangesAsync().ConfigureAwait(false);
}
}

View File

@ -35,6 +35,9 @@ public class UserService : IUserService
var queryable = from user in _userPointManagementDbContext.Users
select user;
queryable = queryable.Where(x => x.Mobile.Contains(req.Keyword) || x.Name.Contains(req.Keyword),
!string.IsNullOrEmpty(req.Keyword));
var count = queryable.Count();
var data = await queryable.OrderByDescending(x => x.Id).Paging(req).ToListAsync().ConfigureAwait(false);

View File

@ -32,7 +32,7 @@
Path = "/user-point",
Name = "用户积分",
Key = "user-point",
Icon = "smile",
Icon = "unordered-list",
}
};

View File

@ -1,4 +1,4 @@
@inherits UserPointManageBase
@inherits UserPointManagement.Web.Pages.UserPointPage.UserPointDetailBase
@page "/user-point"
@using System.ComponentModel.DataAnnotations
@using System.Text.Json
@ -7,7 +7,7 @@
@using UserPointManagement.Application.Services
@inject IUserPointService UserPointService;
<PageContainer Title="用户积分管理">
<PageContainer Title="用户积分明细">
<GridRow Style="margin: 10px 0">
<GridCol Span="12">
<Space Direction="@DirectionVHType.Horizontal">
@ -45,7 +45,14 @@
OnPageSizeChange="OnPageSizeChange">
<PropertyColumn Property="c => c.Name" title="用户姓名"/>
<PropertyColumn Property="c => c.Point" title="积分"/>
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd hh:mm"/>
<PropertyColumn Property="c => c.CreateTime" title="新增时间" Format="yyyy-MM-dd HH:mm"/>
<ActionColumn Title="操作" Width="220">
<Space Size=@("middle")>
<SpaceItem>
<Button Danger OnClick="()=>Delete(context.UserPointId)">删除</Button>
</SpaceItem>
</Space>
</ActionColumn>
</Table>
</PageContainer>

View File

@ -9,10 +9,11 @@ using UserPointManagement.Model.Dtos.UserPoint;
namespace UserPointManagement.Web.Pages.UserPointPage;
public class UserPointManageBase : ComponentBase
public class UserPointDetailBase : ComponentBase
{
[Inject] private IUserPointService _UserPointService { get; set; }
[Inject] private IUserService _UserService { get; set; }
[Inject] private IUserPointService UserPointService { get; set; }
[Inject] private IUserService UserService { get; set; }
[Inject] private MessageService MessageService { get; set; }
protected List<UserPointDto> _userPoints;
protected List<UserDto> _users;
@ -24,7 +25,7 @@ public class UserPointManageBase : ComponentBase
protected override async Task OnInitializedAsync()
{
_users = await _UserService.GetAllUsers().ConfigureAwait(false);
_users = await UserService.GetAllUsers().ConfigureAwait(false);
await RefreshTable();
}
@ -38,7 +39,7 @@ public class UserPointManageBase : ComponentBase
protected async Task RefreshTable()
{
_loading = true;
var res = await _UserPointService.GetUserPoints(new GetUserPointDto()
var res = await UserPointService.GetUserPoints(new GetUserPointDto()
{
UserId = _selectedUserId,
PageIndex = _pageIndex,
@ -64,4 +65,11 @@ public class UserPointManageBase : ComponentBase
_pageSize = args.PageSize;
await RefreshTable();
}
protected async Task Delete(long userPointId)
{
await UserPointService.DeletePoint(userPointId).ConfigureAwait(false);
await MessageService.Success("删除成功!");
await RefreshTable();
}
}