示例#1
0
        public static void TryToCreditReferrerAfterPurchase(Member user, Money price, string defaultNote = "PTC purchase")
        {
            if (user.HasReferer)
            {
                var note       = string.Format("{0} /ref/{1}", defaultNote, user.Name);
                var referer    = new Member(user.ReferrerId);
                var commission = Money.MultiplyPercent(price, referer.Membership.PTCPurchaseCommissionPercent);

                if (commission == Money.Zero)
                {
                    return;
                }

                if (AppSettings.Payments.CommissionBalanceEnabled)
                {
                    referer.AddToCommissionBalance(commission, note);
                }
                else
                {
                    referer.AddToMainBalance(commission, note);
                }

                referer.IncreaseEarnings(commission);
                referer.IncreaseEarningsFromDirectReferral(commission);
                referer.StatsCommissionsCurrentWeekIncome  += commission;
                referer.StatsCommissionsCurrentMonthIncome += commission;
                referer.SaveStatisticsAndBalances();

                try
                {
                    if (AppSettings.Emails.NewReferralCommisionEnabled)
                    {
                        Mailer.SendNewReferralCommisionMessage(referer.Name, user.Name, commission, referer.Email, note);
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }
            }
        }
示例#2
0
 protected static void CreditCommissionBalanceHelper(ref Member User, Money Input, string note, BalanceLogType balanceLogType)
 {
     User.AddToCommissionBalance(Input, note, balanceLogType);
     User.IncreaseEarnings(Input);
 }
示例#3
0
        private void TryCreditDirectReferer(PtcAdvert ad)
        {
            if (!User.HasReferer || TitanFeatures.IsGambinos && User.MembershipId == 1)
            {
                return;
            }

            Member referer = new Member(User.ReferrerId);

            if (referer.IsRented)
            {
                return;
            }

            if (referer.HasClickedEnoughToProfitFromReferrals())
            {
                Money amountToCredit = PtcAdvert.CalculateEarningsFromDirectReferral(referer.Membership, ad);

                if (AppSettings.Payments.CommissionBalanceEnabled)
                {
                    referer.AddToCommissionBalance(amountToCredit, "PTC /ref/" + User.Name, BalanceLogType.Other);
                }
                else
                {
                    referer.AddToMainBalance(amountToCredit, "PTC /ref/" + User.Name, BalanceLogType.Other);
                }

                referer.IncreaseEarnings(amountToCredit);
                referer.IncreaseEarningsFromDirectReferral(amountToCredit);
                referer.IncreaseDRClicks();
                referer.IncreaseStatClicks(1);
                referer.IncreaseDRCashLinksEarnings(amountToCredit);

                referer.StatsCommissionsCurrentWeekIncome  += amountToCredit;
                referer.StatsCommissionsCurrentMonthIncome += amountToCredit;

                var pointsEarnings = referer.Membership.DirectReferralAdvertClickEarningsPoints;
                referer.AddToPointsBalance(pointsEarnings, "PTC /ref/" + User.Name);
                referer.IncreaseDirectRefPointsEarnings(pointsEarnings);
                referer.IncreasePointsEarnings(pointsEarnings);

                User.TotalPTCClicksToDReferer    += 1;
                User.TotalEarnedToDReferer       += amountToCredit;
                User.LastDRActivity               = AppSettings.ServerTime;
                User.TotalPointsEarnedToDReferer += pointsEarnings;
                User.SaveStatisticsAndBalances();

                bool isFullSaveRequired1 = false;
                bool isFullSaveRequired2 = false;

                //Achievements trial
                isFullSaveRequired1 = referer.TryToAddAchievements(
                    Prem.PTC.Achievements.Achievement.GetProperAchievements(
                        Prem.PTC.Achievements.AchievementType.AfterClicks, referer.TotalClicks + 1));

                string  inter     = (referer.TotalEarned + amountToCredit).ToClearString();
                Decimal tempMoney = Decimal.Parse(inter, new System.Globalization.CultureInfo("en-US"));

                isFullSaveRequired2 = referer.TryToAddAchievements(
                    Prem.PTC.Achievements.Achievement.GetProperAchievements(
                        Prem.PTC.Achievements.AchievementType.AfterEarning, Convert.ToInt32(tempMoney)));

                if (isFullSaveRequired1 || isFullSaveRequired2)
                {
                    referer.Save();
                }
                else
                {
                    referer.SaveStatisticsAndBalances();
                }
            }
        }
示例#4
0
    private void CreditAncestor(Member ancestor, Money servicePrice, decimal percentage, MatrixLeg leg)
    {
        try
        {
            if (percentage <= 0)
            {
                return;
            }

            Money bonus = Money.MultiplyPercent(servicePrice, percentage);

            //We are adding to left or right leg
            if (leg == MatrixLeg.Left)
            {
                ancestor.MatrixBonusMoneyFromLeftLeg += bonus;
            }
            else
            {
                ancestor.MatrixBonusMoneyFromRightLeg += bonus;
            }

            if (ancestor.MatrixBonusMoneyFromLeftLeg > AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg &&
                ancestor.MatrixBonusMoneyFromRightLeg > AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg)
            {
                int cyclesPerDay = -1;

                if (AppSettings.Matrix.MatrixCyclesFromRank)
                {
                    LeadershipRank rank = ancestor.GetRank();

                    cyclesPerDay = rank != null ? rank.MatrixCyclesPerDay : cyclesPerDay;
                }
                else
                {
                    cyclesPerDay = AppSettings.Matrix.MatrixCyclesPerDay;
                }

                //We cycle or flush out
                if (ancestor.MatrixBonusMoneyCyclesToday < cyclesPerDay)
                {
                    ancestor.MatrixBonusMoneyCyclesToday++;
                    ancestor.MatrixBonusMoneyFromLeftLeg  -= AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg;
                    ancestor.MatrixBonusMoneyFromRightLeg -= AppSettings.Matrix.MatrixCyclesBonusMoneyFromLeg;

                    if (TitanFeatures.IsTrafficThunder)
                    {
                        ancestor.AddToCommissionBalance(AppSettings.Matrix.MatrixCyclesPrizeMoney, "Matrix Cycle bonus");
                    }
                    else
                    {
                        ancestor.AddToMainBalance(AppSettings.Matrix.MatrixCyclesPrizeMoney, "Matrix Cycle bonus");
                    }

                    ancestor.IncreaseMetrixBonusEarnings(AppSettings.Matrix.MatrixCyclesPrizeMoney);
                    ancestor.Save();
                }
                else
                {
                    //We flush
                    ancestor.MatrixBonusMoneyFromLeftLeg  = Money.Zero;
                    ancestor.MatrixBonusMoneyFromRightLeg = Money.Zero;
                    ancestor.SaveMatrixId();
                }
            }
            else
            {
                ancestor.SaveMatrixId();
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }