小程序参赛记录
This commit is contained in:
parent
9540dbcd9f
commit
f7eed7e479
@ -489,69 +489,96 @@ public class MyController : IDynamicApiController
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
|
||||
var query = _orderRepository.AsQueryable()
|
||||
.LeftJoin<EventRegistration>((o, r) => o.RegistrationId == r.Id)
|
||||
.Where((o, r) => o.Id == id && o.CreatedUserId == userId && !o.DeleteMark)
|
||||
.Select((o, r) => new { Order = o, Registration = r });
|
||||
|
||||
var orderInfo = await query.FirstAsync();
|
||||
if (orderInfo == null || orderInfo.Order == null) throw Oops.Bah("订单不存在");
|
||||
// 1. 先查询订单
|
||||
var order = await _orderRepository.GetFirstAsync(o => o.Id == id && o.CreatedUserId == userId && !o.DeleteMark);
|
||||
if (order == null) throw Oops.Bah("订单不存在");
|
||||
|
||||
// 2. 查询关联的报名信息
|
||||
EventRegistration? registration = null;
|
||||
if (order.RegistrationId > 0)
|
||||
{
|
||||
registration = await _registrationRepository.GetFirstAsync(r => r.Id == order.RegistrationId && !r.DeleteMark);
|
||||
}
|
||||
|
||||
// 3. 获取赛事名称
|
||||
var eventName = await _eventRepository.AsQueryable()
|
||||
.Where(e => e.Id == orderInfo.Order.EventId)
|
||||
.Where(e => e.Id == order.EventId)
|
||||
.Select(e => e.EventName)
|
||||
.FirstAsync();
|
||||
|
||||
var items = await _registrationItemRepository.AsQueryable()
|
||||
.Where(i => i.RegistrationId == orderInfo.Order.RegistrationId && !i.DeleteMark)
|
||||
.Select(i => new MyOrderItemDto
|
||||
{
|
||||
ProjectName = i.ProjectName,
|
||||
GroupName = i.GroupName,
|
||||
Fee = i.TotalPrice
|
||||
})
|
||||
.ToListAsync();
|
||||
// 4. 获取报名项目列表(如果有关联的报名记录)
|
||||
List<MyOrderItemDto> items = new List<MyOrderItemDto>();
|
||||
if (order.RegistrationId > 0)
|
||||
{
|
||||
items = await _registrationItemRepository.AsQueryable()
|
||||
.Where(i => i.RegistrationId == order.RegistrationId && !i.DeleteMark)
|
||||
.Select(i => new MyOrderItemDto
|
||||
{
|
||||
ProjectName = i.ProjectName,
|
||||
GroupName = i.GroupName,
|
||||
Fee = i.TotalPrice
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
return new MyOrderDetailDto
|
||||
{
|
||||
Id = orderInfo.Order.Id,
|
||||
OrderNo = orderInfo.Order.OrderNo,
|
||||
Id = order.Id,
|
||||
OrderNo = order.OrderNo,
|
||||
EventName = eventName,
|
||||
ActualAmount = orderInfo.Order.ActualAmount,
|
||||
RefundAmount = orderInfo.Order.OrderType == 2 ? orderInfo.Order.ActualAmount : null,
|
||||
RefundTime = orderInfo.Order.OrderType == 2 ? orderInfo.Order.PaymentTime : null,
|
||||
OrderStatus = orderInfo.Order.OrderStatus,
|
||||
PaymentTime = orderInfo.Order.PaymentTime,
|
||||
PaymentMethod = orderInfo.Registration?.PaymentMethod ?? 0,
|
||||
ActualAmount = order.ActualAmount,
|
||||
RefundAmount = order.OrderType == 2 ? order.ActualAmount : null,
|
||||
RefundTime = order.OrderType == 2 ? order.PaymentTime : null,
|
||||
OrderStatus = order.OrderStatus,
|
||||
PaymentTime = order.PaymentTime,
|
||||
PaymentMethod = registration?.PaymentMethod ?? 0,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 我的参赛记录(暂不对外提供)
|
||||
/// 我的参赛记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ApiDescriptionSettings(false)]
|
||||
[NonAction]
|
||||
[HttpGet("registrations")]
|
||||
[DisplayName("我的参赛记录")]
|
||||
public async Task<PageResult<MyRegistrationDto>> GetRegistrations([FromQuery] MyPageInput input)
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
var query = _registrationRepository.AsQueryable()
|
||||
.LeftJoin<EventInfo>((r, e) => r.EventId == e.Id)
|
||||
|
||||
// 1. 先分页查询报名记录
|
||||
var regQuery = _registrationRepository.AsQueryable()
|
||||
.Where(r => r.CreatedUserId == userId && !r.DeleteMark)
|
||||
.Select((r, e) => new MyRegistrationDto
|
||||
.OrderByDescending(r => r.RegistrationTime);
|
||||
|
||||
var pagedRegs = await regQuery.ToPagedListAsync(input);
|
||||
|
||||
// 2. 获取所有赛事ID,然后批量查询赛事信息
|
||||
var eventIds = pagedRegs.Rows.Select(r => r.EventId).Distinct().ToList();
|
||||
var eventList = await _eventRepository.AsQueryable()
|
||||
.Where(e => eventIds.Contains(e.Id))
|
||||
.ToListAsync();
|
||||
var eventsDict = eventList.ToDictionary(e => e.Id, e => e.EventName);
|
||||
|
||||
// 3. 构建 DTO 列表
|
||||
var result = new PageResult<MyRegistrationDto>
|
||||
{
|
||||
PageNo = pagedRegs.PageNo,
|
||||
PageSize = pagedRegs.PageSize,
|
||||
Total = pagedRegs.Total,
|
||||
Pages = pagedRegs.Pages,
|
||||
Rows = pagedRegs.Rows.Select(r => new MyRegistrationDto
|
||||
{
|
||||
Id = r.Id,
|
||||
EventName = e.EventName,
|
||||
EventName = eventsDict.ContainsKey(r.EventId) ? eventsDict[r.EventId] : "",
|
||||
TeamName = r.TeamName,
|
||||
Status = r.PaymentStatus,
|
||||
RegistrationTime = r.RegistrationTime,
|
||||
ProjectNames = ""
|
||||
})
|
||||
.OrderByDescending(r => r.RegistrationTime);
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
var result = await query.ToPagedListAsync(input);
|
||||
|
||||
// 4. 填充项目名称
|
||||
if (result.Rows.Any())
|
||||
{
|
||||
var registrationIds = result.Rows.Select(r => r.Id).ToList();
|
||||
|
||||
@ -3622,7 +3622,7 @@
|
||||
</member>
|
||||
<member name="M:YD_Event.Application.Client.MyController.GetRegistrations(YD_Event.Application.Client.Dtos.MyPageInput)">
|
||||
<summary>
|
||||
我的参赛记录(暂不对外提供)
|
||||
我的参赛记录
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user