using Operater.DTO.System;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using CommonUtil;
|
using YouZanSDKStandard.Api;
|
using YouZanSDKStandard.Api.Request;
|
using AlibabaSDK.Request;
|
using Operater.DAL;
|
using Operater.DbModel;
|
using YouZanSDKStandard.Api.Domain;
|
using AlibabaSDK.Domain;
|
using System.Linq;
|
using AlibabaSDK.Api;
|
|
namespace Operater.Service.System
|
{
|
public class TradeCreateService : ITradeCreateService
|
{
|
/// <summary>
|
/// 创建1688订单
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
public TradeCreateResponse AliTradeCreate(AliTradeCreateRequest request)
|
{
|
string errMsg = "";
|
TradeCreateResponse response = new TradeCreateResponse();
|
try
|
{
|
//判断该有赞订单是否都已创建过1688订单
|
var hasOrderList = new YzOrderinfoDAL().ListGet(t => t.Tid == request.YzTradeId);
|
if (!hasOrderList.IsNull() && hasOrderList.Count > 0)
|
{
|
var rela = new TradeCreateRelationDAL().ListGet(t => t.YzTid == request.YzTradeId && t.RunStatus == 2);
|
if (!rela.IsNull() && rela.Count > 0 && rela.Count == hasOrderList.Count)
|
{
|
response.Success = false;
|
response.ErrorMsg = "此有赞订单都已创建过1688订单";
|
return response;
|
}
|
}
|
|
//调用有赞接口,获取订单详情
|
YouZanTradeDetailGetRequest yzTradereq = new YouZanTradeDetailGetRequest()
|
{
|
tid = request.YzTradeId
|
};
|
var yzTradeRsp = YouZanClient.Execute(yzTradereq, request.YzToken);
|
if (yzTradeRsp.IsNull() || !yzTradeRsp.success)
|
{
|
response.ErrorMsg = $"获取有赞订单详情失败:{(yzTradeRsp.IsNull() ? "null" : yzTradeRsp.message)}";
|
return response;
|
}
|
//批量解密
|
var decryptInfo = DecryptTrade(yzTradeRsp.data.full_order_info, request.YzToken);
|
if (decryptInfo.IsNull() || decryptInfo.ReceiverName.IsNullOrEmpty())
|
{
|
response.Success = false;
|
response.ErrorMsg = "解密失败!";
|
return response;
|
}
|
int successCount = 0;
|
|
//循环拆单信息创建订单
|
foreach (var order in yzTradeRsp.data.full_order_info.orders)
|
{
|
TradeCreateRelation recordRelation = new TradeCreateRelation()
|
{
|
RunTime = DateTime.Now
|
};
|
//判断是否存在退款行为
|
var refundRelat = new YzRefundDAL().ListGet(t => t.YzOid == order.oid).ToList();
|
if (!refundRelat.IsNull() && refundRelat.Count > 0 && refundRelat[0].YzRefundStaus != "REFUND_CANCLE")
|
{//有退款订单
|
recordRelation.RunStatus = 3;
|
recordRelation.Memo = $"该子订单有退款,不需要创建1688订单,退款单号【{refundRelat[0].RefundId}】";
|
new TradeCreateRelationDAL().Update(recordRelation, i => new { i.RunStatus, i.Memo, i.RunTime }, t => t.YzOid == order.oid);
|
response.Success = false;
|
response.ErrorMsg = $"该子订单有退款,不需要创建1688订单,退款单号【{refundRelat[0].RefundId}】";
|
|
continue;
|
}
|
|
var relaHis = new TradeCreateRelationDAL().GetById(order.oid);
|
if (!relaHis.IsNull() && relaHis.RunStatus != 0)
|
{//已创建过跳过
|
LogUtil.Info($"yz子订单{order.oid},状态:{relaHis.RunStatus},跳过", "创建订单");
|
continue;
|
}
|
TradeCreateRelation tradeCreateRelation = new TradeCreateRelation()
|
{
|
RunStatus = 1
|
};
|
new TradeCreateRelationDAL().Update(tradeCreateRelation, i => new { i.RunStatus }, t => t.YzOid == order.oid);
|
//是否有绑定关系
|
var relation = new DistributionRelationDAL().ListGet(t => t.YzProduct == order.item_id.ToString() && t.ReStatus == 1);
|
if (relation.IsNull() || relation.Count == 0)
|
{
|
errMsg += "非1688商品订单;";
|
recordRelation.RunStatus = 4;
|
recordRelation.Memo = "该商品与1688无绑定关系";
|
new TradeCreateRelationDAL().Update(recordRelation, i => new { i.RunStatus, i.Memo, i.RunTime }, t => t.YzOid == order.oid);
|
//修改有赞子订单状态
|
YzOrderinfo yzOrderinfo = new YzOrderinfo()
|
{
|
AliTradeStatus = 2
|
};
|
new YzOrderinfoDAL().Update(yzOrderinfo, i => new { i.AliTradeStatus}, t => t.Oid == order.oid);
|
continue;
|
}
|
AliCreateTradeResponse createRsp = new AliCreateTradeResponse();
|
CreateTradeReqGetResponse preResponse = new CreateTradeReqGetResponse();
|
if (relation[0].ProSource == 0)
|
{//精选货源
|
createRsp = CreateTradeJx(decryptInfo, yzTradeRsp.data, order, relation, request, yzTradeRsp.data.full_order_info.pay_info.post_fee);
|
|
}
|
else
|
{//代发
|
createRsp = CreateTradeDf(decryptInfo, yzTradeRsp.data, order, relation, request, yzTradeRsp.data.full_order_info.pay_info.post_fee);
|
}
|
if (!createRsp.Success)
|
{
|
recordRelation.RunStatus = 3;
|
recordRelation.Memo = createRsp.ErrorMsg;
|
new TradeCreateRelationDAL().Update(recordRelation, i => new { i.RunStatus, i.Memo, i.RunTime }, t => t.YzOid == order.oid);
|
errMsg += createRsp.ErrorMsg;
|
continue;
|
}
|
else
|
{
|
response.Success = true;
|
successCount++;
|
recordRelation.RunStatus = 2;
|
recordRelation.AliTid = createRsp.AliTid;
|
//获取1688订单信息
|
//AlibabaTradeDeatilGetRequest aliTradeReq = new AlibabaTradeDeatilGetRequest()
|
//{
|
// orderId = aliTradeCreateRsp.Result.orderId,
|
// webSite = "1688"
|
//};
|
//var aliTradeRsp = AliabaClient.Execute(aliTradeReq, request.AliToken);
|
//if (aliTradeRsp.IsNull() || !aliTradeRsp.Success || aliTradeRsp.result.IsNull())
|
//{//接口请求失败
|
// LogUtil.Info("接口获取1688订单详情error:" + (aliTradeRsp.IsNull() ? "null" : aliTradeRsp.ErrorMsg), "创建订单");
|
//}
|
//else
|
//{
|
// recordRelation.AliOid = aliTradeRsp.result.productItems[0].subItemID.ToString();
|
//}
|
//子订单与主订单相同
|
recordRelation.AliOid = createRsp.AliTid;
|
//修改有赞子订单状态
|
YzOrderinfo yzOrderinfo = new YzOrderinfo()
|
{
|
AliTradeStatus = 1,
|
AliTid = createRsp.AliTid,
|
AliOid = createRsp.AliTid
|
};
|
new YzOrderinfoDAL().Update(yzOrderinfo, i => new { i.AliTradeStatus, i.AliTid, i.AliOid }, t => t.Oid == order.oid);
|
//判断退款列表里是否有1688关联关系
|
if (!refundRelat.IsNull() && refundRelat.Count > 0 && refundRelat[0].AliTid.IsNullOrEmpty())
|
{
|
YzRefund yzRefund = new YzRefund()
|
{
|
AliTid = createRsp.AliTid,
|
AliOid = createRsp.AliTid
|
};
|
new YzRefundDAL().Update(yzRefund, i => new { i.AliTid, i.AliOid }, t => t.RefundId == refundRelat[0].RefundId);
|
}
|
}
|
new TradeCreateRelationDAL().Update(recordRelation, i => new { i.RunStatus, i.Memo, i.AliTid, i.AliOid, i.CreateInfo, i.RunTime }, t => t.YzOid == order.oid);
|
}
|
}
|
catch (Exception e)
|
{
|
response.Success = false;
|
response.ErrorMsg = e.ToString();
|
}
|
response.ErrorMsg = errMsg;
|
return response;
|
}
|
|
#region 精选商品创建订单
|
private AliCreateTradeResponse CreateTradeJx(YzDecryptInfo decryptInfo, TradeDetailResult yzResult, StructurizationTradeItemDetail yzOrder, List<DistributionRelation> relation, AliTradeCreateRequest meReq,string postFee)
|
{
|
AliCreateTradeResponse response = new AliCreateTradeResponse();
|
CreateTradeReqGetResponse getReqResponse = CreateTradeReqGet(decryptInfo, yzResult, yzOrder, relation);
|
if (!getReqResponse.Success)
|
{//创建失败的操作
|
response.Success = false;
|
response.ErrorMsg = getReqResponse.ErrorMsg;
|
return response;
|
}
|
response.CreateInfo = JSONUtil.ObjectToJson(getReqResponse.request);
|
//调用预览接口
|
var preRsp = AliCreatePreview(getReqResponse, yzOrder, 0, meReq.AliToken,postFee);
|
if (!preRsp.Success)
|
{
|
response.Success = false;
|
response.ErrorMsg = preRsp.ErrorMsg;
|
return response;
|
}
|
//调用1688接口创建订单
|
var aliTradeCreateRsp = AliabaClient.Execute(getReqResponse.request, meReq.AliToken);
|
if (aliTradeCreateRsp.IsNull() || !aliTradeCreateRsp.Success || aliTradeCreateRsp.Result.IsNull() || aliTradeCreateRsp.Result.orderId.IsNullOrEmpty())
|
{//整单创建失败
|
response.Success = false;
|
response.ErrorMsg = aliTradeCreateRsp.IsNull() ? "接口返回null" : aliTradeCreateRsp.ErrorMsg;
|
return response;
|
}
|
response.Success = true;
|
response.AliTid = aliTradeCreateRsp.Result.orderId;
|
return response;
|
}
|
|
/// <summary>
|
/// 创建订单的request
|
/// </summary>
|
/// <param name="decryptInfo"></param>
|
/// <param name="yzResult"></param>
|
/// <param name="pre"></param>
|
/// <returns></returns>
|
private CreateTradeReqGetResponse CreateTradeReqGet(YzDecryptInfo decryptInfo, TradeDetailResult yzResult, StructurizationTradeItemDetail yzOrder, List<DistributionRelation> relation)
|
{
|
CreateTradeReqGetResponse response = new CreateTradeReqGetResponse();
|
var yzTrade = yzResult.full_order_info;
|
//收货地址信息
|
AddressParamItem addressParamItem = new AddressParamItem()
|
{
|
fullName = decryptInfo.ReceiverName,
|
mobile = decryptInfo.ReceiverTel,
|
phone = decryptInfo.ReceiverTel,
|
cityText = yzTrade.address_info.delivery_city,
|
provinceText = yzTrade.address_info.delivery_province,
|
areaText = yzTrade.address_info.delivery_district,
|
townText = yzTrade.address_info.delivery_district,
|
address = decryptInfo.DeliveryAddress
|
};
|
var orderRe = new OrderRelationDAL().ListGet(t => t.YzTid == yzTrade.order_info.tid && t.CreateStatus == 1);
|
//商品信息
|
List<CargoParamListItem> cargoParamList = new List<CargoParamListItem>();
|
List<OrderRelation> oids = new List<OrderRelation>();
|
|
//判断有赞子订单是否已创建过
|
if (!orderRe.IsNull() && orderRe.Count > 0 && orderRe.Any(t => t.YzSkuId == yzOrder.sku_id.ToString()))
|
{//已经创建成功过
|
response.Success = false;
|
response.ErrorMsg = "已经创建成功过,请勿重复创建!";
|
return response;
|
}
|
|
//判断是否有绑定关系
|
|
if (relation.IsNull() || relation.Count == 0)
|
{
|
response.Success = false;
|
response.ErrorMsg = "该商品与1688无绑定关系";
|
return response;
|
}
|
List<SkuInfosItem> skuInfos = JSONUtil.JsonToObject<List<SkuInfosItem>>(relation[0].AliskuInfo);
|
var aliSku = skuInfos.Where(t => t.skuId == long.Parse(yzOrder.outer_sku_id)).ToList();
|
if (aliSku.IsNull() || aliSku.Count == 0)
|
{
|
response.Success = false;
|
response.ErrorMsg = "1688商品无该sku信息";
|
return response;
|
}
|
|
OrderRelation orderRelation = new OrderRelation();
|
CargoParamListItem carItem = new CargoParamListItem()
|
{
|
offerId = long.Parse(relation[0].SourceProduct),
|
specId = aliSku[0].specId,
|
quantity = yzOrder.num
|
};
|
cargoParamList.Add(carItem);
|
orderRelation.YzOid = yzOrder.oid;
|
orderRelation.YzPayAmount = decimal.Parse(yzOrder.payment);
|
orderRelation.YzItemTitle = yzOrder.title;
|
orderRelation.AliProductId = relation[0].SourceProduct;
|
orderRelation.YzProductId = yzOrder.item_id.ToString();
|
orderRelation.YzImg = yzOrder.pic_path;
|
orderRelation.YzNum = yzOrder.num;
|
orderRelation.AliSkuId = aliSku[0].skuId.ToString();
|
orderRelation.YzSkuId = yzOrder.sku_id.ToString();
|
orderRelation.AliSpecid = aliSku[0].specId;
|
oids.Add(orderRelation);
|
|
|
AlibabaTradeCreateRequest addReq = new AlibabaTradeCreateRequest()
|
{
|
flow = "ttpft",
|
message = yzTrade.remark_info.buyer_message,
|
isvBizTypeStr = "fenxiaoMedia",
|
addressParam = addressParamItem,
|
cargoParamList = cargoParamList,
|
isvBizTypePD = false
|
};
|
response.request = addReq;
|
response.Oids = oids;
|
response.Success = true;
|
return response;
|
}
|
|
#endregion
|
|
#region 代发创建订单
|
|
private AliCreateTradeResponse CreateTradeDf(YzDecryptInfo decryptInfo, TradeDetailResult yzResult, StructurizationTradeItemDetail yzOrder, List<DistributionRelation> relation, AliTradeCreateRequest meReq,string postFee)
|
{
|
AliCreateTradeResponse response = new AliCreateTradeResponse();
|
CreateTradeReqGetResponse getReqResponse = CreateTradeDfReqGet(decryptInfo, yzResult, yzOrder, relation, meReq);
|
if (!getReqResponse.Success)
|
{//创建失败的操作
|
response.Success = false;
|
response.ErrorMsg = getReqResponse.ErrorMsg;
|
return response;
|
}
|
response.CreateInfo = JSONUtil.ObjectToJson(getReqResponse.fxRequest);
|
//先调用预览接口
|
//调用预览接口
|
var preRsp = AliCreatePreview(getReqResponse, yzOrder, 1, meReq.AliToken, postFee);
|
if (!preRsp.Success)
|
{
|
response.Success = false;
|
response.ErrorMsg = preRsp.ErrorMsg;
|
return response;
|
}
|
//调用1688接口创建订单
|
var aliTradeCreateRsp = AliabaClient.Execute(getReqResponse.fxRequest, meReq.AliToken);
|
if (aliTradeCreateRsp.IsNull() || !aliTradeCreateRsp.Success || aliTradeCreateRsp.result.IsNull() || aliTradeCreateRsp.result.orderId.IsNullOrEmpty())
|
{//整单创建失败
|
response.Success = false;
|
response.ErrorMsg = aliTradeCreateRsp.IsNull() ? "接口返回null" : aliTradeCreateRsp.ErrorMsg;
|
return response;
|
}
|
response.Success = true;
|
response.AliTid = aliTradeCreateRsp.result.orderId;
|
return response;
|
}
|
|
|
/// <summary>
|
/// 创建代发订单的request
|
/// </summary>
|
/// <param name="decryptInfo"></param>
|
/// <param name="yzResult"></param>
|
/// <param name="pre"></param>
|
/// <returns></returns>
|
private CreateTradeReqGetResponse CreateTradeDfReqGet(YzDecryptInfo decryptInfo, TradeDetailResult yzResult, StructurizationTradeItemDetail yzOrder, List<DistributionRelation> relation, AliTradeCreateRequest meReq)
|
{
|
CreateTradeReqGetResponse response = new CreateTradeReqGetResponse();
|
var yzTrade = yzResult.full_order_info;
|
//收货地址信息
|
FXOrderAddressParam addressParamItem = new FXOrderAddressParam()
|
{
|
fullName = decryptInfo.ReceiverName,
|
mobile = decryptInfo.ReceiverTel,
|
phone = decryptInfo.ReceiverTel,
|
cityText = yzTrade.address_info.delivery_city,
|
provinceText = yzTrade.address_info.delivery_province,
|
areaText = yzTrade.address_info.delivery_district,
|
townText = yzTrade.address_info.delivery_district,
|
address = decryptInfo.DeliveryAddress
|
};
|
var orderRe = new OrderRelationDAL().ListGet(t => t.YzTid == yzTrade.order_info.tid && t.CreateStatus == 1);
|
//商品信息
|
List<FXOrderCargoParamList> cargoParamList = new List<FXOrderCargoParamList>();
|
// List<OrderRelation> oids = new List<OrderRelation>();
|
|
//判断有赞子订单是否已创建过
|
if (!orderRe.IsNull() && orderRe.Count > 0 && orderRe.Any(t => t.YzSkuId == yzOrder.sku_id.ToString()))
|
{//已经创建成功过
|
response.Success = false;
|
response.ErrorMsg = "已经创建成功过,请勿重复创建!";
|
return response;
|
}
|
|
//判断是否有绑定关系
|
|
if (relation.IsNull() || relation.Count == 0)
|
{
|
response.Success = false;
|
response.ErrorMsg = "该商品与1688无绑定关系";
|
return response;
|
}
|
List<SkuInfosItem> skuInfos = JSONUtil.JsonToObject<List<SkuInfosItem>>(relation[0].AliskuInfo);
|
var aliSku = skuInfos.Where(t => t.skuId == long.Parse(yzOrder.outer_sku_id)).ToList();
|
if (aliSku.IsNull() || aliSku.Count == 0)
|
{
|
response.Success = false;
|
response.ErrorMsg = "1688商品无该sku信息";
|
return response;
|
}
|
|
|
FXOrderCargoParamList carItem = new FXOrderCargoParamList()
|
{
|
offerId = long.Parse(relation[0].SourceProduct),
|
specId = aliSku[0].specId,
|
quantity = yzOrder.num,
|
channel = "youzan",
|
outShopCode = meReq.YzShopId,
|
outItemCode = yzOrder.item_id.ToString()
|
};
|
cargoParamList.Add(carItem);
|
//OrderRelation orderRelation = new OrderRelation();
|
//orderRelation.YzOid = yzOrder.oid;
|
//orderRelation.YzPayAmount = decimal.Parse(yzOrder.payment);
|
//orderRelation.YzItemTitle = yzOrder.title;
|
//orderRelation.AliProductId = relation[0].SourceProduct;
|
//orderRelation.YzProductId = yzOrder.item_id.ToString();
|
//orderRelation.YzImg = yzOrder.pic_path;
|
//orderRelation.YzNum = yzOrder.num;
|
//orderRelation.AliSkuId = aliSku[0].skuId.ToString();
|
//orderRelation.YzSkuId = yzOrder.sku_id.ToString();
|
//orderRelation.AliSpecid = aliSku[0].specId;
|
//oids.Add(orderRelation);
|
FenXiaoOrderCreateRequest addReq = new FenXiaoOrderCreateRequest()
|
{
|
flow = "fenxiao",
|
isvBizTypeStr = "fenxiaoMedia",
|
addressParam = addressParamItem,
|
cargoParamList = cargoParamList,
|
isvBizTypePD = false
|
};
|
response.fxRequest = addReq;
|
// response.Oids = oids;
|
response.Success = true;
|
return response;
|
}
|
|
#endregion
|
|
|
#region 创建订单前预览
|
private AliCreateTradeResponse AliCreatePreview(CreateTradeReqGetResponse tradePara, StructurizationTradeItemDetail yzOrder, int prSource, string aliToken,string postFee)
|
{
|
AliCreateTradeResponse response = new AliCreateTradeResponse();
|
try
|
{
|
if (!tradePara.Success)
|
{
|
return null;
|
}
|
decimal aliTradeAmount = 0;
|
if (prSource == 0)
|
{//精选
|
AlibabaTradeCreatePreviewRequest aliPreReq = new AlibabaTradeCreatePreviewRequest()
|
{
|
flow = "ttpft",
|
addressParam = tradePara.request.addressParam,
|
cargoParamList = tradePara.request.cargoParamList
|
};
|
var aliPreRsp = AliabaClient.Execute(aliPreReq, aliToken);
|
if (aliPreRsp.IsNull() || !aliPreRsp.Success)
|
{
|
response.Success = false;
|
response.ErrorMsg = aliPreRsp.ErrorMsg;
|
return response;
|
}
|
aliTradeAmount = aliPreRsp.orderPreviewResuslt.Sum(t => t.sumPayment);
|
}
|
else
|
{//1688代发
|
FxTradeCreatePreviewRequest dfPreReq = new FxTradeCreatePreviewRequest()
|
{
|
flow = "saleproxy"
|
};
|
dfPreReq.addressParam = JSONUtil.JsonToObject<FXOrderAddressParam>(JSONUtil.ObjectToJson(tradePara.fxRequest.addressParam));
|
dfPreReq.cargoParamList = JSONUtil.JsonToObject<List<FXOrderCargoParamList>>(JSONUtil.ObjectToJson(tradePara.fxRequest.cargoParamList));
|
var dfPreRsp = AliabaClient.Execute(dfPreReq, aliToken);
|
if (dfPreRsp.IsNull() || !dfPreRsp.modelResult.success)
|
{
|
response.Success = false;
|
response.ErrorMsg = dfPreRsp.modelResult.errorMsg;
|
return response;
|
}
|
aliTradeAmount = dfPreRsp.modelResult.orderPreviewResult.Sum(t => t.sumPayment);
|
}
|
decimal post = 0;
|
if(!postFee.IsNullOrEmpty()&&decimal.TryParse(postFee, out post))
|
{
|
|
}
|
if (Math.Round(aliTradeAmount / 100, 2) >= (decimal.Parse(yzOrder.payment)+ post))
|
{
|
response.Success = false;
|
response.ErrorMsg = $"1688金额:{Math.Round(aliTradeAmount / 100, 2)},有赞订单金额:{yzOrder.payment},亏了";
|
return response;
|
}
|
}
|
catch (Exception e)
|
{
|
response.Success = false;
|
response.ErrorMsg = e.ToString();
|
return response;
|
}
|
response.Success = true;
|
return response;
|
}
|
|
#endregion
|
|
|
/// <summary>
|
/// 调用预览接口
|
/// </summary>
|
/// <param name="decryptInfo"></param>
|
/// <param name="yzResult"></param>
|
/// <returns></returns>
|
private AlibabaTradeCreatePreviewRequest CreatePre(YzDecryptInfo decryptInfo, TradeDetailResult yzResult)
|
{
|
var yzTrade = yzResult.full_order_info;
|
//收货地址信息
|
AddressParamItem addressParamItem = new AddressParamItem()
|
{
|
fullName = decryptInfo.ReceiverName,
|
mobile = decryptInfo.ReceiverTel,
|
phone = decryptInfo.ReceiverTel,
|
cityText = yzTrade.address_info.delivery_city,
|
provinceText = yzTrade.address_info.delivery_province,
|
areaText = yzTrade.address_info.delivery_district,
|
townText = yzTrade.address_info.delivery_district,
|
address = decryptInfo.DeliveryAddress
|
};
|
//商品信息
|
List<CargoParamListItem> cargoParamList = new List<CargoParamListItem>();
|
foreach (var item in yzTrade.orders)
|
{
|
//判断是否有绑定关系
|
var relation = new DistributionRelationDAL().ListGet(t => t.YzProduct == item.item_id.ToString() && t.ReStatus == 1);
|
if (relation.IsNull() || relation.Count == 0)
|
{
|
continue;
|
}
|
List<SkuInfosItem> skuInfos = JSONUtil.JsonToObject<List<SkuInfosItem>>(relation[0].AliskuInfo);
|
var aliSku = skuInfos.Where(t => t.skuId == long.Parse(item.outer_sku_id)).ToList();
|
if (aliSku.IsNull() || aliSku.Count == 0)
|
{
|
continue;
|
}
|
CargoParamListItem carItem = new CargoParamListItem()
|
{
|
offerId = long.Parse(relation[0].SourceProduct),
|
specId = aliSku[0].specId,
|
quantity = item.num
|
};
|
cargoParamList.Add(carItem);
|
}
|
|
AlibabaTradeCreatePreviewRequest aliPreReq = new AlibabaTradeCreatePreviewRequest()
|
{
|
flow = "ttpft",
|
addressParam = addressParamItem,
|
cargoParamList = cargoParamList
|
};
|
return aliPreReq;
|
}
|
|
/// <summary>
|
/// 有赞订单解密
|
/// </summary>
|
/// <param name="yzOrderInfo"></param>
|
/// <returns></returns>
|
public YzDecryptInfo DecryptTrade(StructurizationTradeOrderInfo yzOrderInfo, string yzToken)
|
{
|
Dictionary<string, string> deData = new Dictionary<string, string>();
|
deData.Add("delivery_address", yzOrderInfo.address_info.delivery_address);
|
deData.Add("receiver_name", yzOrderInfo.address_info.receiver_name);
|
deData.Add("receiver_tel", yzOrderInfo.address_info.receiver_tel);
|
deData.Add("buyer_phone", yzOrderInfo.buyer_info.buyer_phone);
|
GetDecryptDataRequest deRequest = new GetDecryptDataRequest()
|
{
|
KdtId = yzOrderInfo.order_info.node_kdt_id,
|
Tid = yzOrderInfo.order_info.tid,
|
TradeCreated = yzOrderInfo.order_info.created,
|
YzOpenId = yzOrderInfo.buyer_info.yz_open_id,
|
Data = deData
|
};
|
|
return GetDecryptData(deRequest, yzToken);
|
}
|
|
/// <summary>
|
/// 从数据库或接口获取解密信息
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
public YzDecryptInfo GetDecryptData(GetDecryptDataRequest request, string yzToken)
|
{
|
//先从表里查询
|
var decrRecord = new YzDecryptInfoDAL().GetById(request.Tid);
|
if (!decrRecord.IsNull() && !decrRecord.Tid.IsNullOrEmpty())
|
{
|
return decrRecord;
|
}
|
//从接口获取
|
List<string> source = new List<string>();
|
foreach (var it in request.Data)
|
{
|
source.Add(it.Value);
|
}
|
YouZanDecryptBatchRequest req = new YouZanDecryptBatchRequest()
|
{
|
sources = source
|
};
|
var rsp = YouZanClient.Execute(req, yzToken);
|
YzDecryptInfo yzDecryptInfo = new YzDecryptInfo();
|
yzDecryptInfo.DeliveryAddress = rsp.data[request.Data["delivery_address"]];
|
yzDecryptInfo.ReceiverName = rsp.data[request.Data["receiver_name"]];
|
yzDecryptInfo.ReceiverTel = rsp.data[request.Data["receiver_tel"]];
|
yzDecryptInfo.BuyerPhone = rsp.data[request.Data["buyer_phone"]];
|
yzDecryptInfo.Tid = request.Tid;
|
yzDecryptInfo.TradeCreate = request.TradeCreated;
|
yzDecryptInfo.YzOpenId = request.YzOpenId;
|
yzDecryptInfo.ReceiverName = yzDecryptInfo.ReceiverName.Length < 2 ? (yzDecryptInfo.ReceiverName + "先生") : yzDecryptInfo.ReceiverName;
|
new YzDecryptInfoDAL().Insert(yzDecryptInfo);
|
return yzDecryptInfo;
|
}
|
|
public class CreateTradeReqGetResponse
|
{
|
public AlibabaTradeCreateRequest request { get; set; }
|
|
public FenXiaoOrderCreateRequest fxRequest { get; set; }
|
public List<OrderRelation> Oids { get; set; }
|
|
public bool Success { get; set; }
|
|
public string ErrorMsg { get; set; }
|
}
|
|
public class AliCreateTradeResponse
|
{
|
public bool Success { get; set; }
|
|
public string ErrorMsg { get; set; }
|
public string CreateInfo { get; set; }
|
|
public string AliTid { get; set; }
|
}
|
|
|
}
|
}
|