增加 同步物流服务,并扣款

This commit is contained in:
chfei committed 2026-09-23 16:22:34 +08:00
1 parent f27428b5f9
commit 6863194328
24 files changed
+538 -114

No files matched your search

@@ -2,6 +2,9 @@ using MAX.Core.Commons;
using MAX.Core.DependencyInjection;
using MAX.Core.Logger;
using Store.Contracts.Order.Entitys;
using Store.Contracts.Shops;
using Store.Contracts.User.Entitys;
using Store.Contracts.User.Interfaces;
using Store.VirtualLogistics.Apis;
using Store.VirtualLogistics.Entitys;
using Store.VirtualLogistics.Models;
@@ -16,14 +19,20 @@ namespace Store.VirtualLogistics.Services;
public class VirtualLogisticsService : ITransientDependency
{
/// <summary>
/// 固定费用1.7元
/// </summary>
const decimal FIXEDFEES = 1.7m;
private IFreeSql _freeSql;
private readonly ILoggerFacade _logger;
private readonly IUserService _userService;
private readonly VirtualLogisticsApi _api;
public VirtualLogisticsService(VirtualLogisticsApi api, IFreeSql freeSql, ILoggerFacade logger)
public VirtualLogisticsService(VirtualLogisticsApi api, IFreeSql freeSql, ILoggerFacade logger, IUserService userService)
{
_freeSql = freeSql ?? throw new ArgumentNullException(nameof(freeSql));
_logger = logger;
_userService = userService;
_api = api;
}
@@ -64,15 +73,22 @@ public class VirtualLogisticsService : ITransientDependency
/// <summary>
/// 购买快递
/// </summary>
public List<YhSyncLogisticsEntity> Buy(string orderId, string ds_orderId)
public List<YhSyncLogisticsEntity> Buy(string userName, string orderId, string agentOrderId)
{
var item = _freeSql.Select<OrderPddBuyerOrderEntity>()
if (string.IsNullOrEmpty(orderId) || string.IsNullOrWhiteSpace(agentOrderId))
{
throw new ArgumentNullException(nameof(orderId));
}
var user = _userService.GetUserByUserName(userName);
if (user == null) throw new Exception("错误的账号");
//中间订单
var middleOrder = _freeSql.Select<OrderPddBuyerOrderEntity>()
.Where(a => a.OrderSn == orderId)
.First();
if (item == null) throw new Exception("错误的订单号");
if (middleOrder == null) throw new Exception("错误的订单号");
//middleOrder.TrackingNumber = "YT0709726946568";
var w_order = _freeSql.Select<WeiOrderEntity>()
.Where(a => a.OrderId == item.WxOrderId)
.Where(a => a.OrderId == middleOrder.WxOrderId)
.First();
if (w_order == null) throw new Exception("错误的订单号");
@@ -81,6 +97,12 @@ public class VirtualLogisticsService : ITransientDependency
.First();
if (productItem == null) throw new Exception("错误的订单详情号");
var shop = _freeSql.Select<ShopEntity>()
.Where(a => a.Id == productItem.ShopId)
.First();
if (shop == null) throw new Exception("错误的店铺");
BuyRequest request = new BuyRequest()
{
KuaidiId = "874",
@@ -98,20 +120,28 @@ public class VirtualLogisticsService : ITransientDependency
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=ds_orderId,
DsOrderId=agentOrderId,
SkuId = productItem.SkuId,
ProductId = productItem.ProductId,
SkuCnt = productItem.SkuCnt.ToString(),
SkuCnt = productItem.SkuCnt,
FromShopCode = shop.AppKey,
},
OtherKuaidiSn= "6738192431"//item.TrackingNumber,
ExtendParams=new ExtendParams{
Token="",
Api="",
DsOrderId =agentOrderId
},
OtherKuaidiSn= middleOrder.TrackingNumber,
}
]
@@ -141,6 +171,9 @@ public class VirtualLogisticsService : ITransientDependency
_logger.Error("购买同步单提交到数据库错误");
throw new Exception("记录同步单失败");
}
//todo 更新UserBlance
_userService.UserPayment(user.UserName, orderId, type: Contracts.User.Enums.UserPaymentTypes.同步单号);
return yhSyncs;
}