init
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using FateMaster.API.Data;
|
||||
using FateMaster.API.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FateMaster.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/admin/[controller]")]
|
||||
public class RecordsController : ControllerBase
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public RecordsController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取卜卦记录列表
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> GetRecords(
|
||||
[FromQuery] int page = 1,
|
||||
[FromQuery] int pageSize = 20,
|
||||
[FromQuery] string? type = null,
|
||||
[FromQuery] string? paymentStatus = null)
|
||||
{
|
||||
var query = _context.DivinationRecords.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(type))
|
||||
{
|
||||
query = query.Where(r => r.Type == type);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(paymentStatus))
|
||||
{
|
||||
query = query.Where(r => r.PaymentStatus == paymentStatus);
|
||||
}
|
||||
|
||||
var total = await query.CountAsync();
|
||||
var records = await query
|
||||
.OrderByDescending(r => r.CreatedAt)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
total,
|
||||
page,
|
||||
pageSize,
|
||||
data = records
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取统计数据
|
||||
/// </summary>
|
||||
[HttpGet("statistics")]
|
||||
public async Task<ActionResult> GetStatistics()
|
||||
{
|
||||
var total = await _context.DivinationRecords.CountAsync();
|
||||
var paidCount = await _context.DivinationRecords
|
||||
.CountAsync(r => r.PaymentStatus == "paid");
|
||||
var totalRevenue = await _context.DivinationRecords
|
||||
.Where(r => r.PaymentStatus == "paid")
|
||||
.SumAsync(r => r.Amount);
|
||||
|
||||
var typeStats = await _context.DivinationRecords
|
||||
.GroupBy(r => r.Type)
|
||||
.Select(g => new
|
||||
{
|
||||
Type = g.Key,
|
||||
Count = g.Count()
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
total,
|
||||
paidCount,
|
||||
totalRevenue,
|
||||
typeStats
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user