后台订单详情显示项目
This commit is contained in:
parent
db56ff359a
commit
91ffc069d6
@ -602,14 +602,20 @@ public class MyController : IDynamicApiController
|
|||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 获取赛事名称
|
// 3. 获取赛事信息和名称
|
||||||
var eventName = await _eventRepository.AsQueryable()
|
var eventQuery = await _eventRepository.AsQueryable()
|
||||||
.Where(e => e.Id == order.EventId)
|
.Where(e => e.Id == order.EventId)
|
||||||
.Select(e => e.EventName)
|
.Select(e => new { e.EventName, e.ChargeMode })
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
var eventName = eventQuery.EventName;
|
||||||
|
var chargeMode = eventQuery.ChargeMode;
|
||||||
|
|
||||||
// 4. 获取报名项目列表(如果有关联的报名记录)
|
// 4. 判断是否需要返回项目列表
|
||||||
List<MyOrderItemDto> items = new List<MyOrderItemDto>();
|
List<MyOrderItemDto> items = new List<MyOrderItemDto>();
|
||||||
|
|
||||||
|
// 仅当 ChargeMode 不是 Free 或 FixedPrice 时才查询项目列表
|
||||||
|
if (chargeMode != ChargeMode.Free && chargeMode != ChargeMode.FixedPrice)
|
||||||
|
{
|
||||||
if (order.RegistrationId > 0)
|
if (order.RegistrationId > 0)
|
||||||
{
|
{
|
||||||
if (order.OrderType == 2)
|
if (order.OrderType == 2)
|
||||||
@ -656,8 +662,6 @@ public class MyController : IDynamicApiController
|
|||||||
Fee = i.TotalPrice
|
Fee = i.TotalPrice
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -675,6 +679,7 @@ public class MyController : IDynamicApiController
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 如果是退款订单,查找关联的原始订单,显示原始支付金额
|
// 如果是退款订单,查找关联的原始订单,显示原始支付金额
|
||||||
decimal displayAmount = order.ActualAmount;
|
decimal displayAmount = order.ActualAmount;
|
||||||
|
|||||||
@ -262,11 +262,83 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
|
|||||||
if (orderInfo == null || orderInfo.Order == null) throw Oops.Bah("订单不存在");
|
if (orderInfo == null || orderInfo.Order == null) throw Oops.Bah("订单不存在");
|
||||||
|
|
||||||
var registrationId = orderInfo.Order.RegistrationId;
|
var registrationId = orderInfo.Order.RegistrationId;
|
||||||
var items = await _itemRepository.AsQueryable().Where(x => x.RegistrationId == registrationId).ToListAsync();
|
List<EventRegistrationItem> items = new();
|
||||||
var persons = await _personRepository.AsQueryable().Where(x => x.RegistrationId == registrationId).ToListAsync();
|
List<EventRegistrationPerson> persons = new();
|
||||||
|
List<OrderItemDto> itemDtos = new();
|
||||||
|
List<OrderPersonDto> personDtos = new();
|
||||||
|
string projectNames = "";
|
||||||
|
string groupNames = "";
|
||||||
|
|
||||||
|
// 判断是否需要返回项目列表:仅当 ChargeMode 不是 Free 或 FixedPrice 时才查询项目
|
||||||
|
if (orderInfo.ChargeMode != ChargeMode.Free && orderInfo.ChargeMode != ChargeMode.FixedPrice)
|
||||||
|
{
|
||||||
|
if (orderInfo.Order.OrderType == 2)
|
||||||
|
{
|
||||||
|
// 退款订单:通过 RefundOrderId 字段精准找到对应的软删除记录
|
||||||
|
var refundOrderId = orderInfo.Order.Id;
|
||||||
|
|
||||||
|
// 先找被软删除的人员中 RefundOrderId 等于当前退款订单ID的
|
||||||
|
var deletedPersons = await _db.Queryable<EventRegistrationPerson>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => x.RegistrationId == registrationId &&
|
||||||
|
x.DeleteMark == true &&
|
||||||
|
x.RefundOrderId == refundOrderId)
|
||||||
|
.Select(x => x.RegistrationItemId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (deletedPersons.Any())
|
||||||
|
{
|
||||||
|
// 找出这些人员关联的项目(去重)
|
||||||
|
var distinctItemIds = deletedPersons.Distinct().ToList();
|
||||||
|
items = await _db.Queryable<EventRegistrationItem>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => distinctItemIds.Contains(x.Id))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
// 查询对应的人员
|
||||||
|
persons = await _db.Queryable<EventRegistrationPerson>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => x.RegistrationId == registrationId &&
|
||||||
|
x.DeleteMark == true &&
|
||||||
|
x.RefundOrderId == refundOrderId)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果没有找到匹配的人员,再试试找项目的 RefundOrderId 等于当前退款订单ID的
|
||||||
|
items = await _db.Queryable<EventRegistrationItem>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => x.RegistrationId == registrationId &&
|
||||||
|
x.DeleteMark == true &&
|
||||||
|
x.RefundOrderId == refundOrderId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
// 查询对应的人员
|
||||||
|
var itemIds = items.Select(x => x.Id).ToList();
|
||||||
|
if (itemIds.Any())
|
||||||
|
{
|
||||||
|
persons = await _db.Queryable<EventRegistrationPerson>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => itemIds.Contains(x.RegistrationItemId))
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 普通订单:显示全部的项目(包括已删除的)
|
||||||
|
items = await _db.Queryable<EventRegistrationItem>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => x.RegistrationId == registrationId)
|
||||||
|
.ToListAsync();
|
||||||
|
persons = await _db.Queryable<EventRegistrationPerson>()
|
||||||
|
.ClearFilter()
|
||||||
|
.Where(x => x.RegistrationId == registrationId)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
// 将项目和人员转换为DTO
|
// 将项目和人员转换为DTO
|
||||||
var itemDtos = items.Select(x => new OrderItemDto
|
itemDtos = items.Select(x => new OrderItemDto
|
||||||
{
|
{
|
||||||
Id = x.Id,
|
Id = x.Id,
|
||||||
ProjectId = x.ProjectId,
|
ProjectId = x.ProjectId,
|
||||||
@ -275,7 +347,7 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
|
|||||||
Fee = x.TotalPrice
|
Fee = x.TotalPrice
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var personDtos = persons.Select(x => new OrderPersonDto
|
personDtos = persons.Select(x => new OrderPersonDto
|
||||||
{
|
{
|
||||||
Name = x.Name,
|
Name = x.Name,
|
||||||
GroupName = x.GroupName,
|
GroupName = x.GroupName,
|
||||||
@ -284,6 +356,10 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
|
|||||||
ProjectName = x.ProjectName
|
ProjectName = x.ProjectName
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
projectNames = string.Join(",", items.Select(x => x.ProjectName).Distinct());
|
||||||
|
groupNames = string.Join(",", items.Select(x => x.GroupName).Distinct());
|
||||||
|
}
|
||||||
|
|
||||||
return new OrderDetailOutput
|
return new OrderDetailOutput
|
||||||
{
|
{
|
||||||
Id = orderInfo.Order.Id,
|
Id = orderInfo.Order.Id,
|
||||||
@ -300,8 +376,8 @@ public class OrderService : BaseService<YD_Event.Core.Entities.Order>, ITransien
|
|||||||
orderInfo.Order.OrderStatus == OrderStatus.Completed ? "已完成" : "",
|
orderInfo.Order.OrderStatus == OrderStatus.Completed ? "已完成" : "",
|
||||||
EventName = orderInfo.EventName,
|
EventName = orderInfo.EventName,
|
||||||
ChargeMode = orderInfo.ChargeMode,
|
ChargeMode = orderInfo.ChargeMode,
|
||||||
ProjectNames = string.Join(",", items.Select(x => x.ProjectName).Distinct()),
|
ProjectNames = projectNames,
|
||||||
GroupNames = string.Join(",", items.Select(x => x.GroupName).Distinct()),
|
GroupNames = groupNames,
|
||||||
Items = itemDtos,
|
Items = itemDtos,
|
||||||
Persons = personDtos,
|
Persons = personDtos,
|
||||||
PaymentMethod = orderInfo.Registration?.PaymentMethod == 2 ? "线上" : "线下",
|
PaymentMethod = orderInfo.Registration?.PaymentMethod == 2 ? "线上" : "线下",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user