同步物流修改 二次重试
This commit is contained in:
1 parent
43a11a4015
commit
e39b60ca67
2 files changed
+106
-32
No files matched your search
@@ -26,7 +26,8 @@ public class YhSyncLogisticsEntity
|
||||
/// </summary>
|
||||
[Column(Name = "order_id")]
|
||||
public string OrderId { get; set; }
|
||||
|
||||
[Column(Name = "order_sn")]
|
||||
public string OrderSN { get; set; }
|
||||
/// <summary>
|
||||
/// 同步物流编号
|
||||
/// </summary>
|
||||
|
||||
@@ -102,12 +102,103 @@ public class VirtualLogisticsService : ITransientDependency
|
||||
.First();
|
||||
if (productItem == null) throw new Exception("错误的订单详情号");
|
||||
|
||||
var shop = _freeSql.Select<ShopEntity>()
|
||||
var shop = _freeSql.Select<WXShopEntity>()
|
||||
.Where(a => a.Id == productItem.ShopId)
|
||||
.First();
|
||||
if (shop == null) throw new Exception("错误的店铺");
|
||||
|
||||
//BuyRequest request = new BuyRequest()
|
||||
//{
|
||||
// KuaidiId = "874",
|
||||
// GoodsId = "8473",
|
||||
// CangId = "914",
|
||||
// Platform = 6,
|
||||
// Auth = 1,
|
||||
// SendName = RandomNameHelper.GetRandomName(),
|
||||
// SendMobile = "13024622251",
|
||||
// SendProvince = "上海市",
|
||||
// SendCity = "上海市",
|
||||
// SendDistrict = "普陀区",
|
||||
// SendAddress = "真如镇街道真北路2653弄F区808号楼",
|
||||
// RecList = [
|
||||
// new RecItem
|
||||
// {
|
||||
// OrderSn = orderId,
|
||||
// ShopOrder =w_order.OrderId,
|
||||
// RecName = w_order.UserName,
|
||||
// RecMobile = w_order.TelNumber,
|
||||
// RecProvince = w_order.ProvinceName,
|
||||
// RecCity = w_order.CityName,
|
||||
// RecDistrict = w_order.CountyName,
|
||||
// RecAddress = w_order.DetailInfo,
|
||||
// EwaybillOrderCode="wx7809625286c28f2f",
|
||||
// EncryptDatas=new EncryptDatas
|
||||
// {
|
||||
// DsOrderId=agentOrderId,
|
||||
// SkuId = productItem.SkuId,
|
||||
// ProductId = productItem.ProductId,
|
||||
// SkuCnt = productItem.SkuCnt,
|
||||
// FromShopCode = shop.AppKey,
|
||||
// },
|
||||
// ExtendParams=new ExtendParams{
|
||||
// Token="",
|
||||
// Api="",
|
||||
// DsOrderId =agentOrderId
|
||||
// },
|
||||
// OtherKuaidiSn= middleOrder.TrackingNumber,
|
||||
|
||||
// }
|
||||
// ]
|
||||
//};
|
||||
Result<List<BuyResultItem>> ret = _buyTrackingNumber(orderId, agentOrderId, shop.AppKey, middleOrder.TrackingNumber, w_order, productItem, true);
|
||||
|
||||
if (ret.Success == false)
|
||||
{
|
||||
_logger.Error($"购买同步单错误:{ret.Msg}");
|
||||
throw new Exception("购买同步单失败");
|
||||
}
|
||||
List<YhSyncLogisticsEntity> yhSyncs = new List<YhSyncLogisticsEntity>();
|
||||
foreach (var sync in ret.Data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sync.KuaidiSn))
|
||||
{
|
||||
throw new Exception($"获取快递单号为空,Status:{sync.Status}");
|
||||
}
|
||||
yhSyncs.Add(new YhSyncLogisticsEntity
|
||||
{
|
||||
OrderId = orderId,
|
||||
OrderSN = sync.OrderSn,
|
||||
TrackingNumber = sync.KuaidiSn,
|
||||
SourceTrackingNumber = sync.OtherKuaidiSn
|
||||
});
|
||||
}
|
||||
|
||||
var count = _freeSql.Insert<YhSyncLogisticsEntity>(yhSyncs).ExecuteAffrows();
|
||||
if (count != yhSyncs.Count)
|
||||
{
|
||||
_logger.Error("购买同步单提交到数据库错误");
|
||||
throw new Exception("记录同步单失败");
|
||||
}
|
||||
//todo 更新UserBlance
|
||||
_userService.UserPayment(user.UserName, orderId, type: Contracts.User.Enums.UserPaymentTypes.同步单号);
|
||||
return yhSyncs;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 购买同步物流
|
||||
/// </summary>
|
||||
/// <param name="orderSN"></param>
|
||||
/// <param name="agentOrderId"></param>
|
||||
/// <param name="shopAppkey"></param>
|
||||
/// <param name="sourceTrackingNumber"></param>
|
||||
/// <param name="w_order"></param>
|
||||
/// <param name="productItem"></param>
|
||||
/// <param name="isTestingRepeat">是否二次校验OrderSN是否重复 true 更换OrderSN, fals直接返回内容</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private Result<List<BuyResultItem>> _buyTrackingNumber(string orderSN, string agentOrderId, string shopAppkey, string sourceTrackingNumber, WeiOrderEntity w_order, WeiOrderItemEntity productItem, bool isTestingRepeat = false)
|
||||
{
|
||||
BuyRequest request = new BuyRequest()
|
||||
{
|
||||
KuaidiId = "874",
|
||||
@@ -124,7 +215,7 @@ public class VirtualLogisticsService : ITransientDependency
|
||||
RecList = [
|
||||
new RecItem
|
||||
{
|
||||
OrderSn = orderId,
|
||||
OrderSn = orderSN,
|
||||
ShopOrder =w_order.OrderId,
|
||||
RecName = w_order.UserName,
|
||||
RecMobile = w_order.TelNumber,
|
||||
@@ -139,51 +230,33 @@ public class VirtualLogisticsService : ITransientDependency
|
||||
SkuId = productItem.SkuId,
|
||||
ProductId = productItem.ProductId,
|
||||
SkuCnt = productItem.SkuCnt,
|
||||
FromShopCode = shop.AppKey,
|
||||
FromShopCode = shopAppkey,
|
||||
},
|
||||
ExtendParams=new ExtendParams{
|
||||
Token="",
|
||||
Api="",
|
||||
DsOrderId =agentOrderId
|
||||
},
|
||||
OtherKuaidiSn= middleOrder.TrackingNumber,
|
||||
OtherKuaidiSn= sourceTrackingNumber,
|
||||
|
||||
}
|
||||
]
|
||||
};
|
||||
Result<List<BuyResultItem>> ret = _api.Buy(request);
|
||||
if (ret.Success == false)
|
||||
{
|
||||
if (ret.Msg.Contains("order_sn重复") && isTestingRepeat) //检测重复 替换orderSN
|
||||
{
|
||||
orderSN = orderSN + "_1";//只重复一次
|
||||
ret = _buyTrackingNumber(orderSN, agentOrderId, shopAppkey, sourceTrackingNumber, w_order, productItem, false);
|
||||
}
|
||||
}
|
||||
if (ret.Success == false)
|
||||
{
|
||||
_logger.Error($"购买同步单错误:{ret.Msg}");
|
||||
throw new Exception("购买同步单失败");
|
||||
}
|
||||
|
||||
List<YhSyncLogisticsEntity> yhSyncs = new List<YhSyncLogisticsEntity>();
|
||||
foreach (var sync in ret.Data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sync.KuaidiSn))
|
||||
{
|
||||
throw new Exception($"获取快递单号为空,Status:{sync.Status}");
|
||||
}
|
||||
yhSyncs.Add(new YhSyncLogisticsEntity
|
||||
{
|
||||
OrderId = sync.OrderSn,
|
||||
TrackingNumber = sync.KuaidiSn,
|
||||
SourceTrackingNumber = sync.OtherKuaidiSn
|
||||
});
|
||||
}
|
||||
|
||||
var count = _freeSql.Insert<YhSyncLogisticsEntity>(yhSyncs).ExecuteAffrows();
|
||||
if (count != yhSyncs.Count)
|
||||
{
|
||||
_logger.Error("购买同步单提交到数据库错误");
|
||||
throw new Exception("记录同步单失败");
|
||||
}
|
||||
|
||||
//todo 更新UserBlance
|
||||
_userService.UserPayment(user.UserName, orderId, type: Contracts.User.Enums.UserPaymentTypes.同步单号);
|
||||
return yhSyncs;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user