public ActionResult ZXTCost(string pid) { var result2 = new List <ZXTCost>(); var result = PriceManager.GetZXTPurchaseByPID(pid).OrderBy(c => c.CreatedDatetime).ToList(); if (result.Any()) { var dic = result.GroupBy(_ => _.CreatedDatetime.ToShortDateString()).ToDictionary(_ => _.Key, _ => _.ToList()); foreach (var item in dic) { if (item.Value.Count == 1) { result2.AddRange(item.Value); } else { var tempModel = new ZXTCost() { CreatedDatetime = item.Value.FirstOrDefault().CreatedDatetime, CostPrice = item.Value.Average(_ => _.CostPrice), PID = item.Value.FirstOrDefault().PID, Num = item.Value.Sum(_ => _.Num), WareHouse = "多仓库" }; result2.Add(tempModel); } } if (result2.Any()) { ViewBag.xArr = string.Join(",", result2.Select(_ => $"({_.WareHouse + _.Num}件) " + _.CreatedDatetime.ToShortDateString())); ViewBag.yArr = string.Join(",", result2.Select(_ => _.CostPrice.ToString("0.00"))); } } ViewBag.PID = pid; return(View(result.OrderByDescending(_ => _.CreatedDatetime).ToList())); }