Browse Source

1.在1688改价通知对接拳探改价做平价处理

2.新增拳探商品改价接口
yijia
shanji 2 years ago
parent
commit
25795b92e4
  1. 10
      BBWYB.Server.API/Controllers/ProductController.cs
  2. 8
      BBWYB.Server.API/appsettings.json
  3. 5
      BBWYB.Server.Business/Product/ProductBusiness.cs
  4. 95
      BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
  5. 5
      QuanTan.SDK/Client/Supplier/QuanTan_Supplier_ProductClient.cs
  6. 18
      QuanTan.SDK/Models/Supplier/Request/Product/QuanTan_Supplier_EditProductPriceRequest.cs
  7. 5
      SDKAdapter/OperationPlatform/Client/Base/OP_PlatformClient.cs
  8. 16
      SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs
  9. 16
      SDKAdapter/OperationPlatform/Models/Request/Product/OP_EditProductPriceRequest.cs

10
BBWYB.Server.API/Controllers/ProductController.cs

@ -33,5 +33,15 @@ namespace BBWYB.Server.API.Controllers
{ {
return productBusiness.GetProductSkuList(request); return productBusiness.GetProductSkuList(request);
} }
/// <summary>
/// 修改商品价格
/// </summary>
/// <param name="request"></param>
[HttpPost]
public void EditProductPrice([FromBody] OP_EditProductPriceRequest request)
{
productBusiness.EditProductPrice(request);
}
} }
} }

8
BBWYB.Server.API/appsettings.json

@ -15,9 +15,9 @@
"AllowedSwagger": true, "AllowedSwagger": true,
"Secret": "D96BFA5B-F2AF-45BC-9342-5A55C3F9BBB0", "Secret": "D96BFA5B-F2AF-45BC-9342-5A55C3F9BBB0",
"ApiVersionRequirements": [ "ApiVersionRequirements": [
{ //{
"Api": "/api/purchaseOrder/createpurchaseorder", // "Api": "/api/purchaseOrder/createpurchaseorder",
"MinimumVersion": 10017 // "MinimumVersion": 10017
} //}
] ]
} }

5
BBWYB.Server.Business/Product/ProductBusiness.cs

@ -24,5 +24,10 @@ namespace BBWYB.Server.Business
{ {
return opPlatformClientFactory.GetClient(request.Platform).GetProductSkuList(request); return opPlatformClientFactory.GetClient(request.Platform).GetProductSkuList(request);
} }
public void EditProductPrice(OP_EditProductPriceRequest request)
{
opPlatformClientFactory.GetClient(request.Platform).EditProductPrice(request);
}
} }
} }

95
BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs

@ -14,6 +14,8 @@ using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SDKAdapter; using SDKAdapter;
using SDKAdapter.OperationPlatform.Client;
using SDKAdapter.OperationPlatform.Models;
using SDKAdapter.PurchasePlatform.Client; using SDKAdapter.PurchasePlatform.Client;
using SDKAdapter.PurchasePlatform.Models; using SDKAdapter.PurchasePlatform.Models;
using System.Text; using System.Text;
@ -32,6 +34,7 @@ namespace BBWYB.Server.Business
private Lazy<QiKuManager> qiKuManagerLazy; private Lazy<QiKuManager> qiKuManagerLazy;
private Lazy<RestApiService> restApiServiceLazy; private Lazy<RestApiService> restApiServiceLazy;
private Lazy<JDBusiness> jdBusinessLazy; private Lazy<JDBusiness> jdBusinessLazy;
private Lazy<OP_PlatformClientFactory> opPlatformClientFactoryLazy;
private PP_PlatformClientFactory ppPlatformClientFactory => pplatformClientFactoryLazy.Value; private PP_PlatformClientFactory ppPlatformClientFactory => pplatformClientFactoryLazy.Value;
private TaskSchedulerManager taskSchedulerManager => taskSchedulerManagerLazy.Value; private TaskSchedulerManager taskSchedulerManager => taskSchedulerManagerLazy.Value;
@ -41,6 +44,7 @@ namespace BBWYB.Server.Business
private DingDingBusiness dingDingBusiness => dingDingBusinessLazy.Value; private DingDingBusiness dingDingBusiness => dingDingBusinessLazy.Value;
private QiKuManager qiKuManager => qiKuManagerLazy.Value; private QiKuManager qiKuManager => qiKuManagerLazy.Value;
private RestApiService restApiService => restApiServiceLazy.Value; private RestApiService restApiService => restApiServiceLazy.Value;
private OP_PlatformClientFactory opPlatformClientFactory => opPlatformClientFactoryLazy.Value;
private JDBusiness jdBusiness => jdBusinessLazy.Value; private JDBusiness jdBusiness => jdBusinessLazy.Value;
@ -60,6 +64,8 @@ namespace BBWYB.Server.Business
qiKuManagerLazy = new Lazy<QiKuManager>(() => serviceProvider.GetService<QiKuManager>()); qiKuManagerLazy = new Lazy<QiKuManager>(() => serviceProvider.GetService<QiKuManager>());
restApiServiceLazy = new Lazy<RestApiService>(() => serviceProvider.GetService<RestApiService>()); restApiServiceLazy = new Lazy<RestApiService>(() => serviceProvider.GetService<RestApiService>());
jdBusinessLazy = new Lazy<JDBusiness>(() => serviceProvider.GetService<JDBusiness>()); jdBusinessLazy = new Lazy<JDBusiness>(() => serviceProvider.GetService<JDBusiness>());
opPlatformClientFactoryLazy = new Lazy<OP_PlatformClientFactory>(() => serviceProvider.GetService<OP_PlatformClientFactory>());
cantPurchaseOrderStateList = new List<Enums.OrderState>() cantPurchaseOrderStateList = new List<Enums.OrderState>()
{ {
Enums.OrderState., Enums.OrderState.,
@ -2369,8 +2375,7 @@ namespace BBWYB.Server.Business
/// <param name="callbackPlatform"></param> /// <param name="callbackPlatform"></param>
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform) private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform)
{ {
string currentProgress = string.Empty; bool isEditOrderPrice = true;
try try
{ {
var orderPurchaseInfo = fsql.Select<OrderPurchaseInfo>().Where(opi => opi.PurchaseOrderId == purchaseOrderId).ToOne(); var orderPurchaseInfo = fsql.Select<OrderPurchaseInfo>().Where(opi => opi.PurchaseOrderId == purchaseOrderId).ToOne();
@ -2386,6 +2391,8 @@ namespace BBWYB.Server.Business
if (dbOrderCost == null) if (dbOrderCost == null)
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的成本"); throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的成本");
var shop = fsqlManager.MDSfsql.Select<Shops>().Where(s => s.ShopId == dbOrder.ShopId.ToString()).ToOne();
var dbOrderCostDetails = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == dbOrder.Id && ocd.IsEnabled == true).ToList(); var dbOrderCostDetails = fsql.Select<OrderCostDetail>().Where(ocd => ocd.OrderId == dbOrder.Id && ocd.IsEnabled == true).ToList();
if (dbOrderCostDetails.Count() == 0) if (dbOrderCostDetails.Count() == 0)
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的明细成本"); throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的明细成本");
@ -2395,23 +2402,34 @@ namespace BBWYB.Server.Business
if (dbOrderPurchaseInfoList.Count() == 0) if (dbOrderPurchaseInfoList.Count() == 0)
throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的采购单集合"); throw new Exception($"采购单{purchaseOrderId}-未查询到订单{orderPurchaseInfo.OrderId}的采购单集合");
isEditOrderPrice = dbOrderPurchaseInfoList.Count() == dbOrderPurchaseInfoList.Count(opi => opi.PurchasePlatform == Enums.Platform. &&
opi.PurchaseMethod == Enums.PurchaseMethod.线);
var dbPurchaseOrderIdList = dbOrderPurchaseInfoList.Select(x => x.PurchaseOrderId).ToList(); var dbPurchaseOrderIdList = dbOrderPurchaseInfoList.Select(x => x.PurchaseOrderId).ToList();
var dbOrderPurchaseRelationInfos = fsql.Select<OrderPurchaseRelationInfo>().Where(x => dbPurchaseOrderIdList.Contains(x.PurchaseOrderId)).ToList(); var dbOrderPurchaseRelationInfos = fsql.Select<OrderPurchaseRelationInfo>().Where(x => dbPurchaseOrderIdList.Contains(x.PurchaseOrderId)).ToList();
if (dbOrderPurchaseRelationInfos.Count() == 0) if (dbOrderPurchaseRelationInfos.Count() == 0)
throw new Exception($"采购单{purchaseOrderId}-未查询到采购单关联明细,手动关联的采购单不支持改价"); throw new Exception($"采购单{purchaseOrderId}-未查询到采购单关联明细");
var dbOrderSkus = fsql.Select<OrderSku>().Where(osku => osku.OrderId == orderPurchaseInfo.OrderId).ToList(); var dbOrderSkus = fsql.Select<OrderSku>().Where(osku => osku.OrderId == orderPurchaseInfo.OrderId).ToList();
List<IUpdate<OrderCostDetail>> updateOrderCostDetailList = new List<IUpdate<OrderCostDetail>>(); List<IUpdate<OrderCostDetail>> updateOrderCostDetailList = new List<IUpdate<OrderCostDetail>>();
IUpdate<OrderCost> updateOrderCost = null; IUpdate<OrderCost> updateOrderCost = null;
var client = ppPlatformClientFactory.GetClient(AdapterEnums.PlatformType.); IList<IUpdate<OrderSku>> updateOrderSkuList = new List<IUpdate<OrderSku>>();
IUpdate<Order> updateOrder = null;
IList<OP_EditPriceSkuRequest> op_EditPriceSkuRequests = new List<OP_EditPriceSkuRequest>();
var ppclient = ppPlatformClientFactory.GetClient(AdapterEnums.PlatformType.);
var totalPurchaseProductAmount = 0M; var totalPurchaseProductAmount = 0M;
var totalPurchaseFreight = 0M; var totalPurchaseFreight = 0M;
foreach (var opi in dbOrderPurchaseInfoList) foreach (var opi in dbOrderPurchaseInfoList)
{ {
var purchaseOrderSimpleInfo = client.QueryOrderDetail(new PP_QueryOrderDetailRequest() if (opi.PurchasePlatform != Enums.Platform.)
continue;
var purchaseOrderSimpleInfo = ppclient.QueryOrderDetail(new PP_QueryOrderDetailRequest()
{ {
AppKey = purchaseAccount.AppKey, AppKey = purchaseAccount.AppKey,
AppSecret = purchaseAccount.AppSecret, AppSecret = purchaseAccount.AppSecret,
@ -2429,6 +2447,7 @@ namespace BBWYB.Server.Business
foreach (var belongSkuGroup in belongSkuGroups) foreach (var belongSkuGroup in belongSkuGroups)
{ {
var belongSkuId = belongSkuGroup.Key; var belongSkuId = belongSkuGroup.Key;
var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
var currentOrderSkuProductAmount = 0M; //采购成本 var currentOrderSkuProductAmount = 0M; //采购成本
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和 var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
@ -2444,12 +2463,26 @@ namespace BBWYB.Server.Business
currentOrderSkuProductAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity.Value / currentPurchaseSkuTotalQuantity); currentOrderSkuProductAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity.Value / currentPurchaseSkuTotalQuantity);
} }
var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == belongSkuId); #region 订单sku平价
var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId); var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId);
//dbOrderSkuDetail.SkuAmount = currentOrderSkuProductAmount; if (isEditOrderPrice)
//dbOrderSkuDetail.PurchaseFreight = currentOrderSkuFreightAmount; {
//dbOrderSkuDetail.TotalCost = currentOrderSkuProductAmount + currentOrderSkuFreightAmount; orderSku.Price = currentOrderSkuProductAmount / orderSku.ItemTotal;
orderSku.BuyerPayFreight = currentPurchaseFreight;
op_EditPriceSkuRequests.Add(new OP_EditPriceSkuRequest()
{
Freight = currentPurchaseFreight ?? 0M,
InPackAmountPrice = orderSku.InPackAmount ?? 0M,
OrderSkuId = orderSku.Id.ToString(),
Price = orderSku.Price ?? 0M,
SkuId = orderSku.SkuId
});
updateOrderSkuList.Add(fsql.Update<OrderSku>(orderSku.Id).Set(osku => osku.Price, orderSku.Price)
.Set(osku => osku.BuyerPayFreight, orderSku.BuyerPayFreight));
}
#endregion
var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == belongSkuId && ocd.PurchaseOrderId == opi.PurchaseOrderId);
dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(orderSku.Price.Value * orderSku.ItemTotal.Value, dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(orderSku.Price.Value * orderSku.ItemTotal.Value,
orderSku.BuyerPayFreight ?? 0M, orderSku.BuyerPayFreight ?? 0M,
orderSku.InPackAmount ?? 0M, orderSku.InPackAmount ?? 0M,
@ -2459,12 +2492,16 @@ namespace BBWYB.Server.Business
dbOrderSkuDetail.DeliveryExpressFreight ?? 0M); dbOrderSkuDetail.DeliveryExpressFreight ?? 0M);
updateOrderCostDetailList.Add(fsql.Update<OrderCostDetail>().SetSource(dbOrderSkuDetail)); updateOrderCostDetailList.Add(fsql.Update<OrderCostDetail>().SetSource(dbOrderSkuDetail));
} }
}
//dbOrderCost.TotalCost = dbOrderCost.PurchaseAmount = totalPurchaseAmount; if (isEditOrderPrice)
//dbOrderCost.Profit = dbOrder.OrderTotalPrice - {
// dbOrderCost.PurchaseAmount - dbOrder.OrderTotalPrice = totalPurchaseProductAmount + totalPurchaseFreight;
// dbOrderCost.DeliveryExpressFreight; dbOrder.OrderSellerPrice = totalPurchaseProductAmount;
dbOrder.FreightPrice = totalPurchaseFreight;
updateOrder = fsql.Update<Order>(dbOrder.Id).Set(o => o.OrderTotalPrice, dbOrder.OrderTotalPrice)
.Set(o => o.OrderSellerPrice, dbOrder.OrderSellerPrice)
.Set(o => o.FreightPrice, dbOrder.FreightPrice);
}
dbOrderCost.CalculationOrderCostCostAndProfit(dbOrder.OrderTotalPrice ?? 0M, dbOrderCost.CalculationOrderCostCostAndProfit(dbOrder.OrderTotalPrice ?? 0M,
totalPurchaseProductAmount, totalPurchaseProductAmount,
@ -2478,12 +2515,38 @@ namespace BBWYB.Server.Business
foreach (var update in updateOrderCostDetailList) foreach (var update in updateOrderCostDetailList)
update.ExecuteAffrows(); update.ExecuteAffrows();
updateOrderCost?.ExecuteAffrows(); updateOrderCost?.ExecuteAffrows();
foreach (var update in updateOrderSkuList)
update.ExecuteAffrows();
updateOrder?.ExecuteAffrows();
}); });
if (isEditOrderPrice)
{
#region 通知拳探改价
var opclient = opPlatformClientFactory.GetClient(AdapterEnums.PlatformType.);
opclient.EditPrice(new OP_EditPriceRequest()
{
AppKey = shop.AppKey,
AppSecret = shop.AppSecret,
AppToken = shop.AppToken,
OrderId = dbOrder.Id,
EditItems = op_EditPriceSkuRequests
});
#endregion
#region 通知C端改价
restApiService.SendRequest("https://bbwy.qiyue666.com",
"/Api/PurchaseOrder/QuanTanEditPriceCallback",
new { orderId = dbOrder.Id },
null,
HttpMethod.Post);
#endregion
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId},执行进度[{currentProgress}]"); nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 回调平台{callbackPlatform},采购单号{purchaseOrderId}");
} }
} }

5
QuanTan.SDK/Client/Supplier/QuanTan_Supplier_ProductClient.cs

@ -19,5 +19,10 @@ namespace QuanTan.SDK.Client.Supplier
{ {
return SendRequest<QuanTan_Supplier_ProductSkuListResponse>("api/platform/supply/product/list", request, appId, appSecret); return SendRequest<QuanTan_Supplier_ProductSkuListResponse>("api/platform/supply/product/list", request, appId, appSecret);
} }
public QuanTanResponse<object> EditProductPrice(QuanTan_Supplier_EditProductPriceRequest request, string appId, string appSecret)
{
return SendRequest<object>("api/platform/supply/product/price/change", request, appId, appSecret);
}
} }
} }

18
QuanTan.SDK/Models/Supplier/Request/Product/QuanTan_Supplier_EditProductPriceRequest.cs

@ -0,0 +1,18 @@
namespace QuanTan.SDK.Models.Supplier
{
public class QuanTan_Supplier_EditProductPriceRequest
{
public string productId { get; set; }
public string editAdmin { get; set; }
public IList<QuanTan_Supplier_EditProductSkuPriceRequest> skuList { get; set; }
}
public class QuanTan_Supplier_EditProductSkuPriceRequest
{
public string skuId { get; set; }
public decimal price { get; set; }
}
}

5
SDKAdapter/OperationPlatform/Client/Base/OP_PlatformClient.cs

@ -51,5 +51,10 @@ namespace SDKAdapter.OperationPlatform.Client
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual void EditProductPrice(OP_EditProductPriceRequest request)
{
throw new NotImplementedException();
}
} }
} }

16
SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs

@ -224,5 +224,21 @@ namespace SDKAdapter.OperationPlatform.Client
if (qtResponse.Status != 200) if (qtResponse.Status != 200)
throw new Exception(qtResponse.Message); throw new Exception(qtResponse.Message);
} }
public override void EditProductPrice(OP_EditProductPriceRequest request)
{
var qtResponse = supplier_ProductClient.EditProductPrice(new QuanTan_Supplier_EditProductPriceRequest()
{
productId = request.Spu,
editAdmin = request.AppToken,
skuList = request.EditSkuList.Select(x => new QuanTan_Supplier_EditProductSkuPriceRequest()
{
price = x.Price,
skuId = x.Sku
}).ToList()
}, request.AppKey, request.AppSecret);
if (qtResponse.Status != 200)
throw new Exception(qtResponse.Message);
}
} }
} }

16
SDKAdapter/OperationPlatform/Models/Request/Product/OP_EditProductPriceRequest.cs

@ -0,0 +1,16 @@
namespace SDKAdapter.OperationPlatform.Models
{
public class OP_EditProductPriceRequest : BasePlatformRequest
{
public string Spu { get; set; }
public IList<OP_EditProductSkuPriceRequest> EditSkuList { get; set; }
}
public class OP_EditProductSkuPriceRequest
{
public string Sku { get; set; }
public decimal Price { get; set; }
}
}
Loading…
Cancel
Save