Ejemplo n.º 1
0
    public Money Credit(PtcAdvert ad)
    {
        Money calculated = ad.MoneyToClaimAsCashLink;

        user.AddToMainBalance(calculated, "CashLink", BalanceLogType.CashLinkClick);
        user.IncreaseEarnings(calculated);

        //OK mark as watched and credit
        List <int> av = user.AdsViewed;

        av.Add(ad.Id);
        user.AdsViewed  = av;
        user.LastActive = DateTime.Now;

        Money NewTotalEarned = (user.TotalEarned + calculated);

        user.TryToAddAchievements(
            Prem.PTC.Achievements.Achievement.GetProperAchievements(
                Prem.PTC.Achievements.AchievementType.AfterEarning, NewTotalEarned.GetRealTotals()));

        user.IncreaseUserStatClicks(1);
        user.IncreaseStatClicks(1);
        user.IncreaseCashLinksEarnings(calculated);

        user.Save();

        DailyPoolManager.AddToPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn), DateTime.Now, calculated);
        AdPackProfitDistributionHistory.Add(calculated);

        return(calculated);
    }
Ejemplo n.º 2
0
 public static void AddProfit(ProfitSource source, Money amount, ProfitPoolDistribution targetPool)
 {
     if (targetPool.Pool == PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn))
     {
         //Daily pool
         DailyPoolManager.AddToPool(targetPool.Pool, DateTime.Now, amount);
         AdPackProfitDistributionHistory.Add(amount);
     }
     else
     {
         //Global pool
         GlobalPoolManager.AddToPool(targetPool.Pool, amount);
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Distributes the money from the Profit Source properly
    /// </summary>
    /// <param name="source"></param>
    /// <param name="amount"></param>
    public static bool AddProfit(ProfitSource source, Money amount)
    {
        if (amount != Money.Zero)
        {
            var where = TableHelper.MakeDictionary(ProfitPoolDistribution.Columns.ProfitSource, (int)source);
            var targetPools = TableHelper.SelectRows <ProfitPoolDistribution>(where);

            Money distributed = new Money(0);

            for (int i = 0; i < targetPools.Count; i++)
            {
                var   poolRule     = targetPools[i];
                Money toDistribute = new Money(0);

                //Last pool rule
                if (i == (targetPools.Count - 1))
                {
                    toDistribute = (amount - distributed);
                }
                else
                {
                    toDistribute = Money.MultiplyPercent(amount, poolRule.ProfitPoolPercent);
                    distributed += toDistribute;
                }

                if (poolRule.Pool == PoolsHelper.GetBuiltInProfitPoolId(Pools.AdPackRevenueReturn))
                {
                    //Daily pool
                    DailyPoolManager.AddToPool(poolRule.Pool, AppSettings.ServerTime, toDistribute);
                    AdPackProfitDistributionHistory.Add(toDistribute);
                }
                else
                {
                    //Global pool
                    GlobalPoolManager.AddToPool(poolRule.Pool, toDistribute);
                }
            }
            return(distributed != Money.Zero);
        }
        return(false);
    }
    public static void Add(Money amount)
    {
        AdPackProfitDistributionHistory newRule = null;

        DateTime Now = AppSettings.ServerTime;

        var historyEntries = TableHelper.GetListFromRawQuery <AdPackProfitDistributionHistory>("SELECT * FROM AdPackProfitDistributionHistory WHERE [Date] = '" + Now.Date.ToDBString() + "'");

        if (historyEntries.Count > 0)
        {
            newRule            = historyEntries[0];
            newRule.SumAmount += amount;
        }
        else
        {
            newRule           = new AdPackProfitDistributionHistory();
            newRule.SumAmount = amount;
            newRule.date      = Now.Date;
        }

        newRule.Save();
    }