From 60922c5c62a947ffea3041c0ee8025161be99950 Mon Sep 17 00:00:00 2001 From: wufan Date: Mon, 13 Jan 2025 15:46:42 +0800 Subject: [PATCH 1/7] :ambulance: --- .../APIClients/ShopifyApi/ShopifyAPIClient.cs | 16 +- TradeManageNew/DD_OrderServiceNew.asmx.cs | 238 +++++++++++++++++- TradeUsedSale/Repositories/ErpDbContext.cs | 3 + .../Models/DT_OrderUsedSalePlatform.cs | 5 + .../Models/DT_ShopifyProductGoodsMap.cs | 30 +++ .../Models/DT_ShopifyUsedSaleProduct.cs | 17 ++ .../Repositories/Models/HW_PostFee.cs | 19 ++ TradeUsedSale/TradeUsedSale.csproj | 3 + 8 files changed, 319 insertions(+), 12 deletions(-) create mode 100644 TradeUsedSale/Repositories/Models/DT_ShopifyProductGoodsMap.cs create mode 100644 TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleProduct.cs create mode 100644 TradeUsedSale/Repositories/Models/HW_PostFee.cs diff --git a/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs b/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs index b63349a..806ec12 100644 --- a/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs +++ b/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs @@ -1338,19 +1338,19 @@ namespace APIClients.ShopifyAPI /// 产品重量(g) /// [Newtonsoft.Json.JsonProperty("Weight", Required = Newtonsoft.Json.Required.Always)] - public double Weight { get; set; } + public decimal Weight { get; set; } /// /// 产品价格 /// [Newtonsoft.Json.JsonProperty("JYPrice", Required = Newtonsoft.Json.Required.Always)] - public double JYPrice { get; set; } + public decimal JYPrice { get; set; } /// /// 运费 /// [Newtonsoft.Json.JsonProperty("ShippingFee", Required = Newtonsoft.Json.Required.Always)] - public double ShippingFee { get; set; } + public decimal ShippingFee { get; set; } private System.Collections.Generic.IDictionary _additionalProperties; @@ -2196,7 +2196,7 @@ namespace APIClients.ShopifyAPI /// 产品ID /// [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public double? Id { get; set; } + public string Id { get; set; } private System.Collections.Generic.IDictionary _additionalProperties; @@ -2216,7 +2216,7 @@ namespace APIClients.ShopifyAPI /// Shopify商品ID /// [Newtonsoft.Json.JsonProperty("shoifyGoodsId", Required = Newtonsoft.Json.Required.Always)] - public double ShoifyGoodsId { get; set; } + public string ShoifyGoodsId { get; set; } /// /// 产品SKU @@ -2254,19 +2254,19 @@ namespace APIClients.ShopifyAPI /// 产品重量(g) /// [Newtonsoft.Json.JsonProperty("Weight", Required = Newtonsoft.Json.Required.Always)] - public double Weight { get; set; } + public decimal Weight { get; set; } /// /// 产品价格 /// [Newtonsoft.Json.JsonProperty("JYPrice", Required = Newtonsoft.Json.Required.Always)] - public double JYPrice { get; set; } + public decimal JYPrice { get; set; } /// /// 运费 /// [Newtonsoft.Json.JsonProperty("ShippingFee", Required = Newtonsoft.Json.Required.Always)] - public double ShippingFee { get; set; } + public decimal ShippingFee { get; set; } private System.Collections.Generic.IDictionary _additionalProperties; diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index 239ac16..cadacad 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -33,6 +33,7 @@ using Newtonsoft.Json.Serialization; using NPOI.HSSF.Record.Formula.Functions; using static NPOI.HSSF.Util.HSSFColor; using System.Linq.Expressions; +using APIClients.ShopifyAPI; using LinqToDB; using Match = System.Text.RegularExpressions.Match; using TradeManageNew.APIClients.FedexApi.Tests; @@ -28727,18 +28728,247 @@ namespace TradeManageNew } [WebMethod(EnableSession = true)] - public int OrderUsedSalePlatformPrint(int Id) + public APIReturnModel OrderUsedSalePlatformPrint(List Ids) { // PagesNew.Login(base.Session); using (var db = new TradeUsedSale.Repositories.ErpDbContext()) { - var orderUsedSalePlatform = db.DT_OrderUsedSalePlatform - .Where(x => x.Id == Id) + db.DT_OrderUsedSalePlatform + .Where(x => Ids.Contains(x.Id)) .Set(x => x.IsPrinted, true) .Update(); - return orderUsedSalePlatform; + return new APIReturnModel + { + Code = 1, + Message = "Success", + Datas = null + }; + } + } + + [WebMethod(EnableSession = true)] + public APIReturnModel OrderUsedSalePlatformPublish(List Ids) + { + // PagesNew.Login(base.Session); + using (var db = new TradeUsedSale.Repositories.ErpDbContext()) + { + var orderUsedSalePlatformList = db.DT_OrderUsedSalePlatform.Where(x => Ids.Contains(x.Id)).ToList(); + + foreach (var orderUsedSalePlatform in orderUsedSalePlatformList) + { + if (orderUsedSalePlatform.Status != TradeUsedSale.Enums.UsedSalePlatformStatus.NotListed) + { + continue; + } + + //系统产品信息 + var product = db.HW_GoodsInfo.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId); + if (product is null) + { + var message = $"系统中不存在编码为[{orderUsedSalePlatform.ProductCode}]的产品信息,无法推送至Shopify"; + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + + //毛重 + if (product.Weight is null || product.Weight <= 0) + { + var message = $"产品[{product.GoodsCode}]无毛重信息,无法推送至Shopify"; + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + + //建议售价 + if (product.JYPrice is null || product.JYPrice <= 0) + { + var message = $"产品[{product.GoodsCode}]无建议售价,无法推送至Shopify"; + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + + //预估运费 + var postFee = db.HW_PostFee.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId); + if (postFee is null) + { + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, $"产品[{product.GoodsCode}]无预估运费,无法推送至Shopify") + .Update(); + + continue; + } + var fees = new List() + { + postFee.Fee1, + //postFee.Fee2, + postFee.Fee3, + postFee.Fee4, + postFee.Fee5, + //postFee.Fee6, + postFee.Fee7, + postFee.Fee8, + }.Where(x => x != null).ToList(); + var feeCost = fees.Any() ? fees.Min() : 0; + + if (feeCost <= 0) + { + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, $"产品[{product.GoodsCode}]预估运费小于0,无法推送至Shopify") + .Update(); + + continue; + } + + string shopifyProductId; + + //判断时候在Shopify已创建过产品 + var shopifyProductGoodsMap = + db.DT_ShopifyProductGoodsMap.FirstOrDefault(x => x.SkuId == orderUsedSalePlatform.SkuId); + + //获取SKU的资料信息 + var shopifyProductProfile = + db.DT_ShopifyUsedSaleProduct.FirstOrDefault(x => x.Sku == orderUsedSalePlatform.SkuCode); + + //Shopify客户端 + var shopifyApiClient = new ShopifyAPIClient(); + + if (shopifyProductGoodsMap is null) + { + try + { + //在Shopify创建产品信息 + var createShopifyProductParameter = new Body2 + { + ProductBaseData = new ProductBaseData + { + SKU = shopifyProductProfile?.Sku ?? orderUsedSalePlatform.SkuCode, + Title = shopifyProductProfile?.Title ?? product.GoodsEnglisgName, + ImagePath = shopifyProductProfile?.ImagePath ?? product.FirstImgUrl, + ProductType = shopifyProductProfile?.Category, + Tags = shopifyProductProfile?.Tags, + Weight = product.Weight.Value, + JYPrice = product.JYPrice.Value, + ShippingFee = feeCost.Value, + } + }; + var shopifyProductRes = shopifyApiClient.CreateProductAsync(createShopifyProductParameter) + .ConfigureAwait(false) + .GetAwaiter() + .GetResult(); + + if (string.IsNullOrWhiteSpace(shopifyProductRes?.Data?.Id)) + { + var message = $"产品[{product.GoodsCode}]推送Shopify产品失败,原因:{shopifyProductRes.Message}"; + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + + shopifyProductId = shopifyProductRes.Data.Id; + + var newMap = new TradeUsedSale.Repositories.Models.DT_ShopifyProductGoodsMap + { + ShopifyProductId = shopifyProductId, + SkuId = orderUsedSalePlatform.SkuId, + SkuCode = orderUsedSalePlatform.SkuCode, + CreationTime = DateTime.Now + }; + + db.InsertWithInt32Identity(newMap); + } + catch (Exception ex) + { + var message = $"产品[{product.GoodsCode}]推送Shopify产品失败,原因:{ex.Message}"; + + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + } + else + { + shopifyProductId = shopifyProductGoodsMap.ShopifyProductId; + } + + + try + { + //在Shopify创建产品变体信息 + var createShopifyVariantParameter = new AddVariantRequest + { + ProductBaseData = new ProductBaseData2 + { + ShoifyGoodsId = shopifyProductId, + SKU = shopifyProductProfile?.Sku ?? orderUsedSalePlatform.SkuCode, + Title = shopifyProductProfile?.Title ?? product.GoodsEnglisgName, + ImagePath = shopifyProductProfile?.ImagePath ?? product.FirstImgUrl, + ProductType = shopifyProductProfile?.Category, + Tags = shopifyProductProfile?.Tags, + Weight = product.Weight.Value, + JYPrice = product.JYPrice.Value, + ShippingFee = feeCost.Value + }, + Variants = new Variants + { + Return_quantity = 1, + StoreName = orderUsedSalePlatform.WarehouseLocation.ToString(), + Code = orderUsedSalePlatform.BarCode, + }, + }; + + var productVariantRes = shopifyApiClient.AddProductVariantAsync(createShopifyVariantParameter).ConfigureAwait(false) + .GetAwaiter() + .GetResult(); + + if (productVariantRes.Success == false) + { + var message = $"产品[{product.GoodsCode}]推送Shopify变体失败,原因:{productVariantRes.Message}"; + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + + //推送Shopify成功 + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.Listed) + .Set(x => x.PublishMessage, "推送成功") + .Update(); + + } + catch (Exception ex) + { + var message = $"产品[{product.GoodsCode}]推送Shopify变体失败,原因:{ex.Message}"; + + db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) + .Set(x => x.PublishMessage, message) + .Update(); + + continue; + } + } } + + return new APIReturnModel + { + Code = 1, + Message = "Success", + Datas = null + }; } #endregion diff --git a/TradeUsedSale/Repositories/ErpDbContext.cs b/TradeUsedSale/Repositories/ErpDbContext.cs index 81117e0..f87e4c6 100644 --- a/TradeUsedSale/Repositories/ErpDbContext.cs +++ b/TradeUsedSale/Repositories/ErpDbContext.cs @@ -27,5 +27,8 @@ namespace TradeUsedSale.Repositories public ITable JC_Shop => this.GetTable(); public ITable JC_UserInfo => this.GetTable(); public ITable CK_StorePostion => this.GetTable(); + public ITable DT_ShopifyUsedSaleProduct => this.GetTable(); + public ITable DT_ShopifyProductGoodsMap => this.GetTable(); + public ITable HW_PostFee => this.GetTable(); } } diff --git a/TradeUsedSale/Repositories/Models/DT_OrderUsedSalePlatform.cs b/TradeUsedSale/Repositories/Models/DT_OrderUsedSalePlatform.cs index f4cba8a..cc1849f 100644 --- a/TradeUsedSale/Repositories/Models/DT_OrderUsedSalePlatform.cs +++ b/TradeUsedSale/Repositories/Models/DT_OrderUsedSalePlatform.cs @@ -92,5 +92,10 @@ namespace TradeUsedSale.Repositories.Models /// 修改人 /// public int? LastModifierId { get; set; } + + /// + /// 推送至平台信息 + /// + public string PublishMessage { get; set; } } } \ No newline at end of file diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyProductGoodsMap.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyProductGoodsMap.cs new file mode 100644 index 0000000..804f137 --- /dev/null +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyProductGoodsMap.cs @@ -0,0 +1,30 @@ +using System; +using LinqToDB.Mapping; + +namespace TradeUsedSale.Repositories.Models +{ + /// + /// Shopify产品与系统SKU映射 + /// + public class DT_ShopifyProductGoodsMap + { + [PrimaryKey, Identity] public int Id { get; set; } + + /// + /// Shopify产品Id + /// + public string ShopifyProductId { get; set; } + + /// + /// 系统SKU ID + /// + public int SkuId { get; set; } + + public string SkuCode { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreationTime { get; set; } + } +} \ No newline at end of file diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleProduct.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleProduct.cs new file mode 100644 index 0000000..b47b884 --- /dev/null +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleProduct.cs @@ -0,0 +1,17 @@ +using LinqToDB.Mapping; + +namespace TradeUsedSale.Repositories.Models +{ + /// + /// Shopify产品资料 + /// + public class DT_ShopifyUsedSaleProduct + { + [PrimaryKey, Identity] public int Id { get; set; } + public string Sku { get; set; } + public string Title { get; set; } + public string ImagePath { get; set; } + public string Category { get; set; } + public string Tags { get; set; } + } +} \ No newline at end of file diff --git a/TradeUsedSale/Repositories/Models/HW_PostFee.cs b/TradeUsedSale/Repositories/Models/HW_PostFee.cs new file mode 100644 index 0000000..d01f36a --- /dev/null +++ b/TradeUsedSale/Repositories/Models/HW_PostFee.cs @@ -0,0 +1,19 @@ +using LinqToDB.Mapping; + +namespace TradeUsedSale.Repositories.Models +{ + public class HW_PostFee + { + [PrimaryKey, Identity] + public int Id { get; set; } + public int? GoodsId { get; set; } + public decimal? Fee1 { get; set; } + public decimal? Fee2 { get; set; } + public decimal? Fee3 { get; set; } + public decimal? Fee4 { get; set; } + public decimal? Fee5 { get; set; } + public decimal? Fee6 { get; set; } + public decimal? Fee7 { get; set; } + public decimal? Fee8 { get; set; } + } +} \ No newline at end of file diff --git a/TradeUsedSale/TradeUsedSale.csproj b/TradeUsedSale/TradeUsedSale.csproj index 5068fe5..66be4d3 100644 --- a/TradeUsedSale/TradeUsedSale.csproj +++ b/TradeUsedSale/TradeUsedSale.csproj @@ -56,8 +56,11 @@ + + + From 54769261aa37263c9ca68ed59bb92d305dbe3eac Mon Sep 17 00:00:00 2001 From: wufan Date: Mon, 13 Jan 2025 16:14:51 +0800 Subject: [PATCH 2/7] :sparkles: --- TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs b/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs index 806ec12..35b9c1b 100644 --- a/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs +++ b/TradeManageNew/APIClients/ShopifyApi/ShopifyAPIClient.cs @@ -36,7 +36,7 @@ namespace APIClients.ShopifyAPI public ShopifyAPIClient() #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. { - BaseUrl = "http://192.168.1.54:3000/"; + BaseUrl = "http://192.168.1.51:3000/"; Initialize(); } From e44be324475f7ce60d45551392ac08123cd3e6f9 Mon Sep 17 00:00:00 2001 From: wufan Date: Mon, 13 Jan 2025 16:26:43 +0800 Subject: [PATCH 3/7] :bug: --- TradeManageNew/DD_OrderServiceNew.asmx.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index cadacad..9c8748a 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -28906,6 +28906,7 @@ namespace TradeManageNew try { + var imageUrls = JsonConvert.DeserializeObject>(orderUsedSalePlatform.ImageUrls); //在Shopify创建产品变体信息 var createShopifyVariantParameter = new AddVariantRequest { @@ -28924,7 +28925,15 @@ namespace TradeManageNew Variants = new Variants { Return_quantity = 1, - StoreName = orderUsedSalePlatform.WarehouseLocation.ToString(), + ImgUrl = imageUrls.Length > 0 ? imageUrls[0] : null, + ImgUrl2 = imageUrls.Length > 0 ? imageUrls[0] : null, + ImgUrl3 = imageUrls.Length > 0 ? imageUrls[0] : null, + ImgUrl4 = imageUrls.Length > 0 ? imageUrls[0] : null, + ImgUrl5 = imageUrls.Length > 0 ? imageUrls[0] : null, + StoreName = orderUsedSalePlatform.WarehouseLocation == + TradeUsedSale.Enums.WarehouseLocation.East + ? "E" + : "W", Code = orderUsedSalePlatform.BarCode, }, }; From ee05e49f9f024becf91de7103f0bd5b007f2df5b Mon Sep 17 00:00:00 2001 From: wufan Date: Mon, 13 Jan 2025 16:28:51 +0800 Subject: [PATCH 4/7] :bug: --- TradeManageNew/DD_OrderServiceNew.asmx.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index 9c8748a..e96e49d 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -28925,11 +28925,11 @@ namespace TradeManageNew Variants = new Variants { Return_quantity = 1, - ImgUrl = imageUrls.Length > 0 ? imageUrls[0] : null, - ImgUrl2 = imageUrls.Length > 0 ? imageUrls[0] : null, - ImgUrl3 = imageUrls.Length > 0 ? imageUrls[0] : null, - ImgUrl4 = imageUrls.Length > 0 ? imageUrls[0] : null, - ImgUrl5 = imageUrls.Length > 0 ? imageUrls[0] : null, + 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, StoreName = orderUsedSalePlatform.WarehouseLocation == TradeUsedSale.Enums.WarehouseLocation.East ? "E" From c0b3c4b27cc2c06be0eaeeaf23f60fedc8776bd6 Mon Sep 17 00:00:00 2001 From: wufan Date: Mon, 13 Jan 2025 17:03:12 +0800 Subject: [PATCH 5/7] :memo: --- TradeManageNew/OuterService/ShageService.ashx.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TradeManageNew/OuterService/ShageService.ashx.cs b/TradeManageNew/OuterService/ShageService.ashx.cs index 1f36ff5..07f6b4d 100644 --- a/TradeManageNew/OuterService/ShageService.ashx.cs +++ b/TradeManageNew/OuterService/ShageService.ashx.cs @@ -1389,7 +1389,8 @@ namespace TradeManageNew.OuterService x.SKU2 == input.SkuCode || x.SKU3 == input.SkuCode || x.SKU4 == input.SkuCode || - x.SKU5 == input.SkuCode); + x.SKU5 == input.SkuCode || + x.Barcode == input.SkuCode); if (sku is null) { From 356982014b3f6133a56fc03c13a78d2cdfc8dda6 Mon Sep 17 00:00:00 2001 From: wufan Date: Tue, 14 Jan 2025 14:10:38 +0800 Subject: [PATCH 6/7] :memo: --- .../ShopifyUsedSaleOrderDto.cs | 162 ++++++++++++++++++ TradeManageNew/TradeManageNew.csproj | 1 + .../Models/DT_ShopifyUsedSaleOrder.cs | 100 +++++++++++ .../Models/DT_ShopifyUsedSaleOrderItem.cs | 33 ++++ TradeUsedSale/TradeUsedSale.csproj | 2 + 5 files changed, 298 insertions(+) create mode 100644 TradeManageNew/Models/ShopifyUsedSale/ShopifyUsedSaleOrderDto.cs create mode 100644 TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs create mode 100644 TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs diff --git a/TradeManageNew/Models/ShopifyUsedSale/ShopifyUsedSaleOrderDto.cs b/TradeManageNew/Models/ShopifyUsedSale/ShopifyUsedSaleOrderDto.cs new file mode 100644 index 0000000..243f71c --- /dev/null +++ b/TradeManageNew/Models/ShopifyUsedSale/ShopifyUsedSaleOrderDto.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace TradeManageNew.Models.ShopifyUsedSale +{ + public partial class ShopifyUsedSaleOrderDto + { + [JsonProperty("order")] public Order Order { get; set; } + + [JsonProperty("recipient")] public Recipient Recipient { get; set; } + + [JsonProperty("items")] public List Items { get; set; } + + [JsonProperty("financial")] public Financial Financial { get; set; } + + [JsonProperty("customer")] public Customer Customer { get; set; } + + [JsonProperty("remark")] public Remark Remark { get; set; } + } + + public class Customer + { + [JsonProperty("email")] public string Email { get; set; } + + [JsonProperty("phone")] public string Phone { get; set; } + + [JsonProperty("first_name")] public string FirstName { get; set; } + + [JsonProperty("last_name")] public string LastName { get; set; } + + [JsonProperty("customer_id")] public string CustomerId { get; set; } + } + + public class Financial + { + [JsonProperty("currency")] public string Currency { get; set; } + + [JsonProperty("total_price")] public decimal TotalPrice { get; set; } + + [JsonProperty("subtotal_price")] public decimal SubtotalPrice { get; set; } + + [JsonProperty("total_tax")] public decimal TotalTax { get; set; } + + [JsonProperty("total_discounts")] public decimal TotalDiscounts { get; set; } + + [JsonProperty("shipping_price")] public decimal ShippingPrice { get; set; } + + [JsonProperty("payment_method")] public string PaymentMethod { get; set; } + + [JsonProperty("financial_status")] public string FinancialStatus { get; set; } + + [JsonProperty("refunded_amount")] public decimal RefundedAmount { get; set; } + } + + public class Item + { + [JsonProperty("origin_sku")] public string OriginSku { get; set; } + + [JsonProperty("sku")] public string Sku { get; set; } + + [JsonProperty("product_code")] public string ProductCode { get; set; } + + [JsonProperty("quantity")] public int Quantity { get; set; } + + [JsonProperty("price")] public decimal Price { get; set; } + + [JsonProperty("title")] public string Title { get; set; } + + [JsonProperty("variant_title")] public string VariantTitle { get; set; } + + [JsonProperty("product_id")] public string ProductId { get; set; } + + [JsonProperty("variant_id")] public string VariantId { get; set; } + + [JsonProperty("properties")] public List Properties { get; set; } + + [JsonProperty("image")] public string Image { get; set; } + + [JsonProperty("shipping_method")] public string ShippingMethod { get; set; } + } + + public class Order + { + [JsonProperty("order_id")] public string OrderId { get; set; } + + [JsonProperty("order_number")] public string OrderNumber { get; set; } + + [JsonProperty("order_name")] public string OrderName { get; set; } + + [JsonProperty("created_at")] public DateTimeOffset CreatedAt { get; set; } + + [JsonProperty("updated_at")] public DateTimeOffset UpdatedAt { get; set; } + + [JsonProperty("processed_at")] public DateTimeOffset ProcessedAt { get; set; } + } + + public class Recipient + { + [JsonProperty("name")] public string Name { get; set; } + + [JsonProperty("phone")] public string Phone { get; set; } + + [JsonProperty("address")] public Address Address { get; set; } + } + + public class Address + { + [JsonProperty("full")] public string Full { get; set; } + + [JsonProperty("detail")] public string Detail { get; set; } + + [JsonProperty("detail2")] public string Detail2 { get; set; } + + [JsonProperty("city")] public string City { get; set; } + + [JsonProperty("province")] public string Province { get; set; } + + [JsonProperty("province_code")] public string ProvinceCode { get; set; } + + [JsonProperty("zip")] public string Zip { get; set; } + + [JsonProperty("country")] public string Country { get; set; } + + [JsonProperty("country_code")] public string CountryCode { get; set; } + } + + public partial class Remark + { + [JsonProperty("note")] public string Note { get; set; } + + [JsonProperty("tags")] public string Tags { get; set; } + } + + public partial class ShopifyUsedSaleOrderDto + { + public static ShopifyUsedSaleOrderDto FromJson(string json) => + JsonConvert.DeserializeObject(json, + TradeManageNew.Models.ShopifyUsedSale.Converter.Settings); + } + + public static class Serialize + { + public static string ToJson(this ShopifyUsedSaleOrderDto self) => + JsonConvert.SerializeObject(self, TradeManageNew.Models.ShopifyUsedSale.Converter.Settings); + } + + internal static class Converter + { + public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings + { + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, + DateParseHandling = DateParseHandling.None, + Converters = + { + new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } + }, + }; + } +} \ No newline at end of file diff --git a/TradeManageNew/TradeManageNew.csproj b/TradeManageNew/TradeManageNew.csproj index 8bf2781..30b8669 100644 --- a/TradeManageNew/TradeManageNew.csproj +++ b/TradeManageNew/TradeManageNew.csproj @@ -2920,6 +2920,7 @@ + OrderAPI.ashx diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs new file mode 100644 index 0000000..f856c14 --- /dev/null +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrder.cs @@ -0,0 +1,100 @@ +using System; +using LinqToDB.Mapping; + +namespace TradeUsedSale.Repositories.Models +{ + public class DT_ShopifyUsedSaleOrder + { + [PrimaryKey, Identity] public int Id { get; set; } + + public string OrderId { get; set; } + + public string OrderNumber { get; set; } + + public string OrderName { get; set; } + + public DateTime CreatedAt { get; set; } + + public DateTime UpdatedAt { get; set; } + + public DateTime ProcessedAt { get; set; } + + /// + /// 收件人 + /// + public string Name { get; set; } + + /// + /// 收件人电话 + /// + public string Phone { get; set; } + + /// + /// 完整地址 + /// + public string Full { get; set; } + + /// + /// 地址1 + /// + public string Detail { get; set; } + + /// + /// 地址2 + /// + public string Detail2 { get; set; } + + /// + /// 城市 + /// + public string City { get; set; } + + /// + /// 省 + /// + public string Province { get; set; } + + /// + /// 省编码 + /// + public string ProvinceCode { get; set; } + + /// + /// 邮编 + /// + public string Zip { get; set; } + + /// + /// 国家 + /// + public string Country { get; set; } + + /// + /// 国家编码 + /// + public string CountryCode { get; set; } + + public string Currency { get; set; } + + public decimal TotalPrice { get; set; } + + public decimal SubtotalPrice { get; set; } + + public decimal TotalTax { get; set; } + + public decimal TotalDiscounts { get; set; } + + public decimal ShippingPrice { get; set; } + + public string PaymentMethod { get; set; } + + public string FinancialStatus { get; set; } + + public decimal RefundedAmount { get; set; } + + /// + /// 原始Json + /// + public string OriginJson { get; set; } + } +} \ No newline at end of file diff --git a/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs new file mode 100644 index 0000000..9877285 --- /dev/null +++ b/TradeUsedSale/Repositories/Models/DT_ShopifyUsedSaleOrderItem.cs @@ -0,0 +1,33 @@ +using LinqToDB.Mapping; + +namespace TradeUsedSale.Repositories.Models +{ + public class DT_ShopifyUsedSaleOrderItem + { + [PrimaryKey, Identity] public int Id { get; set; } + + public int DtShopifyUsedSaleOrderId { get; set; } + + public string OriginSku { get; set; } + + public string Sku { get; set; } + + public string ProductCode { get; set; } + + public int Quantity { get; set; } + + public decimal Price { get; set; } + + public string Title { get; set; } + + public string VariantTitle { get; set; } + + public string ProductId { get; set; } + + public string VariantId { get; set; } + + public string Image { get; set; } + + public string ShippingMethod { get; set; } + } +} \ No newline at end of file diff --git a/TradeUsedSale/TradeUsedSale.csproj b/TradeUsedSale/TradeUsedSale.csproj index 66be4d3..d2ca6a4 100644 --- a/TradeUsedSale/TradeUsedSale.csproj +++ b/TradeUsedSale/TradeUsedSale.csproj @@ -57,6 +57,8 @@ + + From c58af8717e3532f83e36687afc1c59750d88aa05 Mon Sep 17 00:00:00 2001 From: wufan Date: Tue, 14 Jan 2025 14:41:57 +0800 Subject: [PATCH 7/7] :memo: --- TradeManageNew/DD_OrderServiceNew.asmx.cs | 82 ++++++++++++++++++++++ TradeUsedSale/Repositories/ErpDbContext.cs | 2 + 2 files changed, 84 insertions(+) diff --git a/TradeManageNew/DD_OrderServiceNew.asmx.cs b/TradeManageNew/DD_OrderServiceNew.asmx.cs index e96e49d..e0d7902 100644 --- a/TradeManageNew/DD_OrderServiceNew.asmx.cs +++ b/TradeManageNew/DD_OrderServiceNew.asmx.cs @@ -38,6 +38,7 @@ using LinqToDB; using Match = System.Text.RegularExpressions.Match; using TradeManageNew.APIClients.FedexApi.Tests; using TradeManageNew.APIClients.FedexAPI.Models.RatesAndTransitTimes; +using TradeManageNew.Models.ShopifyUsedSale; namespace TradeManageNew { @@ -28980,6 +28981,87 @@ namespace TradeManageNew }; } + [WebMethod(EnableSession = true)] + public APIReturnModel PlaceShopifyUsedSaleOrderCallback(string originJson) + { + if (string.IsNullOrWhiteSpace(originJson)) + { + return new APIReturnModel + { + Code = 0, + Message = "下单Json数据为空,请检查", + Datas = null + }; + } + + var originJsonData = ShopifyUsedSaleOrderDto.FromJson(originJson); + + using (var db = new TradeUsedSale.Repositories.ErpDbContext()) + { + var newDtShopifyUsedSaleOrder = new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrder + { + OrderId = originJsonData.Order.OrderId, + OrderNumber = originJsonData.Order.OrderNumber, + OrderName = originJsonData.Order.OrderName, + CreatedAt = originJsonData.Order.CreatedAt.DateTime, + UpdatedAt = originJsonData.Order.UpdatedAt.DateTime, + ProcessedAt = originJsonData.Order.ProcessedAt.DateTime, + Name = originJsonData.Recipient.Name, + Phone = originJsonData.Recipient.Phone, + Full = originJsonData.Recipient.Address.Full, + Detail = originJsonData.Recipient.Address.Detail, + Detail2 = originJsonData.Recipient.Address.Detail2, + City = originJsonData.Recipient.Address.City, + Province = originJsonData.Recipient.Address.Province, + ProvinceCode = originJsonData.Recipient.Address.ProvinceCode, + Zip = originJsonData.Recipient.Address.Zip, + Country = originJsonData.Recipient.Address.Country, + CountryCode = originJsonData.Recipient.Address.CountryCode, + Currency = originJsonData.Financial.Currency, + TotalPrice = originJsonData.Financial.TotalPrice, + SubtotalPrice = originJsonData.Financial.SubtotalPrice, + TotalTax = originJsonData.Financial.TotalTax, + TotalDiscounts = originJsonData.Financial.TotalDiscounts, + ShippingPrice = originJsonData.Financial.ShippingPrice, + PaymentMethod = originJsonData.Financial.PaymentMethod, + FinancialStatus = originJsonData.Financial.FinancialStatus, + RefundedAmount = originJsonData.Financial.RefundedAmount, + OriginJson = originJson + }; + + 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.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem); + } + } + + return new APIReturnModel + { + Code = 1, + Message = "Success", + Datas = null + }; + } + #endregion diff --git a/TradeUsedSale/Repositories/ErpDbContext.cs b/TradeUsedSale/Repositories/ErpDbContext.cs index f87e4c6..22f81c1 100644 --- a/TradeUsedSale/Repositories/ErpDbContext.cs +++ b/TradeUsedSale/Repositories/ErpDbContext.cs @@ -30,5 +30,7 @@ namespace TradeUsedSale.Repositories public ITable DT_ShopifyUsedSaleProduct => this.GetTable(); public ITable DT_ShopifyProductGoodsMap => this.GetTable(); public ITable HW_PostFee => this.GetTable(); + public ITable DT_ShopifyUsedSaleOrder => this.GetTable(); + public ITable DT_ShopifyUsedSaleOrderItem => this.GetTable(); } }