/// <summary> /// 创建会员的结余结果. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> private SettleResult BuildMemberSettleResult(User user) { var orderList = GetOrders(user).ToList(); UserBetOrderDic[user.UserId] = orderList; if (orderList == null || orderList.Count == 0) return null; var oacs = OrderManager.GetTodayOac(user, SettleCompany, BetStatus.Settled).GroupBy(it => it.OrderId).ToDictionary(it => it.Key, it => it.Select(x => x)); OrderOacDic.AddRange(oacs); List<SettleResult> resultList = new List<SettleResult>(); SettleResult result = new SettleResult(); foreach (var order in orderList) { result.OrderCount += 1; result.BetTurnover += order.Turnover; result.Commission += order.Commission; result.TotalWinLost += order.DrawResult; result.TotalCommission += GetOAC(order.OrderId, Role.Agent).CommAmount; } result.WinLost = result.TotalWinLost - result.Commission; result.UpperShareRate = GetParentShareRate(user); result.UpperWinLost = result.WinLost * -1 * (decimal)result.UpperShareRate; //代理输赢=会员输赢×代理成数 result.CompanyWinLost = CountCompanyWinLost(1 - result.UpperShareRate, result.WinLost, result.TotalCommission); result.UpperTotalWinLost = result.TotalWinLost / -1 - result.CompanyWinLost; //代理总输赢=会员总输赢-公司输赢 result.UpperCommission = result.UpperTotalWinLost - result.UpperWinLost; //代理佣金=代理总输赢-代理输赢 result.UserId = user.UserId; result.CompanyId = SettleCompany; AddMemberSettleResultToDic(user, result); return result; }
/// <summary> /// 创建各级用户的结余结果. /// </summary> /// <param name="user">The user.</param> /// <param name="childSettleResultList">The child settle result list.</param> /// <returns></returns> private IList<SettleResult> BuildUserSettleResult(User user, IList<SettleResult> childSettleResultList) { var userWinLost = UserBetOrderDic[user.UserId].Sum(it => it.DrawResult); //用户总佣金,累加子用户所有订单中该用户的佣金 var userTotalComm = UserBetOrderDic[user.UserId].Select(it => GetOAC(it.OrderId, user.Role - 1)).Sum(it => it.CommAmount); //总佣金=父亲用户佣金 List<SettleResult> userResultList = new List<SettleResult>(); var gs = childSettleResultList.GroupBy(it => it.ShareRate + it.UpperShareRate); //用分成来进行分组 foreach (var results in gs) { SettleResult result = new SettleResult(); List<SettleResult> memberSettleResultList = new List<SettleResult>(); foreach (var item in results) { if (item == null) continue; memberSettleResultList.AddRange(MemberSettleResultDic[item.UserId]); //result.OrderCount += item.OrderCount; //累加子用户的订单数量 result.BetTurnover += item.BetTurnover; //累加子用户的下注额 result.WinLost += (item.WinLost + item.UpperWinLost); //累加子用户的输赢 result.Commission += (item.Commission + item.UpperCommission); //累加子用户的佣金 result.TotalWinLost += (item.TotalWinLost + item.UpperTotalWinLost); //累加子用户的总输赢 } var memberWinLost = memberSettleResultList.Distinct().Sum(it => it.WinLost); result.OrderCount = UserBetOrderDic[user.UserId].Count; result.TotalCommission = userTotalComm; result.ShareRate = results.Key; //本级分成数(相对级别,包含本用户及其子用户的分成) result.UpperShareRate = GetParentShareRate(user); //上级分成 result.CompanyWinLost = CountCompanyWinLost(1 - result.UpperShareRate - result.ShareRate, memberWinLost, result.TotalCommission); result.UpperWinLost = memberWinLost * -1 * (decimal)result.UpperShareRate; //上级输赢=子用户输赢(总)×上级成数 result.UpperTotalWinLost = result.TotalWinLost / -1 - result.CompanyWinLost; //上级总输赢=(总输赢/-1)-公司输赢 result.UpperCommission = result.UpperTotalWinLost - result.UpperWinLost; //上级佣金=上级总输赢-上级输赢 result.UserId = user.UserId; result.CompanyId = SettleCompany; userResultList.Add(result); } return userResultList; }
private void AddMemberSettleResultToDic(User user, SettleResult result) { if (!MemberSettleResultDic.ContainsKey(user.UserId)) MemberSettleResultDic.Add(user.UserId, new List<SettleResult>()); MemberSettleResultDic[user.UserId].Add(result); }