diff --git a/Store.SyncLogistics/Entitys/YhSyncLogisticsEntity.cs b/Store.SyncLogistics/Entitys/YhSyncLogisticsEntity.cs
index 3ab26df..fb905f1 100644
--- a/Store.SyncLogistics/Entitys/YhSyncLogisticsEntity.cs
+++ b/Store.SyncLogistics/Entitys/YhSyncLogisticsEntity.cs
@@ -26,7 +26,8 @@ public class YhSyncLogisticsEntity
///
[Column(Name = "order_id")]
public string OrderId { get; set; }
-
+ [Column(Name = "order_sn")]
+ public string OrderSN { get; set; }
///
/// 同步物流编号
///
diff --git a/Store.SyncLogistics/Services/VirtualLogisticsService.cs b/Store.SyncLogistics/Services/VirtualLogisticsService.cs
index 7ad248e..60f1576 100644
--- a/Store.SyncLogistics/Services/VirtualLogisticsService.cs
+++ b/Store.SyncLogistics/Services/VirtualLogisticsService.cs
@@ -102,12 +102,103 @@ public class VirtualLogisticsService : ITransientDependency
.First();
if (productItem == null) throw new Exception("错误的订单详情号");
- var shop = _freeSql.Select()
+ var shop = _freeSql.Select()
.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> ret = _buyTrackingNumber(orderId, agentOrderId, shop.AppKey, middleOrder.TrackingNumber, w_order, productItem, true);
+
+ if (ret.Success == false)
+ {
+ _logger.Error($"购买同步单错误:{ret.Msg}");
+ throw new Exception("购买同步单失败");
+ }
+ List yhSyncs = new List();
+ 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(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;
+
+ }
+
+ ///
+ /// 购买同步物流
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// 是否二次校验OrderSN是否重复 true 更换OrderSN, fals直接返回内容
+ ///
+ ///
+ private Result> _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> 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 yhSyncs = new List();
- 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(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;
}
///