using Binance.TradeRobot.Model.Dto; using System.Collections.Generic; using System.Linq; namespace Binance.TradeRobot.Business.Extensions { public static class UserExtension { /// /// 计算成员分红/本金比例 /// /// /// 比例乘100 public static void CalculateRatio(this IList userList, bool multiplyBy100 = true) { var totalAssets = userList.Sum(u => u.TotalAssets); //总资产 var totalCostAmount = userList.Sum(u => u.CostAmount); //总本金 foreach (var u in userList) { u.CostRatio = totalCostAmount == 0 ? 0 : u.CostAmount / totalCostAmount * (multiplyBy100 ? 100 : 1); u.DividendRatio = totalAssets == 0 ? 0 : u.TotalAssets / totalAssets * (multiplyBy100 ? 100 : 1); } } } }