Ejemplo n.º 1
0
        public static void CRON()
        {
            try
            {
                if (AppSettings.InvestmentPlatform.InvestmentPlatformEnabled)
                {
                    var activePlans = GetAllActivePlans();

                    foreach (var plan in activePlans)
                    {
                        var usersPlans = GetAllUsersActivePlans().FindAll(x => x.PlanId == plan.Id);

                        if (usersPlans.Count == 0 || plan.Roi == 0 || plan.Time == 0 || plan.Price == Money.Zero)
                        {
                            continue;
                        }

                        var note = plan.Name + " credit";

                        foreach (var userPlan in usersPlans)
                        {
                            if (userPlan.PurchaseDate.AddDays(plan.EarningDaysDelay) > DateTime.Now)
                            {
                                continue;
                            }

                            var dailyPool = userPlan.Price * plan.Roi / 100 / plan.Time;

                            //start
                            userPlan.TakeMoneyFromFinishedPlans();

                            userPlan.MoneyReturned += dailyPool;
                            userPlan.MoneyInSystem += dailyPool;

                            Member user = new Member(userPlan.UserId);

                            if (AppSettings.InvestmentPlatform.InvestmentPlatformCreditingPolicy == CreditingPolicy.Automatic && userPlan.MoneyInSystem > GetMembershipMinAmountToCredit(user))
                            {
                                Money creditAmount;

                                //Monthly check
                                if (userPlan.CurrentMonthPayout > DateTime.Now.Day * plan.DailyLimit)
                                {
                                    userPlan.CurrentMonthPayout = Money.Zero;
                                }

                                if (!AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled || userPlan.CurrentMonthPayout < plan.MonthlyLimit)
                                {
                                    if (AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled && userPlan.MoneyInSystem > plan.DailyLimit)
                                    {
                                        creditAmount            = plan.DailyLimit;
                                        userPlan.MoneyInSystem -= plan.DailyLimit;
                                    }
                                    else
                                    {
                                        creditAmount           = userPlan.MoneyInSystem;
                                        userPlan.MoneyInSystem = Money.Zero;
                                    }

                                    //Monthly limit
                                    var leftInMonth = plan.MonthlyLimit - userPlan.CurrentMonthPayout;
                                    if (AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled && creditAmount > leftInMonth)
                                    {
                                        userPlan.MoneyInSystem += (creditAmount - leftInMonth);
                                        creditAmount            = leftInMonth;
                                    }

                                    userPlan.CurrentMonthPayout += creditAmount;

                                    var crediter = new InvestmentPlanCrediter(user);
                                    crediter.CreditPlan(creditAmount, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformPlanCrediting);
                                    //TO DO AFTER ENABLE INVESTMENT BALANCE
                                    //if (AppSettings.InvestmentPlatform.CreditToInvestmentBalanceEnabled)
                                    //    user.AddToInvestmentBalance(creditAmount, note);
                                    //else
                                    //    user.AddToMainBalance(creditAmount, note);

                                    user.SaveBalances();
                                }
                            }

                            if (userPlan.MoneyReturned >= userPlan.MoneyToReturn)
                            {
                                var overPlus = userPlan.MoneyReturned - userPlan.MoneyToReturn;

                                userPlan.MoneyInSystem += overPlus;
                                userPlan.MoneyReturned  = userPlan.MoneyToReturn;
                                userPlan.Finish(false);
                            }
                            userPlan.Save();

                            string historyNote;
                            if (TitanFeatures.IsRetireYoung)
                            {
                                historyNote = string.Format("{0} ({1}/{2}) ", note, dailyPool.ToString(), RetireyoungManager.GetAggregate(user.Id));
                            }
                            else
                            {
                                historyNote = string.Format("{0}: {1}", note, dailyPool.ToString());
                            }
                            History.AddEntry(user.Name, HistoryType.InvestmentPlatformDailyCredit, historyNote);
                            //end
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLogger.Log(e);
            }
        }
Ejemplo n.º 2
0
        public void Finish(bool isSave = true)
        {
            FinishDate = AppSettings.ServerTime;
            Status     = PlanStatus.Finished;

            if (!AppSettings.InvestmentPlatform.InvestmentPlatformDailyLimitsEnabled)
            {
                var user         = Member.CurrentInCache;
                var crediter     = new InvestmentPlanCrediter(user);
                var platformPlan = new InvestmentPlatformPlan(PlanId);
                var note         = string.Format("Finished plan: {0}", platformPlan.Name);

                if (TitanFeatures.IsRetireYoung)
                {
                    crediter.CreditPlan(MoneyInSystem + platformPlan.Price, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);
                }
                else
                {
                    crediter.CreditPlan(MoneyInSystem, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);
                }

                //BONUS
                if (MoneyInSystem >= MoneyToReturn && LastWithdrawalDate == null)
                {
                    var bonus = platformPlan.EndBonus;

                    if (bonus > Money.Zero)
                    {
                        note = string.Format(U6010.BONUSFORFINISHEDPLAN, platformPlan.Name);
                        crediter.CreditPlan(bonus, BalanceType.MainBalance, note, BalanceLogType.InvestmentPlatformWithdrawal);

                        var historyNote = string.Format("{0} ({1}/{2})", note, bonus.ToString(), RetireyoungManager.GetAggregate(user.Id));
                        History.AddEntry(user.Name, HistoryType.InvestmentPlatformBonus, historyNote);
                    }
                }

                MoneyInSystem = Money.Zero;
            }

            if (isSave)
            {
                Save();
            }
        }
Ejemplo n.º 3
0
        private static void TryToSpeedUpReferrer(int referrerId, Money planPrice, string username)
        {
            //ONLY Referrals
            //Matrix - TODO
            if (AppSettings.InvestmentPlatform.InvestmentPlatformSpeedUpOption != SpeedUpOptions.Referrals)
            {
                return;
            }

            var query = string.Format(@"
                    WITH CTE AS 
                        (SELECT TOP 1 * FROM InvestmentUsersPlans WHERE UserId = {0} AND Status = {1} ORDER BY PurchasedDate ASC)
                    UPDATE InvestmentUsersPlans 
                        SET MoneyInSystem += 
                            (SELECT BinaryEarning FROM InvestmentPlatformPlans WHERE Id = (SELECT PlanId FROM CTE)) * {2}
                        WHERE Id = (SELECT Id FROM CTE)",
                                      referrerId, (int)PlanStatus.Active, planPrice / 100);

            TableHelper.ExecuteRawCommandNonQuery(query);

            var bonusQuery = string.Format(@"
                    WITH CTE AS 
                        (SELECT TOP 1 * FROM InvestmentUsersPlans WHERE UserId = {0} AND Status = {1} ORDER BY PurchasedDate ASC)
                    SELECT BinaryEarning FROM InvestmentPlatformPlans WHERE Id = (SELECT PlanId FROM CTE)",
                                           referrerId, (int)PlanStatus.Active);

            try
            {
                var user        = new Member(referrerId);
                var bonus       = (int)TableHelper.SelectScalar(bonusQuery) * planPrice / 100;
                var historyNote = string.Empty;

                if (bonus <= Money.Zero)
                {
                    return;
                }

                if (TitanFeatures.IsRetireYoung)
                {
                    historyNote = string.Format("Investment Plan SpeedUp [ref - {0}] ({1}/{2})", username, bonus.ToString(), RetireyoungManager.GetAggregate(user.Id));
                }
                else
                {
                    historyNote = string.Format("Investment Plan SpeedUp [ref - {0}] ({1})", username, bonus.ToString());
                }

                History.AddEntry(user.Name, HistoryType.InvestmentPlatformSpeedUpBonus, historyNote);
            }
            catch (Exception e) { }
        }