Compare commits

..

No commits in common. "849c04c10b0827363d9367a4e71c883a2ee6806d" and "920442ec6d3f5488d27cd25ce21c6740bd802a12" have entirely different histories.

3 changed files with 33 additions and 75 deletions

View File

@ -15,7 +15,6 @@ using Nop.Services.Customers;
using DocumentFormat.OpenXml.Wordprocessing; using DocumentFormat.OpenXml.Wordprocessing;
using Mango.Nop.Core.Repositories; using Mango.Nop.Core.Repositories;
using Nop.Core.Caching; using Nop.Core.Caching;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
@ -111,11 +110,15 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
if (product == null) return; if (product == null) return;
var revertLastBid = await auctionService.RevertAuctionBidByProductToAuctionIdAsync(productToAuction.Id); var revertLastBid = await auctionService.RevertAuctionBidByProductToAuctionIdAsync(productToAuction.Id);
if (revertLastBid == null)
{
//TODO: NA ILYENKOR VAN A CUMI... - J.
logger.Warning($"SignalRMessageHandler.HandleRevertAuctionBidRequest(); revertLastBid == null", null, customer);
return;
}
if (revertLastBid == null) await ResetProductToAuction(productToAuction); await SetAuctionBidPrice(revertLastBid.BidPrice, productToAuction, product, revertLastBid.CustomerId);
else await SetAuctionBidPrice(revertLastBid.BidPrice, productToAuction, product, revertLastBid.CustomerId); await SendAuctionBidMessageAsync(revertLastBid, productToAuction, product, customer.Id);
await SendAuctionBidMessageAsync(productToAuction, product, customer.Id);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -155,7 +158,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
return; return;
} }
if (auctionProductStatusRequest.AuctionStatus == AuctionStatus.None) await ResetProductToAuction(productToAuction); if (auctionProductStatusRequest.AuctionStatus == AuctionStatus.None)
{
productToAuction.AuctionStatus = AuctionStatus.None;
await auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
}
else else
{ {
switch (auctionProductStatusRequest.AuctionStatus) switch (auctionProductStatusRequest.AuctionStatus)
@ -175,13 +182,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
productToAuction.AuctionStatus = AuctionStatus.Sold; productToAuction.AuctionStatus = AuctionStatus.Sold;
productToAuction.CurrentPrice = lastAuctionBid.BidPrice; productToAuction.CurrentPrice = lastAuctionBid.BidPrice;
productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId; productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId;
//productToAuction.OrderGuid = Guid.NewGuid(); //TODO: - J.
var placeOrderResult = await auctionService.CreateOrderForWinnerAsync(productToAuction);
if (placeOrderResult is not { Success: true }) return;
//productToAuction.OrderId = placedOrder.PlacedOrder.Id; //TODO: - J.
break; break;
case AuctionStatus.NotSold: case AuctionStatus.NotSold:
@ -217,12 +217,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
} }
} }
private Task ResetProductToAuction(ProductToAuctionMapping productToAuction)
{
productToAuction.AuctionStatus = AuctionStatus.None;
return auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
}
private async Task HandleBidRequest(Customer customer, AuctionBidRequest bidRequestMessage) private async Task HandleBidRequest(Customer customer, AuctionBidRequest bidRequestMessage)
{ {
if (bidRequestMessage == null) if (bidRequestMessage == null)
@ -252,17 +246,22 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
var product = await auctionService.GetProductById(bidRequestMessage.ProductId); var product = await auctionService.GetProductById(bidRequestMessage.ProductId);
if (product == null) return; if (product == null) return;
if (IsValidBidPrice(product.Price, activeProductAuction.CurrentPrice, bidRequestMessage.BidPrice, customer)) return;
var auctionBid = bidRequestMessage.CreateMainEntity(); var auctionBid = bidRequestMessage.CreateMainEntity();
auctionBid.ProductAuctionMappingId = activeProductAuction.Id; auctionBid.ProductAuctionMappingId = activeProductAuction.Id;
//TODO: Validálni, h a bejövő BidPrice valóban a következő licit lépcső! - J.
if (product.Price >= auctionBid.BidPrice || activeProductAuction.CurrentPrice >= auctionBid.BidPrice)
{
logger.Warning($"SignalRMessageHandler.HandleBidRequest(); (product.Price >= bidRequestMessage.BidPrice || activeProductAuction.CurrentPrice >= auctionBid.BidPrice); productPrice: {product.Price}; bidRequestPrice: {auctionBid.BidPrice}; activeProductAuctionPrice: {activeProductAuction.CurrentPrice}", null, customer);
return;
}
await auctionService.InsertBidAsync(auctionBid); await auctionService.InsertBidAsync(auctionBid);
activeProductAuction.AuctionStatus = AuctionStatus.Active; activeProductAuction.AuctionStatus = AuctionStatus.Active;
if (!await SetAuctionBidPrice(auctionBid.BidPrice, activeProductAuction, product, customer.Id)) return; if (!await SetAuctionBidPrice(bidRequestMessage.BidPrice, activeProductAuction, product, customer.Id)) return;
await SendAuctionBidMessageAsync(activeProductAuction, product, customer.Id); await SendAuctionBidMessageAsync(auctionBid, activeProductAuction, product, customer.Id);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -270,21 +269,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
} }
} }
private bool IsValidBidPrice(decimal productPrice, decimal productToAuctionCurrentPrice, decimal bidRequestPrice, Customer customer = null) private async Task SendAuctionBidMessageAsync(AuctionBid auctionBid, ProductToAuctionMapping productToAuction, Product product, int customerId)
{ {
if (productPrice >= bidRequestPrice || productToAuctionCurrentPrice >= bidRequestPrice || bidRequestPrice != GetNextBidPrice(productToAuctionCurrentPrice)) var stepAmount = AuctionService.GetStepAmount(auctionBid.BidPrice);
{ var nextBidPrice = auctionBid.BidPrice + stepAmount;
logger.Warning($"SignalRMessageHandler.IsValidBidPrice(); (productPrice >= bidRequestPrice || productToAuctionCurrentPrice >= bidRequestPrice || bidRequestPrice != GetNextBidPrice(productToAuctionCurrentPrice)); productPrice: {productPrice}; productToAuctionCurrentPrice: {productToAuctionCurrentPrice}; bidRequestPrice: {bidRequestPrice}", null, customer);
return true;
}
return false;
}
private async Task SendAuctionBidMessageAsync(ProductToAuctionMapping productToAuction, Product product, int customerId)
{
var stepAmount = GetStepAmount(productToAuction.CurrentPrice);
var nextBidPrice = GetNextBidPrice(productToAuction.CurrentPrice, stepAmount);
var bidMessage = new MessageWrapper var bidMessage = new MessageWrapper
{ {
@ -293,7 +281,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true)) //TODO: NE KÉRJÜK LE DB-BŐL!!! - j. Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true)) //TODO: NE KÉRJÜK LE DB-BŐL!!! - j.
{ {
ProductName = product.Name, ProductName = product.Name,
CurrentPrice = productToAuction.CurrentPrice, CurrentPrice = auctionBid.BidPrice,
NextStepAmount = stepAmount, NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice, NextBidPrice = nextBidPrice,
ToasterMessage = "EMPTY", //TODO: - J. ToasterMessage = "EMPTY", //TODO: - J.
@ -325,13 +313,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
return false; return false;
} }
private static decimal GetStepAmount(decimal currentBidPrice) => AuctionService.GetStepAmount(currentBidPrice);
private static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount)
{
return currentBidPrice + stepAmount;
}
private static bool IsValidRequestAuctionStatus(AuctionStatus newStatus, AuctionStatus oldStatus) private static bool IsValidRequestAuctionStatus(AuctionStatus newStatus, AuctionStatus oldStatus)
{ {
switch (oldStatus) switch (oldStatus)

View File

@ -36,6 +36,8 @@ public class AuctionService : IAuctionService
/// Ctor /// Ctor
/// </summary> /// </summary>
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="shortTermCacheManager">Short term cache manager</param>
/// <param name="staticCacheManager">Cache manager</param>
/// <param name="productService"></param> /// <param name="productService"></param>
/// <param name="workContext"></param> /// <param name="workContext"></param>
/// <param name="logger"></param> /// <param name="logger"></param>
@ -185,35 +187,11 @@ public class AuctionService : IAuctionService
await _ctx.AuctionBids.DeleteAsync(pickupPoint, false); await _ctx.AuctionBids.DeleteAsync(pickupPoint, false);
} }
public async Task<PlaceOrderResult> CreateOrderForWinnerAsync(ProductToAuctionMapping auctionItem) public async Task CreateOrderForWinner(ProductToAuctionMapping auctionItem)
{ {
if (auctionItem is not { AuctionStatus: AuctionStatus.Sold }) var processPaymentRequest = new ProcessPaymentRequest();
{
await _logger.InformationAsync($"AuctionService.CreateOrderForWinnerAsync(); (auctionItem is not {{ AuctionStatus: AuctionStatus.Sold }}); auctionItemId: {auctionItem?.Id}; status: {auctionItem?.AuctionStatus}");
return null;
}
try
{
var processPaymentRequest = new ProcessPaymentRequest();
processPaymentRequest.CustomerId = auctionItem.WinnerCustomerId;
processPaymentRequest.CustomValues.Add("ProductToAuctionMappingId", auctionItem.Id);
processPaymentRequest.OrderTotal = auctionItem.CurrentPrice;
//processPaymentRequest.OrderGuid = productToAuction.OrderGuid; //TODO: - J. await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);
processPaymentRequest.OrderGuid = Guid.NewGuid();
var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);
//placeOrderResult.PlacedOrder //TODO:... - J.
return placeOrderResult.Success ? placeOrderResult : null;
}
catch (Exception ex)
{
_logger.Error($"AuctionService.CreateOrderForWinnerAsync(); Exception; auctionItemId: {auctionItem.Id}", ex);
}
return null;
} }
#region auctions #region auctions

View File

@ -3,7 +3,6 @@ using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin.Domains; using Nop.Plugin.Misc.AuctionPlugin.Domains;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Services.Orders;
namespace Nop.Plugin.Misc.AuctionPlugin.Services; namespace Nop.Plugin.Misc.AuctionPlugin.Services;
@ -60,5 +59,5 @@ public interface IAuctionService
Task<ProductToAuctionMapping> GetProductToAuctionMappingByIdAsync(int productToAuctionMappingId); Task<ProductToAuctionMapping> GetProductToAuctionMappingByIdAsync(int productToAuctionMappingId);
Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping); Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping);
Task<PlaceOrderResult> CreateOrderForWinnerAsync(ProductToAuctionMapping productToAuctionMapping); Task CreateOrderForWinner(ProductToAuctionMapping productToAuctionMapping);
} }