|
|
|
using BBWY.Common.Http;
|
|
|
|
using BBWY.Common.Models;
|
|
|
|
using BBWY.Server.Model;
|
|
|
|
using BBWY.Server.Model.Dto;
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using QuanTan.SDK.Client;
|
|
|
|
using QuanTan.SDK.Model;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
namespace BBWY.Server.Business
|
|
|
|
{
|
|
|
|
public class QuanTanBusiness : PlatformSDKBusiness
|
|
|
|
{
|
|
|
|
public override Enums.Platform Platform => Enums.Platform.拳探;
|
|
|
|
private QuanTanOrderClient quanTanOrderClient;
|
|
|
|
|
|
|
|
public QuanTanBusiness(IMemoryCache memoryCache, NLogManager nLogManager, RestApiService restApiService) : base(memoryCache, nLogManager)
|
|
|
|
{
|
|
|
|
this.quanTanOrderClient = new QuanTanOrderClient(restApiService);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override PreviewOrderResponse PreviewOrder(PreviewOrderReuqest previewOrderReuqest)
|
|
|
|
{
|
|
|
|
var quantanPreviewOrderRequest = new QuanTanPreviewOrderRequest()
|
|
|
|
{
|
|
|
|
clientOrderId = "",
|
|
|
|
userAccount = previewOrderReuqest.AppToken,
|
|
|
|
receipt = new QuanTanPreviewOrderReceipt()
|
|
|
|
{
|
|
|
|
province = previewOrderReuqest.Consignee.Province,
|
|
|
|
city = previewOrderReuqest.Consignee.City,
|
|
|
|
area = previewOrderReuqest.Consignee.County,
|
|
|
|
town = previewOrderReuqest.Consignee.Town,
|
|
|
|
address = previewOrderReuqest.Consignee.Address,
|
|
|
|
phone = previewOrderReuqest.Consignee.Mobile,
|
|
|
|
realName = previewOrderReuqest.Consignee.ContactName
|
|
|
|
},
|
|
|
|
buyInfo = previewOrderReuqest.CargoParamList.Select(p => new QuanTanPreviewOrderProduct()
|
|
|
|
{
|
|
|
|
productId = p.ProductId,
|
|
|
|
productSku = p.SkuId,
|
|
|
|
quantity = p.Quantity
|
|
|
|
}).ToList()
|
|
|
|
};
|
|
|
|
|
|
|
|
var qtResponse = quanTanOrderClient.PreviewOrder(quantanPreviewOrderRequest, previewOrderReuqest.AppKey, previewOrderReuqest.AppSecret);
|
|
|
|
if (qtResponse.Status != 200)
|
|
|
|
throw new BusinessException(qtResponse.Message);
|
|
|
|
|
|
|
|
return new PreviewOrderResponse()
|
|
|
|
{
|
|
|
|
TotalAmount = qtResponse.Data.TotalPrice,
|
|
|
|
FreightAmount = qtResponse.Data.PostagePrice,
|
|
|
|
ProductAmount = qtResponse.Data.ProductPrice,
|
|
|
|
Extensions = qtResponse.Data.CartIds
|
|
|
|
//OrderTradeType= new OrderTradeTypeResponse()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override CreateOnlinePurchaseOrderResponse FastCreateOrder(CreateOnlinePurchaseOrderRequest createOnlinePurchaseOrderRequest)
|
|
|
|
{
|
|
|
|
var quantanCreateOrderRequest = new QuanTanCreateOrderRequest()
|
|
|
|
{
|
|
|
|
clientOrderId = createOnlinePurchaseOrderRequest.OrderId,
|
|
|
|
userAccount = createOnlinePurchaseOrderRequest.AppToken,
|
|
|
|
cartIds = createOnlinePurchaseOrderRequest.Extensions,
|
|
|
|
receipt = new QuanTanCreateOrderReceipt()
|
|
|
|
{
|
|
|
|
province = createOnlinePurchaseOrderRequest.Consignee.Province,
|
|
|
|
city = createOnlinePurchaseOrderRequest.Consignee.City,
|
|
|
|
area = createOnlinePurchaseOrderRequest.Consignee.County,
|
|
|
|
town = createOnlinePurchaseOrderRequest.Consignee.Town,
|
|
|
|
address = createOnlinePurchaseOrderRequest.Consignee.Address,
|
|
|
|
phone = createOnlinePurchaseOrderRequest.Consignee.Mobile,
|
|
|
|
realName = createOnlinePurchaseOrderRequest.Consignee.ContactName
|
|
|
|
},
|
|
|
|
extended = JsonConvert.SerializeObject(new
|
|
|
|
{
|
|
|
|
BuyerAccount = createOnlinePurchaseOrderRequest.AppToken,
|
|
|
|
createOnlinePurchaseOrderRequest.SourceSku,
|
|
|
|
createOnlinePurchaseOrderRequest.SourceShopName
|
|
|
|
})
|
|
|
|
};
|
|
|
|
var qtResponse = quanTanOrderClient.CreateOrder(quantanCreateOrderRequest, createOnlinePurchaseOrderRequest.AppKey, createOnlinePurchaseOrderRequest.AppSecret);
|
|
|
|
if (qtResponse.Status != 200)
|
|
|
|
throw new BusinessException(qtResponse.Message);
|
|
|
|
|
|
|
|
var payStatus = !string.IsNullOrEmpty(qtResponse.Data.PayStatus) ? qtResponse.Data.PayStatus.ToLower() : string.Empty;
|
|
|
|
//if (payStatus != "success")
|
|
|
|
// throw new BusinessException($"拳探账户余额不足,支付失败,请前往拳探进行手动支付");
|
|
|
|
|
|
|
|
|
|
|
|
return new CreateOnlinePurchaseOrderResponse()
|
|
|
|
{
|
|
|
|
PurchaseOrderId = qtResponse.Data.OrderId,
|
|
|
|
IsPay = payStatus == "success"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override OnlinePurchaseOrderSimpleResponse GetOrderSimpleInfo(GetOrderInfoRequest getOrderInfoRequest)
|
|
|
|
{
|
|
|
|
var qtResponse = quanTanOrderClient.GetOrderDetail(new QuanTanGetOrderDetailRequest()
|
|
|
|
{
|
|
|
|
orderId = getOrderInfoRequest.OrderId,
|
|
|
|
userAccount = getOrderInfoRequest.AppToken
|
|
|
|
}, getOrderInfoRequest.AppKey, getOrderInfoRequest.AppSecret);
|
|
|
|
if (qtResponse.Status != 200)
|
|
|
|
throw new BusinessException($"获取订单详情失败{getOrderInfoRequest.OrderId},{qtResponse.Message}");
|
|
|
|
return new OnlinePurchaseOrderSimpleResponse()
|
|
|
|
{
|
|
|
|
PurchaseOrderId = getOrderInfoRequest.OrderId,
|
|
|
|
FreightAmount = qtResponse.Data.TotalPostage,
|
|
|
|
ProductAmount = qtResponse.Data.ProductPrice,
|
|
|
|
TotalAmount = qtResponse.Data.TotalPrice,
|
|
|
|
ItemList = qtResponse.Data.OrderProduct.Select(o => new OnlinePurchaseOrderSkuSimpleResponse()
|
|
|
|
{
|
|
|
|
ProductAmount = o.ProductPrice,
|
|
|
|
Price = o.Price,
|
|
|
|
ProductId = o.ProductId,
|
|
|
|
SkuId = o.ProductSku,
|
|
|
|
Quantity = o.Quantity
|
|
|
|
}).ToList()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|