Пример #1
0
        public bool UpdateBetRecord_Pfl_Cap(BetRecord record)
        {
            List<ProfitLossInfo> list_pfloss = new List<ProfitLossInfo>();
            User user = GetUserInfo(record.UserID);
            //投注
            ProfitLossInfo pflInfo = new ProfitLossInfo();
            List<LotteryTypeInfo> lottery = GetLotteryType();
            LotteryTypeInfo currentLottery = (from l in lottery where l.LotteryTypeID == record.LotteryTypeID select l).FirstOrDefault();
            pflInfo.Memo = currentLottery.LotteryName + "[" + record.IssueNo + "]-" + record.PlayTypeDirection;
            pflInfo.ProfitLossTime = record.BetTime;
            pflInfo.ProfitLossType = "投注";
            pflInfo.RecordID = record.RecordID;
            pflInfo.UserID = record.UserID;
            if (record.Direction == 1)
                pflInfo.CurrentEnableScores = GetCapitalInfo(record.UserID).EnableScores - record.BetMoney + Math.Round(user.Bonus / 100 * record.BetMoney, 2);
            else
                pflInfo.CurrentEnableScores = GetCapitalInfo(record.UserID).EnableScores - record.BetMoney + Math.Round(record.BonusPct / 100 * record.BetMoney, 2);
            pflInfo.ProfitLossMoney = -record.BetMoney;

            list_pfloss.Add(pflInfo);
            //SqlHelper.getInstance.ExcuteInsert<ProfitLossInfo>(pflInfo, "ProfitLoss", "");
            //返点上级

            List<User> AllParentUser = GetAllParentUser(record.UserID);
            List<Capital> AllParentCapital = GetAllParentCapital(AllParentUser);
            foreach (User _user in AllParentUser)
            {
                if (_user.UserId == record.UserID)
                    continue;
                Capital _cp = AllParentCapital.Where(c => c.UserId == _user.UserId).FirstOrDefault();
                _cp.EnableScores += Math.Round((_user.Bonus - user.Bonus) / 100 * record.BetMoney, 2);
                _cp.GameScores += Math.Round((_user.Bonus - user.Bonus) / 100 * record.BetMoney, 2);

                //返点
                pflInfo = new ProfitLossInfo();
                pflInfo.Memo = currentLottery.LotteryName + "[" + record.IssueNo + "]-" + record.PlayTypeDirection;
                pflInfo.ProfitLossTime = record.BetTime;
                pflInfo.ProfitLossType = "返点";
                pflInfo.RecordID = record.RecordID;
                pflInfo.UserID = _user.UserId;
                pflInfo.CurrentEnableScores = _cp.EnableScores;
                pflInfo.ProfitLossMoney = Math.Round((_user.Bonus - user.Bonus) / 100 * record.BetMoney, 2);
                list_pfloss.Add(pflInfo);
                user = _user;
            }
            //返点自己并冻结投注资金
            Capital cp = GetCapitalInfo(record.UserID);
            user = GetUserInfo(record.UserID);
            if (record.Direction == 1)//逆向
            {
                cp.EnableScores = Math.Round(cp.EnableScores - Math.Round(record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1), 2)
                    + Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
                cp.DisableScores = Math.Round(cp.DisableScores + Math.Round(record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1), 2)
                    - Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
            }
            else
            {
                cp.EnableScores = Math.Round(cp.EnableScores - record.BetMoney + Math.Round((record.BonusPct / 100) * record.BetMoney, 2), 2);
                cp.DisableScores = Math.Round(cp.DisableScores + record.BetMoney - Math.Round((record.BonusPct / 100) * record.BetMoney, 2), 2);
            }
            cp.GameScores = Math.Round(cp.GameScores, 2);
            AllParentCapital.Add(cp);
            if (cp.EnableScores < 0)
                return false;
            //pflInfo = new ProfitLossInfo();
            //pflInfo.Memo = currentLottery.LotteryName + "[" + record.IssueNo + "]-" + record.PlayTypeDirection;
            //pflInfo.ProfitLossTime = record.BetTime;
            //pflInfo.ProfitLossType = "返点";
            //pflInfo.RecordID = record.RecordID;
            //pflInfo.UserID = record.UserID;
            //pflInfo.CurrentEnableScores = cp.EnableScores;
            //pflInfo.ProfitLossMoney = Math.Round(record.BonusPct / 100 * record.BetMoney, 2);
            //list_pfloss.Add(pflInfo);
            //UpdateCapitalInfo(cp);
            #region
            //============更新admin账户资金===============
            User userAdmin = GetAdmin();
            Capital cpAdmin = GetCapitalInfo(userAdmin.UserId);

            List<ProfitLossInfo> listAdmin_Pfl = new List<ProfitLossInfo>();
            //收入:投注
            cpAdmin.GameScores = cpAdmin.GameScores + record.BetMoney - Math.Round(record.BonusPct / 100 * record.BetMoney, 2);//投注,admin收入
            ProfitLossInfo betAdmin = new ProfitLossInfo();
            betAdmin.CurrentEnableScores = cpAdmin.GameScores;
            betAdmin.Memo = record.UserID + "投注,下注金额:" + record.BetMoney.ToString() + ",玩法:" + record.PlayTypeDirection;
            betAdmin.ProfitLossType = "投注";
            betAdmin.ProfitLossMoney = Math.Abs(record.BetMoney) - Math.Round(record.BonusPct / 100 * record.BetMoney, 2);
            betAdmin.ProfitLossTime = DateTime.Now;
            betAdmin.RecordID = record.RecordID;
            betAdmin.UserID = userAdmin.UserId;
            listAdmin_Pfl.Add(betAdmin);
            //支出:返点
            ProfitLossInfo fdAdmin = new ProfitLossInfo();
            cpAdmin.GameScores = cpAdmin.GameScores - list_pfloss.Where(p => p.ProfitLossType == "返点").Sum(p => p.ProfitLossMoney);
            fdAdmin.CurrentEnableScores = cpAdmin.GameScores;
            fdAdmin.Memo = record.UserID + "以及其上级返点,下注金额:" + record.BetMoney.ToString() + ",玩法:" + record.PlayTypeDirection;
            fdAdmin.ProfitLossType = "返点";
            fdAdmin.ProfitLossMoney = -list_pfloss.Where(p => p.ProfitLossType == "返点").Sum(p => p.ProfitLossMoney);
            fdAdmin.ProfitLossTime = DateTime.Now;
            fdAdmin.RecordID = record.RecordID;
            fdAdmin.UserID = userAdmin.UserId;
            listAdmin_Pfl.Add(fdAdmin);
            //===================================
            #endregion

            list_pfloss.AddRange(listAdmin_Pfl);
            AllParentCapital.Add(cpAdmin);

            //事务批量更新
            List<SQLTranCationParaMeters> paras = new List<SQLTranCationParaMeters>()
            {
                new SQLTranCationParaMeters()
                {
                    SqlText="update CapitalInfo set GameScores=@GameScores,EnableScores=@EnableScores,DisableScores=@DisableScores where UserID=@UserId",
                    type=typeof(Capital),
                    ParameterName=new string[]{"GameScores","EnableScores","UserId","DisableScores"},
                    Data=ConvertHelper.ToListDictionary<Capital>(AllParentCapital)
                },
                new SQLTranCationParaMeters()
                {
                    SqlText =@"Insert into ProfitLoss values(@UserID,@ProfitLossTime,@Memo,@ProfitLossType,
                             @CurrentEnableScores,@RecordID,@ProfitLossMoney)",
                    type=typeof(ProfitLossInfo),
                    ParameterName=new string[] { "UserID", "ProfitLossTime","Memo","ProfitLossType",
                                                "CurrentEnableScores", "RecordID", "ProfitLossMoney"},
                    Data=ConvertHelper.ToListDictionary<ProfitLossInfo>(list_pfloss)
                }
            };
            return SqlHelper.getInstance.ExcuteInsertTrancation(paras);
        }
Пример #2
0
 public int InsertProfitLoss(ProfitLossInfo info)
 {
     return SqlHelper.getInstance.ExcuteInsert<ProfitLossInfo>(info, "ProfitLossInfo");
 }