master
wufan 1 month ago
parent 091a68d186
commit ce6eee3ca7

@ -3,6 +3,8 @@ using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Caching;
using System.Text;
using System.Threading;

@ -13,8 +13,8 @@
public const string XPO_ACCESS_TOKEN_KEY = "XPOAccessToken";
/// <summary>
/// Fedex API access token key.
/// Fedex API access token key prefix.
/// </summary>
public const string FEDEX_ACCESS_TOKEN_KEY = "FedexAccessToken";
public const string FEDEX_ACCESS_TOKEN_PREFIX = "FedexAccessToken";
}
}

@ -1,44 +1,35 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
using TradeData;
using NetLibrary.Data;
using System.Data;
using TradeModel;
using NetLibrary.ReportPrint;
using ApiNew;
using LinqToDB;
using NetLibrary;
using NetLibrary.Data;
using NetLibrary.Express;
using System.Text.RegularExpressions;
using NetLibrary.OnlineTrade;
using System.Web.Script.Serialization;
using System.Text;
using NetLibrary.Log;
using System.Threading;
using ApiNew;
using Aspose.Pdf;
using System.Net;
using System.Runtime.ConstrainedExecution;
using System.IO;
using System.Net.Http;
using NetLibrary.OnlineTrade;
using NetLibrary.ReportPrint;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Pkcs;
using TradeManage;
using System.Security.Cryptography;
using NetLibrary.WebReference;
using FastJSON;
using System.Runtime.CompilerServices;
using Newtonsoft.Json.Serialization;
using NPOI.HSSF.Record.Formula.Functions;
using static NPOI.HSSF.Util.HSSFColor;
using System.Linq.Expressions;
using TradeData;
using TradeManage;
using TradeManageNew.APIClients.FedexApi;
using TradeManageNew.APIClients.FedexApi.Models.Ship;
using TradeManageNew.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;
using TradeModel;
using Match = System.Text.RegularExpressions.Match;
namespace TradeManageNew
{
@ -8723,23 +8714,7 @@ namespace TradeManageNew
return rmodelNew;
}
[WebMethod(EnableSession = true)]
public RateAndTransitTimesResp GetFedexFeeTest()
{
var ratesAndTransitTimesTests = new RatesAndTransitTimesTests();
return ratesAndTransitTimesTests.Should_RateAsync_IsReturn();
}
#region 修改允许发货
[WebMethod(EnableSession = true)]
public void UpdatePostState2(List<DT_Order> list)
@ -29423,6 +29398,339 @@ namespace TradeManageNew
};
}
public APIReturnModel GetOrderUsedSalePlatformLabel(int Id)
{
// PagesNew.Login(base.Session);
using (var db = new TradeUsedSale.Repositories.ErpDbContext())
{
var orderUsedSalePlatform = db.DT_OrderUsedSalePlatform.FirstOrDefault(x =>
x.Id == Id && x.Status == TradeUsedSale.Enums.UsedSalePlatformStatus.PendingPickup);
if (orderUsedSalePlatform is null)
{
return new APIReturnModel
{
Code = 0,
Message = $"不存在Id为{Id}的二手售卖商品",
Datas = null
};
}
var product = db.HW_GoodsInfo.FirstOrDefault(x => x.GoodsId == orderUsedSalePlatform.ProductId);
if (product is null)
{
return new APIReturnModel
{
Code = 0,
Message = $"系统中不存在Id为{orderUsedSalePlatform.ProductId}的产品信息",
Datas = null
};
}
//毛重
if (product.Weight is null || product.Weight <= 0)
{
return new APIReturnModel
{
Code = 0,
Message = $"产品[{product.GoodsCode}]无毛重信息,无法发货",
Datas = null
};
}
//长宽高
if (product.Long is null || product.Long <= 0 ||
product.Width is null || product.Width <= 0 ||
product.Height is null || product.Height <= 0)
{
return new APIReturnModel
{
Code = 0,
Message = $"产品[{product.GoodsCode}]外箱尺寸信息不完整,无法发货",
Datas = null
};
}
var sku = db.HW_GoodsDetail.FirstOrDefault(x => x.DetailId == orderUsedSalePlatform.SkuId);
if (sku is null)
{
return new APIReturnModel
{
Code = 0,
Message = $"系统中不存在Id为{orderUsedSalePlatform.SkuId}的SKU信息",
Datas = null
};
}
if (orderUsedSalePlatform.Status != TradeUsedSale.Enums.UsedSalePlatformStatus.PendingPickup)
{
return new APIReturnModel
{
Code = 0,
Message = $"二手售卖商品[{orderUsedSalePlatform.SkuCode}]不处于待发货状态",
Datas = null
};
}
//Shopify订单信息
var shopifyUsedSaleOrderItem = db.DT_ShopifyUsedSaleOrderItem.FirstOrDefault(x => x.ProductCode == orderUsedSalePlatform.BarCode);
if(shopifyUsedSaleOrderItem is null)
{
return new APIReturnModel
{
Code = 0,
Message = $"未获取到条码为[{ orderUsedSalePlatform.BarCode}]的Shopify订单信息",
Datas = null
};
}
var shopifyUsedSaleOrder = db.DT_ShopifyUsedSaleOrder.FirstOrDefault(x => x.Id == shopifyUsedSaleOrderItem.DtShopifyUsedSaleOrderId);
if(shopifyUsedSaleOrder is null)
{
return new APIReturnModel
{
Code = 0,
Message = $"未获取到条码为[{ orderUsedSalePlatform.BarCode}]的Shopify订单信息",
Datas = null
};
}
//获取Fedex运费和面单
var fedexCredential = new FedexCredential(isDebugMode: true) { ReadResponseAsString = true };
if (orderUsedSalePlatform.WarehouseLocation == TradeUsedSale.Enums.WarehouseLocation.East)
{
fedexCredential.SetEastSandBoxCredential();
}
else
{
fedexCredential.SetWestSandBoxCredential();
}
var serviceTypes = new List<RequestedShipmentServiceType>()
{
RequestedShipmentServiceType.GROUND_HOME_DELIVERY,
RequestedShipmentServiceType.SMART_POST,
RequestedShipmentServiceType.FEDEX_GROUND,
};
var fedexClient = new FedexAPIClient(fedexCredential);
#region 发件人
var shipper = new ShipperParty();
if (orderUsedSalePlatform.WarehouseLocation == TradeUsedSale.Enums.WarehouseLocation.East)
{
shipper.Contact = new PartyContact
{
PersonName = "Karmas Far Inc",
PhoneNumber = "9045971260",
};
shipper.Address = new PartyAddress_2
{
StreetLines = SplitAddress("2615 port industrial Dr. suites 408", 35),
City = "Jacksonville",
StateOrProvinceCode = "FL",
PostalCode = "32226",
CountryCode = "US",
};
}
else
{
shipper.Contact = new PartyContact
{
PersonName = "Karmas Far Inc",
PhoneNumber = "9093726955",
};
shipper.Address = new PartyAddress_2
{
StreetLines = SplitAddress("11190 White Birch Dr Suite 100", 35),
City = "RanchoCucamonga",
StateOrProvinceCode = "CA",
PostalCode = "91730",
CountryCode = "US",
};
}
#endregion
#region 收件人
var recipient = new RecipientsParty
{
Address = new PartyAddress_2
{
StreetLines = SplitAddress(shopifyUsedSaleOrder.Full, 35),
City = shopifyUsedSaleOrder.City,
StateOrProvinceCode = shopifyUsedSaleOrder.ProvinceCode,
PostalCode = shopifyUsedSaleOrder.Zip,
CountryCode = shopifyUsedSaleOrder.CountryCode,
Residential = null
},
Contact = new PartyContact
{
PersonName = shopifyUsedSaleOrder.Name,
PhoneNumber = shopifyUsedSaleOrder.Phone,
}
};
#endregion
#region 商品信息
var requestedPackageLineItems = new List<RequestedPackageLineItem>()
{
new RequestedPackageLineItem()
{
SequenceNumber = 1,
Weight = new Weight()
{
Value = product.Weight.Value/1000,
Units = WeightUnits.KG
},
CustomerReferences = new List<CustomerReference_1>()
{
new CustomerReference_1
{
CustomerReferenceType = CustomerReference_1CustomerReferenceType
.CUSTOMER_REFERENCE,
Value = orderUsedSalePlatform.BarCode,
}
},
PackageSpecialServices = new PackageSpecialServicesRequested
{
SignatureOptionType =
PackageSpecialServicesRequestedSignatureOptionType.SERVICE_DEFAULT
},
Dimensions = new Dimensions
{
Length = Convert.ToInt32(product.Long),
Width = Convert.ToInt32(product.Width),
Height = Convert.ToInt32(product.Height),
Units = DimensionsUnits.CM
}
}
};
#endregion
#region 标签信息
var labelSpecification = new LabelSpecification()
{
ImageType = LabelSpecificationImageType.PDF,
LabelFormatType = LabelSpecificationLabelFormatType.COMMON2D,
LabelStockType = LabelSpecificationLabelStockType.PAPER_4X8,
};
#endregion
foreach (var serviceType in serviceTypes)
{
var apiRequestInfo = new StringBuilder();
try
{
//判断地址类型来跳过部分服务并且收获地址添加是否住宅
var createShipmentParameter = new CreateShipmentReq
{
LabelResponseOptions = LABELRESPONSEOPTIONS.LABEL,
RequestedShipment = new RequestedShipment()
{
Shipper = shipper,
Recipients = new List<RecipientsParty>()
{
recipient
},
ServiceType = serviceType,
PackagingType = RequestedShipmentPackageType.YOUR_PACKAGING,
PickupType = RequestedShipmentPickupType.DROPOFF_AT_FEDEX_LOCATION,
BlockInsightVisibility = false,
ShippingChargesPayment = new Payment()
{
PaymentType = PaymentType.SENDER
},
LabelSpecification = labelSpecification,
RequestedPackageLineItems = requestedPackageLineItems
},
AccountNumber = new ShipperAccountNumber()
{
Value = fedexCredential.AccountNumber
}
};
//记录请求参数
apiRequestInfo.AppendLine($"请求参数:{JsonConvert.SerializeObject(createShipmentParameter)}");
var response = fedexClient.Ship.CreateShipmentAsync(createShipmentParameter)
.ConfigureAwait(false)
.GetAwaiter()
.GetResult();
//记录返回结果
apiRequestInfo.AppendLine($"返回结果:{JsonConvert.SerializeObject(response)}");
}
catch (Exception ex)
{
var apiRequestStr = apiRequestInfo.ToString();
if (!string.IsNullOrWhiteSpace(apiRequestStr))
{
db.InsertWithInt32Identity(new TradeUsedSale.Repositories.Models.DT_TrackCodeApplyLog
{
UsedSaleBarCode = orderUsedSalePlatform.BarCode,
ServiceType = serviceType.ToString(),
Remark = apiRequestStr,
CreationTime = DateTime.Now
});
}
db.InsertWithInt32Identity(new TradeUsedSale.Repositories.Models.DT_TrackCodeApplyLog
{
UsedSaleBarCode = orderUsedSalePlatform.BarCode,
ServiceType = serviceType.ToString(),
Remark = $"请求失败:{ex.Message}",
CreationTime = DateTime.Now
});
}
}
}
return null;
}
static string[] SplitAddress(string address, int maxLength)
{
List<string> addressLines = new List<string>();
while (address.Length > maxLength)
{
int splitIndex = address.LastIndexOf(' ', maxLength);
if (splitIndex == -1) splitIndex = maxLength; // 若无空格,则强行截断
addressLines.Add(address.Substring(0, splitIndex).Trim());
address = address.Substring(splitIndex).Trim();
}
// 添加最后一部分
if (!string.IsNullOrEmpty(address))
{
addressLines.Add(address);
}
return addressLines.ToArray();
}
public APIReturnModel OrderUsedSalePlatformSendOut(int Id ,TradeUsedSale.Enums.ShippingMethod shippingMethod )
{
// PagesNew.Login(base.Session);
using (var db = new TradeUsedSale.Repositories.ErpDbContext())
{
return null;
}
}
#endregion

@ -32,5 +32,6 @@ namespace TradeUsedSale.Repositories
public ITable<HW_PostFee> HW_PostFee => this.GetTable<HW_PostFee>();
public ITable<DT_ShopifyUsedSaleOrder> DT_ShopifyUsedSaleOrder => this.GetTable<DT_ShopifyUsedSaleOrder>();
public ITable<DT_ShopifyUsedSaleOrderItem> DT_ShopifyUsedSaleOrderItem => this.GetTable<DT_ShopifyUsedSaleOrderItem>();
public ITable<DT_TrackCodeApplyLog> DT_TrackCodeApplyLog => this.GetTable<DT_TrackCodeApplyLog>();
}
}

@ -0,0 +1,15 @@
using System;
using LinqToDB.Mapping;
namespace TradeUsedSale.Repositories.Models
{
public class DT_TrackCodeApplyLog
{
[PrimaryKey, Identity] public int Id { get; set; }
public string UsedSaleBarCode { get; set; }
public string ServiceType { get; set; }
public string Remark { get; set; }
public DateTime CreationTime { get; set; }
}
}

@ -60,6 +60,7 @@
<Compile Include="Repositories\Models\DT_ShopifyUsedSaleOrder.cs" />
<Compile Include="Repositories\Models\DT_ShopifyUsedSaleOrderItem.cs" />
<Compile Include="Repositories\Models\DT_ShopifyUsedSaleProduct.cs" />
<Compile Include="Repositories\Models\DT_TrackCodeApplyLog.cs" />
<Compile Include="Repositories\Models\HW_GoodsDetail.cs" />
<Compile Include="Repositories\Models\HW_GoodsInfo.cs" />
<Compile Include="Repositories\Models\HW_PostFee.cs" />

Loading…
Cancel
Save