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.
26 lines
969 B
26 lines
969 B
3 years ago
|
using Binance.TradeRobot.Model.Dto;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace Binance.TradeRobot.Business.Extensions
|
||
|
{
|
||
|
public static class UserExtension
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 计算成员分红/本金比例
|
||
|
/// </summary>
|
||
|
/// <param name="userList"></param>
|
||
|
/// <param name="multiplyBy100">比例乘100</param>
|
||
|
public static void CalculateRatio(this IList<UserResponse> 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|