You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
4.1 KiB
78 lines
4.1 KiB
3 years ago
|
using BBWY.Common.Models;
|
||
|
using BBWY.Server.Model.Db;
|
||
|
using BBWY.Server.Model.Dto;
|
||
|
using System.Collections.Generic;
|
||
|
using Yitter.IdGenerator;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace BBWY.Server.Business
|
||
|
{
|
||
|
public class BillCorrectionBusiness : BaseBusiness, IDenpendency
|
||
|
{
|
||
|
public BillCorrectionBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
public IList<BillCorrectionOrderResponse> GetBillCorrectionOrderList(QueryBillCorrectionOrderRequest request)
|
||
|
{
|
||
|
request.EndTime = request.EndTime.Date.AddDays(1).AddSeconds(-1);
|
||
|
var orderList = fsql.Select<Order>()
|
||
|
.Where(o => request.ShopIds.Contains(o.ShopId) && o.StartTime >= request.StartTime && o.StartTime <= request.EndTime)
|
||
|
.OrderBy(o => o.StartTime)
|
||
|
.ToList(o => new BillCorrectionOrderResponse
|
||
|
{
|
||
|
OrderId = o.Id,
|
||
|
StartTime = o.StartTime,
|
||
|
StorageType = o.StorageType,
|
||
|
OrderState = o.OrderState,
|
||
|
WaybillNo = o.WaybillNo
|
||
|
});
|
||
|
|
||
|
var orderIds = orderList.Select(o => o.OrderId).ToList();
|
||
|
|
||
|
var orderCostDetailList = fsql.Select<OrderCostDetail>()
|
||
|
.Where(ocd => orderIds.Contains(ocd.OrderId))
|
||
|
.GroupBy(ocd => ocd.OrderId)
|
||
|
.ToList(g => new
|
||
|
{
|
||
|
OrderId = g.Key,
|
||
|
DeliveryExpressFreight = g.Sum(g.Value.DeliveryExpressFreight),
|
||
|
SkuAmount = g.Sum(g.Value.SkuAmount),
|
||
|
PurchaseFreight = g.Sum(g.Value.PurchaseFreight),
|
||
|
FirstFreight = g.Sum(g.Value.FirstFreight),
|
||
|
InStorageAmount = g.Sum(g.Value.InStorageAmount),
|
||
|
OutStorageAmount = g.Sum(g.Value.OutStorageAmount),
|
||
|
ConsumableAmount = g.Sum(g.Value.ConsumableAmount),
|
||
|
StorageAmount = g.Sum(g.Value.StorageAmount)
|
||
|
});
|
||
|
|
||
|
var afterOrderList = fsql.Select<AfterSaleOrder>()
|
||
|
.Where(aso => orderIds.Contains(aso.OrderId))
|
||
|
.GroupBy(aso => aso.OrderId)
|
||
|
.ToList(g => new
|
||
|
{
|
||
|
OrderId = g.Key,
|
||
|
AfterTotalCost = g.Sum(g.Value.AfterTotalCost)
|
||
|
});
|
||
|
|
||
|
foreach (var order in orderList)
|
||
|
{
|
||
|
var orderCostDetail = orderCostDetailList.FirstOrDefault(ocd => ocd.OrderId == order.OrderId);
|
||
|
var afterOrder = afterOrderList.FirstOrDefault(aso => aso.OrderId == order.OrderId);
|
||
|
|
||
|
order.DeliveryExpressFreight = orderCostDetail?.DeliveryExpressFreight ?? 0M;
|
||
|
order.SkuAmount = orderCostDetail?.SkuAmount ?? 0M;
|
||
|
order.PurchaseFreight = orderCostDetail?.PurchaseFreight ?? 0M;
|
||
|
order.FirstFreight = orderCostDetail?.FirstFreight ?? 0M;
|
||
|
order.InStorageAmount = orderCostDetail?.InStorageAmount ?? 0M;
|
||
|
order.OutStorageAmount = orderCostDetail?.OutStorageAmount ?? 0M;
|
||
|
order.ConsumableAmount = orderCostDetail?.ConsumableAmount ?? 0M;
|
||
|
order.StorageAmount = orderCostDetail?.StorageAmount ?? 0M;
|
||
|
order.AfterTotalCost = afterOrder?.AfterTotalCost ?? 0M;
|
||
|
}
|
||
|
return orderList;
|
||
|
}
|
||
|
}
|
||
|
}
|