Files
KJD/Work/Business/ProductMappingBLL/ProductMapping.cs
T

3638 lines
182 KiB
C#

using AllBase;
using AllBase.Helper;
using AllBase.Model.Param.ToolsManage;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Work;
using Work.Api;
using Work.Business.ProductMappingBLL;
using Work.CollectClass;
namespace Work.Business.ProductMappingBLL
{
public class ProductMapping
{
public bool isRun { get; set; } = false;
public string Name { get; set; } = "数据转换";
public decimal addPercent { get; set; } = 30;
public decimal addPrice { get; set; } = 10;
public Form ParentFrom { get; set; }
private bool isUseProxyIP { get; set; }
/// <summary>
/// 是否使用资源包
/// </summary>
public bool IsResourcePack { get; set; } = false;
/// <summary>
/// 是否跳过预售
/// </summary>
public bool IsSkipPreSale { get; set; } = true;
/// <summary>
/// 下架等的商品集合。记录下来下次有同id的直接跳过
/// </summary>
private Dictionary<string, string> dicOffSaleProduct = new Dictionary<string, string>();
/// <summary>
/// 转换控制锁,防止高并发
/// </summary>
private static readonly object _lockerMapping = new object();
/// <summary>
/// 待转换商品
/// </summary>
private List<ProductMappingImportParam> lstProductParam = new List<ProductMappingImportParam>();
/// <summary>
/// 已转换商品
/// </summary>
private List<ProductMappingExportInfo> lstProductInfo = new List<ProductMappingExportInfo>();
public static List<string> luceneUrlList = new List<string>();
private CancellationTokenSource m_cancellationTokenSource;
private bool isDelOldData = false;
private ProductMappingExportInfo prodInfo = null;
public static Dictionary<string, int> luceneUrlDic = new Dictionary<string, int>();
public static int luceneUrlPropCount = 0;
/// <summary>
/// 获取转换完成的产品字符串
/// </summary>
public string productStr
{
get
{
if (prodInfo == null)
return "";
var pIdStr = prodInfo.ProductId.ToString();
if (prodInfo.From == "拼多多")
{
if (pIdStr.Length >= 2)
{
var idStrNew = pIdStr[pIdStr.Length - 1] + pIdStr.Substring(1, pIdStr.Length - 2) + pIdStr[0];
pIdStr = idStrNew;
}
}
string text = "\"" + (prodInfo.From == "拼多多" ? "搜款网" : prodInfo.From) + (prodInfo.dataSoure == 1 ? "净化" : "") + "\"," + "\"" + pIdStr + "\","
+ "\"" + prodInfo.ProductTitle?.Trim('\'').Trim('"') + "\",\"0\",\"0\",\"" + prodInfo.CatId + "\","
+ "\"" + ConvertMappingFromTypeToId(prodInfo.FakeMappingFrom) + "\"," + "\"" + prodInfo.FakeMappingProductId + "\","
+ "\"" + this.addPercent + "%+" + this.addPrice + "\","
+ "\"" + prodInfo.FakeMappingProductMinPrice + ":" + prodInfo.FakeMappingProductMaxPrice + ":" + "0" + "\"," + "\"" + prodInfo.MappingQuery + "\"";
return text;
}
}
public void GetFakeFrom(ProductMappingImportParam prod, Form form, bool _isUseProxyIp, ProductCollectBase _product = null, decimal _addPercent = 30, decimal _addPrice = 10)
{
GetFakeFromx(true, "", prod, form, _isUseProxyIp, _product, _addPercent, _addPrice);
}
public void GetFakeSearchFrom(string clientId, ProductMappingImportParam prod, Form form, bool _isUseProxyIp, ProductCollectBase _product = null, decimal _addPercent = 30, decimal _addPrice = 10)
{
GetFakeFromx(false, clientId, prod, form, _isUseProxyIp, _product, _addPercent, _addPrice);
}
public static bool ischeck = false;
/// <summary>
/// 获取虚拟上家
/// </summary>
/// <param name="prod"></param>
/// <returns></returns>
public void GetFakeFromx(bool cache, string clientId, ProductMappingImportParam prod, Form form, bool _isUseProxyIp, ProductCollectBase _product = null, decimal _addPercent = 30, decimal _addPrice = 10)
{
if (prod == null)
return;
//if (form == null)
// return;
string error_area = "0";
this.isRun = true;
this.ParentFrom = form;
this.isUseProxyIP = _isUseProxyIp;
this.addPercent = _addPercent;
this.addPrice = _addPrice;
this.lstProductParam.Add(prod);
m_cancellationTokenSource = new CancellationTokenSource();
try
{
error_area = "10001";
// 随机重连一次ADSL
//if (ChangeIPForm.sIpFormInstance != null && GlobalConfig.sADSLAccountParam.IsUseAdsl)
//{
// if (Randomx.GetId(50) == 1 && !ChangeIPForm.IsConnecting)
// {
// var isChangeIpSuccess = ChangeIPForm.sIpFormInstance.workOnOnce();
// }
//}
ProductCollectBase product = _product;
if (product == null && (prod.From == "搜款网" || prod.From == "拼多多"))
{
if (!isRun)
return;
try
{
TaobaoProductBase tp = new TaobaoProductBase();
tp.FromId = Convert.ToInt64(prod.RealProductId);
if (prod.From == "搜款网")
tp.FromType = "拼多多";
else
tp.FromType = prod.From;
tp.GoodsId = tp.FromId;
int updateIpTimes = 0;
updateIpFinish:
PinduoduoProductCollect pinduoduoProductCollect = new PinduoduoProductCollect(Name, tp);
PinduoduoProductCollect.TempIds.Clear();
//PinduoduoProductCollect.ConPddTokenList = GlobalConfig.PinDuoDuoTokenList; todo
pinduoduoProductCollect.IsUseProxyIP = this.isUseProxyIP;
pinduoduoProductCollect.IsResourcePack = IsResourcePack;
pinduoduoProductCollect.IsUsedForShuJuZhuanHuan = true;
pinduoduoProductCollect.IsSkipPreSale = IsSkipPreSale;
if (IsResourcePack)
{
//Func<bool> canContinue = PinDuoDuoHelperTemp.CanContinueCollectFunc((token) => { return token.ProductDetailStatus == TokenStatus.Valid; }, null, IsResourcePack, m_cancellationTokenSource);
//if (!canContinue())
//{
// prod.MappingResult = "转换失败,没有可以打码的Token";
// ShowMappingResult(prod);
// isRun = false;
// return;
//}
}
bool isOverTime = true;
var t = Task.Run(() =>
{
pinduoduoProductCollect.Get();
isOverTime = false;
});
t.Wait(90000);
product = pinduoduoProductCollect.pb;
if (isOverTime)
{
prod.MappingResult = "转换失败,获取商品超时";
ShowMappingResult(prod);
return;
}
// 如果无法获取拼多多信息了,重连
if (pinduoduoProductCollect.IsNeedLogin)
{
//if (ChangeIPForm.sIpFormInstance != null && GlobalConfig.sADSLAccountParam.IsUseAdsl && updateIpTimes < 2)
//{
// updateIpTimes++;
// if (ChangeIPForm.IsConnecting)
// {
// while (ChangeIPForm.IsConnecting)
// {
// Thread.Sleep(100);
// }
// goto updateIpFinish;
// }
// MappingVDianBLL.IsChangeAdsl = true;
// var isChangeIpSuccess = ChangeIPForm.sIpFormInstance.workOnOnce();
// MappingVDianBLL.IsChangeAdsl = false;
// if (isChangeIpSuccess)
// goto updateIpFinish;
//}
// prod.MappingResult = "转换失败,需要登录拼多多或登录Token!";
//if (ChangeIPForm.sIpFormInstance != null && GlobalConfig.sADSLAccountParam.IsUseAdsl)
// prod.MappingResult = "转换失败,可能是商品不存在或拨号无法获取,请尝试使用Token";
//ShowMappingResult(prod);
//return;
}
if (pinduoduoProductCollect.IsUseProxyIPGetProductFailure)
{
prod.MappingResult = "转换失败,通过代理获取当前商品失败";
ShowMappingResult(prod);
return;
}
if (isUseProxyIP && pinduoduoProductCollect.IsProxyOverdue)
{
prod.MappingResult = "代理ip套餐已过期";
ShowMappingResult(prod);
return;
}
if (pinduoduoProductCollect.IsNotExist)
{
prod.MappingResult = "转换失败,商品不存在";
ShowMappingResult(prod);
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
return;
}
if (pinduoduoProductCollect.IsOnSale == false)
{
if (pinduoduoProductCollect.IsSaleOut)
{
prod.MappingResult = "转换失败,商品已售罄";
}
else if (pinduoduoProductCollect.IsPresale)
{
prod.MappingResult = "转换失败,预售商品不能转换";
}
else
{
prod.MappingResult = "转换失败,可能是商品下架或商品不存在";
}
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
// 下架直接显示
ShowMappingResult(prod);
return;
}
if (pinduoduoProductCollect.IsResultError)
{
prod.MappingResult = "转换失败,可能是商品不存在或服务器出错";
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
ShowMappingResult(prod);
return;
}
}
catch
{
prod.MappingResult = "转换失败,该商品转换异常:获取拼多多商品异常";
ShowMappingResult(prod);
return;
}
}
else if (product == null && prod.From == "淘宝")
{
if (!isRun)
return;
bool isOverTime = true;
try
{
ProductCollectBase proInfo = new ProductCollectBase
{
from_url = "https://item.taobao.com/item.htm?id=" + prod.RealProductId,
from_id = Convert.ToInt64(prod.RealProductId),
};
TaobaoMobileCollect goodsFromTaobaoInfo = new TaobaoMobileCollect(proInfo);
//isOverTime = !t.Wait(180000);
Task.Run(() =>
{
int times = 0;
while (isOverTime)
{
times++;
if (times == 30)
{
if (string.IsNullOrEmpty(prod.MappingResult))
{
prod.MappingResult = "当前采集速度慢,请稍候...";
ShowMappingResult(prod);
break;
}
}
Thread.Sleep(1000);
}
});
goodsFromTaobaoInfo.Get();
isOverTime = false;
prod.MappingResult = " ";
ShowMappingResult(prod);
product = goodsFromTaobaoInfo.Product;
if (goodsFromTaobaoInfo.IsDown)
{
prod.MappingResult = "转换失败,可能是商品已下架或商品不存在";
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
// 下架直接显示
ShowMappingResult(prod);
return;
}
}
catch (Exception ex)
{
isOverTime = false;
prod.MappingResult = "转换失败,该商品转换异常:获取淘宝商品异常";
ShowMappingResult(prod);
return;
}
}
else if (product == null && prod.From == "阿里巴巴")
{
if (!isRun)
return;
ProductCollectBase proInfo = new ProductCollectBase
{
from_url = "https://detail.1688.com/offer/" + prod.RealProductId + ".html",
from_id = Convert.ToInt64(prod.RealProductId),
};
AlibabaProductGet goodsFrom1688Info = new AlibabaProductGet(proInfo);
bool isOverTime = true;
var t = Task.Run(() =>
{
goodsFrom1688Info.Get();
isOverTime = false;
});
t.Wait(60000);
product = goodsFrom1688Info.Product;
product.from_title = product.from_title.Trim('\'').Trim('"');
product.name = product.name.Trim('\'').Trim('"');
if (isOverTime)
{
prod.MappingResult = "转换失败,获取商品超时";
ShowMappingResult(prod);
return;
}
if (!goodsFrom1688Info.IsOnSale)
{
prod.MappingResult = "转换失败,商品不存在或不可展示";
ShowMappingResult(prod);
return;
}
}
else if (product == null && prod.From == "京喜")
{
if (!isRun)
return;
AAA:
ProductCollectBase proInfo = new ProductCollectBase
{
from_url = "https://item.m.jd.com/product/" + prod.RealProductId + ".html",
from_id = Convert.ToInt64(prod.RealProductId),
};
JingXiCollect tm = new JingXiCollect(proInfo);
bool isOverTime = true;
var t = Task.Run(() =>
{
tm.Get();
isOverTime = false;
});
t.Wait(600000);
if (ParentFrom != null && JingXiCollect.VerifyCodeUrl.Length > 0 && JingXiCollect.VerifyCodeUrl.Contains("wqs.jd.com/item/spider_check.shtml"))
{
//ParentFrom.Invoke(new Action(() =>
//{
// CollectVerifyForm f = new CollectVerifyForm();
// f.url = JingXiCollect.VerifyCodeUrl;
// f.ShowDialog();
//}));
//if (JingXiCollect.VerifyCodeUrl == "")
//{
// tm.IsVerify = false;
// goto AAA;
//}
//JingXiCollect.VerifyCodeUrl = "";
}
product = tm.Product;
product.from_title = product.from_title.Trim('\'').Trim('"');
product.name = product.name.Trim('\'').Trim('"');
if (product.content == "")
{
}
if (isOverTime)
{
prod.MappingResult = "转换失败,获取商品超时";
ShowMappingResult(prod);
return;
}
if (JingXiCollect.IsProxyOverdue)
{
prod.MappingResult = "请检查ip套餐是否过期";
ShowMappingResult(prod);
this.StopMapping();
return;
}
if (tm.IsVerify)
{
prod.MappingResult = "京喜商品采集受限,建议使用代理IP采集";
ShowMappingResult(prod);
Thread.Sleep(8000);
//this.btnStopMapping_Click(null, null);
return;
}
if (!string.IsNullOrEmpty(JingXiCollect.VerifyCodeUrl))
{
//IeForm ie = new IeForm();
//ie.UrlString = JingXiCollect.VerifyCodeUrl;
////ie.UrlString = "https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F"; // 登录京东后获取买手cookie查看受限商品详情
//ie.Title = "京喜验证";
//ie.ShowDialog();
//JingXiCollect.VerifyCodeUrl = "";
goto AAA;
// prod.MappingResult = "转换失败,商品采集需要验证";
prod.MappingResult = "采集中断,请选择代理ip后继续";
ShowMappingResult(prod);
this.StopMapping();
// BaseMsgForm.ShowInfo("采集中断,请选择代理ip后继续");
return;
}
if (!tm.IsOnSale)
{
prod.MappingResult = "转换失败,商品不存在或不可展示";
ShowMappingResult(prod);
return;
}
}
error_area = "10002";
if (product != null && !string.IsNullOrEmpty(product.content) && (!string.IsNullOrEmpty(product.image) || product.Images.Count > 0))
{
// 确定待转换商品图片
prod.Image = !string.IsNullOrEmpty(product.image) ? product.image : product.Images[0];
if (prod.Image.StartsWith("https:"))
prod.Image = prod.Image.Substring(6);
else if (prod.Image.StartsWith("http:"))
prod.Image = prod.Image.Substring(5);
// 确定待转换商品标题
if (string.IsNullOrEmpty(prod.ProductTitle))
prod.ProductTitle = product.name;
#region 标题过滤功能
//如果标题过滤开启
if (CollectFilterList.IsOpenTittleFilter)
{
error_area = "10003";
if (CollectFilterList.TittleFilterList != null && CollectFilterList.TittleFilterList.Count > 0)
{
//标题有词包含在过滤集合中 则剔除
//if (CollectFilterList.TittleFilterList.Where(p => product.name.Contains(p)).Any())
foreach (string str in CollectFilterList.TittleFilterList)
{
if (prod != null && prod.ProductTitle.Contains(str))
{
prod.MappingResult = "标题包含违规词\"" + str + "\",已成功过滤";
ShowMappingResult(prod);
return;
}
}
}
}
#endregion
// 由于多多进宝等类目输出错误,暂时强制修改拼多多来源商品类目
if (prod.From == "搜款网" || prod.From == "拼多多")
{
error_area = "10004";
prod.CatId = product.cat4 != 0 ? product.cat4.ToString() : product.cat3.ToString();
if (string.IsNullOrEmpty(prod.MainCid))
{
prod.MainCid = product.main_cid.ToString();
}
}
// 获取商品类目
if (string.IsNullOrEmpty(prod.CatId) || string.IsNullOrEmpty(prod.MainCid) || prod.CatId == "0" || prod.MainCid == "0")
{
error_area = "10005";
if (prod.From == "搜款网" || prod.From == "拼多多")
GetCatId(prod);
else
GetCatId(prod, product.cat_id == 0 ? 1 : product.cat_id, "0");
}
//if (string.IsNullOrEmpty(prod.CatId) || string.IsNullOrEmpty(prod.MainCid) || prod.CatId == "0" || prod.MainCid == "0")
//{
// prod.MappingResult = "转换失败,类目识别失败。";
// return;
//}
// 裂变商品商品类目赋值
var prodParams = lstProductParam.Where(l => l.RealProductId == prod.RealProductId && l.From == prod.From);
foreach (var p in prodParams)
{
if (string.IsNullOrEmpty(p.CatId))
p.CatId = prod.CatId;
if (string.IsNullOrEmpty(p.MainCid))
p.MainCid = prod.MainCid;
}
var maxPrice = 0M;
var minPrice = 999999M;
if (product.SkuMaps.Count > 0)
{
error_area = "10006";
foreach (var sku in product.SkuMaps)
{
if (maxPrice < sku.price)
maxPrice = sku.price;
if (minPrice > sku.price)
minPrice = sku.price;
}
}
else
{
minPrice = maxPrice = product.price;
}
prod.MinPrice = Convert.ToInt32(minPrice * 100);
prod.MaxPrice = Convert.ToInt32(maxPrice * 100);
// 计算上家理论价格,将邮费加到总价,加一角钱便于拼宝宝上货取整
var minAfterPrice = (minPrice * (addPercent + 100M) / 100M + addPrice + 0.1M) * 100M * 0.93M + product.express_price * 100M;
var maxAfterPrice = (maxPrice * (addPercent + 100M) / 100M + addPrice + 0.1M) * 100M * 0.93M + product.express_price * 100M;
error_area = "10007";
// 搜索新的上家并显示出来
if (cache)
GetFakeCacheFrom(prod, product, minAfterPrice, maxAfterPrice, ref error_area);
else
GetFakeSearchFrom(clientId, prod, product, minAfterPrice, maxAfterPrice, ref error_area);
error_area = "10009";
}
else
{
error_area = "10008";
if (string.IsNullOrEmpty(product.image) && (product.Images == null || product.Images.Count == 0))
{
prod.MappingResult = "转换失败,未找到商品主图或详情图";
}
else if (string.IsNullOrEmpty(product.content) && !string.IsNullOrEmpty(product.name))
{
prod.MappingResult = "转换失败,上家商品详情为空跳过";
}
else if (string.IsNullOrEmpty(prod.MappingResult))
{
if (prod.From == "拼多多" || prod.From == "搜款网")
prod.MappingResult = "转换失败,可能是不满足转换条件或Token失效";
else
prod.MappingResult = "转换失败,可能是不满足转换条件";
}
ShowMappingResult(prod);
error_area = "10010";
return;
}
}
catch (Exception ex)
{
StackTrace st = new StackTrace(ex, true);
StackFrame[] frames = st.GetFrames();
string Mssg = "";
var frame = frames.LastOrDefault();
#if DEBUG
if (frame != null)
{
//Console.WriteLine("{0}:{1}({2},{3})", frame.GetFileName(), frame.GetMethod().Name, frame.GetFileLineNumber(), frame.GetFileColumnNumber());
var fileName = frame.GetFileName();
fileName = fileName?.Split('\\').LastOrDefault()?.Split('.').FirstOrDefault();
Mssg = "" + fileName + " ----- ";
Mssg += frame.GetMethod().Name;
Mssg += "(" + frame.GetFileLineNumber() + ":";
Mssg += frame.GetFileColumnNumber() + ")";
}
prod.MappingResult = "转换失败,该商品转换异常:" + Mssg + " ----- code:" + error_area;
#else
prod.MappingResult = "转换失败,该商品转换异常:code:" + error_area;
#endif
ShowMappingResult(prod);
LogSave.Add("商品转换出现异常:" + ex.Message + "-" + ex.StackTrace);
}
}
public void GetFakeFromIds(List<Tuple<string, int, int, string>> content, int type, bool cache, string clientId, ProductMappingImportParam prod, Form form, bool _isUseProxyIp, ProductCollectBase _product = null, decimal _addPercent = 30, decimal _addPrice = 10)
{
if (prod == null)
return;
//if (form == null)
// return;
string error_area = "0";
this.isRun = true;
this.ParentFrom = form;
this.isUseProxyIP = _isUseProxyIp;
this.addPercent = _addPercent;
this.addPrice = _addPrice;
this.lstProductParam.Add(prod);
m_cancellationTokenSource = new CancellationTokenSource();
try
{
error_area = "10001";
// 随机重连一次ADSL
//if (ChangeIPForm.sIpFormInstance != null && GlobalConfig.sADSLAccountParam.IsUseAdsl)
//{
// if (Randomx.GetId(50) == 1 && !ChangeIPForm.IsConnecting)
// {
// var isChangeIpSuccess = ChangeIPForm.sIpFormInstance.workOnOnce();
// }
//}
ProductCollectBase product = _product;
if (product == null && (prod.From == "搜款网" || prod.From == "拼多多"))
{
if (!isRun)
return;
try
{
TaobaoProductBase tp = new TaobaoProductBase();
tp.FromId = Convert.ToInt64(prod.RealProductId);
if (prod.From == "搜款网")
tp.FromType = "拼多多";
else
tp.FromType = prod.From;
tp.GoodsId = tp.FromId;
int updateIpTimes = 0;
updateIpFinish:
PinduoduoProductCollect pinduoduoProductCollect = new PinduoduoProductCollect(Name, tp);
PinduoduoProductCollect.TempIds.Clear();
//PinduoduoProductCollect.ConPddTokenList = GlobalConfig.PinDuoDuoTokenList; todo
pinduoduoProductCollect.IsUseProxyIP = this.isUseProxyIP;
pinduoduoProductCollect.IsResourcePack = IsResourcePack;
pinduoduoProductCollect.IsUsedForShuJuZhuanHuan = true;
pinduoduoProductCollect.IsSkipPreSale = IsSkipPreSale;
if (IsResourcePack)
{
//Func<bool> canContinue = PinDuoDuoHelperTemp.CanContinueCollectFunc((token) => { return token.ProductDetailStatus == TokenStatus.Valid; }, null, IsResourcePack, m_cancellationTokenSource);
//if (!canContinue())
//{
// prod.MappingResult = "转换失败,没有可以打码的Token";
// ShowMappingResult(prod);
// isRun = false;
// return;
//}
}
bool isOverTime = true;
var t = Task.Run(() =>
{
pinduoduoProductCollect.Get();
isOverTime = false;
});
t.Wait(90000);
product = pinduoduoProductCollect.pb;
if (isOverTime)
{
prod.MappingResult = "转换失败,获取商品超时";
ShowMappingResult(prod);
return;
}
// 如果无法获取拼多多信息了,重连
if (pinduoduoProductCollect.IsNeedLogin)
{
//if (ChangeIPForm.sIpFormInstance != null && GlobalConfig.sADSLAccountParam.IsUseAdsl && updateIpTimes < 2)
//{
// updateIpTimes++;
// if (ChangeIPForm.IsConnecting)
// {
// while (ChangeIPForm.IsConnecting)
// {
// Thread.Sleep(100);
// }
// goto updateIpFinish;
// }
// MappingVDianBLL.IsChangeAdsl = true;
// var isChangeIpSuccess = ChangeIPForm.sIpFormInstance.workOnOnce();
// MappingVDianBLL.IsChangeAdsl = false;
// if (isChangeIpSuccess)
// goto updateIpFinish;
//}
// prod.MappingResult = "转换失败,需要登录拼多多或登录Token!";
//if (ChangeIPForm.sIpFormInstance != null && GlobalConfig.sADSLAccountParam.IsUseAdsl)
// prod.MappingResult = "转换失败,可能是商品不存在或拨号无法获取,请尝试使用Token";
//ShowMappingResult(prod);
//return;
}
if (pinduoduoProductCollect.IsUseProxyIPGetProductFailure)
{
prod.MappingResult = "转换失败,通过代理获取当前商品失败";
ShowMappingResult(prod);
return;
}
if (isUseProxyIP && pinduoduoProductCollect.IsProxyOverdue)
{
prod.MappingResult = "代理ip套餐已过期";
ShowMappingResult(prod);
return;
}
if (pinduoduoProductCollect.IsNotExist)
{
prod.MappingResult = "转换失败,商品不存在";
ShowMappingResult(prod);
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
return;
}
if (pinduoduoProductCollect.IsOnSale == false)
{
if (pinduoduoProductCollect.IsSaleOut)
{
prod.MappingResult = "转换失败,商品已售罄";
}
else if (pinduoduoProductCollect.IsPresale)
{
prod.MappingResult = "转换失败,预售商品不能转换";
}
else
{
prod.MappingResult = "转换失败,可能是商品下架或商品不存在";
}
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
// 下架直接显示
ShowMappingResult(prod);
return;
}
if (pinduoduoProductCollect.IsResultError)
{
prod.MappingResult = "转换失败,可能是商品不存在或服务器出错";
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
ShowMappingResult(prod);
return;
}
}
catch
{
prod.MappingResult = "转换失败,该商品转换异常:获取拼多多商品异常";
ShowMappingResult(prod);
return;
}
}
else if (product == null && prod.From == "淘宝")
{
if (!isRun)
return;
bool isOverTime = true;
try
{
ProductCollectBase proInfo = new ProductCollectBase
{
from_url = "https://item.taobao.com/item.htm?id=" + prod.RealProductId,
from_id = Convert.ToInt64(prod.RealProductId),
};
TaobaoMobileCollect goodsFromTaobaoInfo = new TaobaoMobileCollect(proInfo);
//isOverTime = !t.Wait(180000);
Task.Run(() =>
{
int times = 0;
while (isOverTime)
{
times++;
if (times == 30)
{
if (string.IsNullOrEmpty(prod.MappingResult))
{
prod.MappingResult = "当前采集速度慢,请稍候...";
ShowMappingResult(prod);
break;
}
}
Thread.Sleep(1000);
}
});
goodsFromTaobaoInfo.Get();
isOverTime = false;
prod.MappingResult = " ";
ShowMappingResult(prod);
product = goodsFromTaobaoInfo.Product;
if (goodsFromTaobaoInfo.IsDown)
{
prod.MappingResult = "转换失败,可能是商品已下架或商品不存在";
if (!dicOffSaleProduct.Keys.Contains(prod.RealProductId + "|" + prod.From))
dicOffSaleProduct.Add(prod.RealProductId + "|" + prod.From, prod.MappingResult);
// 下架直接显示
ShowMappingResult(prod);
return;
}
}
catch (Exception ex)
{
isOverTime = false;
prod.MappingResult = "转换失败,该商品转换异常:获取淘宝商品异常";
ShowMappingResult(prod);
return;
}
}
else if (product == null && prod.From == "阿里巴巴")
{
if (!isRun)
return;
ProductCollectBase proInfo = new ProductCollectBase
{
from_url = "https://detail.1688.com/offer/" + prod.RealProductId + ".html",
from_id = Convert.ToInt64(prod.RealProductId),
};
AlibabaProductGet goodsFrom1688Info = new AlibabaProductGet(proInfo);
bool isOverTime = true;
var t = Task.Run(() =>
{
goodsFrom1688Info.Get();
isOverTime = false;
});
t.Wait(60000);
product = goodsFrom1688Info.Product;
product.from_title = product.from_title.Trim('\'').Trim('"');
product.name = product.name.Trim('\'').Trim('"');
if (isOverTime)
{
prod.MappingResult = "转换失败,获取商品超时";
ShowMappingResult(prod);
return;
}
if (!goodsFrom1688Info.IsOnSale)
{
prod.MappingResult = "转换失败,商品不存在或不可展示";
ShowMappingResult(prod);
return;
}
}
else if (product == null && prod.From == "京喜")
{
if (!isRun)
return;
AAA:
ProductCollectBase proInfo = new ProductCollectBase
{
from_url = "https://item.m.jd.com/product/" + prod.RealProductId + ".html",
from_id = Convert.ToInt64(prod.RealProductId),
};
JingXiCollect tm = new JingXiCollect(proInfo);
bool isOverTime = true;
var t = Task.Run(() =>
{
tm.Get();
isOverTime = false;
});
t.Wait(600000);
if (ParentFrom != null && JingXiCollect.VerifyCodeUrl.Length > 0 && JingXiCollect.VerifyCodeUrl.Contains("wqs.jd.com/item/spider_check.shtml"))
{
//ParentFrom.Invoke(new Action(() =>
//{
// CollectVerifyForm f = new CollectVerifyForm();
// f.url = JingXiCollect.VerifyCodeUrl;
// f.ShowDialog();
//}));
//if (JingXiCollect.VerifyCodeUrl == "")
//{
// tm.IsVerify = false;
// goto AAA;
//}
//JingXiCollect.VerifyCodeUrl = "";
}
product = tm.Product;
product.from_title = product.from_title.Trim('\'').Trim('"');
product.name = product.name.Trim('\'').Trim('"');
if (product.content == "")
{
}
if (isOverTime)
{
prod.MappingResult = "转换失败,获取商品超时";
ShowMappingResult(prod);
return;
}
if (JingXiCollect.IsProxyOverdue)
{
prod.MappingResult = "请检查ip套餐是否过期";
ShowMappingResult(prod);
this.StopMapping();
return;
}
if (tm.IsVerify)
{
prod.MappingResult = "京喜商品采集受限,建议使用代理IP采集";
ShowMappingResult(prod);
Thread.Sleep(8000);
//this.btnStopMapping_Click(null, null);
return;
}
if (!string.IsNullOrEmpty(JingXiCollect.VerifyCodeUrl))
{
//IeForm ie = new IeForm();
//ie.UrlString = JingXiCollect.VerifyCodeUrl;
////ie.UrlString = "https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F"; // 登录京东后获取买手cookie查看受限商品详情
//ie.Title = "京喜验证";
//ie.ShowDialog();
//JingXiCollect.VerifyCodeUrl = "";
goto AAA;
// prod.MappingResult = "转换失败,商品采集需要验证";
prod.MappingResult = "采集中断,请选择代理ip后继续";
ShowMappingResult(prod);
this.StopMapping();
// BaseMsgForm.ShowInfo("采集中断,请选择代理ip后继续");
return;
}
if (!tm.IsOnSale)
{
prod.MappingResult = "转换失败,商品不存在或不可展示";
ShowMappingResult(prod);
return;
}
}
error_area = "10002";
if (product != null && !string.IsNullOrEmpty(product.content) && (!string.IsNullOrEmpty(product.image) || product.Images.Count > 0))
{
// 确定待转换商品图片
prod.Image = !string.IsNullOrEmpty(product.image) ? product.image : product.Images[0];
if (prod.Image.StartsWith("https:"))
prod.Image = prod.Image.Substring(6);
else if (prod.Image.StartsWith("http:"))
prod.Image = prod.Image.Substring(5);
// 确定待转换商品标题
if (string.IsNullOrEmpty(prod.ProductTitle))
prod.ProductTitle = product.name;
#region 标题过滤功能
//如果标题过滤开启
if (CollectFilterList.IsOpenTittleFilter)
{
error_area = "10003";
if (CollectFilterList.TittleFilterList != null && CollectFilterList.TittleFilterList.Count > 0)
{
//标题有词包含在过滤集合中 则剔除
//if (CollectFilterList.TittleFilterList.Where(p => product.name.Contains(p)).Any())
foreach (string str in CollectFilterList.TittleFilterList)
{
if (prod != null && prod.ProductTitle.Contains(str))
{
prod.MappingResult = "标题包含违规词\"" + str + "\",已成功过滤";
ShowMappingResult(prod);
return;
}
}
}
}
#endregion
// 由于多多进宝等类目输出错误,暂时强制修改拼多多来源商品类目
if (prod.From == "搜款网" || prod.From == "拼多多")
{
error_area = "10004";
prod.CatId = product.cat4 != 0 ? product.cat4.ToString() : product.cat3.ToString();
if (string.IsNullOrEmpty(prod.MainCid))
{
prod.MainCid = product.main_cid.ToString();
}
}
// 获取商品类目
if (string.IsNullOrEmpty(prod.CatId) || string.IsNullOrEmpty(prod.MainCid) || prod.CatId == "0" || prod.MainCid == "0")
{
error_area = "10005";
if (prod.From == "搜款网" || prod.From == "拼多多")
GetCatId(prod);
else
GetCatId(prod, product.cat_id == 0 ? 1 : product.cat_id, "0");
}
//if (string.IsNullOrEmpty(prod.CatId) || string.IsNullOrEmpty(prod.MainCid) || prod.CatId == "0" || prod.MainCid == "0")
//{
// prod.MappingResult = "转换失败,类目识别失败。";
// return;
//}
// 裂变商品商品类目赋值
var prodParams = lstProductParam.Where(l => l.RealProductId == prod.RealProductId && l.From == prod.From);
foreach (var p in prodParams)
{
if (string.IsNullOrEmpty(p.CatId))
p.CatId = prod.CatId;
if (string.IsNullOrEmpty(p.MainCid))
p.MainCid = prod.MainCid;
}
var maxPrice = 0M;
var minPrice = 999999M;
if (product.SkuMaps.Count > 0)
{
error_area = "10006";
foreach (var sku in product.SkuMaps)
{
if (maxPrice < sku.price)
maxPrice = sku.price;
if (minPrice > sku.price)
minPrice = sku.price;
}
}
else
{
minPrice = maxPrice = product.price;
}
prod.MinPrice = Convert.ToInt32(minPrice * 100);
prod.MaxPrice = Convert.ToInt32(maxPrice * 100);
// 计算上家理论价格,将邮费加到总价,加一角钱便于拼宝宝上货取整
var minAfterPrice = (minPrice * (addPercent + 100M) / 100M + addPrice + 0.1M) * 100M * 0.93M + product.express_price * 100M;
var maxAfterPrice = (maxPrice * (addPercent + 100M) / 100M + addPrice + 0.1M) * 100M * 0.93M + product.express_price * 100M;
error_area = "10007";
// 搜索新的上家并显示出来
if (type == 1)
GetFakeQueueIdCacheFrom(content, prod, product, minAfterPrice, maxAfterPrice, ref error_area);
else
GetFakeQueuetitleCacheFrom(content, prod, product, minAfterPrice, maxAfterPrice, ref error_area);
error_area = "10009";
}
else
{
error_area = "10008";
if (string.IsNullOrEmpty(product.image) && (product.Images == null || product.Images.Count == 0))
{
prod.MappingResult = "转换失败,未找到商品主图或详情图";
}
else if (string.IsNullOrEmpty(product.content) && !string.IsNullOrEmpty(product.name))
{
prod.MappingResult = "转换失败,上家商品详情为空跳过";
}
else if (string.IsNullOrEmpty(prod.MappingResult))
{
if (prod.From == "拼多多" || prod.From == "搜款网")
prod.MappingResult = "转换失败,可能是不满足转换条件或Token失效";
else
prod.MappingResult = "转换失败,可能是不满足转换条件";
}
ShowMappingResult(prod);
error_area = "10010";
return;
}
}
catch (Exception ex)
{
StackTrace st = new StackTrace(ex, true);
StackFrame[] frames = st.GetFrames();
string Mssg = "";
var frame = frames.LastOrDefault();
#if DEBUG
if (frame != null)
{
//Console.WriteLine("{0}:{1}({2},{3})", frame.GetFileName(), frame.GetMethod().Name, frame.GetFileLineNumber(), frame.GetFileColumnNumber());
var fileName = frame.GetFileName();
fileName = fileName?.Split('\\').LastOrDefault()?.Split('.').FirstOrDefault();
Mssg = "" + fileName + " ----- ";
Mssg += frame.GetMethod().Name;
Mssg += "(" + frame.GetFileLineNumber() + ":";
Mssg += frame.GetFileColumnNumber() + ")";
}
prod.MappingResult = "转换失败,该商品转换异常:" + Mssg + " ----- code:" + error_area;
#else
prod.MappingResult = "转换失败,该商品转换异常:code:" + error_area;
#endif
ShowMappingResult(prod);
LogSave.Add("商品转换出现异常:" + ex.Message + "-" + ex.StackTrace);
}
}
public static bool CompareTitle(string title, string name)
{
if ((name.Length < title.Length + 10) || name.Length <= 30)
{
return true;
}
return false;
}
public void GetFakeQueueIdsCacheFrom(List<ProductMappingImportParam> prods, string mappingFrom = "")
{
try
{
if (!isRun)
return;
//List<Tuple<string, int, int, string>> mappingResultWd = null;
#region Id缓存,按商品Id获取缓存
GetFakeCacheIdsWd(prods, ref mappingFrom);
#endregion
}
catch
{
}
}
public void GetFakeQueueTitlesCacheFrom(List<ProductMappingImportParam> prod, string mappingFrom = "")
{
try
{
if (!isRun)
return;
//List<Tuple<string, int, int, string>> mappingResultWdTitle = null;
#region Id缓存,按商品Id获取缓存
MappingVDianCacheBLL.GetFakeCacheQueueVDianTitle(prod, ref mappingFrom);
#endregion
}
catch
{
}
}
public void GetFakeQueuetitleCacheFrom(List<Tuple<string, int, int, string>> content, ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref string error_area,
List<Tuple<string, int, int, string>> mappingResultCache = null, string mappingFrom = "")
{
if (!isRun)
return;
if (!this.lstProductParam.Contains(prod))
this.lstProductParam.Add(prod);
string mapping_query = "";
List<Tuple<string, int, int, string>> mappingResultNonWd = null;
List<Tuple<string, int, int, string>> mappingResultWd = null;
List<Tuple<string, int, int, string>> mappingResultWdTitle = null;
var result = MappingTaoBaoBLL.FilterItems(mappingResultNonWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count == 0)
result = MappingTaoBaoBLL.FilterItems(mappingResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
bool isCheckOnSale = false;
#region 读取微店虚拟上家缓存
#region 标题缓存,按商品标题MD5获取缓存
if (result.Count == 0)
{
var title = TrimAndRemoveSpecialText(product?.name);
mappingResultWdTitle = content; //MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom);
result = MappingTaoBaoBLL.FilterItems(mappingResultWdTitle, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (mappingResultWdTitle != null && result.Count == 0 && Randomx.GetId(1) == 0)
{
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in mappingResultWdTitle)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
}
// 按一定比例查询确认商品id和图片缓存老数据对应商品是否已被删除,如果删除,则更新数据库(按较低的比例随机,以防调用过高导致微店响应出问题)
if (isCheckOnSale)
{
bool isUpdateDelete = false;
bool isResultCount = result != null && result.Count > 0;
bool isMappingResultWdTitle = mappingResultWdTitle != null && mappingResultWdTitle.Count > 0;
while (result.Count > 0)
{
Thread.Sleep(1000 + Randomx.GetId(2000));
var item = result.First(f => f.Item3 == result.Min(s => s.Item3));
var itemResult = Work.GetPostTaobaoHtml.GetUrl("https://weidian.com/item.html?itemID=" + item.Item1, "", true, "", "_");
// 商品被删除了的界面包含以下情况
if (itemResult.Contains("登录") && !itemResult.Contains("限时折扣价格区域") && !itemResult.Contains("收藏"))
{
isUpdateDelete = true;
result.Remove(item);
//mappingResultWdTitle.Remove(item);
var item2 = mappingResultWdTitle.FirstOrDefault(r => r.Item1 == item.Item1);
if (item2 != null)
mappingResultWdTitle.Remove(item2);
}
else
{
break;
}
}
// 如果有合适的上家商品不用上传新商品了,直接更新缓存服务器
if (isUpdateDelete && isResultCount && isMappingResultWdTitle)
{
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom, true);
//var testResult = MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom); // 读缓存测试
}
}
if (result.Count > 0)
{
bool hit = false;
var selectMinItem = MatchMeetTitleLength(title, result, mappingResultWdTitle, out hit);
var resultData = new List<Tuple<string, int, int, string>>();
if (selectMinItem != null)
{
foreach (var r in mappingResultWdTitle)
{
if (r.Item1 == selectMinItem.Item1 && hit)
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, DateTime.Now.ToString("yyyy-MM-dd")));
else
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, r.Item4));
}
if (hit)
{
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(resultData, title, mappingFrom);
}
mappingFrom = "微店";
prod.MappingResourceType = "标题缓存";
MappingVDianApiBLL.UpDateMappingResultToStatistics("1");
mapping_query = "1";
}
else
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom);
}
}
#endregion
#endregion
#region 转换结果显示
if (result.Count > 0)
{
// 裂变数据
var prodParams = lstProductParam.Where(l => l.RealProductId == prod.RealProductId && l.From == prod.From);
var selectMinItem = result.First(f => f.Item3 == result.Min(s => s.Item3));
var tempTitle = "";
foreach (var p in prodParams)
{
if (!string.IsNullOrEmpty(p.ProductTitle))
{
tempTitle = "";
}
prodInfo = new ProductMappingExportInfo()
{
FakeMappingFrom = mappingFrom,
FakeMappingProductId = selectMinItem.Item1.Split('/')[0],
FakeMappingProductPrice = selectMinItem.Item2,
//ProductDataJson = AllBase.JsonHelper.SerializeObject(pinduoduoProductCollect.pb),
ProductId = p.ProductId,
ProductTitle = p.ProductTitle,
RealProductId = p.RealProductId,
MainCid = p.MainCid,
Image = p.Image,
CatId = p.CatId,
From = p.From,
FakeMappingProductMinPrice = (selectMinItem.Item2 / 100M).ToString("f2"),
FakeMappingProductMaxPrice = (selectMinItem.Item3 / 100M).ToString("f2"),
PostFee = "0",
MappingQuery = mapping_query,
dataSoure = p.dataSoure
};
if (string.IsNullOrEmpty(prodInfo.ProductTitle))
{
prodInfo.ProductTitle = tempTitle;
}
if (prodInfo.FakeMappingFrom == "苏宁")
{
prodInfo.FakeMappingVendorId = result.First().Item1.Split('/')[1];
}
p.MappingResult = prodInfo.MappingResult = "转换成功";
if (!isDelOldData)
lstProductInfo.Add(prodInfo);
//lstProductInfoTemp.Add(prodInfo);
// 显示转换成功
ShowMappingResult(p, prodInfo);
}
}
else
{
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = "转换失败,没有找到合适的转换数据";
else if (prod.MappingResult.Length > 2000)
prod.MappingResult = prod.MappingResult.Substring(2000);
ShowMappingResult(prod);
}
#endregion
}
public void GetFakeQueueIdCacheFrom(List<Tuple<string, int, int, string>> content, ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref string error_area,
List<Tuple<string, int, int, string>> mappingResultCache = null, string mappingFrom = "")
{
if (!isRun)
return;
if (!this.lstProductParam.Contains(prod))
this.lstProductParam.Add(prod);
string mapping_query = "";
List<Tuple<string, int, int, string>> mappingResultNonWd = null;
List<Tuple<string, int, int, string>> mappingResultWd = null;
List<Tuple<string, int, int, string>> mappingResultWdTitle = null;
var result = MappingTaoBaoBLL.FilterItems(mappingResultNonWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count == 0)
result = MappingTaoBaoBLL.FilterItems(mappingResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
#region Id缓存,按商品Id获取缓存
// 按一定比例查询确认商品id和图片缓存老数据对应商品是否已被删除,如果删除,则更新数据库(按较低的比例随机,以防调用过高导致微店响应出问题)
bool isCheckOnSale = false;//(Randomx.GetId(8) == 8);
if (result.Count == 0)
{
Thread.Sleep(500);
var title = TrimAndRemoveSpecialText(product?.name);
mappingResultWd = content;// GetFakeCacheWd(prod, ref mappingFrom);
result = MappingTaoBaoBLL.FilterItems(mappingResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// 按一定比例查询确认商品id和图片缓存老数据对应商品是否已被删除,如果删除,则更新数据库(按较低的比例随机,以防调用过高导致微店响应出问题)
if (isCheckOnSale)
{
bool isUpdateDelete = false;
bool isResultCount = result != null && result.Count > 0;
bool isMappingResultWd = mappingResultWd != null && mappingResultWd.Count > 0;
while (result.Count > 0)
{
Thread.Sleep(1000 + Randomx.GetId(2000));
var item = result.First(f => f.Item3 == result.Min(s => s.Item3));
var itemResult = Work.GetPostTaobaoHtml.GetUrl("https://weidian.com/item.html?itemID=" + item.Item1, "", true, "", "_");
// 商品被删除了的界面包含以下情况
if (itemResult.Contains("登录") && !itemResult.Contains("限时折扣价格区域") && !itemResult.Contains("收藏"))
{
isUpdateDelete = true;
result.Remove(item);
mappingResultWd.Remove(item);
}
else
{
break;
}
}
// 如果有合适的上家商品不用上传新商品了,直接更新缓存服务器
if (isUpdateDelete && isResultCount && isMappingResultWd)
{
SaveFakeCache(mappingResultWd, prod, mappingFrom, false, 0);
}
}
if (result.Count > 0)
{
bool hit = false;
var selectMinItem = MatchMeetTitleLength(title, result, mappingResultWd, out hit);
var resultData = new List<Tuple<string, int, int, string>>();
if (selectMinItem != null)
{
foreach (var r in mappingResultWd)
{
if (r.Item1 == selectMinItem.Item1 && hit)
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, DateTime.Now.ToString("yyyy-MM-dd")));
else
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, r.Item4));
}
if (hit)
{
SaveFakeCache(resultData, prod, mappingFrom, false, 0);
}
prod.MappingResourceType = "上货缓存";
MappingVDianApiBLL.UpDateMappingResultToStatistics("0");
mapping_query = "0";
}
else
SaveFakeCache(mappingResultWd, prod, mappingFrom, false, 0);
}
}
#endregion
#region 转换结果显示
if (result.Count > 0)
{
// 裂变数据
var prodParams = lstProductParam.Where(l => l.RealProductId == prod.RealProductId && l.From == prod.From);
var selectMinItem = result.First(f => f.Item3 == result.Min(s => s.Item3));
var tempTitle = "";
foreach (var p in prodParams)
{
if (!string.IsNullOrEmpty(p.ProductTitle))
{
tempTitle = "";
}
prodInfo = new ProductMappingExportInfo()
{
FakeMappingFrom = mappingFrom,
FakeMappingProductId = selectMinItem.Item1.Split('/')[0],
FakeMappingProductPrice = selectMinItem.Item2,
//ProductDataJson = AllBase.JsonHelper.SerializeObject(pinduoduoProductCollect.pb),
ProductId = p.ProductId,
ProductTitle = p.ProductTitle,
RealProductId = p.RealProductId,
MainCid = p.MainCid,
Image = p.Image,
CatId = p.CatId,
From = p.From,
FakeMappingProductMinPrice = (selectMinItem.Item2 / 100M).ToString("f2"),
FakeMappingProductMaxPrice = (selectMinItem.Item3 / 100M).ToString("f2"),
PostFee = "0",
MappingQuery = mapping_query,
dataSoure = p.dataSoure
};
if (string.IsNullOrEmpty(prodInfo.ProductTitle))
{
prodInfo.ProductTitle = tempTitle;
}
if (prodInfo.FakeMappingFrom == "苏宁")
{
prodInfo.FakeMappingVendorId = result.First().Item1.Split('/')[1];
}
p.MappingResult = prodInfo.MappingResult = "转换成功";
if (!isDelOldData)
lstProductInfo.Add(prodInfo);
//lstProductInfoTemp.Add(prodInfo);
// 显示转换成功
ShowMappingResult(p, prodInfo);
}
}
else
{
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = "转换失败,没有找到合适的转换数据";
else if (prod.MappingResult.Length > 2000)
prod.MappingResult = prod.MappingResult.Substring(2000);
ShowMappingResult(prod);
}
#endregion
}
/// <summary>
/// 根据图片和标题搜索或微店上传符合拼多多价格条件的虚拟上家
/// </summary>
/// <param name="prod">虚拟上家商品</param>
/// <param name="product">原商品</param>
/// <param name="minAfterPrice">加价后最低价格</param>
/// <param name="maxAfterPrice">加价后最高价格</param>
/// <param name="mappingResultCache">预加载缓存,暂未使用</param>
/// <param name="mappingFrom">转换来源</param>
/// <param name="isSyncProduct">是否是商品同步</param>
public void GetFakeCacheFrom(ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref string error_area,
List<Tuple<string, int, int, string>> mappingResultCache = null, string mappingFrom = "", bool isSyncProduct = false)
{
if (!isRun)
return;
if (!this.lstProductParam.Contains(prod))
this.lstProductParam.Add(prod);
string mapping_query = "";
List<Tuple<string, int, int, string>> mappingResultNonWd = null;
List<Tuple<string, int, int, string>> mappingResultWd = null;
List<Tuple<string, int, int, string>> mappingResultWdTitle = null;
var result = MappingTaoBaoBLL.FilterItems(mappingResultNonWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count == 0)
result = MappingTaoBaoBLL.FilterItems(mappingResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
#region 读取微店虚拟上家缓存
#region Id缓存,按商品Id获取缓存
// 按一定比例查询确认商品id和图片缓存老数据对应商品是否已被删除,如果删除,则更新数据库(按较低的比例随机,以防调用过高导致微店响应出问题)
bool isCheckOnSale = false;//(Randomx.GetId(8) == 8);
if (result.Count == 0 && (1 == 2 || isSyncProduct))
{
Thread.Sleep(500);
var title = TrimAndRemoveSpecialText(product?.name);
if (string.IsNullOrEmpty(title))
title = TrimAndRemoveSpecialText(prod?.ProductTitle);
mappingResultWd = GetFakeCacheWd(prod, ref mappingFrom);
result = MappingTaoBaoBLL.FilterItems(mappingResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// 按一定比例查询确认商品id和图片缓存老数据对应商品是否已被删除,如果删除,则更新数据库(按较低的比例随机,以防调用过高导致微店响应出问题)
if (isCheckOnSale)
{
bool isUpdateDelete = false;
bool isResultCount = result != null && result.Count > 0;
bool isMappingResultWd = mappingResultWd != null && mappingResultWd.Count > 0;
while (result.Count > 0)
{
Thread.Sleep(1000 + Randomx.GetId(2000));
var item = result.First(f => f.Item3 == result.Min(s => s.Item3));
var itemResult = Work.GetPostTaobaoHtml.GetUrl("https://weidian.com/item.html?itemID=" + item.Item1, "", true, "", "_");
// 商品被删除了的界面包含以下情况
if (itemResult.Contains("登录") && !itemResult.Contains("限时折扣价格区域") && !itemResult.Contains("收藏"))
{
isUpdateDelete = true;
result.Remove(item);
mappingResultWd.Remove(item);
}
else
{
break;
}
}
// 如果有合适的上家商品不用上传新商品了,直接更新缓存服务器
if (isUpdateDelete && isResultCount && isMappingResultWd)
{
SaveFakeCache(mappingResultWd, prod, mappingFrom, false, 0);
}
}
if (result.Count > 0)
{
bool hit = false;
var selectMinItem = MatchMeetTitleLength(title, result, mappingResultWd, out hit);
var resultData = new List<Tuple<string, int, int, string>>();
if (selectMinItem != null)
{
foreach (var r in mappingResultWd)
{
if (r.Item1 == selectMinItem.Item1 && hit)
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, DateTime.Now.ToString("yyyy-MM-dd")));
else
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, r.Item4));
}
if (hit)
{
SaveFakeCache(resultData, prod, mappingFrom, false, 0);
}
prod.MappingResourceType = "上货缓存";
MappingVDianApiBLL.UpDateMappingResultToStatistics("0");
mapping_query = "0";
}
else
SaveFakeCache(mappingResultWd, prod, mappingFrom, false, 0);
}
}
#endregion
#region 图片缓存,按商品图片MD5获取缓存
//if (result.Count == 0)
//{
//var sameResultWd = GetFakeCacheSamePic(prod, product, ref mappingFrom);
//result = MappingTaoBaoBLL.FilterItems(sameResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
//if (result.Count > 0)
//{
// prod.MappingResourceType = "上货缓存";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("0");
//}
//}
#endregion
#region 标题缓存,按商品标题MD5获取缓存
if (result.Count == 0 && (1 == 2 || isSyncProduct))
{
var title = TrimAndRemoveSpecialText(product?.name);
if (string.IsNullOrEmpty(title))
title = TrimAndRemoveSpecialText(prod?.ProductTitle);
mappingResultWdTitle = MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom);
result = MappingTaoBaoBLL.FilterItems(mappingResultWdTitle, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (mappingResultWdTitle != null && result.Count == 0 && Randomx.GetId(1) == 0)
{
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in mappingResultWdTitle)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
}
// 按一定比例查询确认商品id和图片缓存老数据对应商品是否已被删除,如果删除,则更新数据库(按较低的比例随机,以防调用过高导致微店响应出问题)
if (isCheckOnSale)
{
bool isUpdateDelete = false;
bool isResultCount = result != null && result.Count > 0;
bool isMappingResultWdTitle = mappingResultWdTitle != null && mappingResultWdTitle.Count > 0;
while (result.Count > 0)
{
Thread.Sleep(1000 + Randomx.GetId(2000));
var item = result.First(f => f.Item3 == result.Min(s => s.Item3));
var itemResult = Work.GetPostTaobaoHtml.GetUrl("https://weidian.com/item.html?itemID=" + item.Item1, "", true, "", "_");
// 商品被删除了的界面包含以下情况
if (itemResult.Contains("登录") && !itemResult.Contains("限时折扣价格区域") && !itemResult.Contains("收藏"))
{
isUpdateDelete = true;
result.Remove(item);
//mappingResultWdTitle.Remove(item);
var item2 = mappingResultWdTitle.FirstOrDefault(r => r.Item1 == item.Item1);
if (item2 != null)
mappingResultWdTitle.Remove(item2);
}
else
{
break;
}
}
// 如果有合适的上家商品不用上传新商品了,直接更新缓存服务器
if (isUpdateDelete && isResultCount && isMappingResultWdTitle)
{
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom, true);
//var testResult = MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom); // 读缓存测试
}
}
if (result.Count > 0)
{
bool hit = false;
var selectMinItem = MatchMeetTitleLength(title, result, mappingResultWdTitle, out hit);
var resultData = new List<Tuple<string, int, int, string>>();
if (selectMinItem != null)
{
foreach (var r in mappingResultWdTitle)
{
if (r.Item1 == selectMinItem.Item1 && hit)
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, DateTime.Now.ToString("yyyy-MM-dd")));
else
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, r.Item4));
}
if (hit)
{
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(resultData, title, mappingFrom);
}
mappingFrom = "微店";
prod.MappingResourceType = "标题缓存";
MappingVDianApiBLL.UpDateMappingResultToStatistics("1");
mapping_query = "1";
}
else
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom);
}
}
#endregion
#endregion
#region 微店推荐商品缓存 按比例执行一部分
//bool isUseRecommendTitleSearch = Randomx.GetId(10) > 8;
////isUseRecommendTitleSearch = Randomx.GetId(1) > 0;
//List<Tuple<string, int, int>> mappingRecommendTitle = null;
//if (result.Count == 0 && isUseRecommendTitleSearch)
//{
// var title = TrimAndRemoveSpecialText(product?.name);
// mappingRecommendTitle = MappingVDianCacheBLL.GetFakeCacheVDianFissionTitle(title, ref mappingFrom);
// if (mappingRecommendTitle != null)
// {
// var result2 = new List<Tuple<string, int, int>>();
// foreach (var r in mappingRecommendTitle)
// {
// result2.Add(new Tuple<string, int, int>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt()));
// }
// result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
// }
// if (result.Count > 0)
// {
// mappingFrom = "微店";
// prod.MappingResourceType = "标题分词缓存";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("7");
// }
//}
#endregion
#region 如果点击了停止,退出
if (!isRun)
return;
#endregion
#region 微店分词缓存
bool isUseRecommendTitleSearch = Randomx.GetId(100) < 10;
if (result.Count == 0 && isUseRecommendTitleSearch && TrimAndRemoveSpecialText(product?.name).Length > 14) // && isUseFuzzyTitleSearch && 1 == 2
{
LogSave.Add("分词搜索" + product.from_id);
try
{
var retryId = 0;
var title = TrimAndRemoveSpecialText(product?.name);
if (string.IsNullOrEmpty(title))
title = TrimAndRemoveSpecialText(prod?.ProductTitle);
var fissionTitle = title.Substring(0, 14);
//retryId = 140;
retry:
Thread.Sleep(Randomx.GetId(200, 800));
// 微店分段标题
Stopwatch watch = new Stopwatch();
watch.Start();
//var mappingResultWdFissionTitle = MappingVDianCacheBLL.GetFakeCacheVDianFissionTitle(fissionTitle, ref mappingFrom);
Error("提交中A4...", product);
var mappingResultWdFissionTitle = MappingVDianCacheBLL.GetFakeCacheVDianFissionTitleList(title, ref mappingFrom);
watch.Stop();
Console.WriteLine("微店标题分词mappingResultWdFissionTitle" + watch.ElapsedMilliseconds);
LogSave.Add("商品" + product.from_id + ",微店标题分词搜索结束");
if (mappingResultWdFissionTitle != null)
{
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in mappingResultWdFissionTitle)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
}
if (result.Count == 0 && retryId == 140)
{
fissionTitle = title.Substring(0, 7);
retryId = 70;
goto retry;
}
if (result.Count == 0 && retryId == 70)
{
fissionTitle = title.Substring(7, 7);
retryId = 77;
goto retry;
}
//if (result.Count == 0 && retryId == 77)
//{
// fissionTitle = title.Substring(0, 5);
// retryId = 50;
// goto retry;
//}
//if (result.Count == 0 && retryId == 50)
//{
// fissionTitle = title.Substring(4, 5);
// retryId = 54;
// goto retry;
//}
//if (result.Count == 0 && retryId == 54)
//{
// fissionTitle = title.Substring(8, 5);
// retryId = 58;
// goto retry;
//}
//if (result.Count == 0 && retryId == 58)
//{
// fissionTitle = title.Substring(0, 3);
// retryId = 30;
// goto retry;
//}
////if (result.Count == 0 && retryId == 30)
////{
//// fissionTitle = title.Substring(3, 3);
//// retryId = 33;
//// goto retry;
////}
////if (result.Count == 0 && retryId == 33)
////{
//// fissionTitle = title.Substring(6, 3);
//// retryId = 36;
//// goto retry;
////}
////if (result.Count == 0 && retryId == 36)
////{
//// fissionTitle = title.Substring(9, 3);
//// retryId = 39;
//// goto retry;
////}
////if (result.Count == 0 && retryId == 39)
////{
//// fissionTitle = title.Substring(12, 3);
//// retryId = 312;
//// goto retry;
////}
if (result.Count > 0)
{
Console.WriteLine("微店标题分词搜索找到商品");
mappingFrom = "微店";
prod.MappingResourceType = "标题分词缓存";
mapping_query = "7";
MappingVDianApiBLL.UpDateMappingResultToStatistics("7");
}
}
catch (Exception ex)
{
}
}
#endregion
#region 全文检索匹配搜索结果
List<Tuple<string, int, int, string>> mappingLuceneTitle = null;
if (result.Count == 0)
{
var title = TrimAndRemoveSpecialText(product?.name);
if (string.IsNullOrEmpty(title))
title = TrimAndRemoveSpecialText(prod?.ProductTitle);
List<string> fissionArr = new List<string>();
//int port = new Random().Next(0, luceneUrlList.Count);
//string domain = luceneUrlList[port];
long pid = new Random().Next(0, luceneUrlPropCount * 10);
string domain = "";
int proportion = 0;
foreach (var kvp in luceneUrlDic)
{
if (pid <= (proportion + kvp.Value * 10))
{
domain = kvp.Key;
break;
}
proportion += kvp.Value * 10;
}
var fissionResult = GetHtml.GetUrl(domain + "/api/ProductTitle?name=" + HttpUtility.UrlEncode(title, Encoding.UTF8) + "&type=1", 10);// //http://103.90.155.89:60123
var fissionMatch = BaseRegex.GetMatchRegex(ref fissionResult, "\"data\":\\[([\\s\\S]+?)\"\\]");
if (fissionMatch != null && fissionMatch.Count > 0)
{
fissionArr = fissionMatch[0].Groups[1].ToString().Split(new char[] { '"', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
else
{
fissionArr = title.ToCharArray().Select(c => c.ToString()).ToList();
}
LuceneRetry:
if (fissionArr.Count > 6)
fissionArr.RemoveAt(fissionArr.Count - 1);
string sTit = string.Join("", fissionArr);
string luceneResult = "";
for (int i = 0; i < 2 && fissionArr?.Count > 0; i++)
{
proportion = 0;
pid = new Random().Next(0, luceneUrlPropCount * 10);
foreach (var kvp in luceneUrlDic)
{
if (pid <= (proportion + kvp.Value * 10))
{
domain = kvp.Key;
break;
}
proportion += kvp.Value * 10;
}
//port = new Random().Next(0, luceneUrlList.Count);
//domain = luceneUrlList[port];
luceneResult = GetHtml.GetUrl(domain + "/api/ProductTitle?name=" + HttpUtility.UrlEncode(sTit, Encoding.UTF8) + "&pageSize=10", 7);
Thread.Sleep(100);
if (luceneResult != null && luceneResult.Contains("\"Tag\":1")) // Tag 1成功 2失败
break;
fissionArr.RemoveAt(fissionArr.Count - 1);
sTit = string.Join("", fissionArr);
}
var ids = BaseRegex.GetMatchRegex(ref luceneResult, "\"Id\":\"([\\s\\S]+?)\"");
if (ids == null || ids.Count == 0)
{
if (luceneResult != null && luceneResult.Contains("\"Tag\":1"))
{
//if (fissionArr.Count > 6)
//{
// goto LuceneRetry;
//}
}
if (luceneResult == null || !luceneResult.Contains("\"Tag\":1"))
{
prod.MappingResourceType = "全文检索失败";
MappingVDianApiBLL.UpDateMappingResultToStatistics("13");
mapping_query = "13";
}
else
{
prod.MappingResourceType = "全文检索无满足条件";
MappingVDianApiBLL.UpDateMappingResultToStatistics("12");
mapping_query = "12";
}
}
else
{
foreach (System.Text.RegularExpressions.Match m in ids)
{
var id = m.Groups[1].ToString();
mappingLuceneTitle = MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom, id);
if (mappingLuceneTitle != null)
{
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in mappingLuceneTitle)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
if (result.Count > 0)
{
break;
}
}
}
if (result.Count > 0)
{
bool hit = false;
if (mappingResultWdTitle == null)
mappingResultWdTitle = new List<Tuple<string, int, int, string>>();
if (UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)) && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] != null)
mappingResultWdTitle = UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)];
var selectMinItem = MatchMeetTitleLength(title, result, mappingResultWdTitle, out hit);
var resultData = new List<Tuple<string, int, int, string>>();
if (selectMinItem != null)
{
foreach (var r in mappingResultWdTitle)
{
if (r.Item1 == selectMinItem.Item1 && hit)
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, DateTime.Now.ToString("yyyy-MM-dd")));
else
resultData.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, r.Item3, r.Item4));
}
if (hit)
{
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(resultData, title, mappingFrom);
}
mappingFrom = "微店";
prod.MappingResourceType = "全文检索成功";
MappingVDianApiBLL.UpDateMappingResultToStatistics("11");
mapping_query = "11";
}
else
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom);
}
else
{
prod.MappingResourceType = "全文检索无满足条件";
MappingVDianApiBLL.UpDateMappingResultToStatistics("12");
mapping_query = "12";
}
}
}
#endregion
#region 转换结果显示
if (result.Count > 0)
{
// 裂变数据
var prodParams = lstProductParam.Where(l => l.RealProductId == prod.RealProductId && l.From == prod.From);
var selectMinItem = result.First(f => f.Item3 == result.Min(s => s.Item3));
var tempTitle = "";
foreach (var p in prodParams)
{
if (!string.IsNullOrEmpty(p.ProductTitle))
{
tempTitle = "";
}
prodInfo = new ProductMappingExportInfo()
{
FakeMappingFrom = mappingFrom,
FakeMappingProductId = selectMinItem.Item1.Split('/')[0],
FakeMappingProductPrice = selectMinItem.Item2,
//ProductDataJson = AllBase.JsonHelper.SerializeObject(pinduoduoProductCollect.pb),
ProductId = p.ProductId,
ProductTitle = p.ProductTitle,
RealProductId = p.RealProductId,
MainCid = p.MainCid,
Image = p.Image,
CatId = p.CatId,
From = p.From,
FakeMappingProductMinPrice = (selectMinItem.Item2 / 100M).ToString("f2"),
FakeMappingProductMaxPrice = (selectMinItem.Item3 / 100M).ToString("f2"),
PostFee = "0",
MappingQuery = mapping_query,
dataSoure = p.dataSoure
};
if (string.IsNullOrEmpty(prodInfo.ProductTitle))
{
prodInfo.ProductTitle = tempTitle;
}
if (prodInfo.FakeMappingFrom == "苏宁")
{
prodInfo.FakeMappingVendorId = result.First().Item1.Split('/')[1];
}
p.MappingResult = prodInfo.MappingResult = "转换成功";
if (!isDelOldData)
lstProductInfo.Add(prodInfo);
//lstProductInfoTemp.Add(prodInfo);
// 显示转换成功
ShowMappingResult(p, prodInfo);
}
}
else
{
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = "转换失败,没有找到合适的转换数据";
else if (prod.MappingResult.Length > 2000)
prod.MappingResult = prod.MappingResult.Substring(2000);
ShowMappingResult(prod);
}
#endregion
}
/// <summary>
/// 微店搜索
/// </summary>
/// <param name="prod"></param>
/// <param name="product"></param>
/// <param name="minAfterPrice"></param>
/// <param name="maxAfterPrice"></param>
/// <param name="mappingFrom"></param>
/// <returns></returns>
public bool SearchWdProduct(ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref List<Tuple<string, int, int, string>> result, ref string mappingFrom)
{
try
{
List<Tuple<string, int, int, string>> mappingResultWdTitle = null;
var title = TrimAndRemoveSpecialText(product?.name);
Thread.Sleep(Randomx.GetId(500, 2000));
Stopwatch watch = new Stopwatch();
watch.Start();
Error("提交中A1...", product);
var weidianGetTitleResult = WeiDianCollectBLL.SearchWdProductsByKeywords(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
watch.Stop();
LogSave.Add("商品" + product.from_id + "微店标题搜索结束,花费时间" + watch.ElapsedMilliseconds);
result = MappingVDianTitleSearchBLL.GetTupleListData(title, weidianGetTitleResult);
if (result.Count == 0)
{
LogSave.Add("标题搜索" + product.from_id + "失败");
}
if (result.Count > 0)
{
if (!weidianGetTitleResult.Contains("没有找到相关商品")) // 搜索商品保存到缓存
{
if (mappingResultWdTitle == null)
mappingResultWdTitle = new List<Tuple<string, int, int, string>>();
if (UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)) && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] != null)
mappingResultWdTitle = UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)];
var addList = result.Where(r => !mappingResultWdTitle.Any(m => m.Item1 == r.Item1)).ToList();
mappingResultWdTitle.AddRange(addList);
while (mappingResultWdTitle.Count > 200)
mappingResultWdTitle.RemoveAt(0);
mappingFrom = "微店";
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom, true);
result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count > 0)
{
mappingFrom = "微店";
prod.MappingResourceType = "标题搜索";
MappingVDianApiBLL.UpDateMappingResultToStatistics("2");
return true;
}
}
else
{
result.Clear();
}
}
}
catch (Exception ex)
{
}
return false;
}
/// <summary>
/// 京喜
/// </summary>
/// <param name="prod"></param>
/// <param name="product"></param>
/// <param name="minAfterPrice"></param>
/// <param name="maxAfterPrice"></param>
/// <param name="error_area"></param>
/// <param name="mappingResultCache"></param>
/// <param name="mappingFrom"></param>
public bool SearchJdProduct(ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref List<Tuple<string, int, int, string>> result, ref string mappingFrom)
{
try
{
List<Tuple<string, int, int, string>> mappingRecommendTitle = null;
var title = TrimAndRemoveSpecialText(product?.name);
Thread.Sleep(Randomx.GetId(500, 2000));
Error("提交中A4...", product);
var jingxiGetTitleResult = JingXiCollect.SearchJdProductsByKeywords(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
result = MappingVDianTitleSearchBLL.GetTuplejingxiListV2Data(title, jingxiGetTitleResult);
LogSave.Add("商品" + product.from_id + ",京喜商品标题搜索结束");
if (result.Count == 0)
{
LogSave.Add("京喜标题搜索" + product.from_id + "失败");
}
if (result.Count > 0)
{
if (mappingRecommendTitle == null)
mappingRecommendTitle = new List<Tuple<string, int, int, string>>();
if (UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)) && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] != null)
mappingRecommendTitle = UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)];
var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
mappingRecommendTitle.AddRange(addList);
while (mappingRecommendTitle.Count > 200)
mappingRecommendTitle.RemoveAt(0);
mappingFrom = "京喜";
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingRecommendTitle, title, mappingFrom, true);
}
if (result.Count > 0)
{
result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count > 0)
{
mappingFrom = "京喜";
prod.MappingResourceType = "标题搜索";
MappingVDianApiBLL.UpDateMappingResultToStatistics("16");
return true;
}
}
}
catch (Exception ex)
{
}
return false;
}
/// <summary>
/// 淘宝搜索
/// </summary>
/// <param name="prod"></param>
/// <param name="product"></param>
/// <param name="minAfterPrice"></param>
/// <param name="maxAfterPrice"></param>
/// <param name="mappingFrom"></param>
/// <returns></returns>
public bool SearchTaobaoProduct(ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref List<Tuple<string, int, int, string>> result, ref string mappingFrom)
{
try
{
List<Tuple<string, int, int, string>> mappingRecommendTitle = null;
var title = TrimAndRemoveSpecialText(product?.name);
Thread.Sleep(Randomx.GetId(500, 2000));
Error("提交中A2...", product);
var taobaoGetTitleResult = TaobaoMobileCollect.SearchTaobaoProductsByKeywords_v2(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
result = MappingVDianTitleSearchBLL.GetTupleTaoBaoListV2Data(title, taobaoGetTitleResult);
LogSave.Add("商品" + product.from_id + ",淘宝商品标题搜索结束");
if (result.Count == 0)
{
LogSave.Add("淘宝标题搜索" + product.from_id + "失败");
}
if (result.Count > 0)
{
if (mappingRecommendTitle == null)
mappingRecommendTitle = new List<Tuple<string, int, int, string>>();
if (UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)) && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] != null)
mappingRecommendTitle = UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)];
var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
mappingRecommendTitle.AddRange(addList);
while (mappingRecommendTitle.Count > 200)
mappingRecommendTitle.RemoveAt(0);
mappingFrom = "淘宝";
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingRecommendTitle, title, mappingFrom, true);
}
if (result.Count > 0)
{
result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count > 0)
{
mappingFrom = "淘宝";
prod.MappingResourceType = "标题搜索";
MappingVDianApiBLL.UpDateMappingResultToStatistics("14");
return true;
}
}
}
catch (Exception ex)
{
}
return false;
}
/// <summary>
/// 1688
/// </summary>
/// <param name="prod"></param>
/// <param name="product"></param>
/// <param name="minAfterPrice"></param>
/// <param name="maxAfterPrice"></param>
/// <param name="error_area"></param>
/// <param name="mappingResultCache"></param>
/// <param name="mappingFrom"></param>
public bool Search1688Product(ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref List<Tuple<string, int, int, string>> result, ref string mappingFrom)
{
try
{
List<Tuple<string, int, int, string>> mappingRecommendTitle = null;
var title = TrimAndRemoveSpecialText(product?.name);
Thread.Sleep(Randomx.GetId(500, 2000));
Error("提交中A3...", product);
if (product.from == "淘宝" || product.from == "阿里巴巴" || product.from == "1688")
{
var imgSearch = TaobaoMobileCollect.Request_s_1688_com_imageSearch(product.Images[0]);
result = MappingVDianTitleSearchBLL.GetTuple1688ListData(title, imgSearch);
}
else
{
var res = TaobaoMobileCollect.Request_h5api_m_1688_com_putimage(product.Images[0]);
var imageId = BaseRegex.GetDecimalJson(ref res, "imageId");
var imgSearch = TaobaoMobileCollect.Request_s_1688_com_imageSearch(imageId.ToString());
result = MappingVDianTitleSearchBLL.GetTuple1688ListData(title, imgSearch);
}
LogSave.Add("商品" + product.from_id + ",阿里图片搜索结束");
if (result.Count == 0)
{
LogSave.Add("阿里图片搜索" + product.from_id + "失败");
}
if (result.Count > 0)
{
if (mappingRecommendTitle == null)
mappingRecommendTitle = new List<Tuple<string, int, int, string>>();
if (UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)) && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] != null)
mappingRecommendTitle = UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)];
var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
mappingRecommendTitle.AddRange(addList);
while (mappingRecommendTitle.Count > 200)
mappingRecommendTitle.RemoveAt(0);
mappingFrom = "阿里";
MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingRecommendTitle, title, mappingFrom, true);
}
if (result.Count > 0)
{
result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count > 0)
{
mappingFrom = "阿里";
prod.MappingResourceType = "阿里图片搜索";
MappingVDianApiBLL.UpDateMappingResultToStatistics("15");
return true;
}
}
}
catch (Exception ex)
{
}
return false;
}
public string GetMappingQuery(string mappingFrom)
{
string mapping_query = "";
switch (mappingFrom)
{
case "微店":
mapping_query = "2";
break;
case "淘宝":
mapping_query = "14";
break;
case "京喜":
mapping_query = "16";
break;
case "阿里":
mapping_query = "15";
break;
default:
break;
}
return mapping_query;
}
public static int iFuncNum = 4;
private int[] index;
/// <summary>
/// 乱序
/// </summary>
/// <param name="iEnd"></param>
/// <returns></returns>
private int[] DisruptorIndex(int iEnd, int id)
{
if (index == null)
{
index = new int[iEnd];
for (int ii = 0; ii < iEnd; ii++)
{
index[ii] = ii;
}
}
if (id < 30)
{
index[0] = 0;
}
else if (id < 50)
{
index[0] = 1;
index[1] = 0;
}
else if (id < 80)
{
index[0] = 2;
index[2] = 0;
}
else if (id < 100)
{
index[0] = 3;
index[3] = 0;
}
for (int i = 1; i < iEnd; i++)
{
int j = Randomx.GetId(1, iEnd);
if (j == i)
continue;
index[i] = index[i] ^ index[j];
index[j] = index[i] ^ index[j];
index[i] = index[i] ^ index[j];
}
return index;
}
delegate bool SearchGetProduct(ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref List<Tuple<string, int, int, string>> result, ref string mappingFrom);
private static SearchGetProduct[] searchGetProducts = null;
private void GetFakeSearchFrom(string clientId, ProductMappingImportParam prod, ProductCollectBase product, decimal minAfterPrice, decimal maxAfterPrice, ref string error_area,
List<Tuple<string, int, int>> mappingResultCache = null, string mappingFrom = "")
{
if (!isRun)
return;
List<Tuple<string, int, int, string>> mappingResultNonWd = null;
List<Tuple<string, int, int, string>> mappingResultWd = null;
//List<Tuple<string, int, int, string>> mappingResultWdTitle = null;
string mapping_query = "";
var result = MappingTaoBaoBLL.FilterItems(mappingResultNonWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
if (result.Count == 0)
result = MappingTaoBaoBLL.FilterItems(mappingResultWd, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
try
{
#region 搜索微店商品数据及标题分词缓存
lock (_lockerMapping)
{
if (!isRun)
return;
//List<Tuple<string, int, int, string>> mappingRecommendTitle = null;
//bool isUseFuzzyTitleSearch = Randomx.GetId(300) > 0;
//isUseFuzzyTitleSearch = Randomx.GetId(1) > 0;
int id = new Random().Next(0, 100);
if (searchGetProducts == null)
{
searchGetProducts = new SearchGetProduct[iFuncNum];
searchGetProducts[0] = SearchWdProduct;
searchGetProducts[1] = SearchJdProduct;
searchGetProducts[2] = SearchTaobaoProduct;
searchGetProducts[3] = Search1688Product;
}
int[] funcIndex = DisruptorIndex(iFuncNum, id);
if (searchGetProducts[funcIndex[0]](prod, product, minAfterPrice, maxAfterPrice, ref result, ref mappingFrom)
|| searchGetProducts[funcIndex[1]](prod, product, minAfterPrice, maxAfterPrice, ref result, ref mappingFrom)
|| searchGetProducts[funcIndex[2]](prod, product, minAfterPrice, maxAfterPrice, ref result, ref mappingFrom)
|| searchGetProducts[funcIndex[3]](prod, product, minAfterPrice, maxAfterPrice, ref result, ref mappingFrom))
{
LogSave.Add($"商品{ product.from_id}搜索成功");
}
mapping_query = GetMappingQuery(mappingFrom);
#region 注释代码
//#region 搜索微店数据
//if ((result.Count == 0 && id < 30)|| (result.Count == 0&&retrytimes ==1))
//{
// try
// {
// var title = TrimAndRemoveSpecialText(product?.name);
// Thread.Sleep(Randomx.GetId(500, 2000));
// Stopwatch watch = new Stopwatch();
// watch.Start();
// Error("提交中A1...", product);
// var weidianGetTitleResult = WeiDianCollectBLL.SearchWdProductsByKeywords(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
// watch.Stop();
// LogSave.Add("商品" + product.from_id + "微店标题搜索结束,花费时间" + watch.ElapsedMilliseconds);
// result = MappingVDianTitleSearchBLL.GetTupleListData(title, weidianGetTitleResult);
// if (result.Count == 0)
// {
// LogSave.Add("标题搜索" + product.from_id + "失败");
// }
// if (result.Count > 0)
// {
// if (!weidianGetTitleResult.Contains("没有找到相关商品")) // 搜索商品保存到缓存
// {
// if (mappingResultWdTitle == null)
// mappingResultWdTitle = new List<Tuple<string, int, int, string>>();
// var addList = result.Where(r => !mappingResultWdTitle.Any(m => m.Item1 == r.Item1)).ToList();
// mappingResultWdTitle.AddRange(addList);
// while (mappingResultWdTitle.Count > 200)
// mappingResultWdTitle.RemoveAt(0);
// mappingFrom = "微店";
// MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom, true);
// result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// if (result.Count > 0)
// {
// mappingFrom = "微店";
// prod.MappingResourceType = "标题搜索";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("2");
// mapping_query = "2";
// }
// //var testResult = MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom); // 读缓存测试
// }
// else
// {
// result.Clear();
// }
// //else // 推荐商品保存到分词缓存
// //{
// // if (mappingRecommendTitle == null)
// // mappingRecommendTitle = new List<Tuple<string, int, int>>();
// // var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
// // mappingRecommendTitle.AddRange(addList);
// // while (mappingRecommendTitle.Count > 200)
// // mappingRecommendTitle.RemoveAt(0);
// // mappingFrom = "微店";
// // MappingVDianCacheBLL.SaveFakeCacheVDianFissionTitle(mappingRecommendTitle, title, mappingFrom, true);
// // if (Randomx.GetId(10) > 8)
// // result.Clear();
// //}
// //result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// //if (result.Count == 0 && isUseFuzzyTitleSearch)
// //{
// // result = MappingVDianTitleSearchBLL.GetTupleListData(weidianGetTitleResult);
// // var result2 = new List<Tuple<string, int, int>>();
// // foreach (var r in result)
// // {
// // result2.Add(new Tuple<string, int, int>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt()));
// // }
// // result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
// //}
// //else
// //{
// // //result.Clear();
// //}
// //if (result.Count > 0)
// //{
// // mappingFrom = "微店";
// // prod.MappingResourceType = "标题搜索";
// // MappingVDianApiBLL.UpDateMappingResultToStatistics("2");
// //}
// }
// }
// catch (Exception ex)
// {
// }
//}
//#endregion
//#endregion
//#region 搜索淘宝商品数据
////if (result.Count == 0)
////{
//// try
//// {
//// var title = TrimAndRemoveSpecialText(product?.name);
//// Thread.Sleep(Randomx.GetId(500, 2000));
//// Error("提交中A2...", product);
//// var weidianGetTitleResult = TaobaoMobileCollect.SearchTaobaoProductsByKeywords(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
//// result = MappingVDianTitleSearchBLL.GetTupleTaoBaoListData(weidianGetTitleResult);
//// LogSave.Add("商品" + product.from_id + ",淘宝商品标题搜索结束");
//// if (result.Count == 0)
//// {
//// LogSave.Add("淘宝标题搜索" + product.from_id + "失败");
//// }
//// if (result.Count > 0)
//// {
//// if (!weidianGetTitleResult.Contains("FAIL_BIZ_EMPTY_RESULT::FAIL_BIZ_EMPTY_RESULT")) // 搜索商品保存到缓存
//// {
//// if (mappingResultWdTitle == null)
//// mappingResultWdTitle = new List<Tuple<string, int, int>>();
//// var addList = result.Where(r => !mappingResultWdTitle.Any(m => m.Item1 == r.Item1)).ToList();
//// mappingResultWdTitle.AddRange(addList);
//// if (mappingResultWdTitle.Count > 200)
//// mappingRecommendTitle.RemoveAt(0);
//// //if (mappingResultWdTitle.Count > 200)
//// // mappingResultWdTitle = mappingResultWdTitle.OrderByDescending(m => m.Item2).Take(200).ToList();
//// mappingFrom = "淘宝";
//// MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingResultWdTitle, title, mappingFrom, true);
//// //var testResult = MappingVDianCacheBLL.GetFakeCacheVDianTitle(title, ref mappingFrom); // 读缓存测试
//// }
//// result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
//// if (result.Count == 0 && isUseFuzzyTitleSearch)
//// {
//// result = MappingVDianTitleSearchBLL.GetTupleListData(weidianGetTitleResult);
//// var result2 = new List<Tuple<string, int, int>>();
//// foreach (var r in result)
//// {
//// result2.Add(new Tuple<string, int, int>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt()));
//// }
//// result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
//// }
//// if (result.Count > 0)
//// {
//// mappingFrom = "淘宝";
//// prod.MappingResourceType = "标题搜索";
//// MappingVDianApiBLL.UpDateMappingResultToStatistics("14");
//// }
//// }
//// }
//// catch (Exception ex)
//// {
//// }
////}
//#endregion
//#region 搜索京喜商品数据 //没有找到相关商品
//if ((result.Count == 0 && id < 50)|| (result.Count == 0&&retrytimes == 1))
//{
// try
// {
// var title = TrimAndRemoveSpecialText(product?.name);
// Thread.Sleep(Randomx.GetId(500, 2000));
// Error("提交中A4...", product);
// var jingxiGetTitleResult = JingXiCollect.SearchJdProductsByKeywords(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
// result = MappingVDianTitleSearchBLL.GetTuplejingxiListV2Data(title, jingxiGetTitleResult);
// LogSave.Add("商品" + product.from_id + ",京喜商品标题搜索结束");
// if (result.Count == 0)
// {
// LogSave.Add("京喜标题搜索" + product.from_id + "失败");
// }
// if (result.Count > 0)
// {
// if (mappingRecommendTitle == null)
// mappingRecommendTitle = new List<Tuple<string, int, int, string>>();
// var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
// mappingRecommendTitle.AddRange(addList);
// while (mappingRecommendTitle.Count > 200)
// mappingRecommendTitle.RemoveAt(0);
// mappingFrom = "京喜";
// MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingRecommendTitle, title, mappingFrom, true);
// }
// if (result.Count > 0)
// {
// result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// if (result.Count > 0)
// {
// mappingFrom = "京喜";
// prod.MappingResourceType = "标题搜索";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("16");
// mapping_query = "16";
// }
// }
// }
// catch (Exception ex)
// {
// }
//}
//#endregion
//#region 搜索手机淘宝商品数据 //没有找到相关商品
//if ((result.Count == 0 && id < 80)|| (result.Count == 0&&retrytimes == 1))
//{
// try
// {
// var title = TrimAndRemoveSpecialText(product?.name);
// Thread.Sleep(Randomx.GetId(500, 2000));
// Error("提交中A2...", product);
// var taobaoGetTitleResult = TaobaoMobileCollect.SearchTaobaoProductsByKeywords_v2(title, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
// result = MappingVDianTitleSearchBLL.GetTupleTaoBaoListV2Data(title, taobaoGetTitleResult);
// LogSave.Add("商品" + product.from_id + ",淘宝商品标题搜索结束");
// if (result.Count == 0)
// {
// LogSave.Add("淘宝标题搜索" + product.from_id + "失败");
// }
// if (result.Count > 0)
// {
// if (mappingRecommendTitle == null)
// mappingRecommendTitle = new List<Tuple<string, int, int, string>>();
// var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
// mappingRecommendTitle.AddRange(addList);
// while (mappingRecommendTitle.Count > 200)
// mappingRecommendTitle.RemoveAt(0);
// mappingFrom = "淘宝";
// //MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingRecommendTitle, title, mappingFrom, true);
// }
// if (result.Count > 0)
// {
// result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// if (result.Count > 0)
// {
// mappingFrom = "淘宝";
// prod.MappingResourceType = "标题搜索";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("14");
// mapping_query = "14";
// }
// }
// }
// catch (Exception ex)
// {
// }
//}
//#endregion
//#region 搜索以图搜图 1688商品数据
//if ((result.Count == 0 && id < 100)|| (result.Count == 0&&retrytimes == 1))
//{
// try
// {
// var title = TrimAndRemoveSpecialText(product?.name);
// Thread.Sleep(Randomx.GetId(500, 2000));
// Error("提交中A3...", product);
// if (product.from == "淘宝" || product.from == "阿里巴巴" || product.from == "1688")
// {
// var imgSearch = TaobaoMobileCollect.Request_s_1688_com_imageSearch(product.Images[0]);
// result = MappingVDianTitleSearchBLL.GetTuple1688ListData(title, imgSearch);
// }
// else
// {
// var res = TaobaoMobileCollect.Request_h5api_m_1688_com_putimage(product.Images[0]);
// var imageId = BaseRegex.GetDecimalJson(ref res, "imageId");
// var imgSearch = TaobaoMobileCollect.Request_s_1688_com_imageSearch(imageId.ToString());
// result = MappingVDianTitleSearchBLL.GetTuple1688ListData(title, imgSearch);
// }
// LogSave.Add("商品" + product.from_id + ",阿里图片搜索结束");
// if (result.Count == 0)
// {
// LogSave.Add("阿里图片搜索" + product.from_id + "失败");
// }
// if (result.Count > 0)
// {
// if (mappingRecommendTitle == null)
// mappingRecommendTitle = new List<Tuple<string, int, int, string>>();
// var addList = result.Where(r => !mappingRecommendTitle.Any(m => m.Item1 == r.Item1)).ToList();
// mappingRecommendTitle.AddRange(addList);
// while (mappingRecommendTitle.Count > 200)
// mappingRecommendTitle.RemoveAt(0);
// mappingFrom = "阿里";
// MappingVDianCacheBLL.SaveFakeCacheVDianTitle(mappingRecommendTitle, title, mappingFrom, true);
// }
// if (result.Count > 0)
// {
// result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice));
// if (result.Count > 0)
// {
// mappingFrom = "阿里";
// prod.MappingResourceType = "阿里图片搜索";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("15");
// mapping_query = "15";
// }
// }
// }
// catch (Exception ex)
// {
// }
//}
//#endregion
//#endregion
#endregion
#region 微店分词缓存
bool isUseRecommendTitleSearch = Randomx.GetId(100) < 10|| UploadPinduoduoMain.isSpecialAuth;
if (result.Count == 0 && TrimAndRemoveSpecialText(product?.name).Length > 14 && isUseRecommendTitleSearch)//&& isUseFuzzyTitleSearch && 1 == 2
{
LogSave.Add("分词搜索" + product.from_id);
try
{
var retryId = 0;
var title = TrimAndRemoveSpecialText(product?.name);
var fissionTitle = title.Substring(0, 14);
//retryId = 140;
retry:
Thread.Sleep(Randomx.GetId(200, 800));
// 微店分段标题
Stopwatch watch = new Stopwatch();
watch.Start();
//var mappingResultWdFissionTitle = MappingVDianCacheBLL.GetFakeCacheVDianFissionTitle(fissionTitle, ref mappingFrom);
Error("提交中A4...", product);
var mappingResultWdFissionTitle = MappingVDianCacheBLL.GetFakeCacheVDianFissionTitleList(title, ref mappingFrom);
watch.Stop();
Console.WriteLine("微店标题分词mappingResultWdFissionTitle" + watch.ElapsedMilliseconds);
LogSave.Add("商品" + product.from_id + ",微店标题分词搜索结束");
if (mappingResultWdFissionTitle != null)
{
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in mappingResultWdFissionTitle)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
}
if (result.Count == 0 && retryId == 140)
{
fissionTitle = title.Substring(0, 7);
retryId = 70;
goto retry;
}
if (result.Count == 0 && retryId == 70)
{
fissionTitle = title.Substring(7, 7);
retryId = 77;
goto retry;
}
//if (result.Count == 0 && retryId == 77)
//{
// fissionTitle = title.Substring(0, 5);
// retryId = 50;
// goto retry;
//}
//if (result.Count == 0 && retryId == 50)
//{
// fissionTitle = title.Substring(4, 5);
// retryId = 54;
// goto retry;
//}
//if (result.Count == 0 && retryId == 54)
//{
// fissionTitle = title.Substring(8, 5);
// retryId = 58;
// goto retry;
//}
//if (result.Count == 0 && retryId == 58)
//{
// fissionTitle = title.Substring(0, 3);
// retryId = 30;
// goto retry;
//}
////if (result.Count == 0 && retryId == 30)
////{
//// fissionTitle = title.Substring(3, 3);
//// retryId = 33;
//// goto retry;
////}
////if (result.Count == 0 && retryId == 33)
////{
//// fissionTitle = title.Substring(6, 3);
//// retryId = 36;
//// goto retry;
////}
////if (result.Count == 0 && retryId == 36)
////{
//// fissionTitle = title.Substring(9, 3);
//// retryId = 39;
//// goto retry;
////}
////if (result.Count == 0 && retryId == 39)
////{
//// fissionTitle = title.Substring(12, 3);
//// retryId = 312;
//// goto retry;
////}
if (result.Count > 0)
{
Console.WriteLine("微店标题分词搜索找到商品");
mappingFrom = "微店";
prod.MappingResourceType = "标题分词缓存";
mapping_query = "7";
MappingVDianApiBLL.UpDateMappingResultToStatistics("7");
}
}
catch (Exception ex)
{
}
}
#endregion
#region 微店分词搜索
if (result.Count == 0 && TrimAndRemoveSpecialText(product?.name).Length > 14&&1 == 2)//&& (clientId == "b1981defcd704a7d88c8a734358fb065"||clientId== "7feaefdf527d45129219ca398c922bb0")
{
LogSave.Add("分段标题搜索" + product.from_id);
try
{
var retryId = 0;
var title = TrimAndRemoveSpecialText(product?.name);
var fissionTitle = title.Substring(0, 14);
retryId = 140;
retry:
Thread.Sleep(Randomx.GetId(500, 1000));
// 微店分段标题
var mappingResultWdFissionTitle = new List<Tuple<string, int, int, string>>();
Stopwatch watch = new Stopwatch();
watch.Start();
Error("提交中A5...", product);
var fissionTitleResult = WeiDianCollectBLL.SearchWdProductsByKeywords(fissionTitle, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
watch.Stop();
Console.WriteLine("微店分段标题fissionTitleResult" + watch.ElapsedMilliseconds);
LogSave.Add("商品" + product.from_id + ",微店分段标题搜索结束");
result = MappingVDianTitleSearchBLL.GetTupleListData(title, fissionTitleResult);
if (result.Count > 0 && fissionTitle.Length > 3)
{
if (mappingResultWdFissionTitle == null)
mappingResultWdFissionTitle = new List<Tuple<string, int, int, string>>();
mappingResultWdFissionTitle.AddRange(result.Where(r => !mappingResultWdFissionTitle.Any(m => m.Item1 == r.Item1)));
while (mappingResultWdFissionTitle.Count > 200)
mappingResultWdFissionTitle.RemoveAt(0);
MappingVDianCacheBLL.SaveFakeCacheVDianFissionTitle(mappingResultWdFissionTitle, fissionTitle, mappingFrom);
//var testResult = MappingVDianCacheBLL.GetFakeCacheVDianFissionTitle(fissionTitle, ref mappingFrom); // 读缓存测试
}
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in result)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true);
if (result.Count == 0 && retryId == 0)
{
fissionTitle = title.Substring(0, 14);
retryId = 140;
goto retry;
}
if (result.Count == 0 && retryId == 140)
{
fissionTitle = title.Substring(0, 7);
retryId = 70;
goto retry;
}
if (result.Count == 0 && retryId == 70)
{
fissionTitle = title.Substring(7, 7);
retryId = 77;
goto retry;
}
//if (result.Count == 0 && retryId == 77)
//{
// fissionTitle = title.Substring(0, 5);
// retryId = 50;
// goto retry;
//}
//if (result.Count == 0 && retryId == 50)
//{
// fissionTitle = title.Substring(4, 5);
// retryId = 54;
// goto retry;
//}
//if (result.Count == 0 && retryId == 54)
//{
// fissionTitle = title.Substring(8, 5);
// retryId = 58;
// goto retry;
//}
//if (result.Count == 0 && retryId == 58)
//{
// fissionTitle = title.Substring(0, 3);
// retryId = 30;
// goto retry;
//}
//if (result.Count == 0 && retryId == 30)
//{
// fissionTitle = title.Substring(3, 3);
// retryId = 33;
// goto retry;
//}
//if (result.Count == 0 && retryId == 33)
//{
// fissionTitle = title.Substring(6, 3);
// retryId = 36;
// goto retry;
//}
//if (result.Count == 0 && retryId == 36)
//{
// fissionTitle = title.Substring(9, 3);
// retryId = 39;
// goto retry;
//}
//if (result.Count == 0 && retryId == 39)
//{
// fissionTitle = title.Substring(12, 3);
// retryId = 312;
// goto retry;
//}
if (result.Count > 0)
{
Console.WriteLine("微店分段标题搜索找到商品");
mappingFrom = "微店";
prod.MappingResourceType = "标题分词搜索";
mapping_query = "8";
MappingVDianApiBLL.UpDateMappingResultToStatistics("8");
}
}
catch (Exception ex)
{
}
}
#endregion
}
#endregion
#region 随机种子获取是否微店上传,一定概率故意失败(10%)
var isUseVDianRandom = true;
if (result.Count == 0)
{
isUseVDianRandom = Randomx.GetId(10) > 0;
}
#endregion
#region 微店上传、缓存写入、上传失败返回错误文本的格式处理
if (isUseVDianRandom && result.Count == 0)
{
if (prod.MappingResult != null && prod.MappingResult.Contains("error,"))
prod.MappingResult = prod.MappingResult.Replace("error,", "");
}
#endregion
#region 按类目搜索上传
if (result.Count == 0 && Randomx.GetId(8) > -1 && 1 == 2)
{
var catId = prod.CatId.ParseToLong();
var cName = PinDuoDuoCidName.CidName(catId);
if (cName != "其他")
{
if (cName == "其他电动工具")
cName = "工具";
Error("提交中A5...", product);
var catResult = WeiDianCollectBLL.SearchWdProductsByKeywords(cName, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
LogSave.Add("商品" + product.from_id + ",类目搜索结束");
if (catResult.Contains("非常抱歉,没有找到相关结果"))
{
catId = prod.CatId2.ParseToLong();
cName = PinDuoDuoCidName.CidName(catId);
if (cName != "其他")
catResult = WeiDianCollectBLL.SearchWdProductsByKeywords(cName, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
}
if (catResult.Contains("非常抱歉,没有找到相关结果"))
{
catId = prod.CatId1.ParseToLong();
cName = PinDuoDuoCidName.CidName(catId);
if (cName != "其他")
catResult = WeiDianCollectBLL.SearchWdProductsByKeywords(cName, (minAfterPrice / 100M).ParseToDouble(), (maxAfterPrice / 100M).ParseToDouble() * 3.5);
}
result = MappingVDianTitleSearchBLL.GetTupleListData(cName, catResult);
var result2 = new List<Tuple<string, int, int, string>>();
foreach (var r in result)
{
result2.Add(new Tuple<string, int, int, string>(r.Item1, r.Item2, (r.Item2 * maxAfterPrice / minAfterPrice).ParseToInt(), ""));
}
result = MappingTaoBaoBLL.FilterItems(result2, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true, 25);
if (result.Count > 0)
{
mappingFrom = "微店";
prod.MappingResourceType = "类目搜索";
MappingVDianApiBLL.UpDateMappingResultToStatistics("9");
}
}
//if (result.Count == 0)
//{
// LogSave.AddCrash("添加随机数据" + prod.ProductId);
// result.Add(new Tuple<string, int, int>(Randomx.GetId(100000000, 999999999).ToString() + Randomx.GetId(0, 10).ToString(),
// (minAfterPrice * (1 + Randomx.GetId(0, 10) / 10M)).ParseToInt(),
// (maxAfterPrice * (1 + Randomx.GetId(0, 10) / 10M)).ParseToInt()));
// result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true, 25);
// if (result.Count == 0)
// {
// LogSave.AddCrash("添加随机数据" + product.from_id + "失败");
// }
// if (result.Count > 0)
// {
// mappingFrom = "微店";
// prod.MappingResourceType = "随机数据";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("10");
// LogSave.AddCrash("添加随机数据" + product.from_id + "成功");
// }
//}
}
#endregion
}
catch (Exception ex)
{
LogSave.Add("转换异常" + prod.ProductId);
//result.Add(new Tuple<string, int, int>(Randomx.GetId(100000000, 999999999).ToString() + Randomx.GetId(0, 10).ToString(),
// (minAfterPrice * (1 + Randomx.GetId(0, 10) / 10M)).ParseToInt(),
// (maxAfterPrice * (1 + Randomx.GetId(0, 10) / 10M)).ParseToInt()));
//result = MappingTaoBaoBLL.FilterItems(result, Convert.ToInt32(minAfterPrice), Convert.ToInt32(maxAfterPrice), true, 25);
//if (result.Count == 0)
//{
// LogSave.Add("catch添加随机数据" + product.from_id + "失败");
//}
//if (result.Count > 0)
//{
// mappingFrom = "微店";
// prod.MappingResourceType = "随机数据";
// MappingVDianApiBLL.UpDateMappingResultToStatistics("10");
// LogSave.Add("catch添加随机数据" + product.from_id + "成功");
//}
}
if (!isRun)
return;
Error("提交A结束...", product);
#region 转换结果显示
if (result.Count > 0)
{
// 裂变数据
var prodParams = lstProductParam.Where(l => l.RealProductId == prod.RealProductId && l.From == prod.From);
var selectMinItem = result.FirstOrDefault();// result.First(f => f.Item3 == result.Min(s => s.Item3));
var tempTitle = "";
foreach (var p in prodParams)
{
if (!string.IsNullOrEmpty(p.ProductTitle))
{
tempTitle = "";
}
prodInfo = new ProductMappingExportInfo()
{
FakeMappingFrom = mappingFrom,
FakeMappingProductId = selectMinItem.Item1.Split('/')[0],
FakeMappingProductPrice = selectMinItem.Item2,
//ProductDataJson = AllBase.JsonHelper.SerializeObject(pinduoduoProductCollect.pb),
ProductId = p.ProductId,
ProductTitle = p.ProductTitle,
RealProductId = p.RealProductId,
MainCid = p.MainCid,
Image = p.Image,
CatId = p.CatId,
From = p.From,
FakeMappingProductMinPrice = (selectMinItem.Item2 / 100M).ToString("f2"),
FakeMappingProductMaxPrice = (selectMinItem.Item3 / 100M).ToString("f2"),
PostFee = "0",
MappingQuery = mapping_query,
dataSoure = p.dataSoure
};
if (string.IsNullOrEmpty(prodInfo.ProductTitle))
{
prodInfo.ProductTitle = tempTitle;
}
if (prodInfo.FakeMappingFrom == "苏宁")
{
prodInfo.FakeMappingVendorId = result.First().Item1.Split('/')[1];
}
p.MappingResult = prodInfo.MappingResult = "转换成功";
if (!isDelOldData)
lstProductInfo.Add(prodInfo);
//lstProductInfoTemp.Add(prodInfo);
// 显示转换成功
ShowMappingResult(p, prodInfo);
LogSave.Add("转换" + product.from_id + "成功");
}
}
else
{
prodInfo = null;
LogSave.Add("转换失败" + prod.ProductId);
if (string.IsNullOrEmpty(prod.MappingResult))
prod.MappingResult = "转换失败,没有找到合适的转换数据";
else if (prod.MappingResult.Length > 2000)
prod.MappingResult = prod.MappingResult.Substring(2000);
ShowMappingResult(prod);
LogSave.Add("转换" + product.from_id + "失败");
}
#endregion
}
private Tuple<string, int, int, string> MatchMeetTitleLength(string title, List<Tuple<string, int, int, string>> result, List<Tuple<string, int, int, string>> mappingResultWdTitle, out bool hit)
{
int retryCount = 0;
//暂过滤标题缓存中的淘宝商品
//result = result.FindAll(r => !r.Item1.StartsWith("tb"));
Retry:
hit = false;
var selectMinItem = result.Find(f => f.Item3 == result.Min(s => s.Item3));
//var title = TrimAndRemoveSpecialText(product?.name);
if (selectMinItem != null)
{
System.TimeSpan t = new TimeSpan(0);
if (!string.IsNullOrEmpty(selectMinItem.Item4))
{
// 修复item4时间被错误赋值的数据
if (selectMinItem.Item4 == selectMinItem.Item3.ToString())
{
result.Remove(selectMinItem);
selectMinItem = new Tuple<string, int, int, string>(selectMinItem.Item1, selectMinItem.Item2, selectMinItem.Item3, "2022-02-15");
result.Add(selectMinItem);
}
t = DateTime.Now - selectMinItem.Item4.ParseToDateTime();
}
//if (selectMinItem.Item1.StartsWith("tb-")) //兼容wd-xxxxxx格式的微店商品
//{
// //retryCount++;
// result.Remove(selectMinItem);
// goto Retry;
//}
if (t.Days > 30 || string.IsNullOrEmpty(selectMinItem.Item4))
{
hit = true;
string item1 = selectMinItem.Item1;
int item2 = selectMinItem.Item2;
int item3 = selectMinItem.Item3;
if (item1.StartsWith("wd-")) //兼容wd-xxxxxx格式的微店商品
{
item1 = item1.RemovePrefix("wd-");
}
//查找商品是否存在
string searchTitle = WeiDianCollectBLL.GetProductTitleByHtml(item1);
if (string.IsNullOrEmpty(searchTitle))
{
retryCount++;
result.Remove(selectMinItem);
mappingResultWdTitle.Remove(selectMinItem);
goto Retry;
}
//标题是否 满足要求 查询到的标题长度小于 上货标题+5
bool compare = CompareTitle(title, searchTitle);
if (!compare)
{
//retryCount++;
mappingResultWdTitle.Remove(selectMinItem);
result.Remove(selectMinItem);
goto Retry;
}
}
}
return selectMinItem;
}
private List<Tuple<string, int, int, string>> GetFakeCacheWd(ProductMappingImportParam prod, ref string mappingFrom)
{
return GetFakeCache(prod, ref mappingFrom, true);
}
private void GetFakeCacheIdsWd(List<ProductMappingImportParam> prods, ref string mappingFrom)
{
GetFakeCacheIds(prods, ref mappingFrom, true);
}
private List<Tuple<string, int, int, string>> GetFakeCacheNonWd(ProductMappingImportParam prod, ProductCollectBase product, ref string mappingFrom)
{
return GetFakeCache(prod, ref mappingFrom, false);
}
/// <summary>
/// 读取同款虚假上家列表缓存
/// </summary>
/// <param name="prod"></param>
/// <param name="mappingFrom"></param>
/// <param name="from"></param>
/// <returns></returns>
private List<Tuple<string, int, int, string>> GetFakeCache(ProductMappingImportParam prod, ref string mappingFrom, bool isVDian = false)
{
var result = new List<Tuple<string, int, int, string>>();
var tagStr = "";
if (isVDian)
{
tagStr = "vd";
}
var fromStr = "";
var html = "";
if (prod == null)
return result;
if (prod.From == "淘宝")
fromStr = "tb-";
else if (prod.From == "阿里巴巴")
fromStr = "al-";
else if (prod.From == "搜款网" || prod.From == "拼多多")
fromStr = "pd-";
else if (prod.From == "京喜")
fromStr = "jx-";
mappingFrom = "";
string url = BaseClass.BuildObjString("data_change&act=get");
string data = "";
// 根据商品id查找缓存
if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
{
if (string.IsNullOrEmpty(prod.RealProductId))
prod.RealProductId = prod.ProductId;
long insertGoodId = Convert.ToInt64(prod.RealProductId) % 1024;
data = "&product_id=" + fromStr + tagStr + prod.RealProductId
+ "&img_id="
+ "&suffix=" + insertGoodId
+ "&site_id=&" + UserLogin.GetSignaturex();
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
html = GetHtml.PostUtf8(url, data);
}
//// 根据图片查找缓存
//if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
//{
// if (!string.IsNullOrEmpty(prod.Image))
// {
// var imgId = Md5Base.GetMd5(prod.Image + tagStr).Substring(8, 16);
// var skuMod = Math.Abs(BaseClass.GetLong(imgId));
// var insertImgId = skuMod % 1024;
// data = "&product_id="
// + "&img_id=" + imgId
// + "&suffix=" + insertImgId
// + "&site_id=&" + UserLogin.GetSignaturex();
// html = GetHtml.PostUtf8(url, data);
// if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
// html = GetHtml.PostUtf8(url, data);
// }
//}
// 读取缓存成功
if (!string.IsNullOrEmpty(html) && !html.ToLower().Contains("error"))
{
string siteId = BaseRegex.GetMatchRegexString(html, "\"site_id\":\"([\\s\\S]+?)\"");
if (siteId == "1")
mappingFrom = "淘宝";
else if (siteId == "4")
mappingFrom = "京东";
else if (siteId == "5")
mappingFrom = "苏宁";
else if (siteId == "6")
mappingFrom = "微店";
string content = BaseRegex.GetMatchRegexString(html, "\"content\":\"([\\s\\S]+?)(])\"");
if (content != null)
{
content = content.Replace("\\", "") + "]";
}
else
{
content = BaseRegex.GetMatchRegexString(html, "\"content\":\"([\\s\\S]+?)\"");
}
try
{
if (string.IsNullOrEmpty(prod.Image))
prod.Image = BaseRegex.GetMatchRegexString(html, "\"img_url\":\"([\\s\\S]+?)\"").Replace("\\/", "/");
}
catch (Exception ex)
{
}
try
{
var tupleItems = content.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var tupleItem in tupleItems)
{
var items = tupleItem.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (items.Length >= 2 && items[0].Length > 5)
{
try
{
var item1 = items[0];
var item2 = items[1];
var item3 = items.Length >= 3 ? items[2] : items[1];
var item4 = items.Length >= 4 ? items[3] : "";
result.Add(new Tuple<string, int, int, string>(item1, Convert.ToInt32(item2), Convert.ToInt32(item3), item4));
}
catch (Exception ex)
{
}
}
else if (items.Length == 1 && items[0].StartsWith("tit_"))
{
if (string.IsNullOrEmpty(prod.ProductTitle))
{
prod.ProductTitle = items[0].Replace("tit_", "");
prod.ProductTitle = GetHtml.Unicode2String(prod.ProductTitle).Replace("\\/", "/");
}
}
}
}
catch (Exception ex)
{
}
return result;
}
return null;
}
private void GetFakeCacheIds(List<ProductMappingImportParam> prods, ref string mappingFrom, bool isVDian = false)
{
var tagStr = "";
if (isVDian)
{
tagStr = "vd";
}
var fromStr = "";
var html = "";
string temp = "";
string url = BaseClass.BuildObjString("data_change&act=get_product_id_list");
for (int i = 0; i < prods.Count; i++)
{
fromStr = "";
var prod = prods[i];
if (prod.From == "淘宝")
fromStr = "tb-";
else if (prod.From == "阿里巴巴")
fromStr = "al-";
else if (prod.From == "搜款网" || prod.From == "拼多多" || prod.From == "其他")
fromStr = "pd-";
else if (prod.From == "京喜")
fromStr = "jx-";
mappingFrom = "";
// 根据商品id查找缓存
if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
{
if (string.IsNullOrEmpty(prod.RealProductId))
prod.RealProductId = prod.ProductId;
long insertGoodId = Convert.ToInt64(prod.RealProductId) % 1024;
if (temp != "")
temp += ";";
temp += insertGoodId + "," + fromStr + tagStr + prod.RealProductId;
}
}
string data = "&product_ids=" + temp + "&" + UserLogin.GetSignaturex();
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
html = GetHtml.PostUtf8(url, data);
// 读取缓存成功
if (!string.IsNullOrEmpty(html) && !html.ToLower().Contains("error"))
{
var m = BaseRegex.GetMatchRegex(ref html, @"\{([^\]]+?)\}");
for (int i = 0; i < m.Count; i++)
{
var result = new List<Tuple<string, int, int, string>>();
var proStr = m[i].Groups[0].Value;
string siteId = BaseRegex.GetMatchRegexString(proStr, "\"site_id\":\"([\\s\\S]+?)\"");
if (siteId == "1")
mappingFrom = "淘宝";
else if (siteId == "4")
mappingFrom = "京东";
else if (siteId == "5")
mappingFrom = "苏宁";
else if (siteId == "6")
mappingFrom = "微店";
string pid = BaseRegex.GetStringJson(ref proStr, @"pid");
var prod = prods.Find(s => pid.Contains(s.ProductId));
string content = BaseRegex.GetMatchRegexString(proStr, "\"content\":\"([\\s\\S]+?)\"");
if (content != null)
{
content = content.Replace("\\", "") + "]";
}
else
{
content = BaseRegex.GetMatchRegexString(proStr, "\"content\":\"([\\s\\S]+?)\"");
}
try
{
if (string.IsNullOrEmpty(prod.Image))
prod.Image = BaseRegex.GetMatchRegexString(proStr, "\"img_url\":\"([\\s\\S]+?)\"").Replace("\\/", "/");
}
catch (Exception ex)
{
}
try
{
var tupleItems = content.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var tupleItem in tupleItems)
{
var items = tupleItem.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (items.Length >= 2 && items[0].Length > 5)
{
try
{
var item1 = items[0];
var item2 = items[1];
var item3 = items.Length >= 3 ? items[2] : items[1];
var item4 = items.Length >= 4 ? items[3] : "";
result.Add(new Tuple<string, int, int, string>(item1, Convert.ToInt32(item2), Convert.ToInt32(item3), item4));
}
catch (Exception ex)
{
}
}
else if (items.Length == 1 && items[0].StartsWith("tit_"))
{
if (string.IsNullOrEmpty(prod.ProductTitle))
{
prod.ProductTitle = items[0].Replace("tit_", "");
prod.ProductTitle = GetHtml.Unicode2String(prod.ProductTitle).Replace("\\/", "/");
}
}
}
}
catch (Exception ex)
{
}
UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] = result;
}
}
for (int i = 0; i < prods.Count; i++)
{
var prod = prods[i];
if (!UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)))
UploadPinduoduoMain.goodCacheContent.Add(long.Parse(prod.ProductId), null);
if (UploadPinduoduoMain.goodCacheContent.ContainsKey(long.Parse(prod.ProductId)) && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] != null && UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)].Count == 0)
UploadPinduoduoMain.goodCacheContent[long.Parse(prod.ProductId)] = null;
}
}
public void ShowMappingResult(ProductMappingImportParam prod, ProductMappingExportInfo prodInfo = null)
{
}
private void StopMapping()
{
isRun = false;
m_cancellationTokenSource.Cancel();
}
private void GetCatId(ProductMappingImportParam prod, long outerCatId = 1, string outerCatName = "全部商品")
{
}
/// <summary>
/// 保存商品同款或微店数据缓存
/// </summary>
/// <param name="MappingResult"></param>
/// <param name="prod"></param>
/// <param name="mappingFrom"></param>
/// <param name="isAdd">添加还是更新(微店已有数据请使用更新)</param>
/// <param name="minResultCount"></param>
/// <returns></returns>
private string SaveFakeCache(List<Tuple<string, int, int, string>> MappingResult,
ProductMappingImportParam prod, string mappingFrom, bool isAdd = true, int minResultCount = 10)
{
if (MappingResult.Count >= minResultCount)
{
// 写入缓存
var content = "";
foreach (var item in MappingResult)
{
content += item.Item1 + "," + item.Item2 + "," + item.Item3 + "," + item.Item4 + ";";
}
content = content.Length > 0 ? content.Trim(';') + ";" : "";
string url1 = BaseClass.BuildObjString("data_change&act=add_goods");
string url2 = BaseClass.BuildObjString("data_change&act=add_imgs");
//if (!isAdd)
// url = BaseClass.BuildObjString("data_change&act=update");
string fromStr = "";
if (prod.From == "淘宝")
fromStr = "tb-";
else if (prod.From == "阿里巴巴")
fromStr = "al-";
else if (prod.From == "拼多多" || prod.From == "搜款网")
fromStr = "pd-";
else if (prod.From == "京喜")
fromStr = "jx-";
string tagStr = "";
if (mappingFrom == "微店")
tagStr = "vd";
if (prod.Image.StartsWith("https:"))
prod.Image = prod.Image.Substring(6);
else if (prod.Image.StartsWith("http:"))
prod.Image = prod.Image.Substring(5);
var imgId = Md5Base.GetMd5(prod.Image + tagStr).Substring(8, 16);
string data = "&product_id=" + fromStr + tagStr + prod.RealProductId
+ "&min_price=" + prod.MinPrice
+ "&max_price=" + prod.MaxPrice
+ "&img_url=" + prod.Image
+ "&img_id=" + imgId
+ "&site_id=" + ConvertMappingFromTypeToId(mappingFrom)
+ "&content=" + content //+ ";tit_" + prod.ProductTitle
+ "&" + UserLogin.GetSignaturex();
long insertGoodId = Convert.ToInt64(prod.RealProductId) % 1024;
string html1 = GetHtml.PostUtf8(url1, data + "&suffix=" + insertGoodId);
var skuMod = Math.Abs(BaseClass.GetLong(imgId));
var insertImgId = skuMod % 1024;
string html2 = GetHtml.PostUtf8(url2, data + "&suffix=" + insertImgId);
return html1 + ";" + html2;
}
return "";
}
/// <summary>
/// 读取同款虚假上家列表缓存,寻找商品主图或sku图相同的数据
/// </summary>
/// <param name="prod"></param>
/// <param name="mappingFrom"></param>
/// <param name="from"></param>
/// <returns></returns>
private List<Tuple<string, int, int>> GetFakeCacheSamePic(ProductMappingImportParam prod, ProductCollectBase product, ref string mappingFrom, bool isVDian = false)
{
var result = new List<Tuple<string, int, int>>();
var tagStr = "";
if (isVDian)
{
tagStr = "vd";
}
var html = "";
if (prod == null)
return result;
mappingFrom = "";
string url = BaseClass.BuildObjString("data_change&act=getImgList");
string data = "";
string imgIds = "";
List<string> picList = new List<string>();
List<string> skuPicList = new List<string>();
if (product.Images != null && product.Images.Count > 0)
{
foreach (var img in product.Images)
{
if (!string.IsNullOrEmpty(img) && !picList.Contains(img))
picList.Add(img);
}
}
if (product.SkuMaps != null && product.SkuMaps.Count > 0)
{
foreach (var sku in product.SkuMaps)
{
if (!string.IsNullOrEmpty(sku.prop_image) && !picList.Contains(sku.prop_image) && !skuPicList.Contains(sku.prop_image))
skuPicList.Add(sku.prop_image);
if (skuPicList.Count >= 10)
break;
}
}
picList.AddRange(skuPicList);
foreach (var img in picList)
{
var image = img;
if (image.StartsWith("https:"))
image = image.Substring(6);
if (image.StartsWith("http:"))
image = image.Substring(5);
var imgId = Md5Base.GetMd5(image + tagStr).Substring(8, 16);
var skuMod = Math.Abs(BaseClass.GetLong(imgId));
var insertImgId = skuMod % 1024;
imgIds += insertImgId + "," + imgId + ";";
}
imgIds = imgIds.TrimEnd(';');
data = "&product_id="
+ "&imgIds=" + imgIds
+ "&suffix=" + Randomx.GetId(1024)
+ "&" + UserLogin.GetSignaturex();
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || html.ToLower().Contains("error"))
html = GetHtml.PostUtf8(url, data);
// 读取缓存成功
if (!string.IsNullOrEmpty(html) && !html.ToLower().Contains("error") || html.ToLower().Contains("null"))
{
var arr = html.Split(new string[] { "}", "{", "]", "[" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in arr)
{
string siteId = BaseRegex.GetMatchRegexString(item, "\"site_id\":\"([\\s\\S]+?)\"");
if (siteId == "1")
mappingFrom = "淘宝";
else if (siteId == "4")
mappingFrom = "京东";
else if (siteId == "5")
mappingFrom = "苏宁";
else if (siteId == "6")
mappingFrom = "微店";
string content = BaseRegex.GetMatchRegexString(item, "\"content\":\"([\\s\\S]+?)(])\"");
if (content != null)
{
content = content.Replace("\\", "") + "]";
}
else
{
content = BaseRegex.GetMatchRegexString(item, "\"content\":\"([\\s\\S]+?)\"");
}
try
{
if (string.IsNullOrEmpty(prod.Image))
prod.Image = BaseRegex.GetMatchRegexString(item, "\"img_url\":\"([\\s\\S]+?)\"").Replace("\\/", "/");
}
catch (Exception ex)
{
}
try
{
var tupleItems = content.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var tupleItem in tupleItems)
{
var items = tupleItem.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (items.Length >= 2 && items[0].Length > 5)
{
try
{
var item1 = items[0];
var item2 = items[1];
var item3 = items.Length >= 3 ? items[2] : items[1];
result.Add(new Tuple<string, int, int>(item1, Convert.ToInt32(item2), Convert.ToInt32(item3)));
}
catch (Exception ex)
{
}
}
else if (items.Length == 1 && items[0].StartsWith("tit_"))
{
if (string.IsNullOrEmpty(prod.ProductTitle))
{
prod.ProductTitle = items[0].Replace("tit_", "");
prod.ProductTitle = GetHtml.Unicode2String(prod.ProductTitle).Replace("\\/", "/");
}
}
}
}
catch (Exception ex)
{
}
}
return result;
}
return null;
}
private string TrimAndRemoveSpecialText(string source, string keyWord = "@*.。~")
{
if (string.IsNullOrEmpty(source))
return "";
var title = source.Trim(keyWord.ToCharArray());
while (title.Contains("【") && title.Contains("】"))
{
var t1 = title.IndexOf("【");
var t2 = title.IndexOf("】");
if (t1 < t2)
{
title = title.Substring(0, t1).TrimEnd('【') + title.Substring(t2).TrimStart('】');
}
else
{
title = title.Substring(t2, t1 - t2);
title = title.TrimStart('】').TrimEnd('【');
}
}
return title;
}
/// <summary>
/// 上家对应关系 jd = 4; sn = 5; wd = 6 ; tb = 1;
/// </summary>
/// <param name="fromType"></param>
/// <returns></returns>
private int ConvertMappingFromTypeToId(string fromType)
{
if (fromType == "京东")
return 4;
else if (fromType == "苏宁")
return 5;
else if (fromType == "微店")
return 6;
else if (fromType == "淘宝")
return 1;
return 0;
}
public void Error(string message, ProductCollectBase pb)
{
var obj = UploadPinduoduoMain.ProductTemp.Find(p => p != null && p.guid == pb.out_id);
if (obj != null)
{
obj.Titlte = pb.name;
obj.Message = message;
}
}
}
public class MappingVDianBLL
{
public static bool IsChangeAdsl { get; set; } = false;
}
}