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 @@
+
+
+