Exemplo n.º 1
0
    public static void AddToPool(int poolId, Money amount)
    {
        var pool = GlobalPool.Get(poolId);

        pool.SumAmount += amount;
        pool.Save();
    }
Exemplo n.º 2
0
    public static void CreditFromSundayPool()
    {
        try
        {
            var sundayPool  = GlobalPool.Get(PoolsHelper.GetSundayPoolId());
            var poolPercent = TitanFeatures.StringSawSundayPool.Value;
            if (Money.MultiplyPercent(sundayPool.SumAmount, poolPercent) > Money.Zero)
            {
                var users        = TableHelper.GetListFromRawQuery <Member>(string.Format(@"SELECT * FROM Users WHERE AccountStatusInt = {0} AND UpgradeId != {1} 
            AND UserId IN (SELECT DISTINCT UserId FROM AdPacks WHERE MoneyToReturn > MoneyReturned)", (int)MemberStatus.Active, Membership.Standard.Id));
                var toDistribute = Money.MultiplyPercent(sundayPool.SumAmount, poolPercent);
                var perUser      = Money.Zero;

                if (users.Count > 0)
                {
                    perUser = toDistribute / users.Count;
                }

                if (perUser > Money.Zero)
                {
                    foreach (var user in users)
                    {
                        user.AddToMainBalance(perUser, "Sunday AdPack Distribution");
                        user.SaveBalances();
                    }
                    GlobalPoolManager.SubtractFromPool(sundayPool.GlobalPoolType, toDistribute);
                }
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }
Exemplo n.º 3
0
    public static Money GetMaxPossibleRequest(Member user)
    {
        var amountInPool = GlobalPool.Get(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine)).SumAmount;
        var pendingSum   = GetPendingRequestsSumAmount();
        var left         = amountInPool - pendingSum;

        var amounts = new List <Money>();

        amounts.Add(left);
        amounts.Add(user.Membership.MaxCreditLineRequest);

        if (TitanFeatures.IsCopiousassets)
        {
            amounts.Add(Money.MultiplyPercent(GetThisWeeksMarketplaceSpendings(user.Id), 10));
        }

        return(amounts.Min());
    }
Exemplo n.º 4
0
    public static void AcceptRequest(int creditLineRequestId)
    {
        Money maxLoan = GlobalPool.Get(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine)).SumAmount;

        CreditLineRequest request = new CreditLineRequest(creditLineRequestId);

        if (request.LoanRequested > maxLoan)
        {
            request.Status = CreditLineRequestStatus.Rejected;
            request.Save();
            throw new MsgException("There is not enough money in the pool. The request has been rejected.");
        }

        request.Status = CreditLineRequestStatus.Accepted;
        request.Save();

        Member         user = new Member(request.UserId);
        DateTime       now  = AppSettings.ServerTime;
        CreditLineLoan loan = new CreditLineLoan();

        loan.UserId                    = user.Id;
        loan.Loaned                    = request.LoanRequested;
        loan.FirstDeadline             = now.AddDays(AppSettings.CreditLine.FirstDeadlineDays);
        loan.SecondDeadline            = now.AddDays(AppSettings.CreditLine.SecondDeadlineDays);
        loan.FinalDeadline             = now.AddDays(AppSettings.CreditLine.FinalDeadlineDays);
        loan.AmounBeforeFirstDeadline  = Money.MultiplyPercent(request.LoanRequested, AppSettings.CreditLine.FirstRepayPercent);
        loan.AmounBeforeSecondDeadline = Money.MultiplyPercent(request.LoanRequested, AppSettings.CreditLine.SecondRepayPercent);
        loan.BorrowDate                = now;
        loan.Repaid                    = Money.Zero;
        loan.Save();

        var moneyWithoutFee = Money.MultiplyPercent(request.LoanRequested, 100 - AppSettings.CreditLine.Fee);

        GlobalPoolManager.SubtractFromPool(PoolsHelper.GetBuiltInProfitPoolId(Pools.CreditLine), moneyWithoutFee);

        user.AddToPurchaseBalance(moneyWithoutFee, "Credit Line", BalanceLogType.CreditLine);
        user.SaveBalances();

        Mailer.SendNewCreditLineMessage(user.Email, request.LoanRequested);
    }
Exemplo n.º 5
0
 /// <summary>
 /// 全局分配
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static T GlobalAllocate <T>(IEventArgs arg = null)
 {
     return(_globalPool.Get <T>(arg));
 }