优惠劵完善
This commit is contained in:
parent
b4db8390ea
commit
534bd5f40f
@ -36,29 +36,56 @@ public class CouponService : BaseService<YD_Event.Core.Entities.Coupon>, ITransi
|
|||||||
// 先获取实体列表
|
// 先获取实体列表
|
||||||
var entityList = await query.ToPagedListAsync(input);
|
var entityList = await query.ToPagedListAsync(input);
|
||||||
|
|
||||||
// 转换并填充赛事名称
|
// 获取所有相关的赛事ID
|
||||||
var resultList = new List<CouponPageOutput>();
|
var allEventIds = entityList.Rows
|
||||||
foreach (var item in entityList.Rows)
|
.Where(x => !string.IsNullOrEmpty(x.EventIds))
|
||||||
|
.SelectMany(x => x.EventIds.Split(',', StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
.Select(long.Parse)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var eventMap = new Dictionary<long, string>();
|
||||||
|
if (allEventIds.Any())
|
||||||
{
|
{
|
||||||
var output = item.Adapt<CouponPageOutput>();
|
var events = await _eventRepository.AsQueryable()
|
||||||
output.EventIds = string.IsNullOrEmpty(item.EventIds)
|
.Where(x => allEventIds.Contains(x.Id))
|
||||||
|
.ToListAsync();
|
||||||
|
eventMap = events.ToDictionary(x => x.Id, x => x.EventName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换并填充赛事名称
|
||||||
|
var resultList = entityList.Rows.Select(item =>
|
||||||
|
{
|
||||||
|
var eventIdList = string.IsNullOrEmpty(item.EventIds)
|
||||||
? new List<long>()
|
? new List<long>()
|
||||||
: item.EventIds.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();
|
: item.EventIds.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();
|
||||||
|
|
||||||
if (output.EventIds.Any())
|
var eventNames = "通用";
|
||||||
|
if (eventIdList.Any())
|
||||||
{
|
{
|
||||||
var eventNames = await _eventRepository.AsQueryable()
|
var names = eventIdList
|
||||||
.Where(x => output.EventIds.Contains(x.Id))
|
.Where(id => eventMap.ContainsKey(id))
|
||||||
.Select(x => x.EventName)
|
.Select(id => eventMap[id]);
|
||||||
.ToListAsync();
|
eventNames = string.Join(",", names);
|
||||||
output.EventNames = string.Join(",", eventNames);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
return new CouponPageOutput
|
||||||
{
|
{
|
||||||
output.EventNames = "通用";
|
Id = item.Id,
|
||||||
}
|
Name = item.Name,
|
||||||
resultList.Add(output);
|
Type = item.Type,
|
||||||
}
|
Value = item.Value,
|
||||||
|
StartTime = item.StartTime,
|
||||||
|
EndTime = item.EndTime,
|
||||||
|
RedemptionCode = item.RedemptionCode,
|
||||||
|
TotalQuantity = item.TotalQuantity,
|
||||||
|
ClaimedQuantity = item.ClaimedQuantity,
|
||||||
|
UsedQuantity = item.UsedQuantity,
|
||||||
|
CreatedTime = item.CreatedTime,
|
||||||
|
EventIds = eventIdList,
|
||||||
|
EventNames = eventNames
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
return new CouponPageResult
|
return new CouponPageResult
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user