From 6c17b355986694756ba399f231e9800aee48fb4c Mon Sep 17 00:00:00 2001 From: wufan Date: Tue, 14 Jan 2025 16:38:31 +0800 Subject: [PATCH 1/4] :sparkles: --- TradeManageNew/DD_OrderServiceNew.asmx.cs | 92 ++++++++++++++----- .../Models/DT_ShopifyUsedSaleOrder.cs | 10 ++ 2 files changed, 78 insertions(+), 24 deletions(-) diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index ba254e6..d8aa512 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -28927,10 +28927,10 @@ namespace TradeManageNew { Return_quantity = 1, ImgUrl = imageUrls.Count > 0 ? imageUrls[0] : null, - ImgUrl2 = imageUrls.Count > 0 ? imageUrls[0] : null, - ImgUrl3 = imageUrls.Count > 0 ? imageUrls[0] : null, - ImgUrl4 = imageUrls.Count > 0 ? imageUrls[0] : null, - ImgUrl5 = imageUrls.Count > 0 ? imageUrls[0] : null, + ImgUrl2 = imageUrls.Count > 1 ? imageUrls[1] : null, + ImgUrl3 = imageUrls.Count > 2 ? imageUrls[2] : null, + ImgUrl4 = imageUrls.Count > 3 ? imageUrls[3] : null, + ImgUrl5 = imageUrls.Count > 4 ? imageUrls[4] : null, StoreName = orderUsedSalePlatform.WarehouseLocation == TradeUsedSale.Enums.WarehouseLocation.East ? "E" @@ -29026,31 +29026,75 @@ namespace TradeManageNew PaymentMethod = originJsonData.Financial.PaymentMethod, FinancialStatus = originJsonData.Financial.FinancialStatus, RefundedAmount = originJsonData.Financial.RefundedAmount, - OriginJson = originJson + OriginJson = originJson, + IsPlaceOrderSuccess = false }; var dtShopifyUsedSaleOrderId = db.InsertWithInt32Identity(newDtShopifyUsedSaleOrder); - foreach (var item in originJsonData.Items) - { - var newDtShopifyUsedSaleOrderItem = - new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrderItem - { - DtShopifyUsedSaleOrderId = dtShopifyUsedSaleOrderId, - OriginSku = item.OriginSku, - Sku = item.Sku, - ProductCode = item.ProductCode, - Quantity = item.Quantity, - Price = item.Price, - Title = item.Title, - VariantTitle = item.VariantTitle, - ProductId = item.ProductId, - VariantId = item.VariantId, - Image = item.Image, - ShippingMethod = item.ShippingMethod - }; + db.BeginTransaction(); + + try + { + foreach (var item in originJsonData.Items) + { + var newDtShopifyUsedSaleOrderItem = + new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrderItem + { + DtShopifyUsedSaleOrderId = dtShopifyUsedSaleOrderId, + OriginSku = item.OriginSku, + Sku = item.Sku, + ProductCode = item.ProductCode, + Quantity = item.Quantity, + Price = item.Price, + Title = item.Title, + VariantTitle = item.VariantTitle, + ProductId = item.ProductId, + VariantId = item.VariantId, + Image = item.Image, + ShippingMethod = item.ShippingMethod + }; + + db.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem); + + var statement = db.DT_OrderUsedSalePlatform.Where(x => x.BarCode == item.ProductCode) + .Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.PendingPickup); + + if (item.ShippingMethod == "SP") + { + statement = statement.Set(x => x.ShippingMethod, TradeUsedSale.Enums.ShippingMethod.SelfPickup); + } + + if (item.ShippingMethod == "DL") + { + statement = statement.Set(x => x.ShippingMethod, TradeUsedSale.Enums.ShippingMethod.ExpressDelivery); + } - db.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem); + statement.Update(); + + //Shopify客户端 + //删除产品变体 + // var shopifyApiClient = new ShopifyAPIClient(); + // var productVariantRes = shopifyApiClient.DeleteProductVariantAsync().ConfigureAwait(false) + // .GetAwaiter() + // .GetResult(); + + db.DT_ShopifyUsedSaleOrder.Where(x => x.Id == dtShopifyUsedSaleOrderId) + .Set(x => x.IsPlaceOrderSuccess, true) + .Set(x => x.PlaceOrderMessage, "更新二手订单信息成功") + .Update(); + + } + + db.CommitTransaction(); + } + catch (Exception ex) + { + db.RollbackTransaction(); + + db.DT_ShopifyUsedSaleOrder.Where(x => x.Id == dtShopifyUsedSaleOrderId) + .Set(x => x.PlaceOrderMessage, $"更新二手订单信息失败,原因:{ex.Message}") + .Update(); } } diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs index f856c14..d2e4490 100644 --- a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs @@ -96,5 +96,15 @@ namespace TradeUsedSale.Repositories.Models /// 原始Json /// public string OriginJson { get; set; } + + /// + /// 是否同步下单信息成功 + /// + public bool IsPlaceOrderSuccess { get; set; } + + /// + /// 下单同步信息 + /// + public string PlaceOrderMessage { get; set; } } } \ No newline at end of file From 0d2aba1d60b3ef18f65f4e6ca26cfc8f95a5e0a2 Mon Sep 17 00:00:00 2001 From: wufan Date: Tue, 14 Jan 2025 17:17:52 +0800 Subject: [PATCH 2/4] :memo: --- TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs | 3 +++ .../Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs index d2e4490..ceae844 100644 --- a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs @@ -3,6 +3,9 @@ using LinqToDB.Mapping; namespace TradeUsedSale.Repositories.Models { + /// + /// 二手商品Shopify订单表 + /// public class DT_ShopifyUsedSaleOrder { [PrimaryKey, Identity] public int Id { get; set; } diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs index 9877285..e4bae27 100644 --- a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs @@ -2,6 +2,9 @@ namespace TradeUsedSale.Repositories.Models { + /// + /// 二手商品Shopify订单明细表 + /// public class DT_ShopifyUsedSaleOrderItem { [PrimaryKey, Identity] public int Id { get; set; } From 42aa1c8eca3d0661c6f9e82883226988fa1a77ad Mon Sep 17 00:00:00 2001 From: wufan Date: Tue, 14 Jan 2025 17:27:59 +0800 Subject: [PATCH 3/4] :memo: --- TradeManageNew/DD_OrderServiceNew.asmx.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index d8aa512..392efe7 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -29057,19 +29057,17 @@ namespace TradeManageNew db.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem); + //修改ERP二手商品 var statement = db.DT_OrderUsedSalePlatform.Where(x => x.BarCode == item.ProductCode) .Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.PendingPickup); - if (item.ShippingMethod == "SP") { statement = statement.Set(x => x.ShippingMethod, TradeUsedSale.Enums.ShippingMethod.SelfPickup); } - if (item.ShippingMethod == "DL") { statement = statement.Set(x => x.ShippingMethod, TradeUsedSale.Enums.ShippingMethod.ExpressDelivery); } - statement.Update(); //Shopify客户端 From 29c9d786817a4c90fb42169bca658e47f9d9c627 Mon Sep 17 00:00:00 2001 From: wufan Date: Wed, 15 Jan 2025 10:08:55 +0800 Subject: [PATCH 4/4] :sparkles: --- .../APIClients/ShopifyApi/ShopifyAPIClient.cs | 14 ++++-- TradeManageNew/DD_OrderServiceNew.asmx.cs | 49 ++++++++++++++----- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs b/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs index 35b9c1b..ce541ad 100644 --- a/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs +++ b/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs @@ -1842,10 +1842,18 @@ namespace APIClients.ShopifyAPI public partial class Body3 { /// - /// 变体SKU + /// 产品ID /// - [Newtonsoft.Json.JsonProperty("sku", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Sku { get; set; } + [Newtonsoft.Json.JsonProperty("productId", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string ProductId { get; set; } + + /// + /// 变体编码 + /// + [Newtonsoft.Json.JsonProperty("code", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Code { get; set; } private System.Collections.Generic.IDictionary _additionalProperties; diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index 392efe7..8c04d27 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -29033,7 +29033,7 @@ namespace TradeManageNew var dtShopifyUsedSaleOrderId = db.InsertWithInt32Identity(newDtShopifyUsedSaleOrder); db.BeginTransaction(); - + try { foreach (var item in originJsonData.Items) @@ -29056,32 +29056,57 @@ namespace TradeManageNew }; db.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem); + + //ERP二手商品信息 + var orderUsedSalePlatform = db.DT_OrderUsedSalePlatform.FirstOrDefault(x => x.BarCode == item.ProductCode); + if (orderUsedSalePlatform is null) + { + throw new Exception($"未获取到编码[{item.ProductCode}]的二手商品信息"); + } + + //Shopify商品映射 + var shopifyProductGoodsMap = db.DT_ShopifyProductGoodsMap.FirstOrDefault(x => x.SkuId == orderUsedSalePlatform.SkuId); + if (shopifyProductGoodsMap is null) + { + throw new Exception($"未获取到SKU[{orderUsedSalePlatform.SkuCode}]对应的Shopify产品信息"); + } - //修改ERP二手商品 + //下单后修改二手商品信息 var statement = db.DT_OrderUsedSalePlatform.Where(x => x.BarCode == item.ProductCode) .Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.PendingPickup); if (item.ShippingMethod == "SP") { - statement = statement.Set(x => x.ShippingMethod, TradeUsedSale.Enums.ShippingMethod.SelfPickup); + statement = statement.Set(x => x.ShippingMethod, + TradeUsedSale.Enums.ShippingMethod.SelfPickup); } + if (item.ShippingMethod == "DL") { - statement = statement.Set(x => x.ShippingMethod, TradeUsedSale.Enums.ShippingMethod.ExpressDelivery); + statement = statement.Set(x => x.ShippingMethod, + TradeUsedSale.Enums.ShippingMethod.ExpressDelivery); } statement.Update(); - - //Shopify客户端 - //删除产品变体 - // var shopifyApiClient = new ShopifyAPIClient(); - // var productVariantRes = shopifyApiClient.DeleteProductVariantAsync().ConfigureAwait(false) - // .GetAwaiter() - // .GetResult(); + + // Shopify客户端 + // 删除产品变体 + var shopifyApiClient = new ShopifyAPIClient(); + var productVariantRes = shopifyApiClient.DeleteProductVariantAsync(new Body3 + { + ProductId = shopifyProductGoodsMap.ShopifyProductId, + Code = item.ProductCode, + }).ConfigureAwait(false) + .GetAwaiter() + .GetResult(); + + if (productVariantRes.Success != true) + { + throw new Exception(productVariantRes.Message); + } db.DT_ShopifyUsedSaleOrder.Where(x => x.Id == dtShopifyUsedSaleOrderId) .Set(x => x.IsPlaceOrderSuccess, true) .Set(x => x.PlaceOrderMessage, "更新二手订单信息成功") .Update(); - } db.CommitTransaction();