mirror of
https://gitea.tendokyu.moe/Kayori/MedusaPluginChargeMachine.git
synced 2026-10-08 23:09:47 +03:00
Introduce ChargeMachineDbContext (SQLite) with ArticleContent and ChargeHistory entities, plus migrations, and wire it up via ConfigurePluginServices/OnAppInitialize with startup migration and article-content seeding. - ChargeEaChargeHandler now records each charge to ChargeHistory - GetConfigEaChargeHandler serves article config from the DB instead of hardcoded values, and adds multibills/readagreement fields - GetLastLogEaChargeHandler returns real daily totals and recent charge items from history, keyed by session card - Add GetRecentChargeEaChargeHandler (paginated charge history) and OpChPassEaChargeHandler (PIN change) - Update handlers to the new HandleAsync/primary-constructor style, file-scoped namespaces - Bump EF Core/Identity packages and Abstractions reference to net10.0/10.0.10
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Abstractions.Handlers;
|
|
using Abstractions.SerializationTypes;
|
|
using MedusaPluginChargeMachine.Models.Request;
|
|
using MedusaPluginChargeMachine.Models.Response;
|
|
using MedusaPluginChargeMachine.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace MedusaPluginChargeMachine.Handlers.LA9;
|
|
|
|
public class GetLastLogEaChargeHandler(ISessionService sessionService, ChargeMachineDbContext db)
|
|
: Handler<GetLastLogRequest, GetLastLogEaChargeResponse>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Module("eacharge");
|
|
Method("getlastlog");
|
|
}
|
|
|
|
public override async Task<GetLastLogEaChargeResponse> HandleAsync(GetLastLogRequest req, string model)
|
|
{
|
|
var today = DateTime.UtcNow.Date;
|
|
var cardId = (string?)null;
|
|
|
|
if (req.SessionId is not null)
|
|
{
|
|
var session = sessionService.GetSession(req.SessionId);
|
|
cardId = session.refId;
|
|
}
|
|
|
|
var query = db.ChargeHistories.AsQueryable();
|
|
if (cardId is not null)
|
|
query = query.Where(h => h.CardId == cardId);
|
|
|
|
var todayTotal = await query
|
|
.Where(h => h.OrderDate.Date == today)
|
|
.SumAsync(h => (int?)h.ChargeAmount) ?? 0;
|
|
|
|
var recentItems = await query
|
|
.OrderByDescending(h => h.OrderDate)
|
|
.Take(10)
|
|
.ToListAsync();
|
|
|
|
return new GetLastLogEaChargeResponse
|
|
{
|
|
Status = 0,
|
|
Header = new GetLastLogEaChargeHeader
|
|
{
|
|
Chargedaily = new XrpcInt(todayTotal),
|
|
Items = recentItems.Select((h, i) => new GetLastLogChargeItem
|
|
{
|
|
ChargeId = new XrpcString(h.Id.ToString()),
|
|
ChargeNum = new XrpcInt(h.ChargeNum),
|
|
ChargeAmount = new XrpcInt(h.ChargeAmount)
|
|
}).ToList()
|
|
}
|
|
};
|
|
}
|
|
}
|