This commit is contained in:
jiangdong
2025-10-03 11:24:11 +08:00
commit d81cf186b0
67 changed files with 10243 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
using FateMaster.API.Data;
using FateMaster.API.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace FateMaster.API.Controllers.Admin;
[ApiController]
[Route("api/admin/[controller]")]
public class PricesController : ControllerBase
{
private readonly ApplicationDbContext _context;
public PricesController(ApplicationDbContext context)
{
_context = context;
}
/// <summary>
/// 获取所有价格配置
/// </summary>
[HttpGet]
public async Task<ActionResult<List<PriceConfig>>> GetAll()
{
return await _context.PriceConfigs.ToListAsync();
}
/// <summary>
/// 更新价格配置
/// </summary>
[HttpPut("{id}")]
public async Task<ActionResult> Update(int id, [FromBody] UpdatePriceRequest request)
{
var price = await _context.PriceConfigs.FindAsync(id);
if (price == null)
{
return NotFound();
}
price.Price = request.Price;
price.IsEnabled = request.IsEnabled;
price.UpdatedAt = DateTime.UtcNow;
await _context.SaveChangesAsync();
return Ok(price);
}
}
public record UpdatePriceRequest(decimal Price, bool IsEnabled);

View File

@@ -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
});
}
}

View File

@@ -0,0 +1,88 @@
using FateMaster.API.Data;
using FateMaster.API.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace FateMaster.API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class DivinationController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly ILogger<DivinationController> _logger;
public DivinationController(
ApplicationDbContext context,
ILogger<DivinationController> logger)
{
_context = context;
_logger = logger;
}
/// <summary>
/// 获取价格配置
/// </summary>
[HttpGet("prices")]
public async Task<ActionResult<List<PriceConfig>>> GetPrices()
{
var prices = await _context.PriceConfigs
.Where(p => p.IsEnabled)
.ToListAsync();
return Ok(prices);
}
/// <summary>
/// 提交卜卦请求
/// </summary>
[HttpPost("submit")]
public async Task<ActionResult<DivinationRecord>> Submit([FromBody] SubmitRequest request)
{
try
{
var record = new DivinationRecord
{
Type = request.Type,
InputData = request.InputData,
PaymentStatus = "pending",
PaymentMethod = request.PaymentMethod,
Amount = request.Amount,
ClientIp = HttpContext.Connection.RemoteIpAddress?.ToString(),
Language = request.Language ?? "zh-CN"
};
_context.DivinationRecords.Add(record);
await _context.SaveChangesAsync();
return Ok(record);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error submitting divination request");
return StatusCode(500, new { message = "提交失败" });
}
}
/// <summary>
/// 获取卜卦结果
/// </summary>
[HttpGet("{id}")]
public async Task<ActionResult<DivinationRecord>> GetResult(long id)
{
var record = await _context.DivinationRecords.FindAsync(id);
if (record == null)
{
return NotFound();
}
return Ok(record);
}
}
public record SubmitRequest(
string Type,
string InputData,
string? PaymentMethod,
decimal Amount,
string? Language
);