using AlibabaSDK.Api;
|
using AlibabaSDK.Domain;
|
using AlibabaSDK.Request;
|
using CommonUtil;
|
using DbAccess;
|
using Operater.DAL;
|
using Operater.DbModel;
|
using Operater.DTO.TopMessage;
|
using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using System.Linq;
|
using System.Text;
|
using YouZanSDKStandard.Api;
|
using YouZanSDKStandard.Api.Request;
|
|
namespace TradeInterflow.Handle
|
{
|
public class AliTradeHandle
|
{
|
private static string _logName = "1688订单处理error";
|
public static ISysSqlHelper dbMain = SysSqlHelper.CreateSqlHelper("db_main");
|
public static void HandleExecute(string message)
|
{
|
try
|
{
|
BaseAliMessage aliMsg = JSONUtil.JsonToObject<BaseAliMessage>(message);
|
switch (aliMsg.type)
|
{
|
case "ORDER_BUYER_VIEW_BUYER_MAKE":
|
Console.WriteLine("1688创建订单");
|
CreateTradeMsg(aliMsg.data.ToString());
|
break;
|
case "ORDER_BATCH_PAY":
|
Console.WriteLine("1688订单批量支付状态同步消息");
|
BathPayMsg(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_PAY":
|
Console.WriteLine("1688交易付款(买家视角)");
|
OrderPay(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS":
|
Console.WriteLine("1688订单发货(买家视角");
|
SendGoods(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_SELLER_CLOSE":
|
Console.WriteLine("1688卖家关闭订单(买家视角)");
|
OrderSaleCnacle(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_PRICE_MODIFY":
|
Console.WriteLine("1688修改订单价格(买家视角)");
|
PriceModify(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_SELLER_MODIFY_ADRESS":
|
Console.WriteLine("商家修改订单地址(买家视角)");
|
AddressModify(aliMsg.data.ToString());
|
break;
|
case "LOGISTICS_MAIL_NO_CHANGE":
|
Console.WriteLine("物流单号修改消息");
|
LogisticsChange(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_PART_PART_SENDGOODS":
|
Console.WriteLine("1688订单部分发货(买家视角");
|
SendGoods(aliMsg.data.ToString());
|
break;
|
case "LOGISTICS_BUYER_VIEW_TRACE":
|
Console.WriteLine("1688物流单状态变更(买家视角)");
|
LogisticsSend(aliMsg.data.ToString());
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_SUCCESS":
|
Console.WriteLine("1688交易成功(买家视角)");
|
TradeStatusChange(aliMsg.data.ToString(), "交易成功");
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_BUYER_CLOSE":
|
Console.WriteLine("1688买家关闭订单(买家视角)");
|
TradeStatusChange(aliMsg.data.ToString(), "交易关闭");
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_COMFIRM_RECEIVEGOODS":
|
Console.WriteLine("1688订单确认收货(买家视角)");
|
TradeStatusChange(aliMsg.data.ToString(), "确认收货");
|
break;
|
case "ORDER_BUYER_VIEW_ORDER_BUYER_REFUND_IN_SALES":
|
Console.WriteLine("1688商家退款消息");
|
TradeRefundStatus(aliMsg.data.ToString());
|
break;
|
}
|
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), _logName);
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#region 1688退款状态
|
private static void TradeRefundStatus(string message)
|
{
|
try
|
{
|
TradeRefundStatusMsg msg = JSONUtil.JsonToObject<TradeRefundStatusMsg>(message);
|
YzRefund yzRefund = new YzRefund()
|
{
|
AliRefundStatus = msg.currentStatus,
|
AliRefundAction = msg.refundAction
|
};
|
if (msg.refundAction == "SELLER_AGREE_REFUND")
|
{
|
yzRefund.RelationYzRefund = 2;
|
new YzRefundDAL().Update(yzRefund, i => new { i.AliRefundStatus, i.AliRefundAction, i.RelationYzRefund }, t => t.AliRefundId == msg.refundId);
|
}
|
else
|
{
|
new YzRefundDAL().Update(yzRefund, i => new { i.AliRefundStatus, i.AliRefundAction }, t => t.AliRefundId == msg.refundId);
|
}
|
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688退款状态");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 1688订单状态改变
|
private static void TradeStatusChange(string message, string statusStr)
|
{
|
try
|
{
|
TradeSuccessMsg successMsg = JSONUtil.JsonToObject<TradeSuccessMsg>(message);
|
ChangeTradeStatus(successMsg.orderId, successMsg.currentStatus, statusStr);
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688订单状态改变");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 物流单状态变更(买家视角)
|
private static void LogisticsSend(string message)
|
{
|
try
|
{
|
LogisticsSendMsg logisticsSendMsg = JSONUtil.JsonToObject<LogisticsSendMsg>(message);
|
foreach (var trd in logisticsSendMsg.OrderLogisticsTracingModel.orderLogsItems)
|
{
|
AliLogistics aliLogistics = new AliLogistics()
|
{
|
AliOid = trd.orderEntryId.ToString(),
|
AliTid = trd.orderId.ToString(),
|
CreateTime = DateTime.Now,
|
LogisticsId = logisticsSendMsg.OrderLogisticsTracingModel.logisticsId,
|
CpCode = logisticsSendMsg.OrderLogisticsTracingModel.cpCode,
|
MailNo = logisticsSendMsg.OrderLogisticsTracingModel.mailNo,
|
StatusChanged = logisticsSendMsg.OrderLogisticsTracingModel.statusChanged
|
};
|
var has = new AliLogisticsDAL().GetById(trd.orderEntryId.ToString());
|
if (has.IsNull() || has.AliOid.IsNullOrEmpty())
|
{//新增
|
new AliLogisticsDAL().Insert(aliLogistics);
|
}
|
else
|
{//修改
|
new AliLogisticsDAL().Update(aliLogistics, i => new { i.LogisticsId, i.CpCode, i.MailNo, i.StatusChanged }, t => t.AliOid == trd.orderEntryId.ToString());
|
}
|
if (logisticsSendMsg.OrderLogisticsTracingModel.statusChanged == "CONSIGN")
|
{//发货消息,修改有赞子订单发货状态
|
//var orderRelate = new TradeCreateRelationDAL().ListGet(t => t.AliOid == trd.orderEntryId.ToString());
|
//if (orderRelate.IsNull() || orderRelate.Count == 0)
|
//{
|
// LogUtil.Info($"1688子订单:{trd.orderEntryId.ToString()},未找到对应有赞子订单信息", "物流单状态变更");
|
// continue;
|
//}
|
YzOrderinfo yzOrderinfo = new YzOrderinfo()
|
{
|
AliGoodsStatus = 1
|
};
|
new YzOrderinfoDAL().Update(yzOrderinfo, i => new { i.AliGoodsStatus }, t => t.AliOid == trd.orderEntryId.ToString());
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "物流单状态变更");
|
Console.WriteLine("物流单状态变更主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 1688物流单号修改
|
private static void LogisticsChange(string message)
|
{
|
try
|
{
|
LogisticsChangeMsg msg = JSONUtil.JsonToObject<LogisticsChangeMsg>(message);
|
//获取订单关系
|
string reMsg = GetYzTid(msg.MailNoChangeModel.orderLogsItems[0].orderId);
|
string Msg = $"1688物流单号修改-1688订单{msg.MailNoChangeModel.orderLogsItems[0].orderId},对应有赞订单:{reMsg}";
|
Msg += $",之前的运单号:{msg.MailNoChangeModel.oldMailNo},更改后的运单号:{msg.MailNoChangeModel.newMailNo}";
|
MessageNotify messageNotify = new MessageNotify()
|
{
|
Msg = Msg,
|
Mark = msg.MailNoChangeModel.orderLogsItems[0].orderId,
|
MsgChannel = "1688"
|
};
|
CommonHandle.RecorderMessage(messageNotify);
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688物流单号修改");
|
Console.WriteLine("1688物流单号修改主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 1688商家修改订单地址
|
private static void AddressModify(string message)
|
{
|
try
|
{
|
AddressModifyMsg ModifyMsg = JSONUtil.JsonToObject<AddressModifyMsg>(message);
|
//获取订单关系
|
string msg = GetYzTid(ModifyMsg.orderId);
|
|
MessageNotify messageNotify = new MessageNotify()
|
{
|
Msg = $"1688商家修改订单地址-1688订单{ModifyMsg.orderId},对应有赞订单:{msg}",
|
Mark = ModifyMsg.orderId,
|
MsgChannel = "1688"
|
};
|
CommonHandle.RecorderMessage(messageNotify);
|
//从接口获取订单详情
|
AlibabaTradeDetailDomain topTradeInfo = CommonHandle.GetAliTradeDetail(ModifyMsg.orderId);
|
if (topTradeInfo.IsNull())
|
{
|
return;
|
}
|
AliTradeinfo aliTradeinfo = new AliTradeinfo()
|
{
|
Province = topTradeInfo.nativeLogistics.province,
|
City = topTradeInfo.nativeLogistics.city,
|
Area = topTradeInfo.nativeLogistics.area,
|
Address = topTradeInfo.nativeLogistics.address,
|
Mobile = topTradeInfo.nativeLogistics.mobile,
|
Town = topTradeInfo.nativeLogistics.town
|
};
|
//修改1688订单收货人信息
|
new AliTradeinfoDAL().Update(aliTradeinfo, i => new { i.Province, i.City, i.Area, i.Address, i.Mobile, i.Town }, t => t.Tid == ModifyMsg.orderId);
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688修改订单价格");
|
Console.WriteLine("1688修改订单价格主线程错误:" + e.ToString());
|
}
|
}
|
#endregion
|
|
#region 1688修改订单价格
|
private static void PriceModify(string message)
|
{
|
try
|
{
|
PriceModifyMsg priceModifyMsg = JSONUtil.JsonToObject<PriceModifyMsg>(message);
|
//获取订单关系
|
string msg = GetYzTid(priceModifyMsg.orderId);
|
MessageNotify messageNotify = new MessageNotify()
|
{
|
Msg = $"1688商家修改订单价格-1688订单{priceModifyMsg.orderId},对应有赞订单:{msg}",
|
Mark = priceModifyMsg.orderId,
|
MsgChannel = "1688"
|
};
|
CommonHandle.RecorderMessage(messageNotify);
|
//先删除原1688订单数据
|
new AliTradeinfoDAL().Delete(priceModifyMsg.orderId);
|
new AliOrderinfoDAL().Delete(t => t.Tid == priceModifyMsg.orderId);
|
//重新获取新数据
|
TrdeInfoHandle(priceModifyMsg.orderId);
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688修改订单价格");
|
Console.WriteLine("1688修改订单价格主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
|
#region 1688卖家关闭订单
|
private static void OrderSaleCnacle(string message)
|
{
|
try
|
{
|
OrderSaleCnacleMsg orderSaleCnacleMsg = JSONUtil.JsonToObject<OrderSaleCnacleMsg>(message);
|
ChangeTradeStatus(orderSaleCnacleMsg.orderId, orderSaleCnacleMsg.currentStatus, "交易取消");
|
//获取订单关系
|
// string msg = GetYzTid(orderSaleCnacleMsg.orderId);
|
//MessageNotify messageNotify = new MessageNotify()
|
//{
|
// Msg = $"发货失败-1688订单{orderSaleCnacleMsg.orderId}-商家取消了交易,对应有赞订单:【{msg}】",
|
// Mark = orderSaleCnacleMsg.orderId,
|
// MsgChannel = "1688"
|
//};
|
//CommonHandle.RecorderMessage(messageNotify);
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688卖家关闭订单");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 修改订单状态
|
private static void ChangeTradeStatus(string orderId, string currentStatus, string statusStr)
|
{
|
try
|
{
|
if (TrdeInfoHandle(orderId))
|
{
|
AliTradeinfo aliTradeinfo = new AliTradeinfo()
|
{
|
TradeStatus = currentStatus
|
};
|
new AliTradeinfoDAL().UseTran(() =>
|
{//修改主子订单状态
|
new AliTradeinfoDAL().Update(aliTradeinfo, i => new { i.TradeStatus }, t => t.Tid == orderId);
|
AliOrderinfo aliOrderinfo = new AliOrderinfo()
|
{
|
OrderStatus = currentStatus,
|
StatusStr = statusStr
|
};
|
new AliOrderinfoDAL().Update(aliOrderinfo, i => new { i.OrderStatus, i.StatusStr }, t => t.Tid == orderId);
|
});
|
//修改退款表里1688订单状态
|
YzRefund yzRefund = new YzRefund()
|
{
|
AliTradeStatus = currentStatus
|
};
|
new YzRefundDAL().Update(yzRefund, i => new { i.AliTradeStatus }, t => t.AliTid == orderId);
|
}
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "修改订单状态");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
|
#region 1688订单发货
|
private static void SendGoods(string message)
|
{
|
try
|
{
|
SendGoodsMsg sendGoodsMsg = JSONUtil.JsonToObject<SendGoodsMsg>(message);
|
ChangeTradeStatus(sendGoodsMsg.orderId, sendGoodsMsg.currentStatus, "等待买家收货");
|
//修改有赞子订单1688订单发货状态
|
YzOrderinfo yzOrderinfo = new YzOrderinfo()
|
{
|
AliGoodsStatus = 1
|
};
|
new YzOrderinfoDAL().Update(yzOrderinfo, i => new { i.AliGoodsStatus }, t => t.AliTid == sendGoodsMsg.orderId);
|
#region 可调用AliTradeFlowService.AliTradeSendGoods服务
|
////有赞订单发货
|
////获取订单关系
|
//var tradeRelat = new TradeRelationDAL().GetById(sendGoodsMsg.orderId);
|
//if (tradeRelat.IsNull() || tradeRelat.AliTid.IsNullOrEmpty())
|
//{//异常
|
// MessageNotify messageNotify = new MessageNotify()
|
// {
|
// Msg = $"发货失败-订单{sendGoodsMsg.orderId}没有找到对应有赞的订单关系",
|
// Mark = sendGoodsMsg.orderId,
|
// MsgChannel = "1688"
|
// };
|
// CommonHandle.RecorderMessage(messageNotify);
|
// return;
|
//}
|
////获取关联的子订单
|
//var orderList = new OrderRelationDAL().ListGet(t => t.AliTid == sendGoodsMsg.orderId);
|
//if (orderList.IsNull() || orderList.Count == 0)
|
//{
|
// MessageNotify messageNotify = new MessageNotify()
|
// {
|
// Msg = $"发货失败-订单{sendGoodsMsg.orderId}没有找到子订单信息",
|
// Mark = sendGoodsMsg.orderId,
|
// MsgChannel = "1688"
|
// };
|
// CommonHandle.RecorderMessage(messageNotify);
|
// return;
|
//}
|
////获取1688物流信息
|
//AlibabaGetLogisticsInfosRequest alibabaGetLogisticsInfosRequest = new AlibabaGetLogisticsInfosRequest()
|
//{
|
// orderId = long.Parse(sendGoodsMsg.orderId),
|
// webSite = "1688",
|
// fields = "company,name,sender,receiver,sendgood"
|
//};
|
//var alibabaGetLogisticsInfosRes = AliabaClient.Execute(alibabaGetLogisticsInfosRequest, GetAliToken());
|
//if (alibabaGetLogisticsInfosRes.IsNull() || !alibabaGetLogisticsInfosRes.Succes || alibabaGetLogisticsInfosRes.result.IsNull())
|
//{//获取1688物流信息失败
|
// MessageNotify messageNotify = new MessageNotify()
|
// {
|
// Msg = $"发货失败-订单{sendGoodsMsg.orderId}获取1688物流信息失败:" + (alibabaGetLogisticsInfosRes.IsNull() ? "null" : alibabaGetLogisticsInfosRes.ErrorMsg),
|
// Mark = sendGoodsMsg.orderId,
|
// MsgChannel = "1688"
|
// };
|
// CommonHandle.RecorderMessage(messageNotify);
|
// return;
|
//}
|
////获取1688与有赞的快递公司关联关系
|
//var expressId = new AliExpressDAL().GetById(alibabaGetLogisticsInfosRes.result.logisticsCompanyId);
|
//string outStype = expressId.YzId.ToString();
|
|
////有赞发货
|
|
////根据1688子订单获取有赞子订单数据
|
//var yzOids = orderList.Where(t => alibabaGetLogisticsInfosRes.result.orderEntryIds.Contains(t.AlisOid)).ToList();
|
//if (yzOids.IsNull() || yzOids.Count == 0 || yzOids.Count != alibabaGetLogisticsInfosRes.result.orderEntryIds.Split(',').Length)
|
//{
|
// MessageNotify messageNotify = new MessageNotify()
|
// {
|
// Msg = $"发货失败-1688订单{sendGoodsMsg.orderId}获取有赞子订单失败,1688子订单:" + alibabaGetLogisticsInfosRes.result.orderEntryIds,
|
// Mark = sendGoodsMsg.orderId,
|
// MsgChannel = "1688"
|
// };
|
// CommonHandle.RecorderMessage(messageNotify);
|
// return;
|
//}
|
//var oidArr = yzOids.Select(t => t.YzOid).ToArray();
|
//string oids = string.Join(',', oidArr);
|
//YouZanLogisticsConfirmRequest yzRequest = new YouZanLogisticsConfirmRequest()
|
//{
|
// tid = tradeRelat.YzTid,
|
// out_stype = outStype,
|
// out_sid = alibabaGetLogisticsInfosRes.result.logisticsBillNo,
|
// is_no_express = 0,
|
// oids = oids
|
//};
|
//var yzResponse = YouZanClient.Execute(yzRequest, GetYzToken());
|
//if (yzResponse.IsNull() || !yzResponse.success)
|
//{
|
// MessageNotify messageNotify = new MessageNotify()
|
// {
|
// Msg = $"发货失败-1688订单{sendGoodsMsg.orderId}有赞发货失败:" + (yzResponse.IsNull() ? "null" : yzResponse.message),
|
// Mark = sendGoodsMsg.orderId,
|
// MsgChannel = "yz"
|
// };
|
// CommonHandle.RecorderMessage(messageNotify);
|
// return;
|
//}
|
//LogUtil.Info($"1688订单{sendGoodsMsg.orderId}发货成功:{JSONUtil.ObjectToJson(yzRequest)}", "发货日志");
|
//Console.WriteLine("发货成功");
|
#endregion
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688订单发货");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 1688交易付款(买家视角)
|
|
private static void OrderPay(string message)
|
{
|
try
|
{
|
OrderPayMsg orderPayMsg = JSONUtil.JsonToObject<OrderPayMsg>(message);
|
ChangeTradeStatus(orderPayMsg.orderId, orderPayMsg.currentStatus, "等待卖家发货");
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688交易付款");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
|
#endregion
|
|
#region 批量支付状态同步消息
|
private static void BathPayMsg(string message)
|
{
|
try
|
{
|
BathPayMsg msg = JSONUtil.JsonToObject<BathPayMsg>(message);
|
foreach (var item in msg.batchPay)
|
{
|
|
}
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "批量支付状态同步消息");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
#endregion
|
|
#region 创建订单消息
|
public static void CreateTradeMsg(string msg)
|
{
|
try
|
{
|
AliTradeCreateMsg aliTradeCreateMsg = JSONUtil.JsonToObject<AliTradeCreateMsg>(msg);
|
//先处理订单数据
|
TrdeInfoHandle(aliTradeCreateMsg.orderId.ToString());
|
//if (TrdeInfoHandle(aliTradeCreateMsg.orderId.ToString()))
|
//{
|
// //从数据库获取子订单数据,补全子订单关系表
|
// var orderList = new AliOrderinfoDAL().ListGet(t => t.Tid == aliTradeCreateMsg.orderId.ToString());
|
// if (orderList.IsNull() || orderList.Count == 0)
|
// {
|
// return;
|
// }
|
// foreach (var ord in orderList)
|
// {//补全子订单关系表中的1688子订单号
|
// OrderRelation orderRelation = new OrderRelation()
|
// {
|
// AlisOid = ord.Oid
|
// };
|
// var orderRe = new OrderRelationDAL().ListGet(t => t.AliTid == ord.Tid && t.AliSpecid == ord.SpecId);
|
// new OrderRelationDAL().Update(orderRelation, i => new { i.AlisOid }, t => t.AliTid == ord.Tid && t.AliSpecid == ord.SpecId);
|
// //补全有赞子订单表里的1688对应子订单id
|
// YzOrderinfo yzOrderinfo = new YzOrderinfo()
|
// {
|
// AliOid = ord.Oid
|
// };
|
// new YzOrderinfoDAL().Update(yzOrderinfo, i => new { i.AliOid }, t => t.Oid == orderRe[0].YzOid);
|
// }
|
//}
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("主线程错误:" + e.ToString(), "1688创建订单消息");
|
Console.WriteLine("主线程错误:" + e.ToString());
|
}
|
}
|
#endregion
|
|
|
#region 处理订单表数据
|
private static bool TrdeInfoHandle(string tid)
|
{
|
try
|
{
|
//先检查1688订单表数据是否存在
|
var dbTradeInfo = new AliTradeinfoDAL().GetById(tid);
|
if (!dbTradeInfo.IsNull() && !dbTradeInfo.Tid.IsNullOrEmpty())
|
{//数据库中已存在数据
|
return true;
|
}
|
//从接口获取订单详情
|
AlibabaTradeDetailDomain topTradeInfo = CommonHandle.GetAliTradeDetail(tid);
|
if (topTradeInfo.IsNull())
|
{
|
return false;
|
}
|
//订单数据入库
|
AliTradeinfo aliTradeinfo = new AliTradeinfo()
|
{
|
Tid = topTradeInfo.baseInfo.id.ToString(),
|
PayTime = TimeSpanChange(topTradeInfo.baseInfo.payTime),
|
AllDeliveredTime = TimeSpanChange(topTradeInfo.baseInfo.allDeliveredTime),
|
Discount = topTradeInfo.baseInfo.discount / 100,
|
AlipayTradeId = topTradeInfo.baseInfo.alipayTradeId,
|
SumProductPayment = topTradeInfo.baseInfo.sumProductPayment,
|
BuyerFeedback = topTradeInfo.baseInfo.buyerFeedback,
|
BuyerLoginId = topTradeInfo.baseInfo.buyerLoginId,
|
ModifyTime = TimeSpanChange(topTradeInfo.baseInfo.modifyTime),
|
CloseReason = topTradeInfo.baseInfo.closeReason,
|
SellerAlipayId = topTradeInfo.baseInfo.sellerAlipayId,
|
CompleteTime = TimeSpanChange(topTradeInfo.baseInfo.completeTime),
|
SellerLoginid = topTradeInfo.baseInfo.sellerLoginId,
|
BuyerId = topTradeInfo.baseInfo.buyerID,
|
CloseOperateType = topTradeInfo.baseInfo.closeReason,
|
TotalAmount = topTradeInfo.baseInfo.totalAmount,
|
SellerId = topTradeInfo.baseInfo.sellerID,
|
ShippingFee = topTradeInfo.baseInfo.shippingFee,
|
BuyerUserid = topTradeInfo.baseInfo.buyerUserId.ToString(),
|
BuyerMemo = topTradeInfo.baseInfo.buyerMemo,
|
Refund = topTradeInfo.baseInfo.refund,
|
TradeStatus = topTradeInfo.baseInfo.status,
|
RefundPayment = topTradeInfo.baseInfo.refundPayment,
|
CouponFee = topTradeInfo.baseInfo.couponFee,
|
RefundStatus = topTradeInfo.baseInfo.refundStatus,
|
Remark = topTradeInfo.baseInfo.remark,
|
CloseRemark = topTradeInfo.baseInfo.closeRemark,
|
ReceivingTime = TimeSpanChange(topTradeInfo.baseInfo.receivingTime),
|
SellerUserid = topTradeInfo.baseInfo.sellerUserId.ToString(),
|
CreateTime = TimeSpanChange(topTradeInfo.baseInfo.createTime),
|
RefundId = topTradeInfo.baseInfo.refundId,
|
ContactPerson = topTradeInfo.nativeLogistics.contactPerson,
|
Province = topTradeInfo.nativeLogistics.province,
|
City = topTradeInfo.nativeLogistics.city,
|
Area = topTradeInfo.nativeLogistics.area,
|
Address = topTradeInfo.nativeLogistics.address,
|
Mobile = topTradeInfo.nativeLogistics.mobile,
|
Town = topTradeInfo.nativeLogistics.town
|
};
|
//组装子订单数据
|
List<AliOrderinfo> aliOrderinfos = new List<AliOrderinfo>();
|
foreach (var ord in topTradeInfo.productItems)
|
{
|
AliOrderinfo order = new AliOrderinfo()
|
{
|
Oid = ord.subItemID.ToString(),
|
Tid = topTradeInfo.baseInfo.id.ToString(),
|
ItemAmount = ord.itemAmount,
|
Name = ord.name,
|
Price = ord.price,
|
ProductId = ord.productID.ToString(),
|
ProductImgUrl = ord.productImgUrl[0],
|
ProductSnapshotUrl = ord.productSnapshotUrl,
|
Quantity = ord.quantity,
|
Refund = ord.refund,
|
SkuId = ord.skuID.ToString(),
|
OrderStatus = ord.status,
|
Unit = ord.unit,
|
Weight = ord.weight,
|
WeightUnit = ord.weight_unit,
|
EntryDiscount = ord.entryDiscount / 100,
|
SpecId = ord.specId,
|
StatusStr = ord.statusStr,
|
RefundStatus = ord.refundStatus,
|
CloseReason = ord.closeReason,
|
LogisticsStatus = ord.logisticsStatus,
|
GmtCreate = TimeSpanChange(ord.gmtCreate),
|
GmtModified = TimeSpanChange(ord.gmtModified),
|
GmtCompleted = TimeSpanChange(ord.gmtCompleted),
|
RefundId = ord.refundId,
|
RefundIdForas = ord.refundIdForAs
|
};
|
order.Skuinfos = ord.skuInfos.IsNull() || ord.skuInfos.Count == 0 ? "" : JSONUtil.ObjectToJson(ord.skuInfos);
|
aliOrderinfos.Add(order);
|
}
|
//使用事务入库处理
|
new AliTradeinfoDAL().UseTran(() =>
|
{
|
new AliTradeinfoDAL().Insert(aliTradeinfo);
|
new AliOrderinfoDAL().InsertRange(aliOrderinfos);
|
});
|
return true;
|
}
|
catch (Exception e)
|
{
|
LogUtil.Info("处理订单表数据error:" + e.ToString(), _logName);
|
Console.WriteLine("处理订单表数据error:" + e.ToString());
|
}
|
return false;
|
}
|
|
#endregion
|
|
|
|
|
#region 1688时间格式转换
|
private static DateTime? TimeSpanChange(string timset)
|
{
|
if (timset.IsNullOrEmpty())
|
{
|
return null;
|
}
|
string format = "yyyyMMddHHmmssfffzzz";
|
return DateTime.ParseExact(timset, format, CultureInfo.InvariantCulture, DateTimeStyles.None);
|
}
|
|
#endregion
|
|
|
#region 获取1688对应的有赞订单
|
private static string GetYzTid(string tid)
|
{
|
var tradeRelat = new TradeCreateRelationDAL().ListGet(t => t.AliTid == tid);
|
string msg = "";
|
if (tradeRelat.IsNull() || tradeRelat.Count==0)
|
{
|
msg = "没有找到对应有赞的订单";
|
}
|
else
|
{
|
msg = tradeRelat[0].YzTid;
|
}
|
return msg;
|
}
|
|
#endregion
|
|
|
}
|
}
|