From 99efe9471cc39e4dbce9764b6d51426e7edebd2a Mon Sep 17 00:00:00 2001
From: shanj <18996038927@163.com>
Date: Mon, 17 Apr 2023 01:02:00 +0800
Subject: [PATCH] 1
---
.../Client/Base/PP_PlatformClient.cs | 11 +++
.../Client/Impl/PP_1688Client.cs | 81 +++++++++++++++++++
.../Request/Order/PP_CreateOrderRequest.cs | 21 +++++
.../Response/Order/PP_CreateOrderResponse.cs | 20 +++++
.../PurchasePlatform/PurchasePlatformSDK.cs | 12 ---
5 files changed, 133 insertions(+), 12 deletions(-)
create mode 100644 SDKAdapter/PurchasePlatform/Models/Request/Order/PP_CreateOrderRequest.cs
create mode 100644 SDKAdapter/PurchasePlatform/Models/Response/Order/PP_CreateOrderResponse.cs
delete mode 100644 SDKAdapter/PurchasePlatform/PurchasePlatformSDK.cs
diff --git a/SDKAdapter/PurchasePlatform/Client/Base/PP_PlatformClient.cs b/SDKAdapter/PurchasePlatform/Client/Base/PP_PlatformClient.cs
index eb92d37..d9cad26 100644
--- a/SDKAdapter/PurchasePlatform/Client/Base/PP_PlatformClient.cs
+++ b/SDKAdapter/PurchasePlatform/Client/Base/PP_PlatformClient.cs
@@ -24,5 +24,16 @@ namespace SDKAdapter.PurchasePlatform.Client
{
throw new NotImplementedException();
}
+
+ ///
+ /// 创建订单
+ ///
+ ///
+ ///
+ ///
+ public virtual PP_CreateOrderResponse CreateOrder(PP_CreateOrderRequest request)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/SDKAdapter/PurchasePlatform/Client/Impl/PP_1688Client.cs b/SDKAdapter/PurchasePlatform/Client/Impl/PP_1688Client.cs
index 8c2f404..6fe3495 100644
--- a/SDKAdapter/PurchasePlatform/Client/Impl/PP_1688Client.cs
+++ b/SDKAdapter/PurchasePlatform/Client/Impl/PP_1688Client.cs
@@ -4,6 +4,7 @@ using com.alibaba.openapi.client.entity;
using com.alibaba.openapi.client.policy;
using Newtonsoft.Json.Linq;
using SDKAdapter.PurchasePlatform.Models;
+using System.Text;
namespace SDKAdapter.PurchasePlatform.Client
{
@@ -103,6 +104,7 @@ namespace SDKAdapter.PurchasePlatform.Client
FreightAmount = orderPreviewResuslt.Sum(jt => jt.Value("sumCarriage")) / 100M,
ProductAmount = orderPreviewResuslt.Sum(jt => jt.Value("sumPaymentNoCarriage")) / 100M,
TotalAmount = orderPreviewResuslt.Sum(jt => jt.Value("sumPayment")) / 100M,
+ Extensions = intersectTradeModeList.FirstOrDefault().Value("tradeType")
//OrderTradeType = new OrderTradeTypeResponse()
//{
// Code = intersectTradeModeList.First().Value("tradeType"),
@@ -110,6 +112,85 @@ namespace SDKAdapter.PurchasePlatform.Client
//}
};
}
+
+ public override PP_CreateOrderResponse CreateOrder(PP_CreateOrderRequest request)
+ {
+ var client = GetSyncAPIClient(request.AppKey, request.AppSecret);
+ RequestPolicy reqPolicy = new RequestPolicy();
+ reqPolicy.HttpMethod = "POST";
+ reqPolicy.NeedAuthorization = false;
+ reqPolicy.RequestSendTimestamp = false;
+ reqPolicy.UseHttps = false;
+ reqPolicy.UseSignture = true;
+ reqPolicy.AccessPrivateApi = false;
+
+ Request _request = new Request();
+ APIId apiId = new APIId
+ {
+ Name = "alibaba.trade.fastCreateOrder",
+ NamespaceValue = "com.alibaba.trade",
+ Version = 1
+ };
+ _request.ApiId = apiId;
+
+ var param = new
+ {
+ flow = request.PurchaseMode == AdapterEnums.PurchaseMode.批发 ? "general" : "saleproxy",
+ message = request.Remark,
+ addressParam = new
+ {
+ fullName = request.Consignee.ContactName,
+ mobile = request.Consignee.Mobile,
+ phone = request.Consignee.Mobile,
+ cityText = request.Consignee.City,
+ provinceText = request.Consignee.Province,
+ areaText = request.Consignee.County,
+ townText = request.Consignee.Town,
+ address = request.Consignee.Address
+ },
+ cargoParamList = request.OrderProductParamList.Select(cargo => new
+ {
+ offerId = long.Parse(cargo.ProductId),
+ specId = cargo.SpecId,
+ quantity = cargo.Quantity
+ }),
+ tradeType = request.Extensions
+ };
+
+ _request.RequestEntity = param;
+ if (!string.IsNullOrEmpty(request.AppToken))
+ _request.AccessToken = request.AppToken;
+ var result = client.NewRequest(_request, reqPolicy);
+ if (result.Value("success") != true)
+ {
+ throw new Exception(result.ToString());
+ }
+
+ var totalSuccessAmount = result["result"].Value("totalSuccessAmount") / 100M; //采购单总金额,单位分
+ var purchaseOrderId = result["result"].Value("orderId"); //采购单号
+ var postFee = result["result"].Value("postFee") / 100M; //采购单运费,单位分
+ var purchaseAmount = totalSuccessAmount - postFee; //采购成本
+
+ var failedOfferJArray = result["failedOfferList"] != null ? (JArray)result["failedOfferList"] : null;
+ //if (failedOfferJArray != null)
+ //{
+ // var failOrderStringBuilder = new StringBuilder();
+ // foreach (var failedOfferJToken in failedOfferJArray)
+ // failOrderStringBuilder.AppendLine(failedOfferJToken.ToString());
+ // var ex = new Exception(failOrderStringBuilder.ToString());
+ // nLogManager.Default().Error(ex, $"下单部分商品失败 采购单Id{purchaseOrderId} 请求参数{JsonConvert.SerializeObject(request)}");
+ //}
+
+ return new PP_CreateOrderResponse()
+ {
+ TotalAmount = totalSuccessAmount,
+ ProductAmount = purchaseAmount,
+ FreightAmount = postFee,
+ OrderId = purchaseOrderId,
+ IsPay = false,
+ FailProductMessageList = failedOfferJArray == null ? null : failedOfferJArray.Select(failedOfferJToken => failedOfferJToken.ToString()).ToList()
+ };
+ }
}
public class _1688TradeTypeCompare : IEqualityComparer
diff --git a/SDKAdapter/PurchasePlatform/Models/Request/Order/PP_CreateOrderRequest.cs b/SDKAdapter/PurchasePlatform/Models/Request/Order/PP_CreateOrderRequest.cs
new file mode 100644
index 0000000..ebf03a8
--- /dev/null
+++ b/SDKAdapter/PurchasePlatform/Models/Request/Order/PP_CreateOrderRequest.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SDKAdapter.PurchasePlatform.Models
+{
+ public class PP_CreateOrderRequest : PP_PreviewOrderRequest
+ {
+ ///
+ /// 下单备注
+ ///
+ public string Remark { get; set; }
+
+ ///
+ /// 扩展数据
+ ///
+ public string Extensions { get; set; }
+ }
+}
diff --git a/SDKAdapter/PurchasePlatform/Models/Response/Order/PP_CreateOrderResponse.cs b/SDKAdapter/PurchasePlatform/Models/Response/Order/PP_CreateOrderResponse.cs
new file mode 100644
index 0000000..f68399b
--- /dev/null
+++ b/SDKAdapter/PurchasePlatform/Models/Response/Order/PP_CreateOrderResponse.cs
@@ -0,0 +1,20 @@
+namespace SDKAdapter.PurchasePlatform.Models
+{
+ public class PP_CreateOrderResponse : PP_PreviewOrderResponse
+ {
+ ///
+ /// 订单Id
+ ///
+ public string OrderId { get; set; }
+
+ ///
+ /// 是否支付
+ ///
+ public bool IsPay { get; set; }
+
+ ///
+ /// 下单失败的商品信息
+ ///
+ public IList FailProductMessageList { get; set; }
+ }
+}
diff --git a/SDKAdapter/PurchasePlatform/PurchasePlatformSDK.cs b/SDKAdapter/PurchasePlatform/PurchasePlatformSDK.cs
deleted file mode 100644
index 6cdf9d7..0000000
--- a/SDKAdapter/PurchasePlatform/PurchasePlatformSDK.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SDKAdapter.PurchasePlatform
-{
- internal class PurchasePlatformSDK
- {
- }
-}