|
|
|
@ -33,10 +33,12 @@ 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;
|
|
|
|
|
using TradeManageNew.APIClients.FedexAPI.Models.RatesAndTransitTimes;
|
|
|
|
|
using TradeManageNew.Models.ShopifyUsedSale;
|
|
|
|
|
|
|
|
|
|
namespace TradeManageNew
|
|
|
|
|
{
|
|
|
|
@ -28727,18 +28729,337 @@ namespace TradeManageNew
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
|
|
|
public int OrderUsedSalePlatformPrint(int Id)
|
|
|
|
|
public APIReturnModel OrderUsedSalePlatformPrint(List<int> 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<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
|
|
|
|
|
{
|
|
|
|
|
var imageUrls = JsonConvert.DeserializeObject<List<string>>(orderUsedSalePlatform.ImageUrls);
|
|
|
|
|
//在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,
|
|
|
|
|
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"
|
|
|
|
|
: "W",
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|