标题裂变功能优化 上传裂变商品时筛选重复上货逻辑优化
This commit is contained in:
1 parent
4ae8e4f1b2
commit
1b87ae3a28
23 files changed
+1232
-892
No files matched your search
@@ -1441,6 +1441,94 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}));
|
||||
}
|
||||
|
||||
#region 裂变标题
|
||||
if (BaseClass.UserAuthority.Contains("商品裂变") && chkFissionGoodsName.Checked)
|
||||
{
|
||||
bool isFinish = false;
|
||||
Invoke(new Action(() => {
|
||||
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
if (titles.Count == 0)
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
if (cell != null)
|
||||
cell.Value = "裂变标题数量不足,将暂停上传";
|
||||
BaseMsgForm.ShowError("裂变标题数量不足,将暂停上传");
|
||||
isFinish = true;
|
||||
}
|
||||
selectProd.product_name = titles[0];
|
||||
titles.RemoveAt(0);
|
||||
txtFissionTitle.Text = string.Join("\r\n", titles);
|
||||
cell.Value = "标题裂变成功,更改为:" + selectProd.product_name;
|
||||
}));
|
||||
if (isFinish)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"裂变标题数量不足,将暂停上传\"}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 跳过已上传商品,默认按商品货号,裂变商品按标题。
|
||||
if (chkSkipUploaded.Checked)
|
||||
{
|
||||
// 裂变按标题名称
|
||||
if (chkFissionProduct.Checked || chkFissionGoodsName.Checked)
|
||||
{
|
||||
var searchRst = WXUpload.searchProductWithTitle(shop, GetHtml.UrlEncodeUtf8(selectProd?.product_name));
|
||||
if (!searchRst.Contains("\"code\":0") && !searchRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref searchRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = searchRst;
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + error + "\"}";
|
||||
}
|
||||
try
|
||||
{
|
||||
var num = JObject.Parse(searchRst)["totalNum"].ParseToInt();
|
||||
if (num > 0)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品已存在,选择跳过\"}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + ex.Message + "\"}";
|
||||
}
|
||||
}
|
||||
// 非裂变商品按商品Id
|
||||
else
|
||||
{
|
||||
var searchExtCode = dbProd.ext_code;
|
||||
if (searchExtCode.ParseToString().Length < 10)
|
||||
searchExtCode = "EC1" + dbProd.spu_id + "A";
|
||||
if (dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId"))
|
||||
{
|
||||
var sku_secret_json = dbProd.sku_secret_json;
|
||||
searchExtCode = BaseRegex.GetStringJson(ref sku_secret_json, "goodsId");
|
||||
}
|
||||
var searchRst = WXUpload.searchProduct(shop, searchExtCode);
|
||||
if (!searchRst.Contains("\"code\":0") && !searchRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref searchRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = searchRst;
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + error + "\"}";
|
||||
}
|
||||
try
|
||||
{
|
||||
var num = JObject.Parse(searchRst)["totalNum"].ParseToInt();
|
||||
if (num > 0)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品已存在,选择跳过\"}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + ex.Message + "\"}";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 处理佣金上传
|
||||
int commissionRate = 0;
|
||||
int minCommissionRate = 0;
|
||||
@@ -1520,53 +1608,6 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 跳过已上传商品
|
||||
if (chkSkipUploaded.Checked)
|
||||
{
|
||||
var searchExtCode = dbProd.ext_code;
|
||||
if (searchExtCode.ParseToString().Length < 10)
|
||||
searchExtCode = "EC1" + dbProd.spu_id + "A";
|
||||
if (dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId"))
|
||||
{
|
||||
var sku_secret_json = dbProd.sku_secret_json;
|
||||
searchExtCode = BaseRegex.GetStringJson(ref sku_secret_json, "goodsId");
|
||||
}
|
||||
var searchRst = WXUpload.searchProduct(shop, searchExtCode);
|
||||
if (!searchRst.Contains("\"code\":0") && !searchRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref searchRst, "msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = searchRst;
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + error + "\"}";
|
||||
}
|
||||
try
|
||||
{
|
||||
var num = JObject.Parse(searchRst)["totalNum"].ParseToInt();
|
||||
if (num > 0)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品已存在,选择跳过\"}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + ex.Message + "\"}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
WXGetEditProductInfoLite wxEditProdInfo = null;
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
try
|
||||
{
|
||||
wxEditProdInfo = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(dbProd.product_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"微信商品格式获取失败" + ex.Message + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
#region 将聚水潭产品数据格式进行转换成pdd格式统一上传,匹配加密的spuCode和skuCoke 微信小店的货号spuCode和外部商品编号outProductId/out_product_id对应加密的聚水潭goodsId
|
||||
if (dbProd.product_get_type_text == "厂商直采")
|
||||
{
|
||||
@@ -1582,11 +1623,26 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter().JstPddProdToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 微信格式转换
|
||||
#region 微信店采原始格式还原
|
||||
WXGetEditProductInfoLite wxEditProdInfo = null;
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
try
|
||||
{
|
||||
wxEditProdInfo = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(dbProd.product_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"微信商品格式获取失败" + ex.Message + "\"}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 微信店采格式转换
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
{
|
||||
string convertRst = "";
|
||||
@@ -1596,6 +1652,33 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 微信回采转换
|
||||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1")
|
||||
{
|
||||
string errMsg = "";
|
||||
wxEditProdInfo = GetProductWXComplate(dbProd.secret_spu_id, out errMsg);
|
||||
|
||||
if (wxEditProdInfo == null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = errMsg;
|
||||
}));
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + errMsg + "\"}";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 微信小店app
|
||||
if (dbProd.product_get_type_text == "微信小店")
|
||||
{
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter().WXClientToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 1688格式转换
|
||||
if (dbProd.product_get_type_text == "1688厂家")
|
||||
{
|
||||
@@ -1613,16 +1696,6 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 微信小店app
|
||||
if (dbProd.product_get_type_text == "微信小店")
|
||||
{
|
||||
string convertRst = "";
|
||||
var pInfo = new PDDProdFormConverter().WXClientToPddConvert(out convertRst, dbProd);
|
||||
if (!string.IsNullOrEmpty(convertRst))
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 将产品数据初始化成微信小店支持的参数
|
||||
JObject prodJObj = new JObject();
|
||||
try
|
||||
@@ -1804,22 +1877,7 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1")
|
||||
{
|
||||
string errMsg = "";
|
||||
wxEditProdInfo = GetProductWXComplate(dbProd.secret_spu_id, out errMsg);
|
||||
|
||||
if (wxEditProdInfo == null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = errMsg;
|
||||
}));
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + errMsg + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
#region 图片盗链映射
|
||||
#region 图片盗链映射生成字典(如果有)
|
||||
bool isChangeImgDic = false;
|
||||
Dictionary<string, string> wxImgMapDic = new Dictionary<string, string>();
|
||||
if (!string.IsNullOrEmpty(dbProd.wx_img_map_json))
|
||||
@@ -1952,11 +2010,14 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 初始化上传商品对象
|
||||
// 生成初始化上传商品对象
|
||||
var upProdInitParam = new WXUploadProductInitParam();
|
||||
// 生成上传商品对象
|
||||
var upProdParam = new WXUploadProductParam();
|
||||
#endregion
|
||||
|
||||
#region 获取店铺 Api Token
|
||||
// 获取店铺的accessToken
|
||||
WXShopTokenInfo token = lstWXShopTokenInfo.FirstOrDefault(t => t.shopId == shop.ShopId);
|
||||
if (token == null)
|
||||
@@ -1979,33 +2040,12 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
// 如果店铺token不可用,随机获取一个上传图片的accessToken
|
||||
if (token == null || token.isExpire || string.IsNullOrEmpty(token.accessToken))
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
#endregion
|
||||
|
||||
#region 设置标题
|
||||
string prodTitle = dbProd.product_name.IsNullOrEmpty() ? prodInfo.detail.goods_name : dbProd.product_name;
|
||||
|
||||
// 裂变标题
|
||||
if (BaseClass.UserAuthority.Contains("商品裂变") && chkFissionGoodsName.Checked)
|
||||
{
|
||||
bool isFinish = false;
|
||||
Invoke(new Action(() => {
|
||||
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
if (titles.Count == 0)
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
if (cell != null)
|
||||
cell.Value = "裂变标题数量不足,将暂停上传";
|
||||
BaseMsgForm.ShowError("裂变标题数量不足,将暂停上传");
|
||||
isFinish = true;
|
||||
}
|
||||
prodTitle = titles[0];
|
||||
titles.RemoveAt(0);
|
||||
txtFissionTitle.Text = string.Join("\r\n", titles);
|
||||
}));
|
||||
if (isFinish)
|
||||
{
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"裂变标题数量不足,将暂停上传\"}";
|
||||
}
|
||||
}
|
||||
string prodTitle = selectProd.product_name;
|
||||
if (prodTitle.IsNullOrEmpty())
|
||||
prodTitle = dbProd.product_name.IsNullOrEmpty() ? prodInfo.detail.goods_name : dbProd.product_name;
|
||||
|
||||
upProdInitParam.product.info.title = prodTitle;
|
||||
upProdParam.product.info.title = prodTitle;
|
||||
@@ -3472,21 +3512,31 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
attrValue = "见包装";
|
||||
if (attr.name == "贮存条件")
|
||||
attrValue = "常温";
|
||||
if (attr.name == "保质期")
|
||||
{
|
||||
if (chkDefaultBestBefore.Checked == false)
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品属性不含保质期,跳过上传\"}";
|
||||
if (txtDefaultBestBefore.Text.ParseToInt() < 30)
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品默认保质期设置小于30天,跳过上传\"}";
|
||||
attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||||
}
|
||||
|
||||
//if (attr.name == "保质期")
|
||||
//{
|
||||
// if (chkDefaultBestBefore.Checked == false)
|
||||
// return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品属性不含保质期,跳过上传\"}";
|
||||
// if (txtDefaultBestBefore.Text.ParseToInt() < 15)
|
||||
// return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品默认保质期设置小于15天,跳过上传\"}";
|
||||
// attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||||
//}
|
||||
}
|
||||
|
||||
if (attr.name == "保质期")
|
||||
{
|
||||
if (chkDefaultBestBefore.Checked == false)
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"属性不含保质期,跳过上传\"}";
|
||||
if (txtDefaultBestBefore.Text.ParseToInt() < 3)
|
||||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"默认保质期设置小于3天,跳过上传\"}";
|
||||
attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||||
}
|
||||
}
|
||||
if (attrValue.IsNullOrEmpty() && attr.type == "string")
|
||||
{
|
||||
attrValue = "其他";
|
||||
}
|
||||
if (attr.type == "decimal4_unit" || attr.type == "integer_unit")
|
||||
if (attrValue.IsNullOrEmpty() && (attr.type == "decimal4_unit" || attr.type == "integer_unit"))
|
||||
{
|
||||
if (attr.value == "%")
|
||||
attrValue = "10 %";
|
||||
@@ -4471,10 +4521,23 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
{
|
||||
upProdParam.product.info.extraService.freightInsurance = 0;
|
||||
}
|
||||
// 假1赔3
|
||||
if (upProdParam.product.info.category[0].name == "珠宝首饰" || upProdParam.product.info.category[1].name == "时尚饰品")
|
||||
{
|
||||
upProdParam.product.info.extraService.fakeOnePayFour = 1;
|
||||
}
|
||||
// 坏损包退 damageGuarantee
|
||||
if (upProdParam.product.info.category[0].name == "生鲜" || upProdParam.product.info.category[0].name == "酒类" ||
|
||||
upProdParam.product.info.category[0].name == "食品饮料" || upProdParam.product.info.category[0].name == "保健食品/膳食营养补充食品" ||
|
||||
(upProdParam.product.info.category[0].name == "农资园艺" && upProdParam.product.info.category[1].name == "花卉绿植"))
|
||||
{
|
||||
upProdParam.product.info.extraService.damageGuarantee = 1;
|
||||
}
|
||||
// 生鲜不支持换货,关闭
|
||||
if (upProdParam.product.info.category[0].name == "生鲜")
|
||||
{
|
||||
upProdParam.product.info.extraService.exchangeSupport = 0;
|
||||
}
|
||||
|
||||
if (cell != null)
|
||||
{
|
||||
@@ -4986,12 +5049,30 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
break;
|
||||
foreach (var prod in prodLst)
|
||||
{
|
||||
var selectProd = JsonHelper.DeserializeJsonToObject<TemuDBProductSelect>(JsonHelper.SerializeObject(prod));
|
||||
selectProd.out_product_Id = prod.id.ToString();
|
||||
selectProd.id = 1;
|
||||
if (lstTemuDBProductSelect.Count > 0)
|
||||
selectProd.id = lstTemuDBProductSelect.Max(p => p.id) + 1;
|
||||
this.lstTemuDBProductSelect.Add(selectProd);
|
||||
var productNameLst = new List<string>() { prod.product_name };
|
||||
if (BaseClass.UserAuthority.Contains("商品裂变") && chkFissionProduct.Checked)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var titleCount = txtFissionProductCount.Text.Trim().ParseToInt();
|
||||
if (prod.fission_words.ParseToString().Length > 20 && titleCount > 0)
|
||||
{
|
||||
productNameLst = prod.fission_words.Replace("fission_goods_names:", "")
|
||||
.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).Distinct().Take(titleCount)
|
||||
.ToList();
|
||||
}
|
||||
}));
|
||||
}
|
||||
foreach (var productName in productNameLst)
|
||||
{
|
||||
var selectProd = JsonHelper.DeserializeJsonToObject<TemuDBProductSelect>(JsonHelper.SerializeObject(prod));
|
||||
selectProd.out_product_Id = prod.id.ToString();
|
||||
selectProd.id = 1;
|
||||
selectProd.product_name = productName;
|
||||
if (lstTemuDBProductSelect.Count > 0)
|
||||
selectProd.id = lstTemuDBProductSelect.Max(p => p.id) + 1;
|
||||
this.lstTemuDBProductSelect.Add(selectProd);
|
||||
}
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
@@ -5132,6 +5213,11 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
// 回采数据
|
||||
if (chkWXComplateProd.Checked)
|
||||
data += "&has_wx_format=1";
|
||||
|
||||
if (BaseClass.UserAuthority.Contains("商品裂变") && chkFissionProduct.Checked)
|
||||
{
|
||||
data += "&fission_words=fission_goods_names:";
|
||||
}
|
||||
}));
|
||||
var html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
@@ -5661,7 +5747,8 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
|
||||
private void cmbCateFilter1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||||
if (btnSwitchCatType.Text != "W")
|
||||
return;
|
||||
|
||||
cmbCateFilter2.Text = "";
|
||||
@@ -5681,7 +5768,8 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
|
||||
private void cmbCateFilter2_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||||
if (btnSwitchCatType.Text != "W")
|
||||
return;
|
||||
|
||||
cmbCateFilter3.Text = "";
|
||||
|
||||
Reference in new issue
Block a user