From 8c6d125c962f8c1e2c349dbfc5b19e00906aeabb Mon Sep 17 00:00:00 2001 From: yeziuku Date: Fri, 4 Apr 2025 23:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=89=E5=8F=8A=E5=BA=93=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E7=89=A9=E5=93=81=E8=8E=B7=E5=8F=96=E5=BA=94=E8=AF=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20Guid=20=E8=80=8C=E4=B8=8D=E6=98=AF=20ItemId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DataRequestController.cs | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/FunGame.Server/Controllers/DataRequestController.cs b/FunGame.Server/Controllers/DataRequestController.cs index 6d6de3a..43716dd 100644 --- a/FunGame.Server/Controllers/DataRequestController.cs +++ b/FunGame.Server/Controllers/DataRequestController.cs @@ -1244,8 +1244,8 @@ namespace Milimoe.FunGame.Server.Controller { long offerId = DataRequest.GetDictionaryJsonObject(requestData, OffersQuery.Column_Id); OfferActionType action = DataRequest.GetDictionaryJsonObject(requestData, "action"); - List offerorItems = DataRequest.GetDictionaryJsonObject>(requestData, "offerorItems") ?? []; - List offereeItems = DataRequest.GetDictionaryJsonObject>(requestData, "offereeItems") ?? []; + List offerorItems = DataRequest.GetDictionaryJsonObject>(requestData, "offerorItems") ?? []; + List offereeItems = DataRequest.GetDictionaryJsonObject>(requestData, "offereeItems") ?? []; long userId = Server.User.Id; Offer? offer = SQLHelper.GetOffer(offerId); @@ -1309,7 +1309,11 @@ namespace Milimoe.FunGame.Server.Controller case OfferActionType.OffereeRevise: // 接收方修改报价 - if (!isOfferor && (offer.Status == OfferState.Sent || offer.Status == OfferState.NegotiationAccepted)) + if (!isOfferor && offer.NegotiatedTimes >= 3) + { + msg = "当前协商次数已达上限(3次),不允许接收方修改。"; + } + else if (!isOfferor && (offer.Status == OfferState.Sent || offer.Status == OfferState.NegotiationAccepted)) { // 备份 SQLHelper.BackupOfferItem(offer); @@ -1329,7 +1333,7 @@ namespace Milimoe.FunGame.Server.Controller break; case OfferActionType.OffereeSend: - if (!isOfferor && (offer.Status == OfferState.Sent || offer.Status == OfferState.Negotiating)) + if (!isOfferor && (offer.Status == OfferState.OffereeConfirmed)) { if (offer.NegotiatedTimes < 3) { @@ -1337,7 +1341,7 @@ namespace Milimoe.FunGame.Server.Controller SQLHelper.UpdateOfferNegotiatedTimes(offerId, offer.NegotiatedTimes + 1); canProceed = true; } - else msg = "协商次数已达上限(3次)。"; + else msg = "当前协商次数已达上限(3次),不允许接收方发送。"; } else msg = "当前状态不允许接收方修改。"; break; @@ -1351,13 +1355,13 @@ namespace Milimoe.FunGame.Server.Controller { // 更新物品 SQLHelper.DeleteOfferItemsByOfferId(offerId); - foreach (long itemId in offerorItems) + foreach (Guid itemGuid in offerorItems) { - SQLHelper.AddOfferItem(offerId, offer.Offeror, itemId); + SQLHelper.AddOfferItem(offerId, offer.Offeror, itemGuid); } - foreach (long itemId in offereeItems) + foreach (Guid itemGuid in offereeItems) { - SQLHelper.AddOfferItem(offerId, offer.Offeree, itemId); + SQLHelper.AddOfferItem(offerId, offer.Offeree, itemGuid ); } offer = SQLHelper.GetOffer(offerId); @@ -1452,31 +1456,39 @@ namespace Milimoe.FunGame.Server.Controller { if (offer.Status == OfferState.Completed) { + User offeree = Server.User; User? offeror = SQLHelper.GetUserById(offer.Offeror); if (offeror != null) { - foreach (Item item in offer.OffereeItems) + foreach (Guid itemGuid in offer.OffereeItems) { - Item newItem = item.Copy(); - newItem.User = offeror; - newItem.IsSellable = false; - newItem.IsTradable = false; - newItem.NextSellableTime = DateTimeUtility.GetTradableTime(); - newItem.NextTradableTime = DateTimeUtility.GetTradableTime(); - offeror.Inventory.Items.Add(newItem); + if (offeree.Inventory.Items.FirstOrDefault(i => i.Guid == itemGuid) is Item item) + { + offeree.Inventory.Items.Remove(item); + Item newItem = item.Copy(); + newItem.User = offeror; + newItem.IsSellable = false; + newItem.IsTradable = false; + newItem.NextSellableTime = DateTimeUtility.GetTradableTime(); + newItem.NextTradableTime = DateTimeUtility.GetTradableTime(); + offeror.Inventory.Items.Add(newItem); + } + } + foreach (Guid itemGuid in offer.OfferorItems) + { + if (offeror.Inventory.Items.FirstOrDefault(i => i.Guid == itemGuid) is Item item) + { + offeror.Inventory.Items.Remove(item); + Item newItem = item.Copy(); + newItem.User = offeree; + newItem.IsSellable = false; + newItem.IsTradable = false; + newItem.NextSellableTime = DateTimeUtility.GetTradableTime(); + newItem.NextTradableTime = DateTimeUtility.GetTradableTime(); + offeree.Inventory.Items.Add(newItem); + } } SQLHelper.UpdateInventory(offeror.Inventory); - User offeree = Server.User; - foreach (Item item in offer.OfferorItems) - { - Item newItem = item.Copy(); - newItem.User = offeree; - newItem.IsSellable = false; - newItem.IsTradable = false; - newItem.NextSellableTime = DateTimeUtility.GetTradableTime(); - newItem.NextTradableTime = DateTimeUtility.GetTradableTime(); - offeree.Inventory.Items.Add(newItem); - } SQLHelper.UpdateInventory(offeree.Inventory); SQLHelper.Commit(); resultData.Add("offer", offer);