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; } }
public void AgentCommissionClose(string createByUserId) { var manager = new AgentManager(); var history = manager.GetAgentCaculateHistoryByDesc(); if (history == null) { history = new AgentCaculateHistory() { CaculateTimeFrom = DateTime.Parse("2012-10-01"), CaculateTimeTo = DateTime.Now }; } else { history = new AgentCaculateHistory() { CaculateTimeFrom = history.CaculateTimeTo, CaculateTimeTo = DateTime.Now }; } if (history.CaculateTimeFrom >= history.CaculateTimeTo) { return; } bool tag = true; int totalCount = 0; int pageIndex = 0; int pageSize = 100; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); do { var waitingOrderList = manager.QueryAgentWaitingCommissionOrderList(history.CaculateTimeFrom, history.CaculateTimeTo, pageIndex, pageSize, out totalCount); foreach (var item in waitingOrderList) { try { AddAgentCommissionDetailByTicketing(item.UserId, item.GameCode, item.GameType, item.TotalBuyMoney, 5, item.SchemeId, item.SchemeType, item.ComplateTime, history); history.TotalOrderCount += 1; history.TotalOrderMoney += item.TotalMoney; history.TotalBuyMoney += item.TotalBuyMoney; } catch (Exception ex) { history.ErrorCount += 1; history.ErrorOrderMoney += item.TotalMoney; history.ErrorBuyMoney += item.TotalBuyMoney; history.ErrorSchemeIdList += item.SchemeId + ";"; var writer = Common.Log.LogWriterGetter.GetLogWriter(); } } pageIndex += 1; if (((totalCount + pageSize - 1) / pageSize) <= pageIndex) { tag = false; } }while (tag); stopwatch.Stop(); history.MillisecondSpan = stopwatch.ElapsedMilliseconds; history.CreateBy = createByUserId; history.CreateTime = DateTime.Now; history.TotalAgentCount = ORMHelper.DataTableToList <AgentCloseReturnPointInfo>(AgentReturnPointCollection).GroupBy(o => o.AgentId).Count(); manager.AddAgentCaculateHistory(history); }
public void AddAgentCaculateHistory(AgentCaculateHistory entity) { this.Add <AgentCaculateHistory>(entity); }