Browse Source

订单同步检查SD埋点

qianyi
shanji 3 years ago
parent
commit
6b0ca05981
  1. 18
      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

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

@ -58,7 +58,7 @@ namespace BBWY.Client.ViewModels
public IList<Order> OrderList { get; set; }
public IList<AfterSaleOrder> AfterSaleOrderList { get; set; }
public IList<AfterSaleOrder> AfterSaleOrderList { get; set; }
public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } }
@ -613,11 +613,23 @@ namespace BBWY.Client.ViewModels
if (!response.Success)
{
IsLoading = false;
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "设置刷单成本"));
App.Current.Dispatcher.Invoke(() => MessageBox.Show(response.Msg, "SD成本"));
return;
}
//LoadOrder(PageIndex); //设置刷单刷新订单列表
RefreshOrder(orderId);
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);
}
});
}

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.
public void ConfigureServices(IServiceCollection services)
{
services.AddMemoryCache();
var idOption = new IdGeneratorOptions(1);
var idGenerator = new DefaultIdGenerator(idOption);
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)
{
orderCost.AfterTotalCost = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost);
orderCost.RefundAmount = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M);
orderCost.RefundPurchaseAmount = afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0);
orderCost.AfterTotalCost = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost);
orderCost.RefundAmount = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M);
orderCost.RefundPurchaseAmount = afterSaleOrders == null || afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0);
//退款之后平台扣点
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)
{
orderCost.AfterTotalCost = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost);
orderCost.RefundAmount = afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M);
orderCost.RefundPurchaseAmount = afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0);
orderCost.AfterTotalCost = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.AfterTotalCost);
orderCost.RefundAmount = afterSaleOrders == null || afterSaleOrders.Count == 0 ? 0M : afterSaleOrders.Sum(aso => aso.RefundAmount ?? 0M);
orderCost.RefundPurchaseAmount = afterSaleOrders == null || afterSaleOrders.Count == 0M ? 0M : afterSaleOrders.Sum(aso => aso.RefundPurchaseAmount ?? 0);
//退款之后平台扣点
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.Dto;
using FreeSql;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
@ -32,14 +33,19 @@ namespace BBWY.Server.Business
private Lazy<FreeSqlMultiDBManager> freeSqlMultiDBManagerLazy;
private FreeSqlMultiDBManager freeSqlMultiDBManager => freeSqlMultiDBManagerLazy.Value;
private IMemoryCache memoryCache;
private static TimeSpan sdGroupExpirationTimeSpan = TimeSpan.FromMinutes(20);
public OrderBusiness(RestApiService restApiService,
IFreeSql fsql,
IIdGenerator idGenerator,
IOptions<GlobalConfig> options,
IServiceProvider serviceProvider) : base(restApiService, options)
IServiceProvider serviceProvider,
IMemoryCache memoryCache) : base(restApiService, options)
{
this.fsql = fsql;
this.idGenerator = idGenerator;
this.memoryCache = memoryCache;
freeSqlMultiDBManagerLazy = new Lazy<FreeSqlMultiDBManager>(() => serviceProvider.GetService<FreeSqlMultiDBManager>());
productBusinessLazy = new Lazy<ProductBusiness>(() => serviceProvider.GetService<ProductBusiness>());
}
@ -645,7 +651,12 @@ namespace BBWY.Server.Business
{
var dbOrder = fsql.Select<Order>(sdCalculationCostRequest.OrderId).ToOne();
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);

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

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

Loading…
Cancel
Save