master
wufan 2 months ago
parent 0add6a4248
commit 60922c5c62

@ -1338,19 +1338,19 @@ namespace APIClients.ShopifyAPI
/// 产品重量(g) /// 产品重量(g)
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("Weight", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("Weight", Required = Newtonsoft.Json.Required.Always)]
public double Weight { get; set; } public decimal Weight { get; set; }
/// <summary> /// <summary>
/// 产品价格 /// 产品价格
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("JYPrice", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("JYPrice", Required = Newtonsoft.Json.Required.Always)]
public double JYPrice { get; set; } public decimal JYPrice { get; set; }
/// <summary> /// <summary>
/// 运费 /// 运费
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("ShippingFee", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("ShippingFee", Required = Newtonsoft.Json.Required.Always)]
public double ShippingFee { get; set; } public decimal ShippingFee { get; set; }
private System.Collections.Generic.IDictionary<string, object> _additionalProperties; private System.Collections.Generic.IDictionary<string, object> _additionalProperties;
@ -2196,7 +2196,7 @@ namespace APIClients.ShopifyAPI
/// 产品ID /// 产品ID
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] [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<string, object> _additionalProperties; private System.Collections.Generic.IDictionary<string, object> _additionalProperties;
@ -2216,7 +2216,7 @@ namespace APIClients.ShopifyAPI
/// Shopify商品ID /// Shopify商品ID
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("shoifyGoodsId", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("shoifyGoodsId", Required = Newtonsoft.Json.Required.Always)]
public double ShoifyGoodsId { get; set; } public string ShoifyGoodsId { get; set; }
/// <summary> /// <summary>
/// 产品SKU /// 产品SKU
@ -2254,19 +2254,19 @@ namespace APIClients.ShopifyAPI
/// 产品重量(g) /// 产品重量(g)
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("Weight", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("Weight", Required = Newtonsoft.Json.Required.Always)]
public double Weight { get; set; } public decimal Weight { get; set; }
/// <summary> /// <summary>
/// 产品价格 /// 产品价格
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("JYPrice", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("JYPrice", Required = Newtonsoft.Json.Required.Always)]
public double JYPrice { get; set; } public decimal JYPrice { get; set; }
/// <summary> /// <summary>
/// 运费 /// 运费
/// </summary> /// </summary>
[Newtonsoft.Json.JsonProperty("ShippingFee", Required = Newtonsoft.Json.Required.Always)] [Newtonsoft.Json.JsonProperty("ShippingFee", Required = Newtonsoft.Json.Required.Always)]
public double ShippingFee { get; set; } public decimal ShippingFee { get; set; }
private System.Collections.Generic.IDictionary<string, object> _additionalProperties; private System.Collections.Generic.IDictionary<string, object> _additionalProperties;

@ -33,6 +33,7 @@ using Newtonsoft.Json.Serialization;
using NPOI.HSSF.Record.Formula.Functions; using NPOI.HSSF.Record.Formula.Functions;
using static NPOI.HSSF.Util.HSSFColor; using static NPOI.HSSF.Util.HSSFColor;
using System.Linq.Expressions; using System.Linq.Expressions;
using APIClients.ShopifyAPI;
using LinqToDB; using LinqToDB;
using Match = System.Text.RegularExpressions.Match; using Match = System.Text.RegularExpressions.Match;
using TradeManageNew.APIClients.FedexApi.Tests; using TradeManageNew.APIClients.FedexApi.Tests;
@ -28727,18 +28728,247 @@ namespace TradeManageNew
} }
[WebMethod(EnableSession = true)] [WebMethod(EnableSession = true)]
public int OrderUsedSalePlatformPrint(int Id) public APIReturnModel OrderUsedSalePlatformPrint(List<int> Ids)
{ {
// PagesNew.Login(base.Session); // PagesNew.Login(base.Session);
using (var db = new TradeUsedSale.Repositories.ErpDbContext()) using (var db = new TradeUsedSale.Repositories.ErpDbContext())
{ {
var orderUsedSalePlatform = db.DT_OrderUsedSalePlatform db.DT_OrderUsedSalePlatform
.Where(x => x.Id == Id) .Where(x => Ids.Contains(x.Id))
.Set(x => x.IsPrinted, true) .Set(x => x.IsPrinted, true)
.Update(); .Update();
return orderUsedSalePlatform; return new APIReturnModel
{
Code = 1,
Message = "Success",
Datas = null
};
}
}
[WebMethod(EnableSession = true)]
public APIReturnModel OrderUsedSalePlatformPublish(List<int> 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<decimal?>()
{
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 #endregion

@ -27,5 +27,8 @@ namespace TradeUsedSale.Repositories
public ITable<JC_Shop> JC_Shop => this.GetTable<JC_Shop>(); public ITable<JC_Shop> JC_Shop => this.GetTable<JC_Shop>();
public ITable<JC_UserInfo> JC_UserInfo => this.GetTable<JC_UserInfo>(); public ITable<JC_UserInfo> JC_UserInfo => this.GetTable<JC_UserInfo>();
public ITable<CK_StorePostion> CK_StorePostion => this.GetTable<CK_StorePostion>(); public ITable<CK_StorePostion> CK_StorePostion => this.GetTable<CK_StorePostion>();
public ITable<DT_ShopifyUsedSaleProduct> DT_ShopifyUsedSaleProduct => this.GetTable<DT_ShopifyUsedSaleProduct>();
public ITable<DT_ShopifyProductGoodsMap> DT_ShopifyProductGoodsMap => this.GetTable<DT_ShopifyProductGoodsMap>();
public ITable<HW_PostFee> HW_PostFee => this.GetTable<HW_PostFee>();
} }
} }

@ -92,5 +92,10 @@ namespace TradeUsedSale.Repositories.Models
/// 修改人 /// 修改人
/// </summary> /// </summary>
public int? LastModifierId { get; set; } public int? LastModifierId { get; set; }
/// <summary>
/// 推送至平台信息
/// </summary>
public string PublishMessage { get; set; }
} }
} }

@ -0,0 +1,30 @@
using System;
using LinqToDB.Mapping;
namespace TradeUsedSale.Repositories.Models
{
/// <summary>
/// Shopify产品与系统SKU映射
/// </summary>
public class DT_ShopifyProductGoodsMap
{
[PrimaryKey, Identity] public int Id { get; set; }
/// <summary>
/// Shopify产品Id
/// </summary>
public string ShopifyProductId { get; set; }
/// <summary>
/// 系统SKU ID
/// </summary>
public int SkuId { get; set; }
public string SkuCode { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreationTime { get; set; }
}
}

@ -0,0 +1,17 @@
using LinqToDB.Mapping;
namespace TradeUsedSale.Repositories.Models
{
/// <summary>
/// Shopify产品资料
/// </summary>
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; }
}
}

@ -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; }
}
}

@ -56,8 +56,11 @@
<Compile Include="Repositories\Models\DT_OrderReturn.cs" /> <Compile Include="Repositories\Models\DT_OrderReturn.cs" />
<Compile Include="Repositories\Models\DT_OrderUsedSalePlatform.cs" /> <Compile Include="Repositories\Models\DT_OrderUsedSalePlatform.cs" />
<Compile Include="Repositories\Models\DT_OrderXXInfo.cs" /> <Compile Include="Repositories\Models\DT_OrderXXInfo.cs" />
<Compile Include="Repositories\Models\DT_ShopifyProductGoodsMap.cs" />
<Compile Include="Repositories\Models\DT_ShopifyUsedSaleProduct.cs" />
<Compile Include="Repositories\Models\HW_GoodsDetail.cs" /> <Compile Include="Repositories\Models\HW_GoodsDetail.cs" />
<Compile Include="Repositories\Models\HW_GoodsInfo.cs" /> <Compile Include="Repositories\Models\HW_GoodsInfo.cs" />
<Compile Include="Repositories\Models\HW_PostFee.cs" />
<Compile Include="Repositories\Models\JC_Shop.cs" /> <Compile Include="Repositories\Models\JC_Shop.cs" />
<Compile Include="Repositories\Models\JC_UserInfo.cs" /> <Compile Include="Repositories\Models\JC_UserInfo.cs" />
<Compile Include="Repositories\Utils\ExpressionExtensions.cs" /> <Compile Include="Repositories\Utils\ExpressionExtensions.cs" />

Loading…
Cancel
Save