|
|
@ -17,10 +17,12 @@ namespace BBWY.Server.Business |
|
|
|
{ |
|
|
|
public override Enums.Platform Platform => Enums.Platform.阿里巴巴; |
|
|
|
private RestApiService restApiService; |
|
|
|
private _1688TradeTypeCompare _1688TradeTypeCompare; |
|
|
|
|
|
|
|
public _1688Business(IMemoryCache memoryCache, ILogger logger, RestApiService restApiService) : base(memoryCache, logger) |
|
|
|
{ |
|
|
|
this.restApiService = restApiService; |
|
|
|
_1688TradeTypeCompare = new _1688TradeTypeCompare(); |
|
|
|
} |
|
|
|
|
|
|
|
private SyncAPIClient GetSyncAPIClient(string appKey, string appSecret) |
|
|
@ -82,17 +84,51 @@ namespace BBWY.Server.Business |
|
|
|
request.AccessToken = previewOrderReuqest.AppToken; |
|
|
|
var result = client.NewRequest(request, reqPolicy); |
|
|
|
if (result.Value<bool>("success") != true) |
|
|
|
{ |
|
|
|
throw new BusinessException(result.Value<string>("errorMsg")) { Code = 0 }; |
|
|
|
} |
|
|
|
|
|
|
|
var orderPreviewResuslt = (JArray)result["orderPreviewResuslt"]; |
|
|
|
List<JToken> intersectTradeModeList = new List<JToken>(); |
|
|
|
|
|
|
|
foreach (var orderPreviewJToken in orderPreviewResuslt) |
|
|
|
{ |
|
|
|
if (orderPreviewJToken["tradeModelList"] == null) |
|
|
|
throw new BusinessException("当前交易不可通过API下单,请使用1688网页交易 [交易模式列表为空]"); |
|
|
|
var tradeModeJArray = ((JArray)orderPreviewJToken["tradeModelList"]).Where(tradeJToken => tradeJToken.Value<bool>("opSupport")); |
|
|
|
if (tradeModeJArray.Count() == 0) |
|
|
|
throw new BusinessException("当前交易不可通过API下单,请使用1688网页交易 [没有支持开放平台下单的交易模式]"); |
|
|
|
|
|
|
|
if (intersectTradeModeList.Count() == 0) |
|
|
|
intersectTradeModeList.AddRange(tradeModeJArray); |
|
|
|
else |
|
|
|
intersectTradeModeList = intersectTradeModeList.Intersect(tradeModeJArray, _1688TradeTypeCompare).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
if (intersectTradeModeList.Count() == 0) |
|
|
|
throw new BusinessException("当前交易不可通过API下单,请使用1688网页交易 [多个拆单之间没有相同的交易模式]"); |
|
|
|
return new PreviewOrderResponse() |
|
|
|
{ |
|
|
|
FreightAmount = orderPreviewResuslt.Sum(jt => jt.Value<decimal>("sumCarriage")) / 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, |
|
|
|
OrderTradeType = new OrderTradeTypeResponse() |
|
|
|
{ |
|
|
|
Code = intersectTradeModeList.First().Value<string>("tradeType"), |
|
|
|
Name = intersectTradeModeList.First().Value<string>("name"), |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class _1688TradeTypeCompare : IEqualityComparer<JToken> |
|
|
|
{ |
|
|
|
public bool Equals(JToken x, JToken y) |
|
|
|
{ |
|
|
|
return x.Value<string>("tradeType").Equals(y.Value<string>("tradeType")); |
|
|
|
} |
|
|
|
|
|
|
|
public int GetHashCode(JToken obj) |
|
|
|
{ |
|
|
|
return obj.GetHashCode(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|