Browse Source

订单同步检查SD埋点

qianyi
shanji 3 years ago
parent
commit
6b0ca05981
  1. 14
      BBWY.Client/ViewModels/Order/OrderListViewModel.cs
  2. 2
      BBWY.Server.API/Startup.cs
  3. 12
      BBWY.Server.Business/Extensions/OrderCostExtension.cs
  4. 15
      BBWY.Server.Business/Order/OrderBusiness.cs
  5. 68
      BBWY.Server.Business/Sync/OrderSyncBusiness.cs

14
BBWY.Client/ViewModels/Order/OrderListViewModel.cs

@ -613,11 +613,23 @@ namespace BBWY.Client.ViewModels
if (!response.Success) if (!response.Success)
{ {
IsLoading = false; IsLoading = false;
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "设置刷单成本")); App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "SD成本"));
return; return;
} }
//LoadOrder(PageIndex); //设置刷单刷新订单列表 //LoadOrder(PageIndex); //设置刷单刷新订单列表
var order = OrderList.FirstOrDefault(o => o.Id == orderId);
if (order != null && order.OrderState == Models.OrderState.)
{
App.Current.Dispatcher.Invoke(() =>
{
OrderList.Remove(order);
MessageBox.Show("已设置SD成本", "SD成本");
});
}
else
{
RefreshOrder(orderId); RefreshOrder(orderId);
}
}); });
} }

2
BBWY.Server.API/Startup.cs

@ -36,6 +36,8 @@ namespace BBWY.Server.API
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMemoryCache();
var idOption = new IdGeneratorOptions(1); var idOption = new IdGeneratorOptions(1);
var idGenerator = new DefaultIdGenerator(idOption); var idGenerator = new DefaultIdGenerator(idOption);
services.AddSingleton(typeof(IIdGenerator), idGenerator); services.AddSingleton(typeof(IIdGenerator), idGenerator);

12
BBWY.Server.Business/Extensions/OrderCostExtension.cs

@ -10,9 +10,9 @@ namespace BBWY.Server.Business.Extensions
{ {
public static void CalculationOrderProfitAndCost(this OrderCost orderCost, Order order, IList<AfterSaleOrder> afterSaleOrders) public static void CalculationOrderProfitAndCost(this OrderCost orderCost, Order order, IList<AfterSaleOrder> afterSaleOrders)
{ {
orderCost.AfterTotalCost = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost); orderCost.AfterTotalCost = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost);
orderCost.RefundAmount = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M); orderCost.RefundAmount = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M);
orderCost.RefundPurchaseAmount = afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0); orderCost.RefundPurchaseAmount = afterSaleOrders == null || afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0);
//退款之后平台扣点 //退款之后平台扣点
orderCost.PlatformCommissionAmount = (order.OrderSellerPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio); orderCost.PlatformCommissionAmount = (order.OrderSellerPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio);
@ -27,9 +27,9 @@ namespace BBWY.Server.Business.Extensions
public static void CalculationSDOrderProfitAndCost(this OrderCost orderCost, Order order, IList<AfterSaleOrder> afterSaleOrders) public static void CalculationSDOrderProfitAndCost(this OrderCost orderCost, Order order, IList<AfterSaleOrder> afterSaleOrders)
{ {
orderCost.AfterTotalCost = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost); orderCost.AfterTotalCost = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost);
orderCost.RefundAmount = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M); orderCost.RefundAmount = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M);
orderCost.RefundPurchaseAmount = afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0); orderCost.RefundPurchaseAmount = afterSaleOrders == null || afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0);
//退款之后平台扣点 //退款之后平台扣点
orderCost.PlatformCommissionAmount = (order.OrderSellerPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio); orderCost.PlatformCommissionAmount = (order.OrderSellerPrice - orderCost.RefundAmount) * (orderCost.PlatformCommissionRatio);

15
BBWY.Server.Business/Order/OrderBusiness.cs

@ -7,6 +7,7 @@ using BBWY.Server.Model.Db;
using BBWY.Server.Model.Db.Mds; using BBWY.Server.Model.Db.Mds;
using BBWY.Server.Model.Dto; using BBWY.Server.Model.Dto;
using FreeSql; using FreeSql;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -32,14 +33,19 @@ namespace BBWY.Server.Business
private Lazy<FreeSqlMultiDBManager> freeSqlMultiDBManagerLazy; private Lazy<FreeSqlMultiDBManager> freeSqlMultiDBManagerLazy;
private FreeSqlMultiDBManager freeSqlMultiDBManager => freeSqlMultiDBManagerLazy.Value; private FreeSqlMultiDBManager freeSqlMultiDBManager => freeSqlMultiDBManagerLazy.Value;
private IMemoryCache memoryCache;
private static TimeSpan sdGroupExpirationTimeSpan = TimeSpan.FromMinutes(20);
public OrderBusiness(RestApiService restApiService, public OrderBusiness(RestApiService restApiService,
IFreeSql fsql, IFreeSql fsql,
IIdGenerator idGenerator, IIdGenerator idGenerator,
IOptions<GlobalConfig> options, IOptions<GlobalConfig> options,
IServiceProvider serviceProvider) : base(restApiService, options) IServiceProvider serviceProvider,
IMemoryCache memoryCache) : base(restApiService, options)
{ {
this.fsql = fsql; this.fsql = fsql;
this.idGenerator = idGenerator; this.idGenerator = idGenerator;
this.memoryCache = memoryCache;
freeSqlMultiDBManagerLazy = new Lazy<FreeSqlMultiDBManager>(() => serviceProvider.GetService<FreeSqlMultiDBManager>()); freeSqlMultiDBManagerLazy = new Lazy<FreeSqlMultiDBManager>(() => serviceProvider.GetService<FreeSqlMultiDBManager>());
productBusinessLazy = new Lazy<ProductBusiness>(() => serviceProvider.GetService<ProductBusiness>()); productBusinessLazy = new Lazy<ProductBusiness>(() => serviceProvider.GetService<ProductBusiness>());
} }
@ -645,7 +651,12 @@ namespace BBWY.Server.Business
{ {
var dbOrder = fsql.Select<Order>(sdCalculationCostRequest.OrderId).ToOne(); var dbOrder = fsql.Select<Order>(sdCalculationCostRequest.OrderId).ToOne();
if (dbOrder == null) if (dbOrder == null)
throw new BusinessException($"订单号{sdCalculationCostRequest.OrderId}不存在"); {
//待付款订单SD埋点
//memoryCache.Remove(sdCalculationCostRequest.OrderId);
memoryCache.Set(sdCalculationCostRequest.OrderId, sdCalculationCostRequest, sdGroupExpirationTimeSpan);
return;
}
//修改平台订单备注 //修改平台订单备注
var relayAPIHost = GetPlatformRelayAPIHost(sdCalculationCostRequest.Platform); var relayAPIHost = GetPlatformRelayAPIHost(sdCalculationCostRequest.Platform);

68
BBWY.Server.Business/Sync/OrderSyncBusiness.cs

@ -1,10 +1,12 @@
using BBWY.Common.Http; using BBWY.Common.Http;
using BBWY.Common.Models; using BBWY.Common.Models;
using BBWY.Server.Business.Extensions;
using BBWY.Server.Business.PlatformSDK.DataExtension; using BBWY.Server.Business.PlatformSDK.DataExtension;
using BBWY.Server.Model; using BBWY.Server.Model;
using BBWY.Server.Model.Db; using BBWY.Server.Model.Db;
using BBWY.Server.Model.Dto; using BBWY.Server.Model.Dto;
using FreeSql; using FreeSql;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@ -22,13 +24,16 @@ namespace BBWY.Server.Business
{ {
private IDictionary<Enums.Platform, Action<JArray, long, string, string, string, string, decimal>> syncOrderMethodDic; private IDictionary<Enums.Platform, Action<JArray, long, string, string, string, string, decimal>> syncOrderMethodDic;
private IMemoryCache memoryCache;
public OrderSyncBusiness(RestApiService restApiService, public OrderSyncBusiness(RestApiService restApiService,
IOptions<GlobalConfig> options, IOptions<GlobalConfig> options,
ILogger logger, ILogger logger,
IFreeSql fsql, IFreeSql fsql,
IIdGenerator idGenerator, IIdGenerator idGenerator,
TaskSchedulerManager taskSchedulerManager, TaskSchedulerManager taskSchedulerManager,
VenderBusiness venderBusiness) : base(restApiService, VenderBusiness venderBusiness,
IMemoryCache memoryCache) : base(restApiService,
options, options,
logger, logger,
fsql, fsql,
@ -36,6 +41,7 @@ namespace BBWY.Server.Business
taskSchedulerManager, taskSchedulerManager,
venderBusiness) venderBusiness)
{ {
this.memoryCache = memoryCache;
syncOrderMethodDic = new Dictionary<Enums.Platform, Action<JArray, long, string, string, string, string, decimal>>() syncOrderMethodDic = new Dictionary<Enums.Platform, Action<JArray, long, string, string, string, string, decimal>>()
{ {
{ Enums.Platform., SyncJDOrder } { Enums.Platform., SyncJDOrder }
@ -210,6 +216,7 @@ namespace BBWY.Server.Business
var orderId = orderJToken.Value<string>("orderId"); var orderId = orderJToken.Value<string>("orderId");
var dbOrder = dbOrderList.FirstOrDefault(o => o.Id == orderId); var dbOrder = dbOrderList.FirstOrDefault(o => o.Id == orderId);
var isNewOrder = dbOrder == null; var isNewOrder = dbOrder == null;
SDCalculationCostRequest sDCalculationCostRequest = null; //SD信息埋点
#region 订单基本信息 #region 订单基本信息
var buyerRemark = orderJToken.Value<string>("orderRemark"); var buyerRemark = orderJToken.Value<string>("orderRemark");
@ -241,6 +248,19 @@ namespace BBWY.Server.Business
StoreId = orderJToken.Value<string>("storeId") StoreId = orderJToken.Value<string>("storeId")
}; };
if (memoryCache.TryGetValue(orderId, out sDCalculationCostRequest))
{
dbOrder.StorageType = Enums.StorageType.SD;
dbOrder.SDType = sDCalculationCostRequest.SDType;
dbOrder.Flag = sDCalculationCostRequest.Flag;
if (!string.IsNullOrEmpty(sDCalculationCostRequest.VenderRemark))
dbOrder.VenderRemark = sDCalculationCostRequest.VenderRemark;
dbOrder.SDKey = sDCalculationCostRequest.SDKey;
dbOrder.SDPayBillNo = sDCalculationCostRequest.SDPayBillNo;
dbOrder.SDOperator = sDCalculationCostRequest.SDOperator;
dbOrder.SDPayChannel = sDCalculationCostRequest.SDPayChannel;
}
if (dbOrder.StoreOrder.Contains("京仓")) if (dbOrder.StoreOrder.Contains("京仓"))
dbOrder.StorageType = Enums.StorageType.; dbOrder.StorageType = Enums.StorageType.;
else if (dbOrder.StoreOrder.Contains("云仓")) else if (dbOrder.StoreOrder.Contains("云仓"))
@ -401,7 +421,6 @@ namespace BBWY.Server.Business
#region 扣减库存, 计算成本 #region 扣减库存, 计算成本
if (dbOrder.StorageType != null && if (dbOrder.StorageType != null &&
dbOrder.StorageType != Enums.StorageType.SD &&
dbOrder.StorageType != Enums.StorageType. && dbOrder.StorageType != Enums.StorageType. &&
orderState != null && orderState != null &&
orderState != Enums.OrderState. && orderState != Enums.OrderState. &&
@ -410,8 +429,26 @@ namespace BBWY.Server.Business
var orderCost = dbOrderCostList.FirstOrDefault(oc => oc.OrderId == dbOrder.Id); var orderCost = dbOrderCostList.FirstOrDefault(oc => oc.OrderId == dbOrder.Id);
if (orderCost == null) if (orderCost == null)
{ {
//再查询一次数据库,以防同步开始执行后被人为操作扣减库存,造成重复扣减库存 if (isNewOrder && dbOrder.StorageType == Enums.StorageType.SD && sDCalculationCostRequest != null)
if (!fsql.Select<OrderCost>(dbOrder.Id).Any()) {
//检查SD埋点
if (sDCalculationCostRequest.PlatformCommissionRatio == 0M)
sDCalculationCostRequest.PlatformCommissionRatio = 0.05M;
orderCost = new OrderCost()
{
OrderId = sDCalculationCostRequest.OrderId,
PlatformCommissionRatio = sDCalculationCostRequest.PlatformCommissionRatio,
PreferentialAmount = dbOrder.PreferentialAmount,
Profit = 0,
DeliveryExpressFreight = sDCalculationCostRequest.DeliveryExpressFreight,
CreateTime = DateTime.Now,
IsManualEdited = true,
SDCommissionAmount = sDCalculationCostRequest.SDCommissionAmount
};
orderCost.CalculationSDOrderProfitAndCost(dbOrder, null);
insertOrderCostList.Add(orderCost);
}
else if (!fsql.Select<OrderCost>(dbOrder.Id).Any()) //再查询一次数据库,以防同步开始执行后被人为操作扣减库存,造成重复扣减库存
{ {
var orderSkuJArray = orderJToken["itemInfoList"].Where(skuJToken => skuJToken.Value<decimal>("jdPrice") != 0M); var orderSkuJArray = orderJToken["itemInfoList"].Where(skuJToken => skuJToken.Value<decimal>("jdPrice") != 0M);
if (orderSkuJArray != null && orderSkuJArray.Count() > 0) if (orderSkuJArray != null && orderSkuJArray.Count() > 0)
@ -491,12 +528,13 @@ namespace BBWY.Server.Business
DeliveryExpressFreight = orderDeliveryExpressFreight, DeliveryExpressFreight = orderDeliveryExpressFreight,
CreateTime = DateTime.Now CreateTime = DateTime.Now
}; };
orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio; orderCost.CalculationOrderProfitAndCost(dbOrder, null);
orderCost.Profit = dbOrder.OrderSellerPrice + //orderCost.PlatformCommissionAmount = dbOrder.OrderSellerPrice * orderCost.PlatformCommissionRatio;
dbOrder.FreightPrice - //orderCost.Profit = dbOrder.OrderSellerPrice +
orderCost.PurchaseAmount - // dbOrder.FreightPrice -
orderCost.DeliveryExpressFreight - // orderCost.PurchaseAmount -
orderCost.PlatformCommissionAmount; // orderCost.DeliveryExpressFreight -
// orderCost.PlatformCommissionAmount;
insertOrderCostList.Add(orderCost); insertOrderCostList.Add(orderCost);
#endregion #endregion
} }
@ -526,6 +564,16 @@ namespace BBWY.Server.Business
updateOrderList.Add(updateSql); updateOrderList.Add(updateSql);
} }
#endregion #endregion
#region 删除SD埋点
try
{
if (sDCalculationCostRequest != null)
memoryCache.Remove(orderId);
}
catch { }
#endregion
} }
#region 补齐sku logo #region 补齐sku logo

Loading…
Cancel
Save