public PagedList<CustomerOrderModel> GetOrderListBystateConditional(string state, string conditional, int pageIndex, int pageSize)
{
PagedList<CustomerOrderModel> orderList = new PagedList<CustomerOrderModel>();
try
{
using (var entity = new DBAutoPartsEntities())
{
//订单状态
var orderState = int.Parse(state);
//表数据
var list = (from t in entity.TB_OrderInfo
join b in entity.TB_CustomerInfo on t.CustomerCode equals b.CustomerCode
into s1
from x1 in s1.DefaultIfEmpty()
where t.IsDel == "N" && (t.OrderType == 1 || t.OrderType == 2)
select new CustomerOrderModel
{
OrderCode = t.OrderCode,//订单编码
CreateTime = t.CreateTime,//创建时间(下单时间)
OrderPrice = t.OrderPrice,//订单金额
OrderStatus = t.OrderStatus,//订单状态
CustomerName = x1.CustomerName,//客户名称
TelPhone = x1.Telphone,//客户电话
MobilePhone = x1.MobilePhone,//客户手机
});
if (state == "-1" && conditional != "")
{
list = list.Where(
t => t.OrderCode.Contains(conditional)
|| t.CustomerName.Contains(conditional)
|| t.TelPhone.Contains(conditional)
|| t.MobilePhone.Contains(conditional));
}
else if (state != "-1" && conditional == "")
{
list = list.Where(t => t.OrderStatus == orderState);
}
else if (state != "-1" && conditional != "")
{
list = list.Where(t => t.OrderStatus == orderState
&& (t.OrderCode.Contains(conditional)
|| t.CustomerName.Contains(conditional)
|| t.TelPhone.Contains(conditional)
|| t.MobilePhone.Contains(conditional)));
}
//集合
orderList = list.OrderByDescending(a => a.CreateTime).ToPagedList<CustomerOrderModel>(pageIndex, pageSize);
//每单数量
foreach (var item in orderList.Data)
{
//每一单的商品数量
int proCount = 0;
//每一单商品数量集合
var proNum = entity.TB_OrderDetial.Where(t => t.OrderCode == item.OrderCode).Select(t => t.ProductNum).ToList();
foreach (var proItem in proNum)
{
proCount += proItem;
}
item.productCount = proCount;
}
}
}
catch (Exception)
{
throw;
}
return orderList;
}