master
wufan 2 months ago
parent d920942220
commit e7c785cc64

@ -29004,6 +29004,7 @@ namespace TradeManageNew
[WebMethod(EnableSession = true)] [WebMethod(EnableSession = true)]
public APIReturnModel PlaceShopifyUsedSaleOrderCallback(string originJson) public APIReturnModel PlaceShopifyUsedSaleOrderCallback(string originJson)
{ {
PagesNew.SaveLog(0, "Shopify二手商品下单", $"原始Json{originJson}", 0);
if (string.IsNullOrWhiteSpace(originJson)) if (string.IsNullOrWhiteSpace(originJson))
{ {
return new APIReturnModel return new APIReturnModel
@ -29013,11 +29014,14 @@ namespace TradeManageNew
Datas = null Datas = null
}; };
} }
var originJsonData = JsonConvert.DeserializeObject<ShopifyUsedSaleOrderDto>(originJson); var originJsonData = JsonConvert.DeserializeObject<ShopifyUsedSaleOrderDto>(originJson);
using (var db = new TradeUsedSale.Repositories.ErpDbContext()) using (var db = new TradeUsedSale.Repositories.ErpDbContext())
{ {
var includeUsedSale = false;
var errorMessage = string.Empty;
//Shopify二手订单
var newDtShopifyUsedSaleOrder = new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrder var newDtShopifyUsedSaleOrder = new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrder
{ {
OrderId = originJsonData.Order.OrderId, OrderId = originJsonData.Order.OrderId,
@ -29050,46 +29054,36 @@ namespace TradeManageNew
IsPlaceOrderSuccess = false IsPlaceOrderSuccess = false
}; };
var dtShopifyUsedSaleOrderId = db.InsertWithInt32Identity(newDtShopifyUsedSaleOrder); //Shopify二手订单明细
var newDtShopifyUsedSaleOrderItems =
db.BeginTransaction(); new List<TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrderItem>();
try try
{ {
foreach (var item in originJsonData.Items) foreach (var item in originJsonData.Items)
{ {
//ERP二手商品信息 //ERP二手商品信息
var orderUsedSalePlatform = db.DT_OrderUsedSalePlatform.FirstOrDefault(x => x.BarCode == item.ProductCode); var orderUsedSalePlatform =
db.DT_OrderUsedSalePlatform.FirstOrDefault(x => x.BarCode == item.ProductCode);
if (orderUsedSalePlatform is null) if (orderUsedSalePlatform is null)
{ {
throw new Exception($"未获取到编码[{item.ProductCode}]的二手商品信息"); PagesNew.SaveLog(0, "Shopify二手商品下单", $"未获取到编码[{item.ProductCode}]的二手商品信息", 0);
continue;
} }
includeUsedSale = true;
//Shopify商品映射 //Shopify商品映射
var shopifyProductGoodsMap = db.DT_ShopifyProductGoodsMap.FirstOrDefault(x => x.SkuId == orderUsedSalePlatform.SkuId); var shopifyProductGoodsMap =
db.DT_ShopifyProductGoodsMap.FirstOrDefault(x =>
x.SkuId == orderUsedSalePlatform.SkuId);
if (shopifyProductGoodsMap is null) if (shopifyProductGoodsMap is null)
{ {
throw new Exception($"未获取到SKU[{orderUsedSalePlatform.SkuCode}]对应的Shopify产品信息"); throw new Exception($"未获取到SKU[{orderUsedSalePlatform.SkuCode}]对应的Shopify产品信息");
} }
//下单后修改二手商品信息 // Shopify客户端 删除产品变体
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客户端
// 删除产品变体
var shopifyApiClient = new ShopifyAPIClient(); var shopifyApiClient = new ShopifyAPIClient();
var productVariantRes = shopifyApiClient.DeleteProductVariantAsync(new Body3 var productVariantRes = shopifyApiClient.DeleteProductVariantAsync(new Body3
{ {
@ -29101,19 +29095,14 @@ namespace TradeManageNew
if (productVariantRes.Success != true) if (productVariantRes.Success != true)
{ {
throw new Exception(productVariantRes.Message); throw new Exception($"删除Shopify条码[{item.ProductCode}]变体失败,{productVariantRes.Message}");
} }
db.DT_ShopifyUsedSaleOrder.Where(x => x.Id == dtShopifyUsedSaleOrderId)
.Set(x => x.IsPlaceOrderSuccess, true)
.Set(x => x.PlaceOrderMessage, "更新二手订单信息成功")
.Update();
//添加Shopify订单明细 //添加Shopify订单明细
var newDtShopifyUsedSaleOrderItem = var newDtShopifyUsedSaleOrderItem =
new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrderItem new TradeUsedSale.Repositories.Models.DT_ShopifyUsedSaleOrderItem
{ {
DtShopifyUsedSaleOrderId = dtShopifyUsedSaleOrderId, DtShopifyUsedSaleOrderId = 0,
OriginSku = item.OriginSku, OriginSku = item.OriginSku,
Sku = item.Sku, Sku = item.Sku,
ProductCode = item.ProductCode, ProductCode = item.ProductCode,
@ -29127,18 +29116,78 @@ namespace TradeManageNew
ShippingMethod = item.ShippingMethod ShippingMethod = item.ShippingMethod
}; };
db.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem); newDtShopifyUsedSaleOrderItems.Add(newDtShopifyUsedSaleOrderItem);
} }
db.CommitTransaction();
} }
catch (Exception ex) catch (Exception ex)
{ {
db.RollbackTransaction(); errorMessage = ex.Message;
}
if (includeUsedSale)
{
if (!string.IsNullOrEmpty(errorMessage))
{
newDtShopifyUsedSaleOrder.IsPlaceOrderSuccess = false;
newDtShopifyUsedSaleOrder.PlaceOrderMessage = $"更新二手订单信息失败,原因:{errorMessage}";
db.InsertWithInt32Identity(newDtShopifyUsedSaleOrder);
PagesNew.SaveLog(0, "Shopify二手商品下单", "部分执行成功", 0);
}
else
{
newDtShopifyUsedSaleOrder.IsPlaceOrderSuccess = true;
newDtShopifyUsedSaleOrder.PlaceOrderMessage = "更新二手订单信息成功";
var dtShopifyUsedSaleOrderId = db.InsertWithInt32Identity(newDtShopifyUsedSaleOrder);
try
{
db.BeginTransaction();
foreach (var newDtShopifyUsedSaleOrderItem in newDtShopifyUsedSaleOrderItems)
{
newDtShopifyUsedSaleOrderItem.DtShopifyUsedSaleOrderId = dtShopifyUsedSaleOrderId;
db.InsertWithInt32Identity(newDtShopifyUsedSaleOrderItem);
//下单后修改二手商品信息
var statement = db.DT_OrderUsedSalePlatform.Where(x =>
x.BarCode == newDtShopifyUsedSaleOrderItem.ProductCode)
.Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.PendingPickup);
if (newDtShopifyUsedSaleOrderItem.ShippingMethod == "SP")
{
statement = statement.Set(x => x.ShippingMethod,
TradeUsedSale.Enums.ShippingMethod.SelfPickup);
}
if (newDtShopifyUsedSaleOrderItem.ShippingMethod == "DL")
{
statement = statement.Set(x => x.ShippingMethod,
TradeUsedSale.Enums.ShippingMethod.ExpressDelivery);
}
statement.Update();
}
PagesNew.SaveLog(0, "Shopify二手商品下单", "执行成功", 0);
db.CommitTransaction();
}
catch (Exception ex)
{
db.RollbackTransaction();
db.DT_ShopifyUsedSaleOrder.Where(x => x.Id == dtShopifyUsedSaleOrderId)
.Set(x => x.PlaceOrderMessage, $"更新二手订单信息失败,原因:{ex.Message}")
.Update();
db.DT_ShopifyUsedSaleOrder.Where(x => x.Id == dtShopifyUsedSaleOrderId) PagesNew.SaveLog(0, "Shopify二手商品下单", "部分执行成功", 0);
.Set(x => x.PlaceOrderMessage, $"更新二手订单信息失败,原因:{ex.Message}") }
.Update(); }
}
else
{
PagesNew.SaveLog(0, "Shopify二手商品下单", "该订单未包含任何上传的二手商品", 0);
} }
} }
@ -29153,6 +29202,7 @@ namespace TradeManageNew
[WebMethod(EnableSession = true)] [WebMethod(EnableSession = true)]
public APIReturnModel CancelShopifyUsedSaleOrderCallback(string originJson) public APIReturnModel CancelShopifyUsedSaleOrderCallback(string originJson)
{ {
PagesNew.SaveLog(0, "Shopify二手商品取消", $"原始Json{originJson}", 0);
if (string.IsNullOrWhiteSpace(originJson)) if (string.IsNullOrWhiteSpace(originJson))
{ {
return new APIReturnModel return new APIReturnModel
@ -29167,154 +29217,168 @@ namespace TradeManageNew
using (var db = new TradeUsedSale.Repositories.ErpDbContext()) using (var db = new TradeUsedSale.Repositories.ErpDbContext())
{ {
var shopifyUsedSaleOrder = db.DT_ShopifyUsedSaleOrder.FirstOrDefault(x => x.OrderId == originJsonData.OrderId); var shopifyUsedSaleOrder =
db.DT_ShopifyUsedSaleOrder.FirstOrDefault(x => x.OrderId == originJsonData.OrderId);
if (shopifyUsedSaleOrder is null) if (shopifyUsedSaleOrder is null)
{ {
PagesNew.SaveLog(0, "Shopify二手商品取消", $"未找到ShopifyOrderId为{originJsonData.OrderId}Shopify二手订单原始Json为:{originJson}", 0); PagesNew.SaveLog(0, "Shopify二手商品取消", $"跳过执行,未找到ShopifyOrderId为{originJsonData.OrderId}Shopify二手订单", 0);
} }
else
try
{ {
db.BeginTransaction(); try
{
db.BeginTransaction();
db.DT_ShopifyUsedSaleOrder.Where(x => x.OrderId == originJsonData.OrderId) db.DT_ShopifyUsedSaleOrder.Where(x => x.OrderId == originJsonData.OrderId)
.Set(x => x.IsCancelled, true) .Set(x => x.IsCancelled, true)
.Set(x => x.CancelReason, originJsonData.CancelReason) .Set(x => x.CancelReason, originJsonData.CancelReason)
.Set(x => x.CancelDate, originJsonData.CancelDate.DateTime) .Set(x => x.CancelDate, originJsonData.CancelDate.DateTime)
.Update(); .Update();
var shopifyUsedSaleOrderItems = db.DT_ShopifyUsedSaleOrderItem var shopifyUsedSaleOrderItems = db.DT_ShopifyUsedSaleOrderItem
.Where(x => x.DtShopifyUsedSaleOrderId == shopifyUsedSaleOrder.Id) .Where(x => x.DtShopifyUsedSaleOrderId == shopifyUsedSaleOrder.Id)
.ToList(); .ToList();
foreach (var saleOrderItem in shopifyUsedSaleOrderItems) foreach (var saleOrderItem in shopifyUsedSaleOrderItems)
{
//ERP二手商品
var orderUsedSalePlatform = db.DT_OrderUsedSalePlatform.FirstOrDefault(x => x.BarCode == saleOrderItem.ProductCode);
if (orderUsedSalePlatform is null)
{ {
throw new Exception($"不存在打印条码为[{saleOrderItem.ProductCode}]的二手商品"); //ERP二手商品
} var orderUsedSalePlatform =
db.DT_OrderUsedSalePlatform.FirstOrDefault(x => x.BarCode == saleOrderItem.ProductCode);
if (orderUsedSalePlatform is null)
{
throw new Exception($"不存在打印条码为[{saleOrderItem.ProductCode}]的二手商品");
}
#region 重新上传Shopify变体 #region 重新上传Shopify变体
//系统产品信息 //系统产品信息
var product = db.HW_GoodsInfo.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId); var product =
if (product is null) db.HW_GoodsInfo.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId);
{ if (product is null)
var message = $"系统中不存在编码为[{orderUsedSalePlatform.ProductCode}]的产品信息无法推送至Shopify"; {
throw new Exception(message); var message = $"系统中不存在编码为[{orderUsedSalePlatform.ProductCode}]的产品信息无法推送至Shopify";
} throw new Exception(message);
}
//毛重 //毛重
if (product.Weight is null || product.Weight <= 0) if (product.Weight is null || product.Weight <= 0)
{ {
var message = $"产品[{product.GoodsCode}]无毛重信息无法推送至Shopify"; var message = $"产品[{product.GoodsCode}]无毛重信息无法推送至Shopify";
throw new Exception(message); throw new Exception(message);
} }
//建议售价 //建议售价
if (product.JYPrice is null || product.JYPrice <= 0) if (product.JYPrice is null || product.JYPrice <= 0)
{ {
var message = $"产品[{product.GoodsCode}]无建议售价无法推送至Shopify"; var message = $"产品[{product.GoodsCode}]无建议售价无法推送至Shopify";
throw new Exception(message); throw new Exception(message);
} }
//预估运费 //预估运费
var postFee = db.HW_PostFee.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId); var postFee =
if (postFee is null) db.HW_PostFee.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId);
{ if (postFee is null)
throw new Exception( $"产品[{product.GoodsCode}]无预估运费无法推送至Shopify"); {
} throw new Exception($"产品[{product.GoodsCode}]无预估运费无法推送至Shopify");
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) var fees = new List<decimal?>()
{ {
throw new Exception( $"产品[{product.GoodsCode}]预估运费小于0无法推送至Shopify"); 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;
//Shopify商品映射 if (feeCost <= 0)
var shopifyProductGoodsMap = db.DT_ShopifyProductGoodsMap.FirstOrDefault(x => x.SkuId == orderUsedSalePlatform.SkuId); {
if (shopifyProductGoodsMap is null) throw new Exception($"产品[{product.GoodsCode}]预估运费小于0无法推送至Shopify");
{ }
throw new Exception($"未获取到SKU[{orderUsedSalePlatform.SkuCode}]对应的Shopify产品信息");
}
//获取SKU的资料信息 //Shopify商品映射
var shopifyProductProfile = var shopifyProductGoodsMap =
db.DT_ShopifyUsedSaleProduct.FirstOrDefault(x => x.Sku == orderUsedSalePlatform.SkuCode); db.DT_ShopifyProductGoodsMap.FirstOrDefault(x =>
x.SkuId == orderUsedSalePlatform.SkuId);
if (shopifyProductGoodsMap is null)
{
throw new Exception($"未获取到SKU[{orderUsedSalePlatform.SkuCode}]对应的Shopify产品信息");
}
//Shopify客户端 //获取SKU的资料信息
var shopifyApiClient = new ShopifyAPIClient(); var shopifyProductProfile =
db.DT_ShopifyUsedSaleProduct.FirstOrDefault(x =>
x.Sku == orderUsedSalePlatform.SkuCode);
var imageUrls = JsonConvert.DeserializeObject<List<string>>(orderUsedSalePlatform.ImageUrls); //Shopify客户端
//在Shopify创建产品变体信息 var shopifyApiClient = new ShopifyAPIClient();
var createShopifyVariantParameter = new AddVariantRequest
{
ProductBaseData = new ProductBaseData2
{
ShoifyGoodsId = shopifyProductGoodsMap.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,
ImgUrl = 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"
: "W",
Code = orderUsedSalePlatform.BarCode,
},
};
var productVariantRes = shopifyApiClient.AddProductVariantAsync(createShopifyVariantParameter).ConfigureAwait(false)
.GetAwaiter()
.GetResult();
if (productVariantRes.Success != true) var imageUrls =
{ JsonConvert.DeserializeObject<List<string>>(orderUsedSalePlatform.ImageUrls);
var message = $"产品[{product.GoodsCode}]推送Shopify变体失败原因{productVariantRes.Message}"; //在Shopify创建产品变体信息
throw new Exception(message); var createShopifyVariantParameter = new AddVariantRequest
{
ProductBaseData = new ProductBaseData2
{
ShoifyGoodsId = shopifyProductGoodsMap.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,
ImgUrl = 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"
: "W",
Code = orderUsedSalePlatform.BarCode,
},
};
var productVariantRes = shopifyApiClient
.AddProductVariantAsync(createShopifyVariantParameter).ConfigureAwait(false)
.GetAwaiter()
.GetResult();
if (productVariantRes.Success != true)
{
var message = $"产品[{product.GoodsCode}]推送Shopify变体失败原因{productVariantRes.Message}";
throw new Exception(message);
}
db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id)
.Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.Listed)
.Set(x => x.ShippingMethod, value: null)
.Update();
#endregion
} }
db.DT_OrderUsedSalePlatform.Where(x => x.Id == orderUsedSalePlatform.Id) PagesNew.SaveLog(0, "Shopify二手商品取消", "执行成功", 0);
.Set(x => x.Status, TradeUsedSale.Enums.UsedSalePlatformStatus.Listed)
.Set(x => x.ShippingMethod, value: null)
.Update();
#endregion db.CommitTransaction();
} }
catch (Exception ex)
{
db.RollbackTransaction();
db.CommitTransaction(); PagesNew.SaveLog(0, "Shopify二手商品取消", $"执行失败,{ex.Message}", 0);
} }
catch (Exception ex)
{
db.RollbackTransaction();
PagesNew.SaveLog(0, "Shopify二手商品取消", $"执行失败原始Json为:{originJson},原因:{ex.Message}", 0);
} }
} }

Loading…
Cancel
Save