Exemple #1
0
        /// <summary>
        /// 用户是否能参与活动,true:能参与,反之不能
        /// </summary>
        public bool IsUserJoinPrizeActivity(string userId, string schemeId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(false);
            }
            //特殊用户
            var specialList = ConfigurationManager.AppSettings["SpecialUser"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            if (specialList.Contains(userId))
            {
                return(true);
            }

            var sportsManager = new Sports_Manager();
            var order         = sportsManager.QuerySports_Order_Complate(schemeId);

            if (order == null)
            {
                return(false);
            }
            var together = sportsManager.QuerySports_Together(order.SchemeId);

            if (together == null)
            {
                return(false);
            }
            if (together.SystemGuarantees > 0)
            {
                return(false);
            }
            var agentList = ConfigurationManager.AppSettings["JoinActivityAgent"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            if (agentList.Contains(userId))
            {
                return(false);
            }
            var manager = new UserBalanceManager();
            var user    = manager.GetUserRegister(userId);

            if (user == null)
            {
                return(false);
            }
            if (user.IsAgent == true)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(user.AgentId))
            {
                return(true);
            }
            return(!agentList.Contains(user.AgentId));
        }
        public void UpdateProfileDynamic(string userId, string schemeId, string gameCode, string issuseNumber, decimal totalMoney, string dynamicType)
        {
            try
            {
                DB.Begin();

                var man = new Sports_Manager();
                var ub  = new UserBalanceManager();

                var together = man.QuerySports_Together(schemeId);
                var user2    = string.Empty;
                switch (dynamicType)
                {
                case "参与合买":
                    user2 = together.CreateUserId;
                    break;
                }

                var user1Name = ub.QueryUserRegister(userId);
                var user2Name = new C_User_Register();
                if (!string.IsNullOrEmpty(user2))
                {
                    user2Name = ub.QueryUserRegister(user2);
                }

                var entity = new E_Blog_Dynamic()
                {
                    UserId           = userId,
                    UserDisplayName  = user1Name.DisplayName,
                    UserId2          = user2,
                    User2DisplayName = string.IsNullOrEmpty(user2) ? "" : user2Name.DisplayName,
                    GameCode         = gameCode,
                    GameType         = together == null ? "" : together.GameType,
                    IssuseNumber     = issuseNumber,
                    DynamicType      = dynamicType,
                    Guarantees       = together == null ? 0 : together.Guarantees,
                    Price            = together == null ? 0M : together.Price,
                    Progress         = together == null ? 0M : together.Progress,
                    TotalMonery      = together == null ? 0M : together.TotalMoney,
                    SchemeId         = schemeId,
                    Subscription     = together == null ? 0 : together.Subscription,
                    CreateTime       = DateTime.Now,
                };
                var manager = new BlogManager();
                manager.AddBlog_Dynamic(entity);
                DB.Commit();
            }
            catch (Exception ex)
            {
                DB.Rollback();
                throw ex;
            }
        }
        public void OrderPrize_AfterTranCommit(string userId, string schemeId, string gameCode, string gameType, string issuseNumber, decimal orderMoney, bool isBonus, decimal preTaxBonusMoney, decimal afterTaxBonusMoney, bool isVirtualOrder, DateTime prizeTime)
        {
            using (var biz = new GameBiz.Business.GameBizBusinessManagement())
            {
                biz.BeginTran();

                var sportsManager = new Sports_Manager();
                var order         = sportsManager.QuerySports_Order_Complate(schemeId);
                if (order == null)
                {
                    throw new LogicException(string.Format("自动分红,没有找到订单{0}", schemeId));
                }
                //if (order.IsPayRebate)
                //    throw new LogicException(string.Format("订单{0}已分红", schemeId));
                var bonusAwardsMoney = 0M;
                if (order.AddMoneyDescription.Contains("10"))
                {
                    bonusAwardsMoney = order.AddMoney;
                }
                var bonusMoney = (order.TotalMoney - order.RedBagMoney - order.AfterTaxBonusMoney + bonusAwardsMoney);
                if (order.TicketStatus == TicketStatus.Ticketed && !order.IsVirtualOrder)
                {
                    var msg = string.Empty;
                    //合买判断
                    if (order.SchemeType == SchemeType.TogetherBetting)
                    {
                        var main = sportsManager.QuerySports_Together(schemeId);
                        if (main == null)
                        {
                            msg = string.Format("找不到合买订单:{0}", schemeId);
                        }
                        var sysJoinEntity = sportsManager.QuerySports_TogetherJoin(schemeId, TogetherJoinType.SystemGuarantees);
                        if (sysJoinEntity != null && sysJoinEntity.RealBuyCount > 0)
                        {
                            msg = "网站参与保底,不分红";
                        }

                        if (main.SoldCount + main.Guarantees < main.TotalCount)
                        {
                            throw new Exception("订单未满员,不执行分红");
                        }
                    }

                    if (string.IsNullOrEmpty(msg))
                    {
                        var userManager    = new UserBalanceManager();
                        var ocAgentManager = new OCAgentManager();
                        var orderGameType  = string.Empty;
                        if (new string[] { "CTZQ", "BJDC", "JCZQ", "JCLQ" }.Contains(order.GameCode))
                        {
                            orderGameType = order.GameType;
                        }

                        PayOrderBonus(userManager, ocAgentManager, order.SchemeId, order.SchemeType, order.UserId, order.GameCode, orderGameType, order.UserId, bonusMoney, 0);
                    }
                }

                order.IsPayRebate = true;
                sportsManager.UpdateSports_Order_Complate(order);

                biz.CommitTran();
            }
        }
        public void AgentPayIn(string userId, string gameCode, string gameType, decimal money, string schemeId, SchemeType schemeType)
        {
            try
            {
                if (SchemeType.TogetherBetting == schemeType)
                {
                    var sportsManager = new Sports_Manager();
                    var main          = sportsManager.QuerySports_Together(schemeId);
                    if (main.SystemGuarantees <= 0 && !bool.Parse(new CacheDataBusiness().QueryCoreConfigByKey("IsTogetherFandian").ConfigValue))
                    {
                        return;
                    }
                }

                var manager       = new AgentManager();
                var isExistScheme = manager.GetRebateDetail(schemeId);
                if (!isExistScheme)
                {
                    return;
                }
                //lock (agentLock)
                //{
                using (var biz = new GameBiz.Business.GameBizBusinessManagement())
                {
                    biz.BeginTran();

                    gameType = ConvertGameType(gameCode, gameType);

                    var info = manager.GetAgentReturnPointByUserId(userId, gameCode, gameType);
                    if (info != null)
                    {
                        decimal commission = money * info.ReturnPoint / 100;
                        string  remark     = string.Format("方案{0}出票成功,返利{1:N2}%,共{2:N2}元。", schemeId, info.ReturnPoint, commission);
                        if (commission > 0)
                        {
                            //BusinessHelper.Payin_2Balance(BusinessHelper.FundCategory_SchemeDeduct, schemeId, schemeId, false, string.Empty, string.Empty, userId,
                            //    AccountType.Common, commission, remark);

                            BusinessHelper.Payin_To_Balance(AccountType.Commission, BusinessHelper.FundCategory_SchemeDeduct, userId, schemeId, commission, remark, RedBagCategory.Partner);
                        }

                        manager.AddRebateDetail(new RebateDetail()
                        {
                            SchemeId   = schemeId,
                            SchemeType = schemeType,
                            UserId     = userId,
                            CreateTime = DateTime.Now,
                            GameCode   = gameCode,
                            GameType   = gameType,
                            Point      = info.ReturnPoint,
                            PayinMoney = commission,
                            Remark     = remark
                        });
                    }

                    AgentPayInByReturnPoint(userId, gameCode, gameType, money, 0, 0, schemeId, schemeType);

                    biz.CommitTran();
                }
                //}
            }
            catch (Exception ex)
            {
                var writer = Common.Log.LogWriterGetter.GetLogWriter();
                writer.Write("EXEC_Plugin_AgentPayIn_Error_2222222222", userId, ex);
                //throw ex;
            }
        }
        public void OrderPrize_AfterTranCommit(string userId, string schemeId, string gameCode, string gameType, string issuseNumber, decimal orderMoney, bool isBonus, decimal preTaxBonusMoney, decimal afterTaxBonusMoney, bool isVirtualOrder, DateTime prizeTime)
        {
            //if (isVirtualOrder) return;
            //if (!isBonus) return;
            //if (afterTaxBonusMoney <= 0) return;
            //if (afterTaxBonusMoney >= 10000M) return;

            //开启事务
            using (var biz = new GameBizBusinessManagement())
            {
                biz.BeginTran();

                var manager = new Sports_Manager();
                var order   = manager.QuerySports_Order_Complate(schemeId);
                if (order == null)
                {
                    throw new LogicException(string.Format("自动派钱,没有找到订单{0}", schemeId));
                }
                if (order.IsPrizeMoney)
                {
                    throw new LogicException(string.Format("订单{0}已派奖", schemeId));
                }

                order.IsPrizeMoney = true;
                manager.UpdateSports_Order_Complate(order);

                if (!order.IsVirtualOrder)
                {
                    if (order.SchemeType == SchemeType.GeneralBetting || order.SchemeType == SchemeType.ChaseBetting || order.SchemeType == SchemeType.SingleCopy)
                    {
                        #region 普通、追号、抄单
                        if (order.AfterTaxBonusMoney > 0)
                        {
                            if (order.SchemeType == SchemeType.SingleCopy)//抄单订单,派奖时需减去奖金提成的金额
                            {
                                var bdfxManager           = new BDFXManager();
                                var bdfxRecorSingleEntity = bdfxManager.QueryBDFXRecordSingleCopyBySchemeId(schemeId);
                                var realBonusMoney        = order.AfterTaxBonusMoney;
                                var commissionMoney       = 0M;
                                if (bdfxRecorSingleEntity != null)
                                {
                                    var BDFXEntity = bdfxManager.QueryTotalSingleTreasureBySchemeId(bdfxRecorSingleEntity.BDXFSchemeId);
                                    if (BDFXEntity != null)
                                    {
                                        //计算提成金额
                                        if ((order.AfterTaxBonusMoney - order.TotalMoney) > 0)
                                        {
                                            commissionMoney = (order.AfterTaxBonusMoney - order.TotalMoney) * BDFXEntity.Commission / 100M;
                                            commissionMoney = Math.Truncate(commissionMoney * 100) / 100M;
                                            realBonusMoney  = order.AfterTaxBonusMoney - commissionMoney;
                                            //返提成
                                            if (commissionMoney > 0)
                                            {
                                                BusinessHelper.Payin_To_Balance(AccountType.Bonus, BusinessHelper.FundCategory_BDFXCommissionMoney, BDFXEntity.UserId, schemeId, commissionMoney,
                                                                                string.Format("抄单订单{0}中奖{1:N2}元,提成{2:N0}%,获得奖金盈利提成金额{3:N2}元.", schemeId, order.AfterTaxBonusMoney, BDFXEntity.Commission, commissionMoney));
                                            }
                                        }
                                    }
                                }
                                //返奖金
                                BusinessHelper.Payin_To_Balance(AccountType.Bonus, BusinessHelper.FundCategory_Bonus, order.UserId, schemeId, realBonusMoney,
                                                                string.Format("抄单订单{0}中奖{1:N2}元,扣除奖金盈利提成金额{2:N2}元,实得奖金{3:N2}元.", schemeId, order.AfterTaxBonusMoney, commissionMoney, realBonusMoney));
                            }
                            else
                            {
                                BusinessHelper.Payin_To_Balance(AccountType.Bonus, BusinessHelper.FundCategory_Bonus, order.UserId, schemeId, order.AfterTaxBonusMoney,
                                                                string.Format("中奖奖金{0:N2}元.", order.AfterTaxBonusMoney));
                            }
                        }

                        if (order.AddMoney > 0)
                        {
                            BusinessHelper.Payin_To_Balance(order.AddMoneyDescription == "10" ? AccountType.Bonus : AccountType.RedBag, BusinessHelper.FundCategory_Bonus, order.UserId, schemeId, order.AddMoney,
                                                            string.Format("订单{0}活动赠送{1:N2}元.", schemeId, order.AddMoney));
                        }
                        #endregion
                    }
                    if (order.SchemeType == SchemeType.TogetherBetting)
                    {
                        #region 合买
                        var main = manager.QuerySports_Together(schemeId);
                        if (order.AfterTaxBonusMoney > 0)
                        {
                            //提成
                            var deductMoney = 0M;
                            if (order.AfterTaxBonusMoney > main.TotalMoney)
                            {
                                deductMoney = (order.AfterTaxBonusMoney - main.TotalMoney) * main.BonusDeduct / 100;
                            }
                            //提成金额,只能给合买发起者
                            if (deductMoney > 0M)
                            {
                                BusinessHelper.Payin_To_Balance(AccountType.Bonus, BusinessHelper.FundCategory_Deduct, order.UserId, schemeId, deductMoney,
                                                                string.Format("订单{0}, 合买奖金盈利提成金额{1:N2}元。", schemeId, deductMoney));
                            }

                            //中奖金额,分发到所有参与合买的用户的奖金账户
                            var bonusMoney  = order.AfterTaxBonusMoney - deductMoney;
                            var singleMoney = bonusMoney / main.TotalCount;
                            foreach (var join in manager.QuerySports_TogetherSucessJoin(schemeId))
                            {
                                //if (join.JoinType == TogetherJoinType.SystemGuarantees) continue;//20151015屏蔽原代码,如果合买有系统保底,依然将奖金返还到系统保底账上
                                //发参与奖金
                                if (join.RealBuyCount <= 0)
                                {
                                    continue;
                                }
                                var joinMoney = join.RealBuyCount * singleMoney;
                                //派钱
                                if (joinMoney > 0M)
                                {
                                    BusinessHelper.Payin_To_Balance(AccountType.Bonus, BusinessHelper.FundCategory_Bonus, join.JoinUserId, schemeId, joinMoney,
                                                                    string.Format("中奖分成,奖金¥{0:N2}元。", joinMoney));
                                }
                            }
                        }
                        if (order.AddMoney > 0M)
                        {
                            //加奖金额分配给发起者
                            if (order.DistributionWay == AddMoneyDistributionWay.CreaterOnly)
                            {
                                //加奖
                                if (order.AddMoney > 0)
                                {
                                    BusinessHelper.Payin_To_Balance(order.AddMoneyDescription == "10" ? AccountType.Bonus : AccountType.RedBag, BusinessHelper.FundCategory_Activity, order.UserId, schemeId, order.AddMoney,
                                                                    string.Format("订单{0}活动赠送{1:N2}元。", schemeId, order.AddMoney), RedBagCategory.Activity);
                                }
                            }
                            //处理加奖
                            if (order.DistributionWay == AddMoneyDistributionWay.Average)
                            {
                                var addMonesinglePrice = order.AddMoney / main.TotalCount;
                                foreach (var join in manager.QuerySports_TogetherSucessJoin(schemeId))
                                {
                                    if (join.JoinType == TogetherJoinType.SystemGuarantees)
                                    {
                                        continue;
                                    }

                                    if (join.RealBuyCount <= 0)
                                    {
                                        continue;
                                    }
                                    //发参与奖金
                                    var joinMoney = join.RealBuyCount * addMonesinglePrice;
                                    //派钱
                                    if (joinMoney > 0M)
                                    {
                                        BusinessHelper.Payin_To_Balance(order.AddMoneyDescription == "10" ? AccountType.Bonus : AccountType.RedBag, BusinessHelper.FundCategory_Activity, join.JoinUserId, schemeId, joinMoney,
                                                                        string.Format("订单{0}活动赠送{1:N2}元。", schemeId, joinMoney), RedBagCategory.Activity);
                                    }
                                }
                            }
                            //加奖金额分配给发起者
                            if (order.DistributionWay == AddMoneyDistributionWay.JoinerOnly)
                            {
                                //订单发起者没有加奖
                                var joinList           = manager.QuerySports_TogetherSucessJoin(schemeId);
                                var createrList        = joinList.Where(p => p.JoinUserId == order.UserId).ToList();
                                var createJoinCount    = createrList.Count == 0 ? 0 : createrList.Sum(p => p.RealBuyCount);
                                var addMonesinglePrice = order.AddMoney / (main.TotalCount - createJoinCount);
                                foreach (var join in joinList)
                                {
                                    if (join.JoinType == TogetherJoinType.SystemGuarantees)
                                    {
                                        continue;
                                    }
                                    if (join.JoinUserId == order.UserId)
                                    {
                                        continue;
                                    }

                                    if (join.RealBuyCount <= 0)
                                    {
                                        continue;
                                    }
                                    //发参与奖金
                                    var joinMoney = join.RealBuyCount * addMonesinglePrice;
                                    //派钱
                                    if (joinMoney > 0M)
                                    {
                                        BusinessHelper.Payin_To_Balance(order.AddMoneyDescription == "10" ? AccountType.Bonus : AccountType.RedBag, BusinessHelper.FundCategory_Activity, join.JoinUserId, schemeId, joinMoney,
                                                                        string.Format("订单{0}活动赠送{1:N2}元。", schemeId, joinMoney), RedBagCategory.Activity);
                                    }
                                }
                            }
                        }
                        #endregion
                    }

                    //添加最新中奖记录表
                    if (afterTaxBonusMoney >= 2000M)
                    {
                        var userInfo = new UserBalanceManager().GetUserRegister(order.UserId);
                        if (userInfo != null)
                        {
                            new External.Domain.Managers.SiteMessage.SiteActivityManager().AddLotteryNewBonus(new External.Domain.Entities.SiteMessage.LotteryNewBonus
                            {
                                AfterTaxBonusMoney       = order.AfterTaxBonusMoney,
                                Amount                   = order.Amount,
                                CreateTime               = order.ComplateDateTime,
                                GameCode                 = order.GameCode,
                                GameType                 = order.GameType,
                                IssuseNumber             = order.IssuseNumber,
                                PlayType                 = order.PlayType,
                                PreTaxBonusMoney         = order.PreTaxBonusMoney,
                                SchemeId                 = order.SchemeId,
                                TotalMoney               = order.TotalMoney,
                                UserDisplayName          = userInfo.DisplayName,
                                HideUserDisplayNameCount = userInfo.HideDisplayNameCount
                            });
                        }
                    }
                }

                biz.CommitTran();
            }

            //刷新用户在Redis中的余额
            if (afterTaxBonusMoney > 0M)
            {
                BusinessHelper.RefreshRedisUserBalance(userId);
            }
        }
        /// <summary>
        /// 返点接口
        /// </summary>
        public void ManualAgentPayIn(string schemeId)
        {
            var order = new SchemeManager().QueryOrderDetail(schemeId);

            if (order == null)
            {
                throw new LogicException(string.Format("找不到订单 :{0} ", schemeId));
            }
            if (order.TicketStatus != TicketStatus.Ticketed)
            {
                throw new LogicException("订单未出票完成,不能返点");
            }
            if (order.IsVirtualOrder)
            {
                throw new LogicException("虚拟订单不能返点");
            }

            string          currentUserId   = string.Empty;
            decimal         currentBetMoney = 0M;
            string          currentGameCode = string.Empty;
            bool            currentIsAgent  = false;
            OCAgentBusiness busi            = new OCAgentBusiness();

            using (var biz = new GameBiz.Business.GameBizBusinessManagement())
            {
                biz.BeginTran();

                //查询订单信息
                var sportsManager = new Sports_Manager();

                //真实订单,处理返点数据
                var gameCode = order.GameCode.ToUpper();
                var gameType = order.GameType.ToUpper();
                var userId   = order.UserId;

                var msg = string.Empty;
                //合买判断
                if (order.SchemeType == SchemeType.TogetherBetting)
                {
                    var main = sportsManager.QuerySports_Together(schemeId);
                    if (main == null)
                    {
                        msg = string.Format("找不到合买订单:{0}", schemeId);
                        //throw new Exception(string.Format("找不到合买订单:{0}", schemeId));
                    }
                    //if (main.ProgressStatus != TogetherSchemeProgress.Finish)
                    //    throw new Exception(string.Format("合买订单:{0} 状态不正确", schemeId));
                    var sysJoinEntity = sportsManager.QuerySports_TogetherJoin(schemeId, TogetherJoinType.SystemGuarantees);
                    if (sysJoinEntity != null && sysJoinEntity.RealBuyCount > 0)
                    {
                        msg = "网站参与保底,不返点";
                        //throw new Exception("网站参与保底,不返点");
                    }

                    if (main.SoldCount + main.Guarantees < main.TotalCount)
                    {
                        throw new Exception("订单未满员,不执行返点");
                    }
                    //realMoney -= main.SystemGuarantees * main.Price;
                }

                var realMoney           = 0M;;
                var totalPayRebateMoney = 0M;
                var agentManager        = new OCAgentManager();
                if (string.IsNullOrEmpty(msg))
                {
                    //没有异常,执行返点
                    var noGameTypeArray = new string[] { "CQSSC", "JX11X5", "SSQ", "DLT", "FC3D", "PL3" };
                    if (noGameTypeArray.Contains(gameCode))
                    {
                        gameType = string.Empty;
                    }

                    //真实投注金额,订单成功金额
                    realMoney = order.TotalMoney;
                    //查询用户自身返点
                    var balanceManager = new UserBalanceManager();
                    var user           = balanceManager.QueryUserRegister(userId);
                    currentIsAgent = user.IsAgent;

                    //去掉红包参与金额
                    var redBagJoinMoney = order.RedBagMoney;// new FundManager().QuerySchemeRedBagTotalJoinMoney(schemeId);
                    realMoney -= redBagJoinMoney;
                    //递归调用
                    int rebateType  = 0;
                    var arrGameCode = new string[] { "JCZQ", "JCLQ", "BJDC" };
                    if (!string.IsNullOrEmpty(order.PlayType) && arrGameCode.Contains(order.GameCode))
                    {
                        if (order.PlayType == "1_1")
                        {
                            rebateType = 1;
                        }
                    }
                    totalPayRebateMoney = busi.PayOrderRebate(agentManager, user, schemeId, userId, order.SchemeType, gameCode, gameType, order.TotalMoney, realMoney, 0, rebateType);
                }

                biz.CommitTran();
            }
            //计算代理销量
            busi.CalculationAgentSales(currentUserId, currentGameCode, currentBetMoney, currentIsAgent, 0);
        }