|
|
|
using BBWY.Common.Extensions;
|
|
|
|
using BBWY.Common.Models;
|
|
|
|
using BBWY.Server.Business.PlatformSDK.DataExtension;
|
|
|
|
using BBWY.Server.Model;
|
|
|
|
using BBWY.Server.Model.Dto;
|
|
|
|
using Jd.ACES;
|
|
|
|
using Jd.Api;
|
|
|
|
using Jd.Api.Request;
|
|
|
|
using Jd.Api.Response;
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace BBWY.Server.Business
|
|
|
|
{
|
|
|
|
public class JDBusiness : PlatformSDKBusiness
|
|
|
|
{
|
|
|
|
public override Enums.Platform Platform => Enums.Platform.京东;
|
|
|
|
|
|
|
|
private readonly string searchFields = "orderId,venderId,orderType,payType,orderTotalPrice,orderSellerPrice,orderPayment,freightPrice,orderState,orderStateRemark,orderRemark,orderStartTime,orderEndTime,modified,consigneeInfo,itemInfoList,couponDetailList,taxFee,venderRemark,pin,waybill,storeOrder,storeId,sellerDiscount";
|
|
|
|
|
|
|
|
private readonly IDictionary<string, string> flagDictionary = new Dictionary<string, string>()
|
|
|
|
{
|
|
|
|
{ "Gray","0" },
|
|
|
|
{ "Red","1"},
|
|
|
|
{ "Yellow","2"},
|
|
|
|
{ "Green","3"},
|
|
|
|
{ "Blue","4"},
|
|
|
|
{ "Purple","5"}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public JDBusiness(IMemoryCache memoryCache, NLogManager nLogManager) : base(memoryCache, nLogManager) { }
|
|
|
|
|
|
|
|
private IJdClient GetJdClient(string appKey, string appSecret)
|
|
|
|
{
|
|
|
|
if (!memoryCache.TryGetValue(appKey, out IJdClient jdClient))
|
|
|
|
{
|
|
|
|
jdClient = new DefaultJdClient("https://api.jd.com/routerjson", appKey, appSecret);
|
|
|
|
memoryCache.Set(appKey, jdClient, expirationTimeSpan);
|
|
|
|
}
|
|
|
|
return jdClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override VenderResponse GetVenderInfo(PlatformRequest platformRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(platformRequest.AppKey, platformRequest.AppSecret);
|
|
|
|
|
|
|
|
var shopJDResponse = jdClient.Execute(new VenderShopQueryRequest(), platformRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (shopJDResponse.IsError)
|
|
|
|
throw new BusinessException(string.IsNullOrEmpty(shopJDResponse.ErrorMsg) ? shopJDResponse.ErrMsg : shopJDResponse.ErrorMsg);
|
|
|
|
|
|
|
|
var venderJDResponse = jdClient.Execute(new SellerVenderInfoGetRequest(), platformRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (venderJDResponse.IsError)
|
|
|
|
throw new BusinessException(string.IsNullOrEmpty(venderJDResponse.ErrorMsg) ? venderJDResponse.ErrMsg : venderJDResponse.ErrorMsg);
|
|
|
|
|
|
|
|
nLogManager.Default().Info($"shopJDResponse\r\n{shopJDResponse.Body}\r\n shopJDResponse Json is null {shopJDResponse.Json == null}");
|
|
|
|
|
|
|
|
nLogManager.Default().Info($"venderJDResponse\r\n{venderJDResponse.Body}\r\n venderJDResponse Json is null {venderJDResponse.Json == null}");
|
|
|
|
|
|
|
|
var v = new VenderResponse();
|
|
|
|
v.VenderId = venderJDResponse.Json["jingdong_seller_vender_info_get_responce"]["vender_info_result"].Value<string>("vender_id");
|
|
|
|
v.ShopId = venderJDResponse.Json["jingdong_seller_vender_info_get_responce"]["vender_info_result"].Value<string>("shop_id");
|
|
|
|
v.ShopName = venderJDResponse.Json["jingdong_seller_vender_info_get_responce"]["vender_info_result"].Value<string>("shop_name");
|
|
|
|
v.ColType = venderJDResponse.Json["jingdong_seller_vender_info_get_responce"]["vender_info_result"].Value<string>("col_type"); //0 SOP 1 FBP 100 FCS
|
|
|
|
v.Logo = shopJDResponse.Json["jingdong_vender_shop_query_responce"]["shop_jos_result"].Value<string>("logo_url");
|
|
|
|
v.MainCategoryId = shopJDResponse.Json["jingdong_vender_shop_query_responce"]["shop_jos_result"].Value<string>("category_main");
|
|
|
|
v.MainCategoryName = shopJDResponse.Json["jingdong_vender_shop_query_responce"]["shop_jos_result"].Value<string>("category_main_name");
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override ProductListResponse GetProductList(SearchProductRequest searchProductRequest)
|
|
|
|
{
|
|
|
|
if (searchProductRequest.PageSize == 0)
|
|
|
|
searchProductRequest.PageSize = 5;
|
|
|
|
|
|
|
|
var jdClient = GetJdClient(searchProductRequest.AppKey, searchProductRequest.AppSecret);
|
|
|
|
var req_productList = new WareReadSearchWare4ValidRequest()
|
|
|
|
{
|
|
|
|
orderField = "modified",
|
|
|
|
orderType = "desc",
|
|
|
|
pageSize = searchProductRequest.PageSize,
|
|
|
|
pageNo = searchProductRequest.PageIndex,
|
|
|
|
field = "created,logo"
|
|
|
|
};
|
|
|
|
if (!string.IsNullOrEmpty(searchProductRequest.Spu))
|
|
|
|
req_productList.wareId = searchProductRequest.Spu;
|
|
|
|
if (!string.IsNullOrEmpty(searchProductRequest.ProductItem))
|
|
|
|
req_productList.itemNum = searchProductRequest.ProductItem;
|
|
|
|
if (!string.IsNullOrEmpty(searchProductRequest.ProductName))
|
|
|
|
{
|
|
|
|
req_productList.searchField = "title";
|
|
|
|
req_productList.searchKey = searchProductRequest.ProductName;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rep_productList = jdClient.Execute(req_productList, searchProductRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (rep_productList.IsError)
|
|
|
|
throw new BusinessException(string.IsNullOrEmpty(rep_productList.ErrorMsg) ? rep_productList.ErrMsg : rep_productList.ErrorMsg);
|
|
|
|
return new ProductListResponse()
|
|
|
|
{
|
|
|
|
Count = rep_productList.page.totalItem,
|
|
|
|
Items = ((JArray)rep_productList.Json["jingdong_ware_read_searchWare4Valid_responce"]["page"]["data"]).Select(p => new ProductResponse()
|
|
|
|
{
|
|
|
|
Id = p.Value<string>("wareId"),
|
|
|
|
Title = p.Value<string>("title"),
|
|
|
|
ProductItemNum = p.Value<string>("itemNum"),
|
|
|
|
State = p.Value<int>("wareStatus"),
|
|
|
|
CreateTime = p.Value<long>("created").StampToDateTime(),
|
|
|
|
Logo = $"https://img13.360buyimg.com/n9/s100x100_{p.Value<string>("logo")}"
|
|
|
|
}).ToList()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IList<ProductSkuResponse> GetProductSkuList(SearchProductSkuRequest searchProductSkuRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(searchProductSkuRequest.AppKey, searchProductSkuRequest.AppSecret);
|
|
|
|
var req_skuList = new SkuReadSearchSkuListRequest()
|
|
|
|
{
|
|
|
|
pageSize = 50,//50
|
|
|
|
field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
|
|
|
|
req_skuList.wareId = searchProductSkuRequest.Spu;
|
|
|
|
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
|
|
|
|
req_skuList.skuId = searchProductSkuRequest.Sku;
|
|
|
|
|
|
|
|
var rep_skuList = jdClient.Execute(req_skuList, searchProductSkuRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (rep_skuList.IsError)
|
|
|
|
throw new BusinessException(string.IsNullOrEmpty(rep_skuList.ErrorMsg) ? rep_skuList.ErrMsg : rep_skuList.ErrorMsg);
|
|
|
|
|
|
|
|
return ((JArray)rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
|
|
|
|
{
|
|
|
|
Id = s.Value<string>("skuId"),
|
|
|
|
ProductId = s.Value<string>("wareId"),
|
|
|
|
Price = s.Value<decimal>("jdPrice"),
|
|
|
|
Title = s["saleAttrs"] != null ? string.Join("-", s["saleAttrs"].Select(a => a["attrValueAlias"][0].ToString())) : string.Empty,
|
|
|
|
Logo = $"https://img13.360buyimg.com/n9/s80x80_{s.Value<string>("logo")}",
|
|
|
|
State = s.Value<int>("status"),
|
|
|
|
CreateTime = s.Value<long>("created").StampToDateTime(),
|
|
|
|
Source = searchProductSkuRequest.IsContainSource ? s : null
|
|
|
|
}).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IList<SimpleProductSkuResponse> GetSimpleProductSkuList(SearchProductSkuRequest searchProductSkuRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(searchProductSkuRequest.AppKey, searchProductSkuRequest.AppSecret);
|
|
|
|
var req_skuList = new SkuReadSearchSkuListRequest()
|
|
|
|
{
|
|
|
|
pageSize = 50,//50
|
|
|
|
field = "logo"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
|
|
|
|
req_skuList.wareId = searchProductSkuRequest.Spu;
|
|
|
|
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
|
|
|
|
req_skuList.skuId = searchProductSkuRequest.Sku;
|
|
|
|
|
|
|
|
var rep_skuList = jdClient.Execute(req_skuList, searchProductSkuRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (rep_skuList.IsError)
|
|
|
|
throw new BusinessException(rep_skuList.ErrorMsg);
|
|
|
|
return ((JArray)rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new SimpleProductSkuResponse()
|
|
|
|
{
|
|
|
|
Id = s.Value<string>("skuId"),
|
|
|
|
Logo = $"https://img13.360buyimg.com/n9/s80x80_{s.Value<string>("logo")}"
|
|
|
|
}).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IList<JToken> GetOrderList(SearchPlatformOrderRequest searchOrderRequest)
|
|
|
|
{
|
|
|
|
//logger.Info($"searchOrderRequest ${JsonConvert.SerializeObject(searchOrderRequest)}");
|
|
|
|
if (searchOrderRequest.StartDate == null || searchOrderRequest.EndDate == null)
|
|
|
|
throw new BusinessException("缺少开始/结束日期");
|
|
|
|
if ((searchOrderRequest.EndDate.Value - searchOrderRequest.StartDate.Value).TotalDays > 30)
|
|
|
|
throw new BusinessException("开始/结束相差不能超过30天");
|
|
|
|
|
|
|
|
var jdClient = GetJdClient(searchOrderRequest.AppKey, searchOrderRequest.AppSecret);
|
|
|
|
|
|
|
|
//int orderCount = 0;
|
|
|
|
List<JToken> orderJtokens = new List<JToken>();
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(searchOrderRequest.OrderId))
|
|
|
|
{
|
|
|
|
if (searchOrderRequest.JDColType == "1")
|
|
|
|
{
|
|
|
|
var fbpReq = new PopOrderFbpSearchRequest();
|
|
|
|
if (searchOrderRequest.StartDate != null)
|
|
|
|
fbpReq.startDate = searchOrderRequest.StartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
if (searchOrderRequest.EndDate != null)
|
|
|
|
fbpReq.endDate = searchOrderRequest.EndDate.Value.Date.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
if (string.IsNullOrEmpty(searchOrderRequest.OrderState))
|
|
|
|
{
|
|
|
|
fbpReq.orderState = "DengDaiDaYin,DengDaiChuKu,DengDaiDaBao,DengDaiFaHuo,ZiTiTuZhong,ShangMenTiHuo,ZiTiTuiHuo,DengDaiQueRenShouHuo,PeiSongTuiHuo,HuoDaoFuKuanQueRen,WanCheng,DengDaiFenQiFuKuan,ServiceFinished,SuoDing,DengDaiTuiKuan,DengDaiKeHuHuiFu,TRADE_CANCELED,LOCKED";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fbpReq.orderState = searchOrderRequest.OrderState; //待转换
|
|
|
|
}
|
|
|
|
fbpReq.page = searchOrderRequest.PageIndex.ToString();
|
|
|
|
fbpReq.pageSize = searchOrderRequest.PageSize.ToString();
|
|
|
|
fbpReq.colType = "1";
|
|
|
|
fbpReq.optionalFields = searchFields;
|
|
|
|
fbpReq.sortType = "1";
|
|
|
|
if (searchOrderRequest.SortTimeType != null)
|
|
|
|
fbpReq.dateType = ((int)searchOrderRequest.SortTimeType).ToString();
|
|
|
|
|
|
|
|
var fbpResponse = jdClient.Execute(fbpReq, searchOrderRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (searchOrderRequest.SaveResponseLog)
|
|
|
|
nLogManager.Default().Info($"fbpResponse\r\n{JsonConvert.SerializeObject(fbpResponse)}");
|
|
|
|
if (fbpResponse.IsError)
|
|
|
|
throw new BusinessException($"获取FBP订单失败 {(string.IsNullOrEmpty(fbpResponse.ErrorMsg) ? fbpResponse.ErrMsg : fbpResponse.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (fbpResponse.Json == null)
|
|
|
|
fbpResponse.Json = JObject.Parse(fbpResponse.Body);
|
|
|
|
|
|
|
|
//orderCount = fbpResponse.Json["jingdong_pop_order_fbp_search_responce"]["searchfbporderinfo_result"].Value<int>("orderTotal");
|
|
|
|
orderJtokens.AddRange((JArray)fbpResponse.Json["jingdong_pop_order_fbp_search_responce"]["searchfbporderinfo_result"]["orderInfoList"]);
|
|
|
|
}
|
|
|
|
else if (searchOrderRequest.JDColType == "0")
|
|
|
|
{
|
|
|
|
var sopReq = new PopOrderEnSearchRequest();
|
|
|
|
if (searchOrderRequest.StartDate != null)
|
|
|
|
sopReq.startDate = searchOrderRequest.StartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
if (searchOrderRequest.EndDate != null)
|
|
|
|
sopReq.endDate = searchOrderRequest.EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
if (string.IsNullOrEmpty(searchOrderRequest.OrderState))
|
|
|
|
{
|
|
|
|
//WAIT_SELLER_STOCK_OUT,WAIT_GOODS_RECEIVE_CONFIRM,WAIT_SELLER_DELIVER,PAUSE,FINISHED_L,TRADE_CANCELED,LOCKED
|
|
|
|
sopReq.orderState = "WAIT_SELLER_STOCK_OUT,WAIT_GOODS_RECEIVE_CONFIRM,PAUSE,FINISHED_L,TRADE_CANCELED,LOCKED,NOT_PAY";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sopReq.orderState = searchOrderRequest.OrderState; //待转换
|
|
|
|
}
|
|
|
|
sopReq.optionalFields = searchFields;
|
|
|
|
sopReq.page = searchOrderRequest.PageIndex.ToString();
|
|
|
|
sopReq.pageSize = searchOrderRequest.PageSize.ToString();
|
|
|
|
sopReq.sortType = "1";
|
|
|
|
if (searchOrderRequest.SortTimeType != null)
|
|
|
|
sopReq.dateType = ((int)searchOrderRequest.SortTimeType).ToString();
|
|
|
|
//sopReq.dateType = "";
|
|
|
|
|
|
|
|
var sopResponse = jdClient.Execute(sopReq, searchOrderRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (searchOrderRequest.SaveResponseLog)
|
|
|
|
nLogManager.Default().Info($"sopRequest\r\n{JsonConvert.SerializeObject(searchOrderRequest)} \r\nsopResponse\r\n{JsonConvert.SerializeObject(sopResponse)}");
|
|
|
|
if (sopResponse.IsError)
|
|
|
|
throw new BusinessException($"获取SOP订单失败 {(string.IsNullOrEmpty(sopResponse.ErrorMsg) ? sopResponse.ErrMsg : sopResponse.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (sopResponse.Json == null)
|
|
|
|
sopResponse.Json = JObject.Parse(sopResponse.Body);
|
|
|
|
|
|
|
|
//orderCount = sopResponse.Json["jingdong_pop_order_enSearch_responce"]["searchorderinfo_result"].Value<int>("orderTotal");
|
|
|
|
orderJtokens.AddRange((JArray)sopResponse.Json["jingdong_pop_order_enSearch_responce"]["searchorderinfo_result"]["orderInfoList"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var req = new PopOrderEnGetRequest();
|
|
|
|
req.optionalFields = searchFields;
|
|
|
|
req.orderId = searchOrderRequest.OrderId;
|
|
|
|
|
|
|
|
var jdResponse = jdClient.Execute(req, searchOrderRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (jdResponse.IsError)
|
|
|
|
throw new BusinessException(jdResponse.ErrorMsg);
|
|
|
|
if (searchOrderRequest.SaveResponseLog)
|
|
|
|
nLogManager.Default().Info($"jdResponse\r\n{JsonConvert.SerializeObject(jdResponse)}");
|
|
|
|
if (jdResponse.IsError)
|
|
|
|
throw new BusinessException($"获取单订单失败 {(string.IsNullOrEmpty(jdResponse.ErrorMsg) ? jdResponse.ErrMsg : jdResponse.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (jdResponse.Json == null)
|
|
|
|
jdResponse.Json = JObject.Parse(jdResponse.Body);
|
|
|
|
|
|
|
|
var orderInfo = jdResponse.Json["jingdong_pop_order_enGet_responce"]["orderDetailInfo"]["orderInfo"];
|
|
|
|
if (orderInfo != null)
|
|
|
|
{
|
|
|
|
//orderCount = 1;
|
|
|
|
orderJtokens.Add(orderInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return orderJtokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override ConsigneeSimpleResponse DecryptConsignee(DecryptConsigneeRequest decryptConsigneeRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(decryptConsigneeRequest.AppKey, decryptConsigneeRequest.AppSecret);
|
|
|
|
var req = new PopOrderEnGetRequest();
|
|
|
|
req.optionalFields = searchFields;
|
|
|
|
req.orderId = decryptConsigneeRequest.OrderId;
|
|
|
|
var jdResponse = jdClient.Execute(req, decryptConsigneeRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (jdResponse.IsError)
|
|
|
|
throw new BusinessException($"解密异常 {decryptConsigneeRequest.OrderId} {(string.IsNullOrEmpty(jdResponse.ErrorMsg) ? jdResponse.ErrMsg : jdResponse.ErrorMsg)}");
|
|
|
|
if (jdResponse.Json == null)
|
|
|
|
jdResponse.Json = JObject.Parse(jdResponse.Body);
|
|
|
|
var orderInfo = jdResponse.Json["jingdong_pop_order_enGet_responce"]["orderDetailInfo"]["orderInfo"];
|
|
|
|
if (orderInfo == null)
|
|
|
|
throw new BusinessException($"解密异常 {decryptConsigneeRequest.OrderId}不存在");
|
|
|
|
|
|
|
|
var tdeClient = new TDEClient("https://api.jd.com/routerjson", decryptConsigneeRequest.AppKey, decryptConsigneeRequest.AppSecret, decryptConsigneeRequest.AppToken);
|
|
|
|
var decryptContactName = tdeClient.DecryptString(orderInfo["consigneeInfo"].Value<string>("fullname"));
|
|
|
|
var decryptAddress = tdeClient.DecryptString(orderInfo["consigneeInfo"].Value<string>("fullAddress"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
PopOrderGetmobilelistRequest decryptMobileReq = new PopOrderGetmobilelistRequest();
|
|
|
|
decryptMobileReq.appName = "订单管家";
|
|
|
|
decryptMobileReq.orderId = decryptConsigneeRequest.OrderId;
|
|
|
|
|
|
|
|
var decryptMobileResponse = jdClient.Execute(decryptMobileReq, decryptConsigneeRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (decryptMobileResponse.IsError)
|
|
|
|
throw new BusinessException(string.IsNullOrEmpty(decryptMobileResponse.ErrorMsg) ? decryptMobileResponse.ErrMsg : decryptMobileResponse.ErrorMsg);
|
|
|
|
|
|
|
|
|
|
|
|
if (decryptConsigneeRequest.SaveResponseLog)
|
|
|
|
logger.Info(decryptMobileResponse.Body);
|
|
|
|
|
|
|
|
if (decryptMobileResponse.Json == null)
|
|
|
|
decryptMobileResponse.Json = JObject.Parse(decryptMobileResponse.Body);
|
|
|
|
|
|
|
|
if (decryptMobileResponse.Json["jingdong_pop_order_getmobilelist_responce"]["result"]["data"] == null)
|
|
|
|
throw new BusinessException(decryptMobileResponse.Json["jingdong_pop_order_getmobilelist_responce"]["result"]["message"].ToString());
|
|
|
|
|
|
|
|
var decryptMobile = decryptMobileResponse.Json["jingdong_pop_order_getmobilelist_responce"]["result"]["data"][decryptConsigneeRequest.OrderId].Value<string>("consMobilePhone");
|
|
|
|
var decryptTelePhone = decryptMobileResponse.Json["jingdong_pop_order_getmobilelist_responce"]["result"]["data"][decryptConsigneeRequest.OrderId].Value<string>("customerPhone");
|
|
|
|
*/
|
|
|
|
return new ConsigneeSimpleResponse()
|
|
|
|
{
|
|
|
|
Address = decryptAddress,
|
|
|
|
ContactName = decryptContactName,
|
|
|
|
//Mobile = decryptMobile,
|
|
|
|
//TelePhone = decryptTelePhone
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void EditVenderRemark(EditVenderRemarkRequest editVenderRemarkRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(editVenderRemarkRequest.AppKey, editVenderRemarkRequest.AppSecret);
|
|
|
|
PopOrderModifyVenderRemarkRequest req = new PopOrderModifyVenderRemarkRequest
|
|
|
|
{
|
|
|
|
orderId = long.Parse(editVenderRemarkRequest.OrderId),
|
|
|
|
flag = flagDictionary.ContainsKey(editVenderRemarkRequest.Flag) ? flagDictionary[editVenderRemarkRequest.Flag] : editVenderRemarkRequest.Flag,
|
|
|
|
remark = editVenderRemarkRequest.VenderRemark
|
|
|
|
};
|
|
|
|
|
|
|
|
var response = jdClient.Execute(req, editVenderRemarkRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"修改商家备注失败 {(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IList<LogisticsResponse> GetLogisticsList(PlatformRequest platformRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(platformRequest.AppKey, platformRequest.AppSecret);
|
|
|
|
var response = jdClient.Execute(new FceAlphaGetVenderCarrierRequest(), platformRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"{response.RealErrorMsg}");
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JObject.Parse(response.Body);
|
|
|
|
if (platformRequest.SaveResponseLog)
|
|
|
|
nLogManager.Default().Info(response.Body);
|
|
|
|
|
|
|
|
|
|
|
|
var jarray = (JArray)(response.Json["jingdong_fce_alpha_getVenderCarrier_responce"]["StandardGenericResponse"]["result"]["carrierList"]);
|
|
|
|
return jarray.Select(j => new LogisticsResponse()
|
|
|
|
{
|
|
|
|
Id = j.Value<string>("id"),
|
|
|
|
Name = j.Value<string>("name"),
|
|
|
|
}).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OutStock(OutStockRequest outStockRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(outStockRequest.AppKey, outStockRequest.AppSecret);
|
|
|
|
PopOrderShipmentRequest req = new PopOrderShipmentRequest
|
|
|
|
{
|
|
|
|
orderId = outStockRequest.OrderId,
|
|
|
|
logiCoprId = outStockRequest.LogisticsId,
|
|
|
|
logiNo = outStockRequest.WayBillNo
|
|
|
|
};
|
|
|
|
|
|
|
|
var response = jdClient.Execute(req, outStockRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (outStockRequest.SaveResponseLog)
|
|
|
|
nLogManager.Default().Info($"出库发货 Request:{JsonConvert.SerializeObject(outStockRequest)} Response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"{response.RealErrorMsg}");
|
|
|
|
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JObject.Parse(response.Body);
|
|
|
|
|
|
|
|
if (!response.Json["jingdong_pop_order_shipment_responce"]["sopjosshipment_result"].Value<bool>("success"))
|
|
|
|
{
|
|
|
|
throw new BusinessException($"{response.Json["jingdong_pop_order_shipment_responce"]["sopjosshipment_result"].Value<string>("chineseErrCode")}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetRefundList(SearchRefundPlatformOrderRequest searchRefundPlatformOrderRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(searchRefundPlatformOrderRequest.AppKey, searchRefundPlatformOrderRequest.AppSecret);
|
|
|
|
|
|
|
|
|
|
|
|
AscServiceAndRefundViewRequest req = new AscServiceAndRefundViewRequest();
|
|
|
|
|
|
|
|
//req.orderId = ;
|
|
|
|
|
|
|
|
//req.applyTimeBegin = ;
|
|
|
|
|
|
|
|
//req.applyTimeEnd = ;
|
|
|
|
if (!string.IsNullOrEmpty(searchRefundPlatformOrderRequest.OrderId))
|
|
|
|
req.orderId = long.Parse(searchRefundPlatformOrderRequest.OrderId);
|
|
|
|
req.approveTimeBegin = searchRefundPlatformOrderRequest.StartDate;
|
|
|
|
req.approveTimeEnd = searchRefundPlatformOrderRequest.EndDate;
|
|
|
|
req.pageNumber = searchRefundPlatformOrderRequest.PageIndex.ToString();
|
|
|
|
req.pageSize = searchRefundPlatformOrderRequest.PageSize.ToString();
|
|
|
|
|
|
|
|
var response = jdClient.Execute(req, searchRefundPlatformOrderRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (searchRefundPlatformOrderRequest.SaveResponseLog)
|
|
|
|
nLogManager.Default().Info($"获取退款订单 Request:{JsonConvert.SerializeObject(searchRefundPlatformOrderRequest)} Response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"获取退款订单失败 {(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JsonConvert.DeserializeObject<JObject>(response.Body);
|
|
|
|
|
|
|
|
//return base.GetRefundList(searchRefundPlatformOrderRequest);
|
|
|
|
return (JArray)response.Json["jingdong_asc_serviceAndRefund_view_responce"]["pageResult"]["data"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetAfterOrderList(SyncAfterOrderRequest syncAfterOrderRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(syncAfterOrderRequest.AppKey, syncAfterOrderRequest.AppSecret);
|
|
|
|
var req = new AscQueryListRequest();
|
|
|
|
req.buId = syncAfterOrderRequest.VenderId;
|
|
|
|
req.operatePin = "开发测试";
|
|
|
|
req.operateNick = "开发测试";
|
|
|
|
req.finishTimeBegin = syncAfterOrderRequest.StartDate;
|
|
|
|
req.finishTimeEnd = syncAfterOrderRequest.EndDate;
|
|
|
|
req.pageNumber = syncAfterOrderRequest.PageIndex.ToString();
|
|
|
|
req.pageSize = syncAfterOrderRequest.PageSize.ToString();
|
|
|
|
if (!string.IsNullOrEmpty(syncAfterOrderRequest.OrderId))
|
|
|
|
req.orderId = long.Parse(syncAfterOrderRequest.OrderId);
|
|
|
|
|
|
|
|
AscQueryListResponse response = jdClient.Execute(req, syncAfterOrderRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"获取售后订单失败 {(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JsonConvert.DeserializeObject<JObject>(response.Body);
|
|
|
|
return (JArray)response.Json["jingdong_asc_query_list_responce"]["pageResult"]["data"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JToken GetNoPayOrder(SearchPlatformOrderRequest searchOrderRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(searchOrderRequest.AppKey, searchOrderRequest.AppSecret);
|
|
|
|
|
|
|
|
PopOrderNotPayOrderByIdRequest req = new PopOrderNotPayOrderByIdRequest();
|
|
|
|
|
|
|
|
req.orderId = searchOrderRequest.OrderId;
|
|
|
|
|
|
|
|
|
|
|
|
PopOrderNotPayOrderByIdResponse response = jdClient.Execute(req, searchOrderRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
nLogManager.Default().Info(response);
|
|
|
|
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"获取未付款订单失败,{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JsonConvert.DeserializeObject<JObject>(response.Body);
|
|
|
|
if (response.Json["jingdong_pop_order_notPayOrderById_responce"] == null)
|
|
|
|
throw new BusinessException($"未查询到未付款订单");
|
|
|
|
|
|
|
|
return response.Json;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetJDShopSopularizeRecordList(SyncShopPopularizeRequest syncShopPopularizeRequest)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(syncShopPopularizeRequest.AppKey, syncShopPopularizeRequest.AppSecret);
|
|
|
|
var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest();
|
|
|
|
req.beginDate = syncShopPopularizeRequest.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.endDate = syncShopPopularizeRequest.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.pageNo = syncShopPopularizeRequest.PageIndex == 0 ? 1 : syncShopPopularizeRequest.PageIndex;
|
|
|
|
req.pageSize = 100;
|
|
|
|
req.moneyType = 1;
|
|
|
|
|
|
|
|
var response = jdClient.Execute(req, syncShopPopularizeRequest.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"获取JD推广费用失败,{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JsonConvert.DeserializeObject<JObject>(response.Body);
|
|
|
|
return (JArray)response.Json["jingdong_dsp_platform_finance_openapi_querycostdetails_responce"]["returnType"]["data"]["page"]["data"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetJDSopularizeReportFormBySkuLevel(SyncJDPopularizeReportFormRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
var req = new AdsIbgUniversalJosServiceSkuQueryRequest();
|
|
|
|
req.businessType = request.Business.ToString();
|
|
|
|
req.isDaily = "true";
|
|
|
|
req.clickOrOrderDay = "0";
|
|
|
|
req.pageSize = "100";
|
|
|
|
req.page = request.PageIndex.ToString();
|
|
|
|
req.clickOrOrderCaliber = "1";
|
|
|
|
req.startDay = request.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.endDay = request.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.giftFlag = "0";
|
|
|
|
req.orderStatusCategory = "1";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取JD推广报表-Sku维度出错,{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
return (JArray)res.Json["jingdong_ads_ibg_UniversalJosService_sku_query_responce"]["returnType"]["data"]["datas"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetJDSopularizeReportFormByAdLevel(SyncJDPopularizeReportFormRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
|
|
|
|
var req = new AdsIbgUniversalJosServiceAdQueryRequest();
|
|
|
|
req.businessType = request.Business.ToString();
|
|
|
|
req.isDaily = "true";
|
|
|
|
req.clickOrOrderDay = "0";
|
|
|
|
req.pageSize = "100";
|
|
|
|
req.page = request.PageIndex.ToString();
|
|
|
|
req.clickOrOrderCaliber = "1";
|
|
|
|
req.startDay = request.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.endDay = request.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.giftFlag = "0";
|
|
|
|
req.orderStatusCategory = "1";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取JD推广报表-创意维度出错,{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
return (JArray)res.Json["jingdong_ads_ibg_UniversalJosService_ad_query_responce"]["returnType"]["data"]["datas"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetJDSopularizeReportFormByCampaignLevel(SyncJDPopularizeReportFormRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
|
|
|
|
var req = new AdsIbgUniversalJosServiceCampaignQueryRequest();
|
|
|
|
req.startDay = request.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.endDay = request.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.businessType = request.Business.ToString();
|
|
|
|
req.clickOrOrderDay = "0";
|
|
|
|
req.clickOrOrderCaliber = "1";
|
|
|
|
req.giftFlag = "0";
|
|
|
|
req.isDaily = "true";
|
|
|
|
req.pageSize = "100";
|
|
|
|
req.page = request.PageIndex.ToString();
|
|
|
|
req.orderStatusCategory = "1";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取JD推广报表-计划维度出错,{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
return (JArray)res.Json["jingdong_ads_ibg_UniversalJosService_campaign_query_responce"]["returnType"]["data"]["datas"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetJDSopularizeReportFormByAdGroupLevel(SyncJDPopularizeReportFormRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
|
|
|
|
var req = new AdsIbgUniversalJosServiceGroupQueryRequest();
|
|
|
|
req.startDay = request.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.endDay = request.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.businessType = request.Business.ToString();
|
|
|
|
req.clickOrOrderDay = "0";
|
|
|
|
req.giftFlag = "0";
|
|
|
|
req.clickOrOrderCaliber = "1";
|
|
|
|
req.pageSize = "100";
|
|
|
|
req.isDaily = "true";
|
|
|
|
req.page = request.PageIndex.ToString();
|
|
|
|
req.orderStatusCategory = "1";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取JD推广报表-单元维度出错,{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
return (JArray)res.Json["jingdong_ads_ibg_UniversalJosService_group_query_responce"]["returnType"]["data"]["datas"];
|
|
|
|
}
|
|
|
|
public override JArray GetJDSopularizeReportFormByOrderLevel(SyncJDPopularizeReportFormRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
var req = new AdsIbgUniversalJosServiceOrderQueryRequest();
|
|
|
|
req.businessType = request.Business.ToString();
|
|
|
|
req.clickOrOrderDay = "15";
|
|
|
|
req.pageSize = "100";
|
|
|
|
req.clickOrOrderCaliber = "1";
|
|
|
|
req.orderStartDay = request.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.orderEndDay = request.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.clickStartDay = request.StartDate.ToString("yyyy-MM-dd");
|
|
|
|
req.clickEndDay = request.EndDate.ToString("yyyy-MM-dd");
|
|
|
|
req.giftFlag = "0";
|
|
|
|
//req.orderStatus = "4";
|
|
|
|
req.page = request.PageIndex.ToString();
|
|
|
|
//if (request.Business == 134217728)
|
|
|
|
req.myself = "1,3";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取JD推广报表-订单维度出错,{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
return (JArray)res.Json["jingdong_ads_ibg_UniversalJosService_order_query_responce"]["returnType"]["data"]["datas"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetStoreHouseList(PlatformRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
var req = new StoreFindPartitionWhByIdAndStatusRequest();
|
|
|
|
req.status = "2";
|
|
|
|
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取仓库出错 {(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
|
|
|
|
return (JArray)res.Json["jingdong_store_findPartitionWhByIdAndStatus_responce"]["find_Partition_Warehouse_Result"]["result"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override JArray GetStockNumBySku(SearchProductSkuRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
var req = new StockReadFindSkuStockRequest();
|
|
|
|
|
|
|
|
|
|
|
|
req.skuId = long.Parse(request.Sku); // 10036238533172; //京仓sku
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取sku库存出错 {(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
|
|
|
|
|
|
return (JArray)res.Json["jingdong_stock_read_findSkuStock_responce"]["skuStocks"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void DeleteSku(DeleteSkuRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
var req = new SkuWriteDeleteSkuRequest();
|
|
|
|
req.skuId = long.Parse(request.Sku);
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void DeleteSkuList(DeleteSkuListRequest request)
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
foreach (var sku in request.SkuList)
|
|
|
|
{
|
|
|
|
var req = new SkuWriteDeleteSkuRequest();
|
|
|
|
req.skuId = long.Parse(sku);
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override long StartJDPromotionTask(StartPromotionTaskRequest2 request)
|
|
|
|
{
|
|
|
|
var stepText = string.Empty;
|
|
|
|
//stepText.AppendLine($"任务Id {request.Id} 店铺Id {request.ShopId}");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
long wareId = long.Parse(request.MainProductSpu);
|
|
|
|
List<string> giftSkuIdList = new List<string>();
|
|
|
|
long promotionId = 0;
|
|
|
|
var brandName = string.Empty;
|
|
|
|
#region 获取主商品品牌
|
|
|
|
{
|
|
|
|
stepText = "获取主商品品牌";
|
|
|
|
var req = new WareReadFindWareByIdRequest();
|
|
|
|
req.wareId = wareId;
|
|
|
|
req.field = "barCode,categoryId,brandName";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"获取主商品品牌失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
brandName = res.Json["jingdong_ware_read_findWareById_responce"]["ware"].Value<string>("brandName");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 设置精简标题
|
|
|
|
{
|
|
|
|
stepText = "设置精简标题";
|
|
|
|
var req = new WareWriteUpdateWareTitleRequest();
|
|
|
|
req.wareId = wareId;
|
|
|
|
//req.title = request.SimpleTitle;
|
|
|
|
if (!request.SimpleTitle.StartsWith(brandName))
|
|
|
|
req.title = $"{brandName}{request.SimpleTitle}";
|
|
|
|
else
|
|
|
|
req.title = request.SimpleTitle;
|
|
|
|
var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"设置精简标题出错-{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(request.GiftTemplateSku))
|
|
|
|
{
|
|
|
|
#region 上架赠品
|
|
|
|
string barCode = string.Empty, categoryId = string.Empty;
|
|
|
|
IList<JToken> multiCateProps = null;
|
|
|
|
#region 获取主商品sku信息 barCode,categoryId,multiCateProps
|
|
|
|
{
|
|
|
|
stepText = "获取主商品sku信息";
|
|
|
|
var mainSkuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
IsContainSource = true,
|
|
|
|
Platform = request.Platform,
|
|
|
|
Spu = request.MainProductSpu
|
|
|
|
});
|
|
|
|
if (mainSkuList.Count() == 0)
|
|
|
|
throw new BusinessException($"获取主商品sku信息-未查询到sku信息");
|
|
|
|
|
|
|
|
barCode = mainSkuList[0].Source.Value<string>("barCode");
|
|
|
|
categoryId = mainSkuList[0].Source.Value<string>("categoryId");
|
|
|
|
multiCateProps = mainSkuList[0].Source["multiCateProps"] != null ? mainSkuList[0].Source["multiCateProps"].ToList() : null;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 获取赠品sku信息
|
|
|
|
stepText = "获取赠品sku信息";
|
|
|
|
var selectGiftSkuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
IsContainSource = true,
|
|
|
|
Platform = request.Platform,
|
|
|
|
Sku = request.GiftTemplateSku
|
|
|
|
});
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 获取销售属性
|
|
|
|
stepText = "获取销售属性";
|
|
|
|
IList<JToken> colorSaleAttrs = null;
|
|
|
|
{
|
|
|
|
var req = new CategoryReadFindAttrsByCategoryIdUnlimitCateRequest();
|
|
|
|
req.cid = long.Parse(categoryId);
|
|
|
|
req.attributeType = 4;
|
|
|
|
req.field = "attrValueList,attrGroup";
|
|
|
|
var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.Json == null)
|
|
|
|
response.Json = JObject.Parse(response.Body);
|
|
|
|
var colorProperty = response.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"].FirstOrDefault(j => j.Value<string>("name") == "颜色");
|
|
|
|
if (colorProperty == null)
|
|
|
|
throw new Exception("获取销售属性-缺少颜色属性");
|
|
|
|
colorSaleAttrs = colorProperty["attrValueList"].ToList();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 组装上架/改名/设置细节图参数
|
|
|
|
stepText = "组装上架/改名/设置细节图参数";
|
|
|
|
var takeColorIndex = colorSaleAttrs.Count() - 1;
|
|
|
|
var skusParamList = new List<SkuWriteUpdateSkusItem>();
|
|
|
|
var updateSkuTitleParamList = new List<WareWriteUpdateWareSaleAttrvalueAliasRequestItem>();
|
|
|
|
var imageWriteUpdateRequestList = new List<ImageWriteUpdateRequest>();
|
|
|
|
|
|
|
|
for (var i = 0; i < selectGiftSkuList.Count(); i++)
|
|
|
|
{
|
|
|
|
var giftSku = selectGiftSkuList[i];
|
|
|
|
var colorProperty = colorSaleAttrs[takeColorIndex];
|
|
|
|
|
|
|
|
var p = new SkuWriteUpdateSkusItem()
|
|
|
|
{
|
|
|
|
type = "com.jd.pop.ware.ic.api.domain.Sku",
|
|
|
|
wareId = wareId,
|
|
|
|
//skuId = long.Parse(sku.Id),
|
|
|
|
jdPrice = giftSku.Price,
|
|
|
|
stockNum = 500,
|
|
|
|
barCode = barCode,
|
|
|
|
saleAttrs = new List<SkuWriteUpdateSkusItemSaleAttrs>()
|
|
|
|
{
|
|
|
|
new SkuWriteUpdateSkusItemSaleAttrs()
|
|
|
|
{
|
|
|
|
type = "com.jd.pop.ware.ic.api.domain.Prop",
|
|
|
|
attrId = colorProperty.Value<string>("attId"),
|
|
|
|
attrValues = new List<string>() { colorProperty.Value<string>("id") },
|
|
|
|
index = takeColorIndex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
p.multiCateProps = new List<SkuWriteUpdateSkusItemSaleAttrs>();
|
|
|
|
if (multiCateProps != null && multiCateProps.Count() > 0)
|
|
|
|
{
|
|
|
|
foreach (var multiCateProp in multiCateProps)
|
|
|
|
{
|
|
|
|
var m = new SkuWriteUpdateSkusItemSaleAttrs();
|
|
|
|
m.type = "com.jd.pop.ware.ic.api.domain.Prop";
|
|
|
|
m.attrId = multiCateProp.Value<string>("attrId");
|
|
|
|
m.attrValues = multiCateProp.Value<JArray>("attrValues").Select(x => x.ToString()).ToList();
|
|
|
|
p.multiCateProps.Add(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//修改标题参数
|
|
|
|
updateSkuTitleParamList.Add(new WareWriteUpdateWareSaleAttrvalueAliasRequestItem()
|
|
|
|
{
|
|
|
|
attrId = p.saleAttrs[0].attrId,
|
|
|
|
attrValues = p.saleAttrs[0].attrValues,
|
|
|
|
attrValueAlias = new List<string>() { giftSku.Title }
|
|
|
|
});
|
|
|
|
|
|
|
|
//修改商品细节图参数
|
|
|
|
var imgUrlBuilder = new StringBuilder();
|
|
|
|
var imgIndexBuilder = new StringBuilder();
|
|
|
|
imgUrlBuilder.Append($"{giftSku.Logo.Substring(giftSku.Logo.IndexOf("jfs"))},");
|
|
|
|
imgIndexBuilder.Append("1,");
|
|
|
|
imageWriteUpdateRequestList.Add(new ImageWriteUpdateRequest()
|
|
|
|
{
|
|
|
|
wareId = wareId,
|
|
|
|
colorId = colorProperty.Value<string>("id"),
|
|
|
|
imgUrl = imgUrlBuilder.ToString().Trim(','),
|
|
|
|
imgIndex = imgIndexBuilder.ToString().Trim(',')
|
|
|
|
});
|
|
|
|
|
|
|
|
takeColorIndex--;
|
|
|
|
skusParamList.Add(p);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 上架sku
|
|
|
|
{
|
|
|
|
stepText = "上架sku";
|
|
|
|
var req = new SkuWriteUpdateSkusRequest();
|
|
|
|
req.wareId = wareId;
|
|
|
|
req.skus = skusParamList;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"上架sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList().Select(x => x.Value<string>("skuId")).ToList();
|
|
|
|
giftSkuIdList.AddRange(newSkuList);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region sku改名
|
|
|
|
{
|
|
|
|
stepText = "sku改名";
|
|
|
|
var req = new WareWriteUpdateWareSaleAttrvalueAliasRequest()
|
|
|
|
{
|
|
|
|
wareId = wareId,
|
|
|
|
props = updateSkuTitleParamList
|
|
|
|
};
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"sku改名失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region sku修改细节图
|
|
|
|
stepText = "sku修改细节图";
|
|
|
|
foreach (var imageWriteUpdateRequest in imageWriteUpdateRequestList)
|
|
|
|
{
|
|
|
|
var res = jdClient.Execute(imageWriteUpdateRequest, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var skuList = request.MainProductGiftSku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
giftSkuIdList.AddRange(skuList);
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 创建活动
|
|
|
|
{
|
|
|
|
stepText = "创建活动";
|
|
|
|
var req = new SellerPromotionAddRequest();
|
|
|
|
req.name = request.ActivityName;
|
|
|
|
req.type = 4; //赠品促销
|
|
|
|
req.beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
req.endTime = DateTime.Now.AddDays(180).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
//req.bound = 123;
|
|
|
|
//req.member = 123;
|
|
|
|
//req.slogan = "abc";
|
|
|
|
//req.comment = "abc";
|
|
|
|
//req.favorMode = 123;
|
|
|
|
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.Json == null)
|
|
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
if (res.IsError)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(request.GiftTemplateSku))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (var deleteSku in giftSkuIdList)
|
|
|
|
{
|
|
|
|
DeleteSku(new DeleteSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = request.Platform,
|
|
|
|
Sku = deleteSku
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
}
|
|
|
|
throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
promotionId = res.Json["jingdong_seller_promotion_add_responce"].Value<long>("promo_id");
|
|
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 添加活动sku
|
|
|
|
{
|
|
|
|
#region 查询奶妈和主商品sku
|
|
|
|
var mainSkuList = new List<ProductSkuResponse>();
|
|
|
|
if (!string.IsNullOrEmpty(request.MotherTemplateSku))
|
|
|
|
{
|
|
|
|
var skuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = Enums.Platform.京东,
|
|
|
|
Sku = request.MotherTemplateSku
|
|
|
|
});
|
|
|
|
mainSkuList.AddRange(skuList);
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(request.MainProductSku))
|
|
|
|
{
|
|
|
|
var skuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = Enums.Platform.京东,
|
|
|
|
Sku = request.MainProductSku
|
|
|
|
});
|
|
|
|
mainSkuList.AddRange(skuList);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 查询赠品sku
|
|
|
|
|
|
|
|
var giftSkuList = new List<ProductSkuResponse>();
|
|
|
|
if (giftSkuIdList.Count() > 0)
|
|
|
|
{
|
|
|
|
var giftSkuIds = string.Join(",", giftSkuIdList);
|
|
|
|
var skuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = Enums.Platform.京东,
|
|
|
|
Sku = giftSkuIds
|
|
|
|
});
|
|
|
|
giftSkuList.AddRange(skuList);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
stepText = "添加活动sku";
|
|
|
|
var req = new SellerPromotionSkuAddRequest();
|
|
|
|
req.promoId = promotionId;
|
|
|
|
|
|
|
|
foreach (var sku in mainSkuList)
|
|
|
|
{
|
|
|
|
req.skuIds = $"{req.skuIds}{sku.Id},";
|
|
|
|
req.jdPrices = $"{req.jdPrices}{sku.Price},";
|
|
|
|
req.bindType = $"{req.bindType}1,";
|
|
|
|
req.num = $"{req.num}1,";
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var sku in giftSkuList)
|
|
|
|
{
|
|
|
|
req.skuIds = $"{req.skuIds}{sku.Id},";
|
|
|
|
req.jdPrices = $"{req.jdPrices}{sku.Price},";
|
|
|
|
req.bindType = $"{req.bindType}2,";
|
|
|
|
req.num = $"{req.num}1,";
|
|
|
|
}
|
|
|
|
|
|
|
|
req.skuIds = req.skuIds.Substring(0, req.skuIds.Length - 1);
|
|
|
|
req.jdPrices = req.jdPrices.Substring(0, req.jdPrices.Length - 1);
|
|
|
|
req.bindType = req.bindType.Substring(0, req.bindType.Length - 1);
|
|
|
|
req.num = req.num.Substring(0, req.num.Length - 1);
|
|
|
|
|
|
|
|
//req.skuIds = "";
|
|
|
|
|
|
|
|
//req.jdPrices = ;
|
|
|
|
|
|
|
|
//req.promoPrices = ;
|
|
|
|
|
|
|
|
//req.seq = ;
|
|
|
|
|
|
|
|
//req.num = ;
|
|
|
|
|
|
|
|
//req.bindType = ;
|
|
|
|
|
|
|
|
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
throw new BusinessException($"添加活动sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 提交活动
|
|
|
|
{
|
|
|
|
var req = new SellerPromotionCommitRequest();
|
|
|
|
req.promoId = promotionId;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(request.GiftTemplateSku))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (var deleteSku in giftSkuIdList)
|
|
|
|
{
|
|
|
|
DeleteSku(new DeleteSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = request.Platform,
|
|
|
|
Sku = deleteSku
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
}
|
|
|
|
throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 审核活动
|
|
|
|
{
|
|
|
|
stepText = "审核活动";
|
|
|
|
var req = new SellerPromotionCheckRequest();
|
|
|
|
req.promoId = promotionId;
|
|
|
|
req.status = 4;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.IsError)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(request.GiftTemplateSku))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (var deleteSku in giftSkuIdList)
|
|
|
|
{
|
|
|
|
DeleteSku(new DeleteSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = request.Platform,
|
|
|
|
Sku = deleteSku
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
}
|
|
|
|
throw new BusinessException($"审核活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 下架赠品sku
|
|
|
|
foreach (var deleteSku in giftSkuIdList)
|
|
|
|
{
|
|
|
|
DeleteSku(new DeleteSkuRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = request.Platform,
|
|
|
|
Sku = deleteSku
|
|
|
|
});
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 设置完整标题
|
|
|
|
{
|
|
|
|
stepText = "设置完整标题";
|
|
|
|
var req = new WareWriteUpdateWareTitleRequest();
|
|
|
|
req.wareId = long.Parse(request.MainProductSpu);
|
|
|
|
if (!request.FullTitle.StartsWith(brandName))
|
|
|
|
req.title = $"{brandName}{request.FullTitle}";
|
|
|
|
else
|
|
|
|
req.title = request.FullTitle;
|
|
|
|
var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (response.IsError)
|
|
|
|
throw new BusinessException($"设置完整标题出错-{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
return promotionId;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
nLogManager.Default().Error(ex, $"任务Id {request.Id} 店铺Id {request.ShopId} 执行步骤 {stepText}");
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|