Browse Source

1

updatebug
shanji 2 years ago
parent
commit
99efe9471c
  1. 11
      SDKAdapter/PurchasePlatform/Client/Base/PP_PlatformClient.cs
  2. 81
      SDKAdapter/PurchasePlatform/Client/Impl/PP_1688Client.cs
  3. 21
      SDKAdapter/PurchasePlatform/Models/Request/Order/PP_CreateOrderRequest.cs
  4. 20
      SDKAdapter/PurchasePlatform/Models/Response/Order/PP_CreateOrderResponse.cs
  5. 12
      SDKAdapter/PurchasePlatform/PurchasePlatformSDK.cs

11
SDKAdapter/PurchasePlatform/Client/Base/PP_PlatformClient.cs

@ -24,5 +24,16 @@ namespace SDKAdapter.PurchasePlatform.Client
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <summary>
/// 创建订单
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public virtual PP_CreateOrderResponse CreateOrder(PP_CreateOrderRequest request)
{
throw new NotImplementedException();
}
} }
} }

81
SDKAdapter/PurchasePlatform/Client/Impl/PP_1688Client.cs

@ -4,6 +4,7 @@ using com.alibaba.openapi.client.entity;
using com.alibaba.openapi.client.policy; using com.alibaba.openapi.client.policy;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SDKAdapter.PurchasePlatform.Models; using SDKAdapter.PurchasePlatform.Models;
using System.Text;
namespace SDKAdapter.PurchasePlatform.Client namespace SDKAdapter.PurchasePlatform.Client
{ {
@ -103,6 +104,7 @@ namespace SDKAdapter.PurchasePlatform.Client
FreightAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumCarriage")) / 100M, FreightAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumCarriage")) / 100M,
ProductAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumPaymentNoCarriage")) / 100M, ProductAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumPaymentNoCarriage")) / 100M,
TotalAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumPayment")) / 100M, TotalAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumPayment")) / 100M,
Extensions = intersectTradeModeList.FirstOrDefault().Value<string>("tradeType")
//OrderTradeType = new OrderTradeTypeResponse() //OrderTradeType = new OrderTradeTypeResponse()
//{ //{
// Code = intersectTradeModeList.First().Value<string>("tradeType"), // Code = intersectTradeModeList.First().Value<string>("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<bool>("success") != true)
{
throw new Exception(result.ToString());
}
var totalSuccessAmount = result["result"].Value<long>("totalSuccessAmount") / 100M; //采购单总金额,单位分
var purchaseOrderId = result["result"].Value<string>("orderId"); //采购单号
var postFee = result["result"].Value<long>("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<JToken> public class _1688TradeTypeCompare : IEqualityComparer<JToken>

21
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
{
/// <summary>
/// 下单备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 扩展数据
/// </summary>
public string Extensions { get; set; }
}
}

20
SDKAdapter/PurchasePlatform/Models/Response/Order/PP_CreateOrderResponse.cs

@ -0,0 +1,20 @@
namespace SDKAdapter.PurchasePlatform.Models
{
public class PP_CreateOrderResponse : PP_PreviewOrderResponse
{
/// <summary>
/// 订单Id
/// </summary>
public string OrderId { get; set; }
/// <summary>
/// 是否支付
/// </summary>
public bool IsPay { get; set; }
/// <summary>
/// 下单失败的商品信息
/// </summary>
public IList<string> FailProductMessageList { get; set; }
}
}

12
SDKAdapter/PurchasePlatform/PurchasePlatformSDK.cs

@ -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
{
}
}
Loading…
Cancel
Save