You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2114 lines
111 KiB
2114 lines
111 KiB
using BBWY.Common.Extensions;
|
|
using BBWY.Common.Models;
|
|
using BBWY.JDSDK.Request;
|
|
using BBWY.Server.Model;
|
|
using BBWY.Server.Model.Dto;
|
|
using BBWY.Server.Model.Dto.Request.JD;
|
|
using Jd.ACES;
|
|
using Jd.ACES.Common;
|
|
using Jd.Api;
|
|
using Jd.Api.Domain;
|
|
using Jd.Api.Request;
|
|
using Jd.Api.Response;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace BBWY.Server.Business
|
|
{
|
|
public class JDBusiness : PlatformSDKBusiness
|
|
{
|
|
private DingDingBusiness dingDingBusiness;
|
|
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, DingDingBusiness dingDingBusiness, APIExecutionTimesRecorder apiExecutionTimesRecorder) : base(memoryCache, nLogManager, apiExecutionTimesRecorder)
|
|
{
|
|
this.dingDingBusiness = dingDingBusiness;
|
|
}
|
|
|
|
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,brandName"
|
|
};
|
|
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")}",
|
|
BrandName = p.Value<string>("brandName")
|
|
}).ToList()
|
|
};
|
|
}
|
|
|
|
private string GetSkuTitle(JToken s)
|
|
{
|
|
if (s["saleAttrs"] == null)
|
|
return string.Empty;//throw new BusinessException($"{s["skuId"]}没有名字");
|
|
StringBuilder titleBuilder = new StringBuilder();
|
|
List<string> attrValueAliasList = new List<string>();
|
|
|
|
attrValueAliasList.AddRange(s["saleAttrs"].Select(a => a["attrValueAlias"][0].ToString()));
|
|
/*
|
|
[{\"unit\":\"\",\"valueId\":\"1120738\",\"id\":8488,\"value\":\"手动\"},{\"unit\":\"个\",\"id\":8489,\"value\":\"30\"},{\"unit\":\"\",\"id\":8490,\"value\":\"大号M416火焰红\"}]-8弹壳+40软弹+复位标靶AWM软弹枪
|
|
*/
|
|
|
|
foreach (var attrValueAlias in attrValueAliasList)
|
|
{
|
|
if (attrValueAlias.Contains("{") && attrValueAlias.Contains("}") && attrValueAlias.Contains(":"))
|
|
{
|
|
titleBuilder.Append(string.Join(string.Empty, JArray.Parse(attrValueAlias).Select(j => $"{j.Value<string>("value")}{j.Value<string>("unit")}")));
|
|
}
|
|
else
|
|
{
|
|
titleBuilder.Append(attrValueAlias);
|
|
}
|
|
}
|
|
return titleBuilder.ToString();
|
|
}
|
|
|
|
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,promiseId,saleAttrTemplateId,enable,stockNum"
|
|
};
|
|
|
|
var skuList = new List<ProductSkuResponse>();
|
|
IList<string> skuIdList = null;
|
|
var pageIndex = 1;
|
|
var pageSize = 20;
|
|
var totalPageSize = 1;
|
|
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
|
|
{
|
|
totalPageSize = 1;
|
|
searchProductSkuRequest.IsCheckSkuCount = false;
|
|
}
|
|
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
|
|
{
|
|
skuIdList = searchProductSkuRequest.Sku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
totalPageSize = (skuIdList.Count() - 1) / pageSize + 1;
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
|
|
req_skuList.wareId = searchProductSkuRequest.Spu;
|
|
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
|
|
req_skuList.skuId = string.Join(",", skuIdList.Skip((pageIndex - 1) * pageSize).Take(pageSize));
|
|
|
|
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);
|
|
|
|
var currentList = ((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 = GetSkuTitle(s),
|
|
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();
|
|
|
|
if (currentList != null && currentList.Count() > 0)
|
|
skuList.AddRange(currentList);
|
|
|
|
if (pageIndex >= totalPageSize)
|
|
break;
|
|
pageIndex++;
|
|
}
|
|
|
|
if (searchProductSkuRequest.IsCheckSkuCount &&
|
|
!string.IsNullOrEmpty(searchProductSkuRequest.Sku) &&
|
|
skuIdList.Count() != skuList.Count())
|
|
{
|
|
var targetSkuIdList = skuList.Select(s => s.Id);
|
|
var exceptSkuIdList = skuIdList.Except(targetSkuIdList);
|
|
// throw new BusinessException($"{searchProductSkuRequest.CheckStep}-sku条件数量和查询结果数量不一致\r\n{string.Join(",", exceptSkuIdList)}");
|
|
//throw new BusinessException($"{JsonConvert.SerializeObject(skuIdList)} 以上SKU可能已下架,请修改任务将该SKU移除奶妈列表");
|
|
throw new BusinessException($"以上{searchProductSkuRequest.CheckStep}状态异常,可能被系统自动下架,请检查任务的精简标题是否正确\r\n{string.Join(",", exceptSkuIdList)}");
|
|
}
|
|
return skuList;
|
|
|
|
}
|
|
|
|
public override ProductCategoryResponse GetCategoryInfo(JDQueryCategoryRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new CategoryReadFindByIdRequest();
|
|
req.cid = long.Parse(request.CategoryId);
|
|
req.field = "fid,id,lev,name";
|
|
|
|
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);
|
|
var j = res.Json["jingdong_category_read_findById_responce"]["category"];
|
|
return new ProductCategoryResponse()
|
|
{
|
|
Fid = j.Value<string>("fid"),
|
|
Id = j.Value<string>("id"),
|
|
Name = j.Value<string>("name"),
|
|
Lev = j.Value<string>("lev")
|
|
};
|
|
}
|
|
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)
|
|
{
|
|
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 pageIndex = 1;
|
|
var pageSize = 100;
|
|
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 = pageSize.ToString();
|
|
sopReq.sortType = "1";
|
|
if (searchOrderRequest.SortTimeType != null)
|
|
sopReq.dateType = ((int)searchOrderRequest.SortTimeType).ToString();
|
|
|
|
|
|
while (true)
|
|
{
|
|
sopReq.page = pageIndex.ToString();
|
|
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");
|
|
var orderJarray = (JArray)sopResponse.Json["jingdong_pop_order_enSearch_responce"]["searchorderinfo_result"]["orderInfoList"];
|
|
orderJtokens.AddRange(orderJarray);
|
|
if (orderJarray.Count() < pageSize)
|
|
break;
|
|
pageIndex++;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var req = new PopOrderEnGetRequest();
|
|
apiExecutionTimesRecorder.Record(req.ApiName);
|
|
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 (platformRequest.SaveResponseLog)
|
|
nLogManager.Default().Info(response.Body);
|
|
|
|
if (!string.IsNullOrEmpty(response.Body) && response.Body.Contains("token已过期"))
|
|
throw new BusinessException($"查询客服组失败-服务应用到期或未订购,请订购后进行授权\r\n订购链接:https://fw.jd.com/main/detail/FW_GOODS-187201");
|
|
if (response.IsError)
|
|
throw new BusinessException($"{response.RealErrorMsg}");
|
|
if (response.Json == null)
|
|
response.Json = JObject.Parse(response.Body);
|
|
|
|
if (!string.IsNullOrEmpty(response.ErrorMsg) && response.ErrorMsg.Contains("token已过期"))
|
|
throw new BusinessException($"查询客服组失败-服务应用到期或未订购,请订购后进行授权\r\n订购链接:https://fw.jd.com/main/detail/FW_GOODS-187201");
|
|
if (!string.IsNullOrEmpty(response.ErrMsg) && response.ErrMsg.Contains("token已过期"))
|
|
throw new BusinessException($"查询客服组失败-服务应用到期或未订购,请订购后进行授权\r\n订购链接:https://fw.jd.com/main/detail/FW_GOODS-187201");
|
|
|
|
|
|
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").Trim(),
|
|
}).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 JDQueryWareHouse(JDQueryWareHouseRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new EclpMasterQueryWarehouseRequest();
|
|
|
|
req.deptNo = request.deptNo;
|
|
req.warehouseNos = request.wareHouseNos;
|
|
//req.status = "abc";
|
|
|
|
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_eclp_master_queryWarehouse_responce"]["querywarehouse_result"];
|
|
}
|
|
|
|
public override JArray GetStockNumBySku(GetStockNumBySkuRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new StockReadFindSkuStockRequest();
|
|
|
|
|
|
if (request.Field != null)
|
|
req.field = string.Join(",", request.Field);
|
|
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 void SetProductTitle(SetProductTitleRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var wareId = long.Parse(request.Spu);
|
|
|
|
string brandName;
|
|
#region 获取主商品品牌
|
|
{
|
|
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 设置标题
|
|
{
|
|
if (string.IsNullOrEmpty(brandName))
|
|
return;
|
|
var req = new WareWriteUpdateWareTitleRequest() { wareId = wareId };
|
|
if (!request.Title.StartsWith(brandName))
|
|
req.title = $"{brandName}{request.Title}";
|
|
else
|
|
req.title = request.Title;
|
|
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
|
|
|
|
}
|
|
|
|
private void RollBackWhenStartPromotionError(string appKey,
|
|
string appSecret,
|
|
string appToken,
|
|
IList<string> deleteSkuList,
|
|
string mainProductSpu,
|
|
string fullTitle,
|
|
string brandName,
|
|
bool haveGiftTemplateSku,
|
|
int isNewProduct)
|
|
{
|
|
var jdClient = GetJdClient(appKey, appSecret);
|
|
|
|
if (haveGiftTemplateSku && deleteSkuList != null && deleteSkuList.Count() > 0 && !deleteSkuList.Any(s => string.IsNullOrEmpty(s)))
|
|
DeleteSkuList(new DeleteSkuListRequest()
|
|
{
|
|
AppKey = appKey,
|
|
AppSecret = appSecret,
|
|
AppToken = appToken,
|
|
Platform = Enums.Platform.京东,
|
|
SkuList = deleteSkuList
|
|
});
|
|
|
|
#region 设置完整标题
|
|
{
|
|
if (isNewProduct == 0 || string.IsNullOrEmpty(brandName) || string.IsNullOrEmpty(fullTitle))
|
|
return;
|
|
var req = new WareWriteUpdateWareTitleRequest();
|
|
req.wareId = long.Parse(mainProductSpu);
|
|
if (!fullTitle.StartsWith(brandName))
|
|
req.title = $"{brandName}{fullTitle}";
|
|
else
|
|
req.title = fullTitle;
|
|
var response = jdClient.Execute(req, appToken, DateTime.Now.ToLocalTime());
|
|
if (response.IsError)
|
|
throw new BusinessException($"设置完整标题出错-{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
private void DisableGiftSku(string appKey,
|
|
string appSecret,
|
|
string appToken,
|
|
IList<string> deleteSkuList,
|
|
string mainProductSpu,
|
|
string fullTitle,
|
|
string brandName,
|
|
bool haveGiftTemplateSku,
|
|
int isNewProduct)
|
|
{
|
|
var jdClient = GetJdClient(appKey, appSecret);
|
|
var wareId = long.Parse(mainProductSpu);
|
|
if (haveGiftTemplateSku && deleteSkuList != null && deleteSkuList.Count() > 0 && !deleteSkuList.Any(s => string.IsNullOrEmpty(s)))
|
|
{
|
|
var disableSkuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
{
|
|
AppKey = appKey,
|
|
AppSecret = appSecret,
|
|
AppToken = appToken,
|
|
Platform = Enums.Platform.京东,
|
|
Sku = string.Join(",", deleteSkuList),
|
|
IsContainSource = true,
|
|
CheckStep = "",
|
|
IsCheckSkuCount = false
|
|
});
|
|
|
|
var req = new SkuWriteUpdateSkusRequest();
|
|
req.wareId = wareId;
|
|
req.skus = disableSkuList.Select(ps =>
|
|
{
|
|
var p = JsonConvert.DeserializeObject<SkuWriteUpdateSkusItem>(ps.Source.ToString());
|
|
p.enable = 2; //禁用
|
|
return p;
|
|
}).ToList();
|
|
|
|
var res = jdClient.Execute(req, appToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
if (res.IsError)
|
|
{
|
|
var errorMsg = res.Body.Contains("en_desc") ?
|
|
res.Json["error_response"].Value<string>("en_desc") :
|
|
(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg);
|
|
|
|
RollBackWhenStartPromotionError(appKey, appSecret, appToken, deleteSkuList, mainProductSpu, fullTitle, brandName, false, isNewProduct);
|
|
throw new BusinessException($"禁用赠品sku失败-{errorMsg}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加JD促销活动sku
|
|
/// </summary>
|
|
/// <param name="jdClient"></param>
|
|
/// <param name="token"></param>
|
|
/// <param name="promotionId"></param>
|
|
/// <param name="skuList"></param>
|
|
/// <param name="isGift"></param>
|
|
/// <param name="taskCount"></param>
|
|
/// <exception cref="BusinessException"></exception>
|
|
private void AddJDPromotionSku(IJdClient jdClient, string token, long promotionId, IList<ProductSkuResponse> skuList, bool isGift, int taskCount)
|
|
{
|
|
var req = new SellerPromotionSkuAddRequest();
|
|
req.promoId = promotionId;
|
|
|
|
var pageIndex = 1;
|
|
var pageSize = 100;
|
|
var totalPage = (skuList.Count() - 1) / pageSize + 1;
|
|
|
|
while (pageIndex <= totalPage)
|
|
{
|
|
req.skuIds = string.Empty;
|
|
req.jdPrices = string.Empty;
|
|
req.bindType = string.Empty;
|
|
req.num = string.Empty;
|
|
req.promoPrices = string.Empty;
|
|
var currentPageList = skuList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
|
|
|
foreach (var sku in currentPageList)
|
|
{
|
|
req.skuIds = $"{req.skuIds}{sku.Id},";
|
|
req.jdPrices = $"{req.jdPrices}{sku.Price},";
|
|
req.bindType = $"{req.bindType}{(isGift ? 2 : 1)},";
|
|
req.num = $"{req.num}{(isGift ? 1 : taskCount)},";
|
|
req.promoPrices = $"{req.promoPrices}{(isGift ? 0 : sku.Price)},";
|
|
}
|
|
|
|
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.promoPrices = req.promoPrices.Substring(0, req.promoPrices.Length - 1);
|
|
|
|
var res = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
throw new BusinessException($"添加活动sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
pageIndex++;
|
|
}
|
|
}
|
|
|
|
private string SkuShangJiaFanYi(string errorMsg)
|
|
{
|
|
if (errorMsg.Contains("销售属性值组合重复") && errorMsg.Contains("业务要求唯一性"))
|
|
errorMsg = "该任务已上架赠品,请手动下架赠品,系统10分钟后将自动重新启动该任务";
|
|
if (errorMsg.Contains("属性[产品尺寸]扩展值数量与值数量不一致"))
|
|
errorMsg = "上架赠品失败,评价助手暂无法上架带有[产品尺寸]的商品,请手动上架赠品后在评价助手创建已上架赠品模式";
|
|
return errorMsg;
|
|
}
|
|
|
|
public override StartPromotionTaskResponse StartJDPromotionTask(StartPromotionTaskRequest2 request)
|
|
{
|
|
var stepText = string.Empty;
|
|
List<string> giftSkuIdList = new List<string>();
|
|
var brandName = string.Empty;
|
|
var haveGiftTemplateSku = request.GiftTemplateSkuList != null && request.GiftTemplateSkuList.Count() > 0;
|
|
try
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
long wareId = long.Parse(request.MainProductSpu);
|
|
long promotionId = 0;
|
|
|
|
|
|
#region 前置检查各项sku
|
|
var searchProductSkuRequest = new SearchProductSkuRequest()
|
|
{
|
|
AppKey = request.AppKey,
|
|
AppSecret = request.AppSecret,
|
|
AppToken = request.AppToken,
|
|
Platform = Enums.Platform.京东,
|
|
IsCheckSkuCount = true,
|
|
IsContainSource = true
|
|
};
|
|
|
|
IList<ProductSkuResponse> motherTemplateSkuList = null;
|
|
IList<ProductSkuResponse> customerMotherSkuList = null;
|
|
IList<ProductSkuResponse> mainProductSkuList = null;
|
|
IList<ProductSkuResponse> giftSkuList = null;
|
|
|
|
#region 查询奶妈模板SKU
|
|
if (!string.IsNullOrEmpty(request.MotherTemplateSku))
|
|
{
|
|
stepText = "查询奶妈模板SKU";
|
|
searchProductSkuRequest.Sku = request.MotherTemplateSku;
|
|
searchProductSkuRequest.CheckStep = "奶妈模板SKU";
|
|
motherTemplateSkuList = GetProductSkuList(searchProductSkuRequest);
|
|
}
|
|
#endregion
|
|
|
|
#region 查询自定义奶妈SKU
|
|
if (!string.IsNullOrEmpty(request.CustomMotherSku))
|
|
{
|
|
stepText = "查询自定义奶妈SKU";
|
|
searchProductSkuRequest.Sku = request.CustomMotherSku;
|
|
searchProductSkuRequest.CheckStep = "自定义奶妈SKU";
|
|
customerMotherSkuList = GetProductSkuList(searchProductSkuRequest);
|
|
}
|
|
#endregion
|
|
|
|
#region 查询主商品sku
|
|
if (!string.IsNullOrEmpty(request.MainProductSku))
|
|
{
|
|
stepText = "查询主商品SKU";
|
|
searchProductSkuRequest.Sku = request.MainProductSku;
|
|
searchProductSkuRequest.CheckStep = "主商品SKU";
|
|
mainProductSkuList = GetProductSkuList(searchProductSkuRequest);
|
|
if (mainProductSkuList != null && mainProductSkuList.Any(s => s.ProductId != request.MainProductSpu))
|
|
throw new BusinessException("主商品SKU归属有误");
|
|
}
|
|
#endregion
|
|
|
|
#region 查询主商品赠品sku
|
|
if (!string.IsNullOrEmpty(request.MainProductGiftSku))
|
|
{
|
|
stepText = "查询主商品赠品SKU";
|
|
searchProductSkuRequest.Sku = request.MainProductGiftSku;
|
|
searchProductSkuRequest.CheckStep = "赠品SKU";
|
|
giftSkuList = GetProductSkuList(searchProductSkuRequest);
|
|
giftSkuIdList = giftSkuList.Select(gs => gs.Id).ToList();
|
|
|
|
if (giftSkuList != null && giftSkuList.Any(s => s.ProductId != request.MainProductSpu))
|
|
throw new BusinessException("主商品赠品SKU归属有误");
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#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 新品设置精简标题
|
|
if (request.IsNewProduct == 1)
|
|
{
|
|
stepText = "设置精简标题";
|
|
var req = new WareWriteUpdateWareTitleRequest();
|
|
req.wareId = wareId;
|
|
if (string.IsNullOrEmpty(request.SimpleTitle) || !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 (haveGiftTemplateSku)
|
|
{
|
|
#region 上架赠品
|
|
|
|
#region 获取销售属性
|
|
stepText = "获取销售属性";
|
|
var attrId = string.Empty;
|
|
List<List<AttrValueAliasJson>> strutsSaleAttrValueList = new List<List<AttrValueAliasJson>>();
|
|
var isStruts = false;
|
|
{
|
|
var req = new CategoryReadFindSaleAttrTemplatesRequest();
|
|
req.cid = int.Parse(request.MainProductCategoryId);
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
{
|
|
var errorMsg = string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg;
|
|
throw new BusinessException(errorMsg);
|
|
}
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
if (res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateType"].ToString() == "1")
|
|
{
|
|
//非结构属性
|
|
var tempDataJarray = JArray.Parse(res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateData"].ToString());
|
|
var colorProperty = tempDataJarray.FirstOrDefault(j => (j.Value<string>("name") == "颜色" ||
|
|
j.Value<string>("name") == "规格" ||
|
|
j.Value<string>("name") == "类别" ||
|
|
j.Value<string>("name") == "香型" ||
|
|
j.Value<string>("name") == "色温") &&
|
|
j["attrValueList"].Children().Count() > 0);
|
|
if (colorProperty == null)
|
|
{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku);
|
|
throw new BusinessException("缺少包含attrValueList的销售属性");
|
|
}
|
|
var colorSaleAttrs = colorProperty["attrValueList"].ToList();
|
|
attrId = colorSaleAttrs[0].Value<string>("attId");
|
|
}
|
|
else if (res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateType"].ToString() == "2")
|
|
{
|
|
var tempDataJarray = JArray.Parse(res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateData"].ToString());
|
|
var tempDataJToken = tempDataJarray.FirstOrDefault(j => j.Value<string>("valueRules").Contains("颜色") ||
|
|
j.Value<string>("valueRules").Contains("款式") ||
|
|
j.Value<string>("valueRules").Contains("规格") ||
|
|
j.Value<string>("valueRules").Contains("尺寸") ||
|
|
j.Value<string>("valueRules").Contains("玩偶种类"));
|
|
if (tempDataJToken == null)
|
|
{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku);
|
|
throw new BusinessException("缺少必要的结构化属性");
|
|
}
|
|
attrId = tempDataJToken.Value<string>("attrId");
|
|
if (tempDataJToken.Value<string>("type") == "1")
|
|
{
|
|
isStruts = true;
|
|
var tempDataValuesJToken = JObject.Parse(tempDataJToken["valueRules"].ToString());
|
|
var tempDataValues_Level1_JToken = tempDataValuesJToken["items"][0];
|
|
if (tempDataValuesJToken["items"].Count() == 3 &&
|
|
tempDataValuesJToken["items"][0]["properties"]["id"]["type"].ToString() == "model" &&
|
|
tempDataValuesJToken["items"][1]["properties"]["id"]["type"].ToString() == "number" &&
|
|
tempDataValuesJToken["items"][1]["properties"]["value"]["type"].ToString() == "number" &&
|
|
tempDataValuesJToken["items"][2]["properties"]["id"]["type"].ToString() == "number" &&
|
|
tempDataValuesJToken["items"][2]["properties"]["value"]["type"].ToString() == "string")
|
|
{
|
|
var f_id = int.Parse(tempDataValuesJToken["items"][0]["properties"]["id"]["enum"][0].ToString());
|
|
var f_tempJarray = tempDataValuesJToken["items"][0]["properties"]["value"]["enum"][0]["preprocessingSaleAttrValTemplateValueList"] as JArray;
|
|
var f_value = f_tempJarray.FirstOrDefault().Value<string>("name");
|
|
var f_valueId = f_tempJarray.FirstOrDefault().Value<int>("id");
|
|
|
|
var s_id = int.Parse(tempDataValuesJToken["items"][1]["properties"]["id"]["enum"][0].ToString());
|
|
var s_unit = tempDataValuesJToken["items"][1]["properties"]["unit"]["enum"][0].ToString();
|
|
//var s_value = "1";
|
|
|
|
var t_id = int.Parse(tempDataValuesJToken["items"][2]["properties"]["id"]["enum"][0].ToString());
|
|
var t_value = "待替换的备注";
|
|
|
|
for (var i = 0; i < request.GiftTemplateSkuList.Count(); i++)
|
|
{
|
|
strutsSaleAttrValueList.Add(new List<AttrValueAliasJson>()
|
|
{
|
|
new AttrValueAliasJson()
|
|
{
|
|
id = f_id,
|
|
value = f_value,
|
|
valueId = f_valueId,
|
|
unit = string.Empty
|
|
},
|
|
new AttrValueAliasJson()
|
|
{
|
|
id = s_id,
|
|
value = "1",
|
|
unit = s_unit
|
|
},
|
|
new AttrValueAliasJson()
|
|
{
|
|
id = t_id,
|
|
value = t_value,
|
|
isReName = true
|
|
}
|
|
});
|
|
}
|
|
}
|
|
else if (tempDataValues_Level1_JToken["properties"]["id"]["type"].ToString() == "model")
|
|
{
|
|
//[{\"id\":5,\"unit\":\"\",\"value\":\"红色\","valueId":1234567}]
|
|
var tempJarray = tempDataValues_Level1_JToken["properties"]["value"]["enum"][0]["preprocessingSaleAttrValTemplateValueList"] as JArray;
|
|
strutsSaleAttrValueList.AddRange(tempJarray.Select(j => new List<AttrValueAliasJson>()
|
|
{
|
|
new AttrValueAliasJson
|
|
{
|
|
id = int.Parse(tempDataValues_Level1_JToken["properties"]["id"]["enum"][0].ToString()),
|
|
value = j.Value<string>("name"),
|
|
valueId = j.Value<int>("id"),
|
|
unit = string.Empty,
|
|
isReName = true
|
|
}
|
|
}));
|
|
}
|
|
else if (tempDataValues_Level1_JToken["properties"]["id"]["type"].ToString() == "number" &&
|
|
tempDataValues_Level1_JToken["properties"]["value"]["type"].ToString() == "number" &&
|
|
tempDataValuesJToken["items"][1]["properties"]["id"]["type"].ToString() == "number" &&
|
|
tempDataValuesJToken["items"][1]["properties"]["value"]["type"].ToString() == "string")
|
|
{
|
|
var f_id = int.Parse(tempDataValues_Level1_JToken["properties"]["id"]["enum"][0].ToString());
|
|
var f_unit = tempDataValues_Level1_JToken["properties"]["unit"]["enum"][0].ToString();
|
|
var s_id = int.Parse(tempDataValuesJToken["items"][1]["properties"]["id"]["enum"][0].ToString());
|
|
|
|
strutsSaleAttrValueList.AddRange(request.GiftTemplateSkuList.Select(x => new List<AttrValueAliasJson>()
|
|
{
|
|
new AttrValueAliasJson()
|
|
{
|
|
id = f_id,
|
|
value = "1",
|
|
unit = f_unit
|
|
},
|
|
new AttrValueAliasJson()
|
|
{
|
|
id = s_id,
|
|
value = "待替换的备注",
|
|
isReName = true
|
|
}
|
|
}));
|
|
|
|
}
|
|
else
|
|
throw new BusinessException($"不支持的properties.id.type {tempDataValues_Level1_JToken["properties"]["id"]["type"]} 或取其分支情况");
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 组装上架/改名/设置细节图参数
|
|
stepText = "组装上架/改名/设置细节图参数";
|
|
var indexCount = 39;// colorSaleAttrs.Count() - 1;
|
|
var noUsedIndexList = new List<int>();
|
|
bool isClearMainProductSkuList = false;
|
|
try
|
|
{
|
|
if (mainProductSkuList == null || mainProductSkuList.Count() == 0)
|
|
{
|
|
isClearMainProductSkuList = true;
|
|
mainProductSkuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
{
|
|
AppKey = request.AppKey,
|
|
AppSecret = request.AppSecret,
|
|
AppToken = request.AppToken,
|
|
IsContainSource = true,
|
|
Platform = Enums.Platform.京东,
|
|
Spu = request.MainProductSpu
|
|
});
|
|
}
|
|
|
|
var usedIndexList = new List<int>();
|
|
usedIndexList.AddRange(mainProductSkuList.Select(ps => Convert.ToInt32(ps.Source["saleAttrs"][0]["attrValuesSeqNo"][0].ToString())));
|
|
for (var i = 0; i <= indexCount; i++)
|
|
{
|
|
if (usedIndexList.Contains(i))
|
|
continue;
|
|
noUsedIndexList.Add(i);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
for (var i = 0; i <= indexCount; i++)
|
|
{
|
|
noUsedIndexList.Add(i);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (isClearMainProductSkuList && mainProductSkuList != null)
|
|
{
|
|
mainProductSkuList.Clear();
|
|
mainProductSkuList = null;
|
|
}
|
|
}
|
|
|
|
var skusParamList = new List<SkuWriteUpdateSkusItem>();
|
|
var updateSkuTitleParamList = new List<WareWriteUpdateWareSaleAttrvalueAliasRequestItem>();
|
|
var imageWriteUpdateRequestList = new List<ImageWriteUpdateRequest>();
|
|
//var skuIndex = noUsedIndexList.Count() - 1;
|
|
var skuIndex = isStruts ? strutsSaleAttrValueList.Count() - 1 : noUsedIndexList.Count() - 1;
|
|
|
|
for (var i = 0; i < request.GiftTemplateSkuList.Count(); i++)
|
|
{
|
|
var giftSku = request.GiftTemplateSkuList[i];
|
|
//var colorPropertyValue = colorSaleAttrs[takeColorIndex];
|
|
|
|
var attrValueAlias = string.Empty;
|
|
if (isStruts)
|
|
{
|
|
var values = strutsSaleAttrValueList[skuIndex];
|
|
values.FirstOrDefault(v => v.isReName).value = giftSku.Title;
|
|
attrValueAlias = JsonConvert.SerializeObject(values);
|
|
}
|
|
else
|
|
{
|
|
attrValueAlias = giftSku.Title;
|
|
}
|
|
|
|
var p = new SkuWriteUpdateSkusItem()
|
|
{
|
|
type = "com.jd.pop.ware.ic.api.domain.Sku",
|
|
wareId = wareId,
|
|
enable = 1,
|
|
jdPrice = giftSku.Price ?? 0,
|
|
stockNum = 9999,
|
|
barCode = request.MainProductBarCode,
|
|
outerId = $"{request.OuterId}{(i + 1).ToString().PadLeft(3, '0')}",
|
|
saleAttrs = new List<SkuWriteUpdateSkusItemSaleAttrs>()
|
|
{
|
|
new SkuWriteUpdateSkusItemSaleAttrs()
|
|
{
|
|
type = "com.jd.pop.ware.ic.api.domain.Prop",
|
|
attrId = attrId,
|
|
attrValueAlias = new List<string>(){ attrValueAlias },
|
|
index = noUsedIndexList[skuIndex],
|
|
attrValuesSeqNo = new List<int?>(){ noUsedIndexList[skuIndex] }
|
|
}
|
|
},
|
|
saleAttrTemplateId = "POP_MODEL"
|
|
};
|
|
|
|
p.multiCateProps = new List<SkuWriteUpdateSkusItemSaleAttrs>();
|
|
if (request.MainProductMultiCateProps != null && request.MainProductMultiCateProps.Count() > 0)
|
|
{
|
|
foreach (var multiCateProp in request.MainProductMultiCateProps)
|
|
{
|
|
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();
|
|
m.expands = multiCateProp.Value<JArray>("expands").Select(x => x.ToString()).ToList();
|
|
m.units = multiCateProp.Value<JArray>("units").Select(x => x.ToString()).ToList();
|
|
p.multiCateProps.Add(m);
|
|
}
|
|
}
|
|
skuIndex--;
|
|
//takeColorIndex--;
|
|
skusParamList.Add(p);
|
|
}
|
|
#endregion
|
|
|
|
#region 上架sku
|
|
{
|
|
stepText = "上架sku";
|
|
var req = new SkuWriteUpdateSkusRequest();
|
|
req.wareId = wareId;
|
|
req.skus = skusParamList;
|
|
|
|
//输出日志
|
|
//nLogManager.Default().Info($"上架赠品请求参数,任务Id{request.Id},{JsonConvert.SerializeObject(req)}");
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
if (res.IsError)
|
|
{
|
|
var errorMsg = res.Body.Contains("en_desc") ?
|
|
res.Json["error_response"].Value<string>("en_desc") :
|
|
(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg);
|
|
if (errorMsg.Contains("此类目发货时效必填"))
|
|
{
|
|
int? promiseId = null;
|
|
#region 查询时效模板
|
|
{
|
|
stepText = "查询时效模板";
|
|
var shixiaoReq = new SellerDeliverySendPromiseTemplateJsfServiceQuerySendTemplateByCategoryRequest();
|
|
shixiaoReq.categoryId = int.Parse(request.MainProductCategoryId);
|
|
shixiaoReq.dzSku = true;
|
|
var shixiaoRes = jdClient.Execute(shixiaoReq, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (shixiaoRes.IsError)
|
|
{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, null, request.MainProductSpu, request.FullTitle, brandName, false);
|
|
throw new BusinessException($"查询时效模板失败-{(string.IsNullOrEmpty(shixiaoRes.ErrorMsg) ? shixiaoRes.ErrMsg : shixiaoRes.ErrorMsg)}");
|
|
}
|
|
if (shixiaoRes.Json == null)
|
|
shixiaoRes.Json = JObject.Parse(shixiaoRes.Body);
|
|
var shixiaoJToken = shixiaoRes.Json["jingdong_seller_delivery_SendPromiseTemplateJsfService_querySendTemplateByCategory_responce"]["returnType"]["bizResponse"]["promiseTemplateDtoList"].Children().FirstOrDefault();
|
|
if (shixiaoJToken == null)
|
|
{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, null, request.MainProductSpu, request.FullTitle, brandName, false);
|
|
throw new BusinessException($"查询时效模板失败-未查询到时效模板");
|
|
}
|
|
promiseId = shixiaoJToken.Value<int>("templateId");
|
|
}
|
|
#endregion
|
|
stepText = "再次上架sku";
|
|
foreach (var skuParam in req.skus)
|
|
skuParam.promiseId = promiseId;
|
|
res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
{
|
|
errorMsg = res.Body.Contains("en_desc") ?
|
|
res.Json["error_response"].Value<string>("en_desc") :
|
|
(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg);
|
|
errorMsg = SkuShangJiaFanYi(errorMsg);
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, null, request.MainProductSpu, request.FullTitle, brandName, false);
|
|
throw new BusinessException($"上架sku失败-{errorMsg}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
errorMsg = SkuShangJiaFanYi(errorMsg);
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, null, request.MainProductSpu, request.FullTitle, brandName, false);
|
|
throw new BusinessException($"上架sku失败-{errorMsg}");
|
|
}
|
|
}
|
|
|
|
Thread.Sleep(30 * 1000);
|
|
stepText = "查询上架的赠品";
|
|
giftSkuList = new List<ProductSkuResponse>();
|
|
var newMainProductSkuList = GetProductSkuList(new SearchProductSkuRequest()
|
|
{
|
|
AppKey = request.AppKey,
|
|
AppSecret = request.AppSecret,
|
|
AppToken = request.AppToken,
|
|
Platform = Enums.Platform.京东,
|
|
Spu = request.MainProductSpu,
|
|
IsContainSource = true
|
|
});
|
|
|
|
//记录上架返回值
|
|
//nLogManager.Default().Info($"查询上架的赠品,任务Id {request.Id} 店铺Id {request.ShopId}, {JsonConvert.SerializeObject(newMainProductSkuList)}");
|
|
|
|
foreach (var ps in newMainProductSkuList)
|
|
{
|
|
if (request.GiftTemplateSkuList.Any(x => x.Title == ps.Title || ps.Title.Contains(x.Title)))
|
|
{
|
|
//此sku是赠品sku
|
|
//newSkuIdList.Add(ps.Id);
|
|
giftSkuList.Add(ps);
|
|
}
|
|
}
|
|
if (giftSkuList.Count() == 0)
|
|
throw new BusinessException("未能从sku列表接口正常获取新上架sku");
|
|
|
|
giftSkuIdList.AddRange(giftSkuList.Select(gs => gs.Id));
|
|
|
|
stepText = "设置赠品图片";
|
|
//var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList();
|
|
var imgIndex = 1;
|
|
StringBuilder colorBuilder = new StringBuilder();
|
|
StringBuilder imgUrlBuilder = new StringBuilder();
|
|
StringBuilder imgIndexBuilder = new StringBuilder();
|
|
foreach (var giftsku in giftSkuList)
|
|
{
|
|
var skuJToken = giftsku.Source;
|
|
//var skuTitle = skuJToken["saleAttrs"][0]["attrValueAlias"][0].ToString();
|
|
var skuTitle = GetSkuTitle(skuJToken);
|
|
var colorId = "0000000000";
|
|
try
|
|
{
|
|
colorId = skuJToken["saleAttrs"][0]["attrValues"][0].ToString();
|
|
}
|
|
catch { }
|
|
var currentImgIndex = imgIndex;
|
|
imgIndex++;
|
|
var giftSku = request.GiftTemplateSkuList.FirstOrDefault(x => x.Title == skuTitle || skuTitle.Contains(x.Title));
|
|
var imgUrl = giftSku.Logo.Substring(giftSku.Logo.IndexOf("jfs"));
|
|
|
|
colorBuilder.Append($"{colorId},");
|
|
imgUrlBuilder.Append($"{imgUrl},");
|
|
imgIndexBuilder.Append($"{currentImgIndex},");
|
|
}
|
|
|
|
imageWriteUpdateRequestList.Add(new ImageWriteUpdateRequest()
|
|
{
|
|
wareId = wareId,
|
|
colorId = colorBuilder.ToString().TrimEnd(','),
|
|
imgUrl = imgUrlBuilder.ToString().TrimEnd(','),
|
|
imgIndex = imgIndexBuilder.ToString().TrimEnd(',')
|
|
});
|
|
}
|
|
#endregion
|
|
|
|
#region sku修改细节图
|
|
stepText = "sku修改细节图";
|
|
foreach (var imageWriteUpdateRequest in imageWriteUpdateRequestList)
|
|
{
|
|
var res = jdClient.Execute(imageWriteUpdateRequest, request.AppToken, DateTime.Now.ToLocalTime());
|
|
}
|
|
#endregion
|
|
|
|
#region 设置sku全国仓库存
|
|
{
|
|
if (request.MainProductSkuInStore)
|
|
{
|
|
stepText = "设置sku全国仓库存";
|
|
Thread.Sleep(60 * 1000);
|
|
//try
|
|
//{
|
|
foreach (var giftSkuId in giftSkuIdList)
|
|
{
|
|
var req = new StockWriteUpdateSkuStockRequest();
|
|
req.skuId = long.Parse(giftSkuId);
|
|
req.stockNum = 9999;
|
|
req.storeId = 0;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
throw new BusinessException($"设置全国仓库存失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
}
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, true);
|
|
// throw ex;
|
|
//}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
|
|
#region 创建活动
|
|
var deleteGiftSkuRequest = new DeleteSkuListRequest()
|
|
{
|
|
AppKey = request.AppKey,
|
|
AppSecret = request.AppSecret,
|
|
AppToken = request.AppToken,
|
|
Platform = request.Platform,
|
|
SkuList = giftSkuIdList
|
|
};
|
|
|
|
{
|
|
stepText = "创建活动";
|
|
Thread.Sleep(60 * 1000);
|
|
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.per_min_num = 1;
|
|
//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)
|
|
{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku);
|
|
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
|
|
{
|
|
if (motherTemplateSkuList != null && motherTemplateSkuList.Count() > 0)
|
|
{
|
|
stepText = "添加奶妈模板SKU";
|
|
AddJDPromotionSku(jdClient, request.AppToken, promotionId, motherTemplateSkuList, false, request.TaskCount);
|
|
}
|
|
|
|
if (customerMotherSkuList != null && customerMotherSkuList.Count() > 0)
|
|
{
|
|
stepText = "添加自定义奶妈SKU";
|
|
AddJDPromotionSku(jdClient, request.AppToken, promotionId, customerMotherSkuList, false, request.TaskCount);
|
|
}
|
|
|
|
if (mainProductSkuList != null && mainProductSkuList.Count() > 0)
|
|
{
|
|
stepText = "添加主商品SKU";
|
|
AddJDPromotionSku(jdClient, request.AppToken, promotionId, mainProductSkuList, false, request.TaskCount);
|
|
}
|
|
|
|
if (giftSkuList != null && giftSkuList.Count() > 0)
|
|
{
|
|
stepText = "添加赠品SKU";
|
|
AddJDPromotionSku(jdClient, request.AppToken, promotionId, giftSkuList, true, request.TaskCount);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 提交活动
|
|
{
|
|
stepText = "提交活动";
|
|
Thread.Sleep(3000);
|
|
var req = new SellerPromotionCommitRequest();
|
|
req.promoId = promotionId;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
{
|
|
//RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku);
|
|
throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//Task.Factory.StartNew(() => StartJDPromotionTaskDelay(deleteGiftSkuRequest, request, brandName, promotionId), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler);
|
|
|
|
return new StartPromotionTaskResponse()
|
|
{
|
|
BrandName = brandName,
|
|
JDPromotionId = promotionId,
|
|
DeleteGiftSkuList = giftSkuIdList
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
nLogManager.Default().Error(ex, $"任务Id {request.Id} 店铺Id {request.ShopId} 执行步骤 {stepText}");
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku, request.IsNewProduct);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public override void StartJDPromotionDelayTask(StartPromotionTaskDelayRequest request)
|
|
{
|
|
Thread.Sleep(60 * 1000);
|
|
try
|
|
{
|
|
CheckJDPromotionTask(request.JDPromotionId, request.AppKey, request.AppSecret, request.AppToken);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, request.HaveGiftTemplate, request.IsNewProduct);
|
|
throw;
|
|
}
|
|
|
|
Thread.Sleep(10000);
|
|
|
|
#region 检查奶妈sku是否完全生效
|
|
var lastQueryJoinCount = 0;
|
|
List<string> noJoinSkuList = null;
|
|
var isJoinCompleted = false;
|
|
{
|
|
var repeatCount = 0;
|
|
while (true)
|
|
{
|
|
var promotionTaskSkuList = GetPromotionTaskSku(request.AppKey, request.AppSecret, request.AppToken, request.JDPromotionId);
|
|
//var currentQueryJoinCount = promotionTaskSkuList.Count(s => s.Value<int>("bind_type") == 1 && s.Value<int>("sku_status") == 1);
|
|
var currentQueryJoinList = promotionTaskSkuList.Where(s => s.Value<int>("bind_type") == 1 && s.Value<int>("sku_status") == 1)
|
|
.Select(s => s.Value<string>("sku_id")).ToList();
|
|
var currentQueryJoinCount = currentQueryJoinList.Count();
|
|
if (currentQueryJoinCount == request.JoinSkuCount)
|
|
{
|
|
isJoinCompleted = true;
|
|
break;
|
|
}
|
|
|
|
if (lastQueryJoinCount == 0)
|
|
lastQueryJoinCount = currentQueryJoinCount;
|
|
else if (lastQueryJoinCount == currentQueryJoinCount)
|
|
{
|
|
repeatCount++;
|
|
if (repeatCount > 2)
|
|
{
|
|
noJoinSkuList = request.JoinSkuList.Except(currentQueryJoinList).ToList();
|
|
break;
|
|
}
|
|
|
|
}
|
|
lastQueryJoinCount = currentQueryJoinCount;
|
|
Thread.Sleep(30000);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 发送钉钉消息
|
|
try
|
|
{
|
|
var ddMsg = new StringBuilder();
|
|
ddMsg.AppendLine($"活动名称:{request.ActivityName}");
|
|
ddMsg.AppendLine("任务状态:开始");
|
|
if (!isJoinCompleted)
|
|
{
|
|
ddMsg.AppendLine($"任务奶妈数:{request.JoinSkuCount}");
|
|
ddMsg.AppendLine($"参与奶妈数:{lastQueryJoinCount}");
|
|
ddMsg.AppendLine("参与任务的奶妈数异常请检查");
|
|
if (noJoinSkuList != null && noJoinSkuList.Count > 0)
|
|
{
|
|
foreach (var noJoinSku in noJoinSkuList)
|
|
ddMsg.AppendLine(noJoinSku);
|
|
ddMsg.AppendLine("以上SKU可能已下架或同时参与多个赠品促销活动");
|
|
ddMsg.AppendLine("1.如已下架请将对应的SKU移除奶妈列表");
|
|
ddMsg.AppendLine("2.系统会自动剔除同时参与多个赠品促销的SKU,请检查以上SKU是否在失效的促销活动,请及时删除,已暂停或已停止的促销活动");
|
|
}
|
|
|
|
}
|
|
if (!string.IsNullOrEmpty(request.PJZSDingDingKey) && !string.IsNullOrEmpty(request.PJZSDingDingWebHook))
|
|
dingDingBusiness.SendDingDingBotMessage(request.PJZSDingDingKey, request.PJZSDingDingWebHook, ddMsg.ToString());
|
|
}
|
|
catch { }
|
|
#endregion
|
|
|
|
//DisableGiftSku(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, true, request.IsNewProduct);
|
|
}
|
|
|
|
public override void DeleteJDPromotionTask(DeleteJDPromotionTaskRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
//var req = new SellerPromotionDeleteRequest();
|
|
|
|
//req.promoId = request.PromotionId;
|
|
//var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
var req = new SellerPromotionV2RemoveRequest();
|
|
req.requestId = Guid.NewGuid().ToString();
|
|
req.promoId = request.PromotionId;
|
|
req.promoType = 4;
|
|
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)}");
|
|
}
|
|
|
|
public override void DeleteJDPromotionTaskSku(DeleteJDPromotionTaskSkuRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
|
|
var req = new SellerPromotionDeleteSkuInPromoRequest();
|
|
req.promoId = request.PromotionId;
|
|
req.skuId = request.SkuId;
|
|
|
|
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)}");
|
|
}
|
|
|
|
public override void SuspendJDPromotionTask(SuspendDPromotionTaskRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
//var req = new SellerPromotionSuspendRequest();
|
|
//req.promoId = request.PromotionId;
|
|
|
|
var req = new SellerPromotionV2SuspendRequest();
|
|
|
|
req.requestId = Guid.NewGuid().ToString();
|
|
req.promoId = request.PromotionId;
|
|
req.promoType = 4;
|
|
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)}");
|
|
}
|
|
|
|
private void CheckJDPromotionTask(long promotionId, string appkey, string appSecret, string token)
|
|
{
|
|
var jdClient = GetJdClient(appkey, appSecret);
|
|
Thread.Sleep(3000);
|
|
|
|
var req = new PopMarketWritePromotionGiftApproveRequest();
|
|
req.promoId = promotionId;
|
|
req.requestId = Guid.NewGuid().ToString();
|
|
|
|
var res = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
{
|
|
//RollBackWhenStartPromotionError(deleteGiftSkuRequest, request, brandName, haveGiftTemplateSku);
|
|
throw new BusinessException($"审核活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
}
|
|
}
|
|
|
|
private List<JToken> GetPromotionTaskSku(string appkey, string appSecret, string token, long promotionId)
|
|
{
|
|
var jdClient = GetJdClient(appkey, appSecret);
|
|
var pageIndex = 1;
|
|
var pageSize = 20;
|
|
List<JToken> skuList = new List<JToken>();
|
|
while (true)
|
|
{
|
|
var req = new SellerPromotionV2SkuListRequest();
|
|
req.promoId = promotionId;
|
|
//req.bindType = ;
|
|
|
|
req.promoType = 4;
|
|
|
|
req.page = pageIndex.ToString();
|
|
|
|
req.pageSSize = pageSize.ToString();
|
|
var response = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
|
|
Console.WriteLine(JsonConvert.SerializeObject(response));
|
|
if (response.IsError)
|
|
continue;
|
|
if (response.Json == null)
|
|
response.Json = JObject.Parse(response.Body);
|
|
var jarray = response.Json["jingdong_seller_promotion_v2_sku_list_responce"]["promotion_sku_list"] as JArray;
|
|
skuList.AddRange(jarray);
|
|
if (jarray.Count() >= pageSize)
|
|
pageIndex++;
|
|
else
|
|
break;
|
|
}
|
|
|
|
return skuList;
|
|
}
|
|
|
|
public override IList<WaiterResponse> GetServiceGroupList(PlatformRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new ImPopGroupinfoGetRequest();
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
{
|
|
if (!string.IsNullOrEmpty(res.ErrorMsg) && res.ErrorMsg.Contains("token已过期"))
|
|
throw new BusinessException($"查询客服组失败-服务应用到期或未订购,请订购后进行授权\r\n订购链接:https://fw.jd.com/main/detail/FW_GOODS-187201");
|
|
if (!string.IsNullOrEmpty(res.ErrMsg) && res.ErrMsg.Contains("token已过期"))
|
|
throw new BusinessException($"查询客服组失败-服务应用到期或未订购,请订购后进行授权\r\n订购链接:https://fw.jd.com/main/detail/FW_GOODS-187201");
|
|
|
|
throw new BusinessException($"查询客服组失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
}
|
|
|
|
if (res.Json == null)
|
|
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
|
|
return res.Json["jingdong_im_pop_groupinfo_get_responce"]["popgroup"]["waiterList"].Select(j => new WaiterResponse()
|
|
{
|
|
Id = "",
|
|
Level = j.Value<string>("level"),
|
|
Name = j.Value<string>("waiter")
|
|
}).ToList();
|
|
}
|
|
|
|
public override JArray GetServiceOrderList(Model.Dto.QueryServiceOrderRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new AscSyncListRequest();
|
|
|
|
req.buId = request.VenderId;
|
|
req.operatePin = "开发者测试";
|
|
req.operateNick = "开发者测试";
|
|
if (!string.IsNullOrEmpty(request.OrderId))
|
|
req.orderId = long.Parse(request.OrderId);
|
|
if (!string.IsNullOrEmpty(request.ServiceId))
|
|
req.serviceId = int.Parse(request.ServiceId);
|
|
if (request.ServiceStatus != null)
|
|
req.serviceStatus = request.ServiceStatus;
|
|
//req.serviceId = 1687549909;
|
|
//req.orderId = ;
|
|
//req.serviceStatus = ;
|
|
|
|
req.updateTimeBegin = request.UpdateTimeBegin;
|
|
req.updateTimeEnd = request.UpdateTimeEnd;
|
|
|
|
//req.freightUpdateDateBegin = ;
|
|
//req.freightUpdateDateEnd = ;
|
|
|
|
req.pageNumber = request.PageIndex.ToString();
|
|
req.pageSize = request.PageSize.ToString();
|
|
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_asc_sync_list_responce"]["pageResult"]["data"];
|
|
}
|
|
|
|
public override JToken GetServiceOrderDetail(QueryServiceOrderDetailRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new AscQueryViewRequest();
|
|
req.buId = request.VenderId;
|
|
req.operatePin = "开发测试";
|
|
req.operateNick = "开发测试";
|
|
if (!string.IsNullOrEmpty(request.ServiceId))
|
|
req.serviceId = long.Parse(request.ServiceId);
|
|
if (!string.IsNullOrEmpty(request.OrderId))
|
|
req.orderId = long.Parse(request.OrderId);
|
|
|
|
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 res.Json["jingdong_asc_query_view_responce"]["result"]["data"];
|
|
}
|
|
|
|
public override JToken GetServiceOrderDeliveryDetail(QueryServiceOrderDetailRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new AscFreightViewRequest();
|
|
|
|
req.buId = request.VenderId;
|
|
req.operatePin = "开发测试";
|
|
req.operateNick = "开发测试";
|
|
if (!string.IsNullOrEmpty(request.ServiceId))
|
|
req.serviceId = long.Parse(request.ServiceId);
|
|
if (!string.IsNullOrEmpty(request.OrderId))
|
|
req.orderId = long.Parse(request.OrderId);
|
|
|
|
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 res.Json["jingdong_asc_freight_view_responce"]["result"]["data"];
|
|
}
|
|
|
|
public override JToken GetJDInStorePurchaseOrderDetail(GetJDInStorePurchaseOrderDetailRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new EclpPoQueryPoOrderRequest();
|
|
req.poOrderNo = request.PoOrderNo;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (!string.IsNullOrEmpty(res.ErrorMsg) || !string.IsNullOrEmpty(res.ErrMsg))
|
|
{
|
|
var errormsg = !string.IsNullOrEmpty(res.ErrMsg) ? res.ErrMsg : res.ErrorMsg;
|
|
if (errormsg.Contains("非法用户"))
|
|
errormsg = $"{errormsg}\r\n请联系京东物流负责人,开通对应事业部ISV的授权操作";
|
|
throw new BusinessException(errormsg);
|
|
}
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
return res.Json;
|
|
}
|
|
|
|
public override JToken GetJDSupplierDetail(GetJDSupplierDetailRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new EclpMasterQuerySupplierRequest();
|
|
req.deptNo = request.DeptNo;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
return res.Json;
|
|
}
|
|
|
|
public override IList<JDInStoreOrderDetail> GetJDInStorePurchaseOrderList(GetJDInStorePurchaseOrderListRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new EclpPoQueryPoOrderRequest();
|
|
req.poOrderNo = request.PoOrderNos;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
if (!string.IsNullOrEmpty(res.ErrorMsg) || !string.IsNullOrEmpty(res.ErrMsg))
|
|
{
|
|
var errormsg = !string.IsNullOrEmpty(res.ErrMsg) ? res.ErrMsg : res.ErrorMsg;
|
|
if (errormsg.Contains("非法用户"))
|
|
errormsg = $"{errormsg}\r\n请联系京东物流负责人,开通对应事业部ISV的授权操作";
|
|
throw new BusinessException(errormsg);
|
|
}
|
|
|
|
return res.Json["jingdong_eclp_po_queryPoOrder_responce"]["queryPoModelList"].Children().Select(x => new JDInStoreOrderDetail()
|
|
{
|
|
deptNo = x.Value<string>("deptNo"),
|
|
isvPoOrderNo = x.Value<string>("isvPoOrderNo"),
|
|
poOrderNo = x.Value<string>("poOrderNo"),
|
|
poOrderStatus = x.Value<string>("poOrderStatus"),
|
|
storageStatus = x.Value<string>("storageStatus"),
|
|
supplierNo = x.Value<string>("supplierNo"),
|
|
whNo = x.Value<string>("whNo")
|
|
}).ToList();
|
|
}
|
|
|
|
public override JToken GetOrderCouponDetail(QueryOrderCouponDetailRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
//var req = new PopOrderCoupondetailRequest();
|
|
var req = new PopOrderQueryCouponDetaiRequest();
|
|
|
|
req.orderId = request.OrderId;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
return res.Json;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取事业部方法
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public override JToken QueryDept(PlatformRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
EclpMasterQueryDeptRequest req = new EclpMasterQueryDeptRequest();
|
|
|
|
// req.deptNos = ;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
|
|
|
|
return (JArray)res.Json["jingdong_eclp_master_queryDept_responce"]["querydept_result"];
|
|
}
|
|
|
|
public override JToken GetStockNumByWareHouseNo(GetStockNumByWareHouseNoRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
EclpStockQueryStockRequest req = new EclpStockQueryStockRequest();
|
|
|
|
req.deptNo = request.DeptNo;
|
|
|
|
req.warehouseNo = request.WareHouseNo;
|
|
|
|
//req.stockStatus = ;
|
|
if (request.StockType != null)
|
|
req.stockType = (int)request.StockType.Value;//仓库类型状态
|
|
|
|
//req.goodsNo = ;
|
|
if (request.CurrentPage != null)
|
|
req.currentPage = request.CurrentPage.Value;
|
|
|
|
// req.pageSize = "100";
|
|
|
|
//req.returnZeroStock = ;
|
|
|
|
//req.returnIsvLotattrs = ;
|
|
|
|
//req.goodsLevel = ;
|
|
|
|
//req.isvSku = ;
|
|
|
|
//req.sellerGoodsSign = ;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
return (JArray)res.Json["jingdong_eclp_stock_queryStock_responce"]["querystock_result"];
|
|
}
|
|
|
|
|
|
public override JToken GetProductById(GetProductByIdRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new WareReadFindWareByIdRequest() { wareId = request.SpuId };
|
|
|
|
if (request.Field != null)
|
|
req.field = request.Field;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
return JsonConvert.DeserializeObject<dynamic>(res.Body).jingdong_ware_read_findWareById_responce.ware;
|
|
return JsonConvert.DeserializeObject<dynamic>(res.Json.ToString()).jingdong_ware_read_findWareById_responce.ware;
|
|
}
|
|
|
|
|
|
public override JToken GetAttrsByCategoryId(GetAttrsByCategoryIdRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new CategoryReadFindAttrsByCategoryIdUnlimitCateRequest() { cid = request.CatId };
|
|
|
|
if (request.AttributeType != null)
|
|
req.attributeType = request.AttributeType;
|
|
if (request.Field != null)
|
|
req.field = request.Field;
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
return (JArray)res.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"];
|
|
}
|
|
|
|
public override void SetSkuStockNum(SetSkuStockNumRequest request)
|
|
{
|
|
/*
|
|
foreach (var giftSkuId in giftSkuIdList)
|
|
{
|
|
var req = new StockWriteUpdateSkuStockRequest();
|
|
req.skuId = long.Parse(giftSkuId);
|
|
req.stockNum = 9999;
|
|
req.storeId = 0;
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.IsError)
|
|
throw new BusinessException($"设置全国仓库存失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
}
|
|
*/
|
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
foreach (var item in request.Items)
|
|
{
|
|
var req = new StockWriteUpdateSkuStockRequest();
|
|
req.skuId = long.Parse(item.Sku);
|
|
req.stockNum = item.StockNum;
|
|
req.storeId = item.StoreId;
|
|
_ = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
//if (res.IsError)
|
|
// throw new BusinessException($"设置全国仓库存失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
}
|
|
}
|
|
|
|
public override JToken GetCategoryInfoById(GetCategoryInfoByIdRequest request)
|
|
{
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
|
|
var req = new CategoryReadFindByIdRequest();
|
|
req.cid = request.CategoryId;
|
|
req.field = "id,fid,name,lev";
|
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
if (res.Json == null)
|
|
res.Json = JObject.Parse(res.Body);
|
|
return res.Json["jingdong_category_read_findById_responce"]["category"];
|
|
}
|
|
}
|
|
}
|
|
|