public void AddAgentCommissionDetailByTicketing(string userId, string gameCode, string gameType, decimal money, decimal deduction, string schemeId, SchemeType schemeType, DateTime complateTime, AgentCaculateHistory history) { try { gameType = ConvertGameType(gameCode, gameType); var manager = new AgentManager(); int category = 0; string agentId = userId; while (!string.IsNullOrWhiteSpace(agentId)) { category += 1; AgentCloseReturnPointInfo info; var rows = AgentReturnPointCollection.Select("AgentId='" + agentId + "' and GameCode='" + gameCode + "' and GameType='" + gameType + "'"); if (rows.Length == 0) { info = manager.GetAgentReturnPointByUserId(agentId, gameCode, gameType); if (info == null) { throw new Exception("没有返点信息"); } AgentReturnPointCollection.Rows.Add ( info.GameCode, info.GameType, info.AgentId, info.SetLevel, info.ReturnPoint, info.PAgentId, info.PSetLevel, info.PReturnPoint ); } else { info = ORMHelper.ConvertDataRowToEntity <AgentCloseReturnPointInfo>(rows[0]); } if (string.IsNullOrWhiteSpace(info.PAgentId)) { break; } decimal initialPoint = info.PReturnPoint; decimal lowerPoint = info.ReturnPoint; decimal actualPoint = initialPoint - lowerPoint; if (actualPoint < 0) { throw new Exception("实际返点小于0"); } if (actualPoint == 0) { break; } agentId = info.PAgentId; var beforeCommission = money * actualPoint / 100; var actualCommission = beforeCommission * (100 - deduction) / 100; history.TotalCommisionMoney += actualCommission; //需要添加用户佣金明细资金 manager.AddAgentCommissionDetail(new AgentCommissionDetail() { GameCode = gameCode, GameType = ConvertGameType(gameCode, gameType), ApplyState = 0, CreateTime = DateTime.Now, PAgentId = agentId, //给上级用户 UserId = userId, //传个来的用户 Category = category, Sale = money, InitialPoint = initialPoint, //上级用户的返点 LowerPoint = lowerPoint, //传个来的用户的返点 ActualPoint = actualPoint, // 0,//上级用户的返点 - 传个来的用户的返点 Deduction = deduction, BeforeCommission = beforeCommission, ActualCommission = actualCommission, //代购方案¥100.00 返点2.00%=¥2.00-扣量5%=¥1.90///去除扣量2012-11-23 23:15:51 Remark = string.Format("{0}¥{1:N2} 返点{2:#.##}%=¥{3:N2}" , schemeType == SchemeType.TogetherBetting ? "成功发起合买" : "代购方案", money, actualPoint, beforeCommission), DetailKeyword = schemeId, ComplateDateTime = complateTime }); userId = agentId; } //需要添加用户资金 } catch (Exception ex) { throw ex; } }