protected void RecalculateRenta(Renta renta, string qrDecoded, SIN newsin) { renta.SinId = newsin.Id; var anon = GetAnon(newsin.Character.Model); renta.CurrentScoring = newsin.Scoring.CurerentRelative + newsin.Scoring.CurrentFix; var gmdescript = BillingHelper.GetGmDescription(newsin.Passport, renta.Sku, anon); _ereminService.UpdateQR(qrDecoded, renta.BasePrice, BillingHelper.GetFinalPrice(renta), gmdescript, renta.Id, BillingHelper.GetLifestyle(renta.LifeStyle)).GetAwaiter().GetResult(); SaveContext(); }
protected Price CreateNewPrice(Sku sku, ShopWallet shop, SIN sin) { decimal modeldiscount; try { var eService = new EreminService(); modeldiscount = eService.GetDiscount(sin.Character.Model, BillingHelper.GetDiscountType(sku.Nomenklatura.Specialisation.ProductType.DiscountType)); } catch (Exception e) { Console.Error.WriteLine(e.ToString()); modeldiscount = 1; } decimal discount = 1; if (sin.Passport.Mortgagee == sku.Corporation.Alias) { discount *= 0.9m; } discount *= modeldiscount; var currentScoring = sin.Scoring.CurrentFix + sin.Scoring.CurerentRelative; if (currentScoring == 0) { currentScoring = 1; } var price = new Price { Sku = sku, Shop = shop, BasePrice = sku.Nomenklatura.BasePrice, CurrentScoring = currentScoring, DateCreated = DateTime.Now.ToUniversalTime(), Discount = discount, Sin = sin, ShopComission = BillingHelper.GetShopComission(shop.LifeStyle), ShopPrice = BillingHelper.GetShopPrice(sku) }; price.FinalPrice = BillingHelper.GetFinalPrice(price); Add(price); SaveContext(); return(price); }
protected void CloseOverdraft(Renta renta, Wallet mir, SIN sin, bool first = false) { decimal comission; if (renta.FullPrice) { comission = BillingHelper.GetFinalPrice(renta); } else { comission = BillingHelper.CalculateComission(renta); } //create KPI here renta.Sku.Corporation.CurrentKPI += renta.ShopPrice; if (first) { renta.Sku.Corporation.SkuSold += renta.ShopPrice; } //comission AddNewTransfer(mir, renta.Shop.Wallet, comission, $"Рентное начисление: {renta.Sku.Name} в {renta.Shop.Name} от {sin.Passport.PersonName}", false, renta.Id, false); }
/// <summary> /// НЕ ВЫПОЛНЯЕТСЯ SAVECONTEXT /// </summary> protected void ProcessRenta(Renta renta, Wallet mir, SIN sin, bool first = false) { if (renta?.Shop?.Wallet == null || renta?.Sku?.Corporation?.Wallet == null || sin?.Character == null || sin?.Wallet == null || renta?.Sku?.Nomenklatura == null) { throw new Exception("Ошибка загрузки моделей по ренте"); } var finalPrice = BillingHelper.GetFinalPrice(renta); //если баланс положительный if (sin.Wallet.Balance > 0) { AddNewTransfer(sin.Wallet, mir, finalPrice, $"Рентный платеж: { renta.Sku.Name} в {renta.Shop.Name}", false, renta.Id, false); CloseOverdraft(renta, mir, sin, first); } else { AddNewTransfer(sin.Wallet, mir, finalPrice, $"Рентный платеж: {renta.Sku.Name} в {renta.Shop.Name}", false, renta.Id, true); } }
public BeatCharacterLocalDto ProcessCharacterBeat(int sinId, WorkModelDto workDto, decimal K, JobLifeStyleDto lastdto) { var sw = new Stopwatch(); sw.Start(); var localDto = new BeatCharacterLocalDto(); var sin = BlockCharacter(sinId, s => s.Wallet, s => s.Character, s => s.Passport, s => s.Scoring); SaveContext(); var mir = GetMIR(); decimal income = 0; decimal outcome = 0; var mortagee = GetMortagee(sin.Passport); //ability if (workDto.Dividends1) { var def1 = _settings.GetDecimalValue(SystemSettingsEnum.dividents1_k); var sum = GetDividends(mortagee, 0.01m, def1); AddNewTransfer(mir, sin.Wallet, sum, "Дивиденды *"); income += sum; localDto.SumDividends += sum; } if (workDto.Dividends2) { var def2 = _settings.GetDecimalValue(SystemSettingsEnum.dividents2_k); var sum = GetDividends(mortagee, 0.03m, def2); AddNewTransfer(mir, sin.Wallet, sum, "Дивиденды **"); income += sum; localDto.SumDividends += sum; } if (workDto.Dividends3) { var def3 = _settings.GetDecimalValue(SystemSettingsEnum.dividents3_k); var sum = GetDividends(mortagee, 0.05m, def3); AddNewTransfer(mir, sin.Wallet, sum, "Дивиденды ***"); income += sum; localDto.SumDividends += sum; } //karma if (workDto.KarmaCount > 0) { var avg = lastdto.GetAvergeKarma(); decimal x1 = 0; if (avg != 0) { x1 = (lastdto.GetAvergeRents() * K) / lastdto.GetAvergeKarma(); } else { x1 = (lastdto.GetAvergeRents() * K) / 700; } if (x1 == 0) { x1 = 0.3m; } var karmasum = x1 * workDto.KarmaCount; income += karmasum; localDto.SumKarma += karmasum; AddNewTransfer(mir, sin.Wallet, karmasum, "Пассивный доход"); } var swIncome = Cut(sw); //rentas var rentas = GetList <Renta>(r => r.SinId == sin.Id, r => r.Shop.Wallet, r => r.Sku.Corporation.Wallet, r => r.Sku.Nomenklatura); foreach (var renta in rentas) { ProcessRenta(renta, mir, sin); } var swRentas = Cut(sw); //overdrafts if (sin.Wallet.Balance > 0) { var allOverdrafts = GetList <Transfer>(t => t.Overdraft && t.WalletFromId == sin.Wallet.Id && t.RentaId > 0); foreach (var overdraft in allOverdrafts) { overdraft.Overdraft = false; var closingRenta = Get <Renta>(r => r.Id == overdraft.RentaId, r => r.Sku.Corporation, r => r.Shop.Wallet, r => r.Sku.Nomenklatura); CloseOverdraft(closingRenta, mir, sin); } } var swoverdrafts = Cut(sw); //metatype if (sin.Passport.MetatypeId != sin.OldMetaTypeId) { var scoring = IoC.IocContainer.Get <IScoringManager>(); scoring.OnMetatypeChanged(sin); sin.OldMetaTypeId = sin.Passport.MetatypeId; } //insurance var insurance = GetInsurance(sin.CharacterId); if (insurance?.LifeStyle != sin.OldInsurance) { if ((insurance?.LifeStyle ?? 0) > 0 != (sin.OldInsurance ?? 0) > 0) { var scoring = IoC.IocContainer.Get <IScoringManager>(); scoring.OnInsuranceChanged(sin, (insurance?.LifeStyle ?? 0) > 0); } sin.OldInsurance = insurance?.LifeStyle; } //summary localDto.Scoringvalue = BillingHelper.GetFullScoring(sin.Scoring); //forecast outcome += rentas.Sum(r => BillingHelper.GetFinalPrice(r)); if (workDto.StockGainPercentage > 0) { var stock = outcome * (workDto.StockGainPercentage / 100); income += stock; AddNewTransfer(mir, sin.Wallet, stock, "Игра на бирже"); } localDto.SumRents += outcome; sin.Wallet.IncomeOutcome = income - outcome; if (sin.Wallet.IsIrridium) { localDto.IsIrridium = true; } else { localDto.Balance = sin.Wallet.Balance; localDto.Forecast = BillingHelper.GetForecast(sin.Wallet); } SaveContext(); var swOther = Cut(sw); sw.Stop(); sin.DebugTime = Serialization.Serializer.ToJSON(new { swIncome, swRentas, swoverdrafts, swOther }); UnblockCharacter(sin); return(localDto); }
private void WriteRenta(Renta renta, string qrDecoded) { var code = renta.Sku.Nomenklatura.Code; var pt = ProductTypeEnum.Spirit.ToString(); if (renta.Sku.Nomenklatura.Specialisation.ProductType.Alias == pt) { var magic = new MagicService(); var intqr = int.Parse(qrDecoded); magic.PutSpiritInJar(intqr, code).GetAwaiter().GetResult(); qrDecoded = $"spirit {qrDecoded}"; } else { var name = renta.Sku.Name; var description = renta.Sku.Nomenklatura.Description; _ereminService.WriteQR(qrDecoded, code, name, description, renta.Count, renta.BasePrice, BillingHelper.GetFinalPrice(renta), renta.Secret, renta.Id, (Lifestyles)renta.LifeStyle).GetAwaiter().GetResult(); var oldQR = Get <Renta>(r => r.QRRecorded == qrDecoded); if (oldQR != null) { oldQR.QRRecorded = $"{qrDecoded} deleted"; } } renta.QRRecorded = qrDecoded; }
public List <InsolventDto> GetInsolvents() { var overdrafts = GetList <Transfer>(t => t.Overdraft == true); var listIds = overdrafts.Select(s => s.WalletFromId).Distinct().ToList(); var sins = GetList <SIN>(s => listIds.Contains(s.WalletId ?? 0), s => s.Wallet, s => s.Passport, s => s.Character); var sinIds = sins.Select(s => s.Id).ToList(); var rents = GetList <Renta>(r => sinIds.Contains(r.SinId ?? 0), r => r.Sku); var insolvents = new List <InsolventDto>(); foreach (var sin in sins) { var personOverdrafts = overdrafts.Where(o => o.WalletFromId == sin.WalletId); var insolvent = new InsolventDto { Balance = sin.Wallet.Balance, Citizenship = sin.Passport.Citizenship, ModelId = sin.Character.Model, SinText = sin.Passport.Sin, PersonName = sin.Passport.PersonName, IsIrridium = sin.Wallet.IsIrridium }; insolvent.SumOverdraft = personOverdrafts.Where(t => t.WalletFromId == sin.WalletId).Sum(s => s.Amount); insolvent.SumRents = rents.Where(r => r.SinId == sin.Id).Sum(r => BillingHelper.GetFinalPrice(r)); insolvent.Debts = new List <Debt>(); foreach (var personaloverdraft in personOverdrafts) { var renta = rents.FirstOrDefault(r => r.Id == personaloverdraft.RentaId); var skuName = "взломано"; if (renta != null) { skuName = renta.Sku.Name; } var debt = new Debt { FinalPrice = personaloverdraft.Amount, RentId = personaloverdraft.RentaId ?? 0, SkuName = skuName }; insolvent.Debts.Add(debt); } insolvents.Add(insolvent); } return(insolvents); }