public JsonResult CalcFreight(int addressId, CalcFreightparameter[] parameters) { Dictionary <long, decimal> dictionary = OrderApplication.CalcFreight(addressId, (from p in parameters group p by p.ShopId).ToDictionary <IGrouping <long, CalcFreightparameter>, long, Dictionary <long, int> >(p => p.Key, p => (from pp in p group pp by pp.ProductId).ToDictionary <IGrouping <long, CalcFreightparameter>, long, int>(pp => pp.Key, pp => pp.Sum <CalcFreightparameter>((Func <CalcFreightparameter, int>)(ppp => ppp.Count))))); if (dictionary.Count == 0) { return(base.Json(new { success = false, msg = "计算运费失败" })); } return(base.Json(new { success = true, freights = (from p in dictionary select new { shopId = p.Key, freight = p.Value }).ToArray() })); }
public JsonResult CalcFreight(int addressId, CalcFreightparameter[] parameters) { var result = OrderApplication.CalcFreight(addressId, parameters.GroupBy(p => p.ShopId).ToDictionary(p => p.Key, p => p.GroupBy(pp => pp.ProductId).ToDictionary(pp => pp.Key, pp => string.Format("{0}${1}", pp.Sum(ppp => ppp.Count), pp.Sum(ppp => ppp.Amount))))); if (result.Count == 0) { return(ErrorResult("计算运费失败")); } else { return(SuccessResult <dynamic>(data: result.Select(p => new { shopId = p.Key, freight = p.Value }).ToArray())); } }
public JsonResult CalcFreight(int addressId, CalcFreightparameter[] parameters) { var result = OrderApplication.CalcFreight(addressId, parameters.GroupBy(p => p.ShopId).ToDictionary(p => p.Key, p => p.GroupBy(pp => pp.ProductId).ToDictionary(pp => pp.Key, pp => string.Format("{0}${1}", pp.Sum(ppp => ppp.Count), pp.Sum(ppp => ppp.Amount))))); if (result.Count == 0) { return(Json(new { success = false, msg = "计算运费失败" })); } else { return(Json(new { success = true, freights = result.Select(p => new { shopId = p.Key, freight = p.Value }).ToArray() })); } }