3252 lines
169 KiB
C#
3252 lines
169 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using AllBase;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Text.RegularExpressions;
|
||
|
||
namespace Work.Api
|
||
{
|
||
public class UploadPinduoduoProperties
|
||
{
|
||
public static List<ModelBase> Properties = new List<ModelBase>();
|
||
public static Dictionary<int, CatTemplateBase> CatTemplate = new Dictionary<int, CatTemplateBase>();
|
||
public static Dictionary<string, string> DefaultProperties = new Dictionary<string, string>();
|
||
|
||
public static void Ini()
|
||
{
|
||
//if (DefaultProperties.Count == 0)
|
||
//{
|
||
// GetDefaultProperties();
|
||
//}
|
||
////string file = FileBase.ReadAllText("mobelx.dll");
|
||
////if (string.IsNullOrEmpty(file))
|
||
//// return;
|
||
////CatTemplate = JsonHelper.DeserializeJsonToObject<Dictionary<int, CatTemplateBase>>(file);
|
||
////if (CatTemplate == null)
|
||
//// CatTemplate = new Dictionary<int, CatTemplateBase>();
|
||
////for (int i = 0; i < Properties.Count; i++)
|
||
////{
|
||
//// Properties[i].value_unit = "";
|
||
//// for (int j = 0; j < Properties[i].Values.Count; j++)
|
||
//// {
|
||
//// if (string.IsNullOrEmpty(Properties[i].Values[j].p_unit))
|
||
//// Properties[i].Values[j].p_unit = "";
|
||
//// }
|
||
//// if (Properties[i].pid == 93)
|
||
//// {
|
||
//// for (int j = 0; j < Properties[i].cats.Count; j++)
|
||
//// {
|
||
//// if (Properties.Exists(p => p.pid == 59 && p.cats.Contains(Properties[i].cats[j])))
|
||
//// continue;
|
||
//// var m = new ModelBase();
|
||
//// m.name = "中国国家强制性产品认证证书";
|
||
//// m.name_all = "中国国家强制性产品认证证书";
|
||
//// m.must = true;
|
||
//// m.show_type = 1;
|
||
//// m.template_pid = 33178;
|
||
//// m.template_module_id = 7207;
|
||
//// m.pid = 59;
|
||
//// m.cats = Properties[i].cats;
|
||
//// m.value_unit = "";
|
||
//// Properties.Add(m);
|
||
//// }
|
||
//// }
|
||
////}
|
||
}
|
||
/// <summary>
|
||
/// 获取必填项
|
||
/// </summary>
|
||
/// <param name="catId"></param>
|
||
/// <param name="pc"></param>
|
||
/// <returns></returns>
|
||
public static string GetNew(int catId, int cat1, ref ProductCollectBase pc, ref ShopChatBase shop, out string mustCode, bool flag = false)
|
||
{
|
||
mustCode = "";
|
||
CatTemplateBase ct = null;
|
||
if (!UploadPinduoduoMain.CatDayTemp.ContainsKey(catId))
|
||
{
|
||
try
|
||
{
|
||
UploadPinduoduoMain.GetCateTempHtml(catId);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
string html = "";
|
||
if (UploadPinduoduoMain.CatDayTemp.ContainsKey(catId))
|
||
{
|
||
if (UploadPinduoduoMain.CatDayTemp[catId] > DateTime.Now.AddHours(-24))
|
||
html = UploadPinduoduoMain.CatHtmlTemp[catId];
|
||
else
|
||
{
|
||
if (CatTemplate.ContainsKey(catId))
|
||
CatTemplate.Remove(catId);
|
||
}
|
||
}
|
||
if (!CatTemplate.ContainsKey(catId))
|
||
{
|
||
if (string.IsNullOrEmpty(html))
|
||
{
|
||
html = new PinduoduoApiGetProduct(shop).GetCatTemp(catId);
|
||
if (html.Contains("提交错误"))
|
||
{
|
||
Thread.Sleep(20 * 1000);
|
||
html = new PinduoduoApiGetProduct(shop).GetCatTemp(catId);
|
||
}
|
||
else
|
||
{
|
||
if (UploadPinduoduoMain.CatDayTemp.ContainsKey(catId))
|
||
UploadPinduoduoMain.CatDayTemp[catId] = DateTime.Now;
|
||
else
|
||
UploadPinduoduoMain.CatDayTemp.Add(catId, DateTime.Now);
|
||
|
||
if (UploadPinduoduoMain.CatHtmlTemp.ContainsKey(catId))
|
||
UploadPinduoduoMain.CatHtmlTemp[catId] = html;
|
||
else
|
||
UploadPinduoduoMain.CatHtmlTemp.Add(catId, html);
|
||
|
||
string tempFile = "temp/cattemp/" + catId + "cathtml.tjm";
|
||
string temp = catId + "@" + DateTime.Now.ToString("yyyy-MM-dd") + "@" + html + "\r\n";
|
||
FileBase.WriteAllText(tempFile, temp);
|
||
}
|
||
}
|
||
try
|
||
{
|
||
if (html.Contains("properties"))
|
||
ct = JsonHelper.DeserializeJsonToObject<CatTemplateBase>(html);
|
||
CatTemplate.Add(catId, ct);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
}
|
||
string code = "";
|
||
//if (catId == 14932)
|
||
//{
|
||
// code =
|
||
// ",{\"template_pid\":40870,\"template_module_id\":8747,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40871,\"template_module_id\":8747,\"pid\":9,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40872,\"template_module_id\":8747,\"pid\":55,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40874,\"template_module_id\":8747,\"pid\":316,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"},{\"template_pid\":40875,\"template_module_id\":8747,\"pid\":317,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"},{\"template_pid\":40876,\"template_module_id\":8747,\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"}," +
|
||
// "{\"template_pid\":40877,\"template_module_id\":8747,\"pid\":351,\"vid\":0,\"value\":\"" +
|
||
// Randomx.GetId(2000, 5017) + "/" + Randomx.GetId(10000, 50017) +
|
||
// "\",\"value_unit\":\"\"},{\"template_pid\":40878,\"template_module_id\":8747,\"pid\":352,\"vid\":84120,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40879,\"template_module_id\":8747,\"pid\":175,\"vid\":84126,\"value\":\"\",\"value_unit\":\"\"}";
|
||
// return code;
|
||
//}
|
||
if (catId == 17402) //卷筒纸
|
||
{
|
||
//code =
|
||
// ",{\"template_pid\":45053,\"template_module_id\":9772,\"pid\":275,\"vid\":0,\"value\":\"" +
|
||
// Randomx.GetId(20, 200) +
|
||
// "\",\"value_unit\":\"g\"},{\"template_pid\":45054,\"template_module_id\":9772,\"pid\":162,\"vid\":0,\"value_unit\":\"卷\"},{\"template_pid\":45055,\"template_module_id\":9772,\"pid\":64,\"vid\":0,\"value\":\"100,100\",\"value_unit\":\"mm\"},{\"template_pid\":45056,\"template_module_id\":9772,\"pid\":336,\"vid\":83637,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45057,\"template_module_id\":9772,\"pid\":33,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45058,\"template_module_id\":9772,\"pid\":16,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45059,\"template_module_id\":9772,\"pid\":340,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45060,\"template_module_id\":9772,\"pid\":339,\"value\":\"\",\"value_unit\":\"\"}";
|
||
|
||
code = ",{\"template_pid\":59755,\"template_module_id\":14554,\"pid\":275,\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(20, 200) + "\",\"value_unit\":\"g\"},{\"template_pid\":59756,\"template_module_id\":14554,\"pid\":162,\"vid\":0,\"value_unit\":\"卷\"},{\"template_pid\":59757,\"template_module_id\":14554,\"pid\":64,\"vid\":0,\"value\":\"100,100\",\"value_unit\":\"mm\"},{\"template_pid\":59758,\"template_module_id\":14554,\"pid\":336,\"vid\":83639,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":59759,\"template_module_id\":14554,\"pid\":33,\"vid\":\"\",\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":59760,\"template_module_id\":14554,\"pid\":16,\"vid\":83630,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":59761,\"template_module_id\":14554,\"pid\":340,\"vid\":\"\",\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":59762,\"template_module_id\":14554,\"pid\":339,\"vid\":\"\",\"value\":\"\",\"value_unit\":\"\"}";
|
||
return code;
|
||
}
|
||
if (catId == 17399) //抽纸
|
||
{
|
||
code =
|
||
",{\"template_pid\":45017,\"template_module_id\":9766,\"pid\":336,\"vid\":83637,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45018,\"template_module_id\":9766,\"pid\":191,\"vid\":0,\"value\":\"100\",\"value_unit\":\"抽\"},{\"template_pid\":45020,\"template_module_id\":9766,\"pid\":64,\"vid\":0,\"value\":\"100,100\",\"value_unit\":\"mm\"}";
|
||
return code;
|
||
}
|
||
//if (catId == 8653) //国产腕表
|
||
//{
|
||
// code =
|
||
// ",{\"template_pid\":57869,\"template_module_id\":14217,\"pid\":133,\"vid\":0,\"value\":\"26\",\"value_unit\":\"mm\"}";
|
||
// return code;
|
||
//}
|
||
if (!CatTemplate.ContainsKey(catId) || CatTemplate[catId] == null)
|
||
return code;
|
||
var template = CatTemplate[catId].open_api_response;
|
||
if (template.properties == null || template.properties.Count == 0)
|
||
return code;
|
||
|
||
|
||
var propertiesTemp = new List<PropertiesBase>();
|
||
foreach (PropertiesBase p in template.properties)
|
||
propertiesTemp.Add(p);
|
||
//存放 父-儿 父vid 子vid 通过父节点找子节点
|
||
Dictionary<int?, int?> dicPro = new Dictionary<int?, int?>();
|
||
|
||
List<int?> parentlist = new List<int?>();
|
||
List<int?> prolst = new List<int?>();
|
||
LinkList nodelst = new LinkList();
|
||
for (int i = 0; i < propertiesTemp.Count; i++)
|
||
{
|
||
if (propertiesTemp[i].parent_id > 0)
|
||
{
|
||
if (!prolst.Contains(propertiesTemp[i].id))
|
||
prolst.Add(propertiesTemp[i].id);
|
||
if (!prolst.Contains(propertiesTemp[i].parent_id))
|
||
{
|
||
prolst.Add(propertiesTemp[i].parent_id);
|
||
parentlist.Add(propertiesTemp[i].parent_id);
|
||
}
|
||
dicPro.Add(propertiesTemp[i].id, propertiesTemp[i].parent_id);
|
||
}
|
||
}
|
||
foreach (KeyValuePair<int?, int?> kvp in dicPro)
|
||
{
|
||
Node current = nodelst.GetNodeValue(1);
|
||
int index = 0;
|
||
bool ishas = false;
|
||
while (current != null)
|
||
{
|
||
if (current.id == kvp.Value)
|
||
{
|
||
index++;
|
||
ishas = true;
|
||
break;
|
||
}
|
||
current = current.next;
|
||
}
|
||
if (ishas)
|
||
{
|
||
nodelst.Insert((int)kvp.Key, index);
|
||
}
|
||
else
|
||
{
|
||
nodelst.Append((int)kvp.Key);
|
||
nodelst.Append((int)kvp.Value);
|
||
}
|
||
}
|
||
|
||
|
||
Dictionary<int?, string> dic = new Dictionary<int?, string>();
|
||
for (int i = 0; i < parentlist.Count; i++)
|
||
{
|
||
string str = "";
|
||
foreach (KeyValuePair<int?, int?> kvp in dicPro)
|
||
{
|
||
if (kvp.Value == parentlist[i])
|
||
{
|
||
str += "," + kvp.Key;
|
||
}
|
||
}
|
||
if (str.Split(',').Length > 2)
|
||
dic.Add(parentlist[i], str);
|
||
}
|
||
Node tempNode = nodelst.GetNodeValue(1);
|
||
prolst.Clear();
|
||
while (tempNode != null)
|
||
{
|
||
prolst.Add(tempNode.id);
|
||
tempNode = tempNode.next;
|
||
}
|
||
//prolst.Sort((left, right) =>
|
||
//{
|
||
// if (left > right)
|
||
// return -1;
|
||
// else if (left == right)
|
||
// return 0;
|
||
// else
|
||
// return 1;
|
||
//});
|
||
//prolst.Clear();
|
||
//foreach (var item in dicPro.Keys)
|
||
//{
|
||
// prolst.Add(item);
|
||
//}
|
||
//foreach (var item in dicPro.Values)
|
||
//{
|
||
// if (!prolst.Contains(item))
|
||
// prolst.Add(item);
|
||
//}
|
||
//prolst.Sort((left, right) =>
|
||
//{
|
||
// if (left > right)
|
||
// return -1;
|
||
// else if (left == right)
|
||
// return 0;
|
||
// else
|
||
// return 1;
|
||
//});
|
||
|
||
var properties = new List<PropertiesBase>();
|
||
foreach (PropertiesBase p in template.properties)
|
||
properties.Add(p);
|
||
|
||
var levelproperties = new List<PropertiesBase>();
|
||
for (int i = 0; i < prolst.Count; i++)
|
||
{
|
||
var p = propertiesTemp.Find(pr => pr.id == prolst[i]);
|
||
if (p != null)
|
||
{
|
||
levelproperties.Add(p);
|
||
properties.Remove(p);
|
||
}
|
||
}
|
||
Dictionary<int, List<int>> vidParentIds = new Dictionary<int, List<int>>();
|
||
|
||
for (int i = 0; i < levelproperties.Count; i++)
|
||
{
|
||
string value = "";
|
||
int vid = 0;
|
||
KeyValueBase po = null;
|
||
var p = levelproperties[i];
|
||
if (p.name == null)
|
||
p.name = p.name_alias;
|
||
if (p.name == null)
|
||
continue;
|
||
bool isskp = false;
|
||
foreach (KeyValuePair<int?, string> kvp in dic)
|
||
{
|
||
if (kvp.Value.Contains(p.id.ToString()) && p.required == false)
|
||
{
|
||
isskp = true;
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
break;
|
||
}
|
||
}
|
||
if (isskp)
|
||
continue;
|
||
if (flag && (p.name.Contains("材质") || p.name.Contains("成分含量") || p.name.Contains("面料")))
|
||
continue;
|
||
#region 产地
|
||
if (p.name == "产地")
|
||
{
|
||
var area = p.values.Find(v => v.vid == 24044);
|
||
if (area == null) continue;
|
||
int? parentid = p.parent_id;
|
||
vid = 24044;//中国
|
||
po = pc.Prop.Find(pr => pr.Key == "产地");
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("产地"));
|
||
if (!string.IsNullOrEmpty(pc.country) && shop.MainCatName == "海淘进口")
|
||
{
|
||
string country = pc.country;
|
||
if (p.values.Find(v => v.value == country) != null)
|
||
{
|
||
vid = (int)(p.values.Find(v => v.value == country).vid);
|
||
}
|
||
}
|
||
if (po != null || catId == 18680 || p.required == true)
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
#endregion
|
||
|
||
#region 成分含量
|
||
if (p.name == "成分含量")
|
||
{
|
||
po = pc.Prop.Find(pr => pr.Key == "材质成分");
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("成分"));
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Value.Contains("%"));
|
||
if (po != null && (po.Value.Contains("其他") || po.Value.Contains("其它")))
|
||
po.Value = "95%";
|
||
string percent = "";
|
||
if (po != null)
|
||
percent = BaseRegex.GetMatchRegexString(po.Value, @"([\d.]+)%");
|
||
|
||
int? vidxt = 0;//父节点ID
|
||
foreach (int key in dicPro.Keys)//子节点找父节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (po == null && (pc.from_name.Contains("纯") || pc.from_name.Contains("100%")
|
||
|| pc.name.Contains("纯") || pc.name.Contains("100%")
|
||
|| (!string.IsNullOrEmpty(pc.content_pinduoduo) && pc.content_pinduoduo.Contains("100%"))))
|
||
{
|
||
po = new KeyValueBase("成分含量", "100");
|
||
percent = "100";
|
||
}
|
||
if (po == null || string.IsNullOrEmpty(percent))//未匹配到则自动选择最低
|
||
{
|
||
vid = 14503;//少于30%
|
||
for (int k = 0; p.values != null && k < p.values.Count; k++)
|
||
{
|
||
if (p.values[k].value.Contains("30%"))
|
||
{
|
||
vid = (int)p.values[k].vid;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (vid > 0 && p.values != null)
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
{
|
||
if (item != null && item.parent_vids != null)
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
}
|
||
}
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
int per = (int)(decimal.Parse(percent));
|
||
for (int j = 0; p.values != null && j < p.values.Count; j++)
|
||
{
|
||
var m = BaseRegex.GetMatchRegex(p.values[j].value, @"([\d]+)%");
|
||
int min = 0, max = 0;
|
||
if (m == null || m.Count == 0)
|
||
break;
|
||
if (m.Count == 1)
|
||
{
|
||
min = max = int.Parse(m[0].Groups[1].Value);
|
||
if (p.values[j].value.Contains("小于") || p.values[j].value.Contains("少于") || p.values[j].value.Contains("以下"))
|
||
min = 0;
|
||
if (p.values[j].value.Contains("大于") || p.values[j].value.Contains("多于") || p.values[j].value.Contains("以上"))
|
||
max = 100;
|
||
}
|
||
if (m.Count == 2)
|
||
{
|
||
min = int.Parse(m[0].Groups[1].Value);
|
||
max = int.Parse(m[1].Groups[1].Value);
|
||
}
|
||
if (per >= min && per <= max)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
if (p.values[j].parent_vids.Count <= 1)
|
||
continue;
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
if (!p.values[j].value.Contains("其它"))
|
||
break;
|
||
}
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if (vid == 0)
|
||
vid = 14503;//少于30%
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
#endregion
|
||
if (p.name != null && p.name.Contains("材质"))
|
||
po = pc.Prop.Find(pr => pr.Key == "材质成分" && (pr.Key.Contains(p.name) || pr.Key.Contains(p.name_alias)));
|
||
else
|
||
po = pc.Prop.Find(pr => pr.Key == p.name || pr.Key == p.name_alias);
|
||
if (po != null && po.Key == "材质" && po.Value.Contains("他"))
|
||
po = pc.Prop.Find(pr => pr.Key == "材质成分" && (pr.Key.Contains(p.name) || pr.Key.Contains(p.name_alias)));
|
||
if (po == null&&p.name != null && p.name.Contains("材质"))
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("材质"));
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Key.Contains(p.name) || pr.Key.Contains(p.name_alias));
|
||
if (p.name == "3C认证证书编号")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("证书编号"));
|
||
if (po == null && p.name == "包装规格" && p.name_alias == "药品规格")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("规格"));
|
||
if (po == null && p.name == "包装规格" && p.name_alias == "商品规格")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("规格"));
|
||
if (po == null && p.name == "药品类别")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("类别"));
|
||
if (p.name == "容量")
|
||
po = pc.Prop.Find(pr => pr.Key == "3C规格型号");
|
||
#region 面料材质
|
||
if (p.name.Contains("面料俗称") || p.name.Contains("面料材质") || p.name.Contains("材质") || p.name == "材质" || p.name == "面料")
|
||
{
|
||
if (po == null||Regex.IsMatch(po.Value,"^[0-9%]+$"))
|
||
{
|
||
po = pc.Prop.Find(pr => pr.Key == p.name || pr.Key == p.name_alias || pr.Key.Contains("材质") || pr.Key.Contains("面料"));//|| pr.Key.Contains("材质") || pr.Key.Contains("面料")
|
||
}
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
if (po != null && po.Key.Contains("/"))
|
||
{
|
||
string v1 = po.Value.Split('/')[0];
|
||
|
||
string v2 = po.Value.Split('/').Length == 2 ? po.Value.Split('/')[1] : v1;
|
||
|
||
//if (p.values[j].value.Contains(v1) || p.values[j].value.Contains(v2) || v1.Contains(p.values[j].value)
|
||
// || v2.Contains(p.values[j].value))
|
||
if ((p.name.Contains("面料") && (p.values[j].value.Contains(v1) || v1.Contains(p.values[j].value))) || (p.name.Contains("材质") && (p.values[j].value.Contains(v2) || v2.Contains(p.values[j].value))))
|
||
{
|
||
int? vidxt = 0;//父节点ID
|
||
foreach (int key in dicPro.Keys)//子节点找父节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
vid = (int)p.values[j].vid;
|
||
//判断是否允许选择该vid,是否在可选范围内
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
var px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
if (px > 0)
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
if (px == 0)
|
||
{
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
// break;
|
||
//else
|
||
// continue;
|
||
} //如果子节点没有找到
|
||
|
||
if (p.parent_id == 0)
|
||
break;
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
//if (px>0)
|
||
break;
|
||
}
|
||
if (p.values[j].parent_vids == null)
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}//
|
||
else
|
||
{
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Value == p.values[j].value);
|
||
if (po != null)
|
||
{
|
||
if (po.Value.Contains("%"))
|
||
{
|
||
po.Value = BaseRegex.GetMatchRegexString(ref po.Value, @"([\s\S]+?)[\d]");
|
||
}
|
||
if (p.values[j].value.Contains("(") || p.values[j].value.Contains("("))
|
||
{
|
||
p.values[j].value = BaseRegex.GetMatchRegexString(ref p.values[j].value, @"[(|(]([\s\S]+?)[)|)]");
|
||
}
|
||
if (p.values[j].value.Contains(po.Value.Replace(")", ")").Replace("(", "(")) || po.Value.Contains(p.values[j].value.Replace(")", ")").Replace("(", "("))
|
||
|| p.values[j].value.Contains(po.Value.Split('+')[0]))
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
vid = (int)p.values[j].vid;
|
||
//判断是否允许选择该vid,是否在可选范围内
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
var px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
if (px > 0)
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
if (px == 0)
|
||
{
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
// break;
|
||
//else
|
||
// continue;
|
||
} //如果子节点没有找到
|
||
|
||
if (p.parent_id == 0)
|
||
break;
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
break;
|
||
//if (p.parent_id > 0)
|
||
//{
|
||
// if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
// {
|
||
// vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
// //if (px>0)
|
||
// break;
|
||
// }
|
||
// vid = 0;
|
||
// continue;
|
||
//}
|
||
//if (!p.values[j].value.Contains("其它"))
|
||
// break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
if (po != null && po.Value.Contains("(") || po.Value.Contains("("))
|
||
{
|
||
po.Value = po.Value.Replace("(", "(");
|
||
int index = po.Value.IndexOf("(");
|
||
string subStr = po.Value.Substring(0, index);
|
||
if (p.values[j].value.Contains(subStr) || po.Value.Contains(p.values[j].value.Replace(")", ")").Replace("(", "("))
|
||
|| p.values[j].value.Contains(po.Value.Split('+')[0]))
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
vid = (int)p.values[j].vid;
|
||
//判断是否允许选择该vid,是否在可选范围内
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
var px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
if (px > 0)
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
if (px == 0)
|
||
{
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
} //如果子节点没有找到
|
||
|
||
if (p.parent_id == 0)
|
||
break;
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
if (p.values[j].value.Contains("/"))
|
||
{
|
||
string v1 = p.values[j].value.Split('/')[0];
|
||
string v2 = p.values[j].value.Split('/')[1];
|
||
po = pc.Prop.Find(pr => pr.Value.Contains(v1) || pr.Value.Contains(v2));
|
||
if (po != null)
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
vid = (int)p.values[j].vid;
|
||
//判断是否允许选择该vid,是否在可选范围内
|
||
if (vidParentIds.ContainsKey((int)p.id))
|
||
{
|
||
var px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (px > 0)//&& !p.values[j].value.Contains("其它")
|
||
break;
|
||
else
|
||
continue;
|
||
} //如果子节点没有找到
|
||
|
||
if (p.parent_id == 0)
|
||
break;
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
//if (!p.values[j].value.Contains("其它"))
|
||
break;
|
||
}
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if (pc.from_name.Contains(p.values[j].value))
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
var px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (p.parent_id > 0)
|
||
{
|
||
int? vidxt = 0;//父节点ID
|
||
foreach (int key in dicPro.Keys)//子节点找父节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[j].parent_vids);
|
||
if (px > 0)
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
if (px == 0)
|
||
{
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
if (p.parent_id == 0)//!p.values[j].value.Contains("其它") ||
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}//
|
||
}//for循环结束
|
||
if (po == null)
|
||
{
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
po = pc.Prop.Find(pr => (pr.Key == p.name || pr.Key == p.name_alias) && pr.Value.Contains(p.values[j].value));
|
||
if (po != null)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (!p.values[j].value.Contains("其它") && p.parent_id == 0)
|
||
{
|
||
int count = vidParentIds[(int)p.id].Count;
|
||
var pid = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (pid == 0)
|
||
vid = vidParentIds[(int)p.id][count - 1];
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
if (p.values[j].value.Contains("/"))
|
||
{
|
||
string v1 = p.values[j].value.Split('/')[0];
|
||
string v2 = p.values[j].value.Split('/')[1];
|
||
po = pc.Prop.Find(pr => pr.Value.Contains(v1) || pr.Value.Contains(v2));
|
||
if (po != null)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (!p.values[j].value.Contains("其它") && p.parent_id == 0)
|
||
{
|
||
int count = vidParentIds[(int)p.id].Count;
|
||
var pid = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (pid == 0)
|
||
vid = vidParentIds[(int)p.id][count - 1];
|
||
break;
|
||
}
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
if (pc.from_name.Contains(p.values[j].value))
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
var px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (px > 0)
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[j].parent_vids != null)//限制父节点取值
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
|
||
}
|
||
//&& !p.values[j].value.Contains("其它")
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
} //如果子节点没有找到
|
||
if (!p.values[j].value.Contains("其它") && p.parent_id == 0)
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
if (p.required != null && vid == 0)
|
||
{
|
||
if (p.name.Contains("面料") || p.name.Contains("材质"))
|
||
{
|
||
//判断是否允许选择该vid,是否在可选范围内
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
int count = vidParentIds[(int)p.id].Count;
|
||
int px = 0;
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
if (pc.from_name.Contains(p.values[q].value.Replace("纤维", "")))
|
||
{
|
||
px = (int)p.values[q].vid;
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
px = vidParentIds[(int)p.id].Find(s => s == px);
|
||
if (px > 0)//&& !p.values[j].value.Contains("其它")
|
||
break;
|
||
else
|
||
continue;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
if (px == 0)
|
||
{
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
if (p.values[q].value.Contains("其它") || p.values[q].value.Contains("其他"))
|
||
{
|
||
px = (int)p.values[q].vid;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
var pid = vidParentIds[(int)p.id].Find(s => s == px);
|
||
if (pid == 0)
|
||
px = vidParentIds[(int)p.id][count - 1];
|
||
if (px > 0)
|
||
{
|
||
vid = px;
|
||
if (p.parent_id == 0)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
if (item != null && item.parent_vids != null)
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (vid == 0)
|
||
{//如果子节点没有找到
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
if (pc.from_name.Contains(p.values[q].value.Replace("纤维", "")))
|
||
{
|
||
vid = (int)p.values[q].vid;
|
||
if (vidParentIds.ContainsKey((int)p.id) && vidParentIds[(int)p.id] != null && vidParentIds[(int)p.id].Count > 0)
|
||
{
|
||
var pxx = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (pxx > 0)//&& !p.values[j].value.Contains("其它")
|
||
break;
|
||
else
|
||
continue;
|
||
}
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
if (item != null && item.parent_vids != null)
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
|
||
}
|
||
break;
|
||
}
|
||
if (p.values[q].value.Contains("其它") || p.values[q].value.Contains("其他"))
|
||
{
|
||
vid = (int)p.values[q].vid;
|
||
int vidchild = 0;
|
||
foreach (KeyValuePair<int?, int?> kv in dicPro)
|
||
{
|
||
if (kv.Value == p.id)
|
||
{
|
||
vidchild = (int)kv.Key;
|
||
break;
|
||
}
|
||
}
|
||
if (code.Contains(vidchild.ToString()) && p.values[q].value.Contains("其他"))
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + vidchild + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
string vidstr = mc[0].Groups[1].Value;
|
||
string item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
}
|
||
if (code.Contains(vidchild.ToString()) && p.name.Contains("材质") && p.values[q].value.Contains("其它"))
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + vidchild + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
string vidstr = mc[0].Groups[1].Value;
|
||
string item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
}
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt) && p.values[q].parent_vids != null)//限制父节点取值
|
||
{
|
||
vidParentIds.Add((int)vidxt, p.values[q].parent_vids);
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
else
|
||
{
|
||
var pxv = p.values.Find(s => s.vid == vid);
|
||
if (pxv != null && pxv.value == "其他")
|
||
{
|
||
int vidchild = 0;
|
||
foreach (KeyValuePair<int?, int?> kv in dicPro)
|
||
{
|
||
if (kv.Value == p.id)
|
||
{
|
||
vidchild = (int)kv.Key;
|
||
break;
|
||
}
|
||
}
|
||
if (code.Contains(vidchild.ToString()) && catId != 9524)
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + vidchild + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
string vidstr = mc[0].Groups[1].Value;
|
||
string item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
mustCode = mustCode.Replace(item, "");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (vid > 0)
|
||
{
|
||
var pxv = p.values.Find(s => s.vid == vid);
|
||
if (pxv == null)
|
||
{
|
||
pxv = p.values.Find(s => s.value == "其他" || s.value == "其它");
|
||
if (pxv != null)
|
||
vid = (int)pxv.vid;
|
||
else
|
||
vid = 0;
|
||
}
|
||
if (pxv != null && pxv.value == "PU")
|
||
{
|
||
pxv = p.values.Find(s => s.value == "其他" || s.value == "其它");
|
||
if (pxv == null && !(bool)p.required)
|
||
continue;
|
||
vid = (int)pxv.vid;
|
||
}
|
||
if (pxv != null && pxv.value == "其他")
|
||
{
|
||
int vidchild = 0;
|
||
foreach (KeyValuePair<int?, int?> kv in dicPro)
|
||
{
|
||
if (kv.Value == p.id)
|
||
{
|
||
vidchild = (int)kv.Key;
|
||
break;
|
||
}
|
||
}
|
||
if (code.Contains(vidchild.ToString()) && catId != 9524)
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + vidchild + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
string vidstr = mc[0].Groups[1].Value;
|
||
string item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
mustCode = mustCode.Replace(item, "");
|
||
}
|
||
}
|
||
}
|
||
|
||
if (vid > 0)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
}
|
||
continue;
|
||
}
|
||
#endregion
|
||
if (p.values == null||p.values.Count==0)//输入型
|
||
{
|
||
if (po == null)
|
||
continue;
|
||
if (!string.IsNullOrEmpty(p.value_unit))
|
||
value = po.Value.Replace(p.value_unit, "");
|
||
else
|
||
value = po.Value;
|
||
if (p.value_type == 1)//数值型
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.X]+)" + p.value_unit);//
|
||
if (string.IsNullOrEmpty(value))
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.]+)");
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.]+)");
|
||
}
|
||
if (p.name.Contains("年龄"))
|
||
p.value_unit = "岁";
|
||
if (p.name.Contains("定价"))
|
||
p.value_unit = "元";
|
||
if (po.Value.Contains("—"))
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.—X]+)" + p.value_unit);//
|
||
value = value.Replace("—", ",");
|
||
}
|
||
if (!string.IsNullOrEmpty(p.value_unit))
|
||
p.value_unit = p.value_unit.Trim();
|
||
if (catId == 10492 || catId == 10487)
|
||
{
|
||
p.value_unit = "cm";
|
||
value = (int.Parse(value) / 10).ToString();
|
||
}
|
||
if (catId == 18629)
|
||
{
|
||
p.value_unit = "g";
|
||
}
|
||
if ((p.name_alias.Contains("包") || p.name.Contains("包")) && string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
p.value_unit = "包";
|
||
}
|
||
if (catId == 17378 || catId == 17377 && string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
p.value_unit = "包";
|
||
}
|
||
if (catId == 4668)
|
||
{
|
||
p.value_unit = "张";
|
||
}
|
||
if (catId == 17360 && p.value_unit.Contains("L"))
|
||
{
|
||
decimal result = 0M;
|
||
decimal.TryParse(value, out result);
|
||
value = ((int)(result * 1000)).ToString();
|
||
p.value_unit = "mL";
|
||
}
|
||
if (p.value_unit.Contains("-") || p.value_unit.Contains("(") || p.value_unit.Contains(")"))
|
||
{
|
||
p.value_unit = p.value_unit.Replace("-", "").Replace("(", "").Replace(")", "");
|
||
}
|
||
if (catId == 7799 && p.value_unit.Contains("mL"))
|
||
p.value_unit = "mL";
|
||
if (string.IsNullOrEmpty(value) && p.required == true)//必填强制指定
|
||
value = "1";
|
||
}
|
||
if (p.value_type == 5)
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(value, @"([\d]{4}-[\d]{1,2}-[\d]{1,2})");
|
||
if (string.IsNullOrEmpty(value))
|
||
value = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
|
||
}
|
||
if (p.value_type != 0)
|
||
value = value.Replace("X", ",");
|
||
if (string.IsNullOrEmpty(value) && p.name == "3C认证证书编号")
|
||
{
|
||
value = +Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999);
|
||
}
|
||
if (p.name.Contains("期") && p.value_unit == null)
|
||
p.value_unit = "天";
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
|
||
var pcode = template.properties.Find(t => t.id == p.parent_id);
|
||
if (pcode != null && pcode.name == "产地" && !code.Contains(pcode.id.ToString()))
|
||
code += ",{\"template_pid\":" + pcode.id + ",\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"}";
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
else if (p.is_sale == true && p.values.Count > 0)//复选多属性
|
||
{
|
||
continue;
|
||
}
|
||
else if (p.values.Count > 0)
|
||
{
|
||
if (po != null)
|
||
{
|
||
var v = p.values.Find(va => va.value == po.Value.Trim());
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value.Contains(po.Value.Trim()) || po.Value.Trim().Contains(va.value));
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value.Replace("其它", "其他") == po.Value.Replace("其它", "其他"));
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value == po.Value.Replace("插电", "电源"));
|
||
if (v == null && p.name == "适用年龄段")
|
||
{
|
||
var mage = BaseRegex.GetMatchRegex(ref po.Value, @"[\d]+");
|
||
if (mage != null && mage.Count == 2)
|
||
{
|
||
string item1 = mage[0].Groups[0].Value;
|
||
string item2 = mage[1].Groups[0].Value;
|
||
v = p.values.Find(va => va.value.Contains(item1) && va.value.Contains(item2));
|
||
}
|
||
}
|
||
|
||
if (v == null && p.required == true) //必填强制随机
|
||
v = p.values[Randomx.GetId(p.values.Count)];
|
||
if (v != null)
|
||
vid = (int)v.vid;
|
||
if (p.name.Contains("特殊"))
|
||
{
|
||
if (code.Contains("国妆")|| code.Contains("QB"))
|
||
{
|
||
vid = (int)p.values.Find(pt => pt.value == "是").vid;
|
||
}
|
||
}
|
||
if (vid > 0)
|
||
value = v.value;
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
{
|
||
var item = p.values.Find(vx => vx.vid == vid);
|
||
if (item != null && item.parent_vids != null)
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
|
||
}
|
||
}
|
||
//判断是否允许选择该vid,是否在可选范围内
|
||
if (vidParentIds.ContainsKey((int)p.id))
|
||
{
|
||
int count = vidParentIds[(int)p.id].Count;
|
||
int px = 0;
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
vid = (int)p.values[q].vid;
|
||
if (vidParentIds.ContainsKey((int)p.id))
|
||
{
|
||
px = vidParentIds[(int)p.id].Find(s => s == vid);
|
||
if (px > 0)//&& !p.values[j].value.Contains("其它")
|
||
break;
|
||
else
|
||
continue;
|
||
}
|
||
}
|
||
var pid = vidParentIds[(int)p.id].Find(s => s == px);
|
||
if (pid == 0)
|
||
px = vidParentIds[(int)p.id][count - 1];
|
||
if (px > 0)
|
||
{
|
||
vid = px;
|
||
if (p.parent_id == 0)
|
||
{
|
||
}
|
||
else
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
if (item != null && item.parent_vids != null)
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (vid == 0 && (bool)p.required)
|
||
{
|
||
vid = (int)p.values[0].vid;
|
||
if (p.name.Contains("特殊"))
|
||
{
|
||
if (code.Contains("国妆") || code.Contains("QB"))
|
||
{
|
||
vid = (int)p.values.Find(pt=>pt.value=="是").vid;
|
||
}
|
||
}
|
||
if (p.name.Contains("营养食品类型"))
|
||
{
|
||
if (code.Contains("国"))
|
||
vid = (int)p.values.Find(s => s.value.Contains("保健")).vid;
|
||
else if (code.Contains("SC") || string.IsNullOrEmpty(code))
|
||
vid = (int)p.values.Find(s => s.value.Contains("普通膳食")).vid;
|
||
else
|
||
vid = (int)p.values.Find(s => s.value.Contains("海外膳食")).vid;
|
||
}
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (p.parent_id > 0)
|
||
{
|
||
if (!vidParentIds.ContainsKey((int)vidxt))//限制父节点取值
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
if (item != null && item.parent_vids != null)
|
||
vidParentIds.Add((int)vidxt, item.parent_vids);
|
||
}
|
||
|
||
}
|
||
}
|
||
if (vid > 0)
|
||
{
|
||
if (p.name == "省份" && String.IsNullOrEmpty(code))
|
||
{
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
}
|
||
if (vid > 0)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (po == null)
|
||
{
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
}
|
||
}
|
||
|
||
}
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Value.Contains(p.name) || pr.Value.Contains(p.name_alias));
|
||
if (po == null || vid == 0)
|
||
continue;
|
||
levelproperties.RemoveAt(i);
|
||
i--;
|
||
}
|
||
//for (int i = 0; i < levelproperties.Count; i++)
|
||
//{
|
||
// properties.Add(levelproperties[i]);
|
||
//}
|
||
for (int i = 0; i < properties.Count; i++)
|
||
{
|
||
string value = "";
|
||
int vid = 0;
|
||
KeyValueBase po = null;
|
||
var p = properties[i];
|
||
if (p.name == null)
|
||
p.name = p.name_alias;
|
||
if (p.name == null)
|
||
continue;
|
||
if (p.required == true)
|
||
{
|
||
}
|
||
if (catId == 3109 && (p.name == "电池容量" || p.name_alias == "电池容量"))
|
||
continue;
|
||
if (p.name == "品牌")
|
||
{
|
||
if (UploadPinduoduoMain.ckBrandName && !string.IsNullOrEmpty(UploadPinduoduoMain.BrandName))
|
||
{
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
string barand = p.values[j].value;
|
||
int id = (int)p.values[j].vid;
|
||
if (barand.Contains("/"))
|
||
barand = barand.Split('/')[1];
|
||
if (barand == UploadPinduoduoMain.BrandName)
|
||
{
|
||
vid = id;
|
||
break;
|
||
}
|
||
}
|
||
if (vid==0)
|
||
{
|
||
string url = "https://mms.pinduoduo.com/draco-ms/mms/template/property/value/search";
|
||
string data = "{\"cat_id\":"+catId+",\"template_pid\":"+p.id+",\"parent_vid\":0,\"value\":\""+ UploadPinduoduoMain.BrandName + "\"}";
|
||
string htmlVid = GetPostTaobaoHtml.UploadTaobaoPost(url, url, true, data, false,shop.Cookies);
|
||
vid = BaseRegex.GetIntJson(ref htmlVid, "vid");
|
||
}
|
||
if (vid == 0)
|
||
continue;
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
}
|
||
if (pc.main_cat_name == "食品保健" && pc.from_shop_name!=null&&pc.from_shop_name.Contains("专卖店") && p.name.Contains("品牌") && p.name_alias == "品牌")
|
||
{
|
||
po = pc.Prop.Find(pr => pr.Key == p.name || pr.Key == p.name_alias);
|
||
if (po == null)
|
||
continue;
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
string barand = p.values[j].value;
|
||
int id = (int)p.values[j].vid;
|
||
if (barand.Contains("/"))
|
||
barand = barand.Split('/')[1];
|
||
if (barand == po.Value)
|
||
{
|
||
vid = id;
|
||
break;
|
||
}
|
||
}
|
||
if (vid == 0)
|
||
continue;
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
if (code.Contains("保健食品") && p.name == "厂名" && p.required == false)
|
||
{
|
||
continue;
|
||
}
|
||
if (code.Contains("保健食品") && p.name == "厂址" && p.required == false)
|
||
{
|
||
continue;
|
||
}
|
||
if (UploadPinduoduoMain.brandNameList.Count == 0 && p.name.Contains("品牌") && p.name_alias == "品牌" && !UploadPinduoduoMain.isPriceModel)
|
||
continue;
|
||
//先处理特殊类型
|
||
#region 产地
|
||
if (p.name == "产地")
|
||
{
|
||
var area = p.values.Find(v => v.vid == 24044);
|
||
if (area == null) continue;
|
||
int? parentid = p.parent_id;
|
||
if (p.parent_id > 0 && !string.IsNullOrEmpty(code))
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + parentid + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
string vidstr = mc[0].Groups[1].Value;
|
||
string item = mc[0].Groups[0].Value;
|
||
int result = area.parent_vids.Find(v => v.ToString() == vidstr);
|
||
if (result == 0)
|
||
{
|
||
code = code.Replace(item, "");
|
||
code += item.Replace("\"vid\":10629", "\"vid\":" + area.parent_vids[0] + "");
|
||
}
|
||
}
|
||
vid = 24044;//中国
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
#endregion
|
||
|
||
#region 成分含量
|
||
if (p.name == "成分含量")
|
||
{
|
||
po = pc.Prop.Find(pr => pr.Key == "材质成分");
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("成分"));
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Value.Contains("%"));
|
||
string percent = "";
|
||
if (po != null)
|
||
percent = BaseRegex.GetMatchRegexString(po.Value, @"([\d.]+)%");
|
||
if (po == null || string.IsNullOrEmpty(percent))//未匹配到则自动选择最低
|
||
{
|
||
var m = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.parent_id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (m == null || m.Count == 0) continue;
|
||
string goodItem = m[0].Groups[0].Value;
|
||
long vidxt = BaseRegex.GetLongJson(ref goodItem, "vid");
|
||
bool ishas = false;
|
||
vid = 14503;//少于30%
|
||
if (vid > 0)
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
var temp = item.parent_vids.Find(s => s == vidxt);//判断成分含量是否包含父节点
|
||
if (temp > 0)
|
||
ishas = true;
|
||
}
|
||
if (!ishas)
|
||
{
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
var temp = p.values[q].parent_vids.Find(s => s == vidxt);//判断成分含量是否包含父节点
|
||
if (temp > 0)
|
||
{
|
||
vid = (int)p.values[q].vid;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
int per = (int)(decimal.Parse(percent));
|
||
for (int j = 0; p.values != null && j < p.values.Count; j++)
|
||
{
|
||
var m = BaseRegex.GetMatchRegex(p.values[j].value, @"([\d]+)%");
|
||
int min = 0, max = 0;
|
||
if (m == null || m.Count == 0)
|
||
break;
|
||
if (m.Count == 1)
|
||
{
|
||
min = max = int.Parse(m[0].Groups[1].Value);
|
||
if (p.values[j].value.Contains("小于") || p.values[j].value.Contains("少于") || p.values[j].value.Contains("以下"))
|
||
min = 0;
|
||
if (p.values[j].value.Contains("大于") || p.values[j].value.Contains("多于") || p.values[j].value.Contains("以上"))
|
||
max = 100;
|
||
}
|
||
if (m.Count == 2)
|
||
{
|
||
min = int.Parse(m[0].Groups[1].Value);
|
||
max = int.Parse(m[1].Groups[1].Value);
|
||
}
|
||
if (per >= min && per <= max)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
//m = BaseRegex.GetMatchRegex(ref code, @"""vid"":([\d]+)");
|
||
m = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.parent_id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (m == null || m.Count == 0) continue;
|
||
bool ishas = false;
|
||
string goodItem = m[0].Groups[0].Value;
|
||
long vidx = BaseRegex.GetLongJson(ref goodItem, "vid");
|
||
if (vid > 0)
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
var temp = item.parent_vids.Find(s => s == vidx);//判断成分含量是否包含父节点
|
||
if (temp > 0)
|
||
ishas = true;
|
||
}
|
||
if (!ishas)
|
||
{
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
var temp = p.values[q].parent_vids.Find(s => s == vidx);//判断成分含量是否包含父节点
|
||
if (temp > 0)
|
||
{
|
||
vid = (int)p.values[q].vid;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
if (vid == 0)
|
||
vid = 14503;//少于30%
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
#endregion
|
||
|
||
po = pc.Prop.Find(pr => pr.Key == p.name || pr.Key == p.name_alias);
|
||
if (po != null && po.Key == "材质" && po.Value.Contains("他"))
|
||
po = pc.Prop.Find(pr => pr.Key == "材质成分" && (pr.Key.Contains(p.name) || pr.Key.Contains(p.name_alias)));
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Key.Contains(p.name) || pr.Key.Contains(p.name_alias));
|
||
if (p.name == "3C认证证书编号")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("证书编号"));
|
||
if (po == null && p.name == "包装规格" && p.name_alias == "药品规格")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("规格"));
|
||
if (po == null && p.name == "包装规格" && p.name_alias == "商品规格")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("规格"));
|
||
if (po == null && p.name == "药品类别")
|
||
po = pc.Prop.Find(pr => pr.Key.Contains("类别"));
|
||
if (p.name == "容量")
|
||
po = pc.Prop.Find(pr => pr.Key == "3C规格型号");
|
||
|
||
if (p.name == "品牌"&&po!=null)
|
||
{
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
string barand = p.values[j].value;
|
||
int id = (int)p.values[j].vid;
|
||
if (barand == po.Value)
|
||
{
|
||
vid = id;
|
||
break;
|
||
}
|
||
}
|
||
if (vid == 0)
|
||
continue;
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
continue;
|
||
}
|
||
|
||
#region MyRegion
|
||
if (p.name.Contains("面料俗称") || p.name.Contains("面料材质") || p.name.Contains("材质") || p.name == "材质" || p.name == "面料")
|
||
{
|
||
if (po == null)
|
||
{
|
||
po = pc.Prop.Find(pr => pr.Key == p.name || pr.Key == p.name_alias || pr.Key.Contains("材质") || pr.Key.Contains("面料"));
|
||
}
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
if (po != null && po.Key.Contains("/"))
|
||
{
|
||
string v1 = po.Value.Split('/')[0];
|
||
//string v2 = po.Value.Split('/')[1];
|
||
string v2 = po.Value.Split('/').Length == 2 ? po.Value.Split('/')[1] : v1;
|
||
if (p.values[j].value.Contains(v1) || p.values[j].value.Contains(v2) || v1.Contains(p.values[j].value)
|
||
|| v2.Contains(p.values[j].value))
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (p.parent_id == 0)
|
||
break;
|
||
var m = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.parent_id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (m == null || m.Count == 0)
|
||
{
|
||
var px = properties.Find(pr => pr.id == p.parent_id);
|
||
if (px == null)
|
||
continue;
|
||
int vidxt = p.values[j].parent_vids[p.values[j].parent_vids.Count - 1];
|
||
if (vidxt > 0)
|
||
{
|
||
code += ",{\"template_pid\":" + px.id + ",\"vid\":" + vidxt + ",\"value\":\"" + value + "\",\"value_unit\":\"" + px.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + px.id + ",\"vid\":" + vidxt + ",\"value\":\"" + value + "\",\"value_unit\":\"" + px.value_unit + "\"}";
|
||
break;
|
||
}
|
||
continue;
|
||
}
|
||
string goodItem = m[0].Groups[0].Value;
|
||
long vidx = BaseRegex.GetLongJson(ref goodItem, "vid");
|
||
var temp = p.values[j].parent_vids.Find(s => s == vidx);
|
||
if (temp > 0)
|
||
{
|
||
if (!p.values[j].value.Contains("其它"))
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
else
|
||
continue;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Value == p.values[j].value);
|
||
//if (po==null)
|
||
// po = pc.Prop.Find(pr => pr.Value.Contains(p.values[j].value));
|
||
if (po != null)
|
||
{
|
||
|
||
if (p.values[j].value.Contains(po.Value.Replace(")", ")").Replace("(", "(")) || po.Value.Contains(p.values[j].value.Replace(")", ")").Replace("(", "(")))
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (p.parent_id == 0)
|
||
break;
|
||
var m = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.parent_id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (m == null || m.Count == 0)
|
||
{
|
||
var px = properties.Find(pr => pr.id == p.parent_id);
|
||
if (px == null)
|
||
continue;
|
||
int vidxt = p.values[j].parent_vids[p.values[j].parent_vids.Count - 1];
|
||
if (vidxt > 0)
|
||
{
|
||
code += ",{\"template_pid\":" + px.id + ",\"vid\":" + vidxt + ",\"value\":\"" + value + "\",\"value_unit\":\"" + px.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + px.id + ",\"vid\":" + vidxt + ",\"value\":\"" + value + "\",\"value_unit\":\"" + px.value_unit + "\"}";
|
||
break;
|
||
}
|
||
continue;
|
||
}
|
||
string goodItem = m[0].Groups[0].Value;
|
||
int vidx = BaseRegex.GetIntJson(ref goodItem, "vid");
|
||
var temp = p.values[j].parent_vids.Find(s => s == vidx);
|
||
if (temp > 0)
|
||
{
|
||
if (!p.values[j].value.Contains("其它"))
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
else
|
||
continue;
|
||
}
|
||
}
|
||
if (p.values[j].value.Contains("/"))
|
||
{
|
||
string v1 = p.values[j].value.Split('/')[0];
|
||
string v2 = p.values[j].value.Split('/')[1];
|
||
po = pc.Prop.Find(pr => pr.Value.Contains(v1) || pr.Value.Contains(v2));
|
||
if (po != null)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
break;
|
||
}
|
||
}
|
||
if (pc.from_name.Contains(p.values[j].value))
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (!p.values[j].value.Contains("其它") || p.parent_id == 0)
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if (po == null)
|
||
{
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
po = pc.Prop.Find(pr => (pr.Key == p.name || pr.Key == p.name_alias) && pr.Value.Contains(p.values[j].value));
|
||
if (po != null)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (!p.values[j].value.Contains("其它") || p.parent_id == 0)
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
if (p.values[j].value.Contains("/"))
|
||
{
|
||
string v1 = p.values[j].value.Split('/')[0];
|
||
string v2 = p.values[j].value.Split('/')[1];
|
||
po = pc.Prop.Find(pr => pr.Value.Contains(v1) || pr.Value.Contains(v2));
|
||
if (po != null)
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
break;
|
||
}
|
||
}
|
||
if (pc.from_name.Contains(p.values[j].value))
|
||
{
|
||
vid = (int)p.values[j].vid;
|
||
if (!p.values[j].value.Contains("其它") || p.parent_id == 0)
|
||
break;
|
||
vid = 0;
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
if (p.required != null && p.required == true && vid == 0)
|
||
{
|
||
if (po == null && p.values.Count > 0 && vid == 0)
|
||
vid = (int)p.values[0].vid;
|
||
if (p.name.Contains("面料材质") || p.name == "材质")
|
||
{
|
||
bool ishas = false;
|
||
var m = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.parent_id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (m == null || m.Count == 0) continue;
|
||
string goodItem = m[0].Groups[0].Value;
|
||
long vidVal = BaseRegex.GetLongJson(ref goodItem, "vid");
|
||
if (vid > 0)
|
||
{
|
||
var item = p.values.Find(v => v.vid == vid);
|
||
var temp = item.parent_vids.Find(s => s == vidVal);//判断成分含量是否包含父节点
|
||
if (temp > 0)
|
||
ishas = true;
|
||
}
|
||
if (!ishas)
|
||
{
|
||
for (int q = 0; q < p.values.Count; q++)
|
||
{
|
||
var temp = p.values[q].parent_vids.Find(s => s == vidVal);//判断成分含量是否包含父节点
|
||
if (temp > 0)
|
||
{
|
||
vid = (int)p.values[q].vid;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (p.required != null && p.required == false && vid == 0)
|
||
{
|
||
if (p.values.Count > 0)
|
||
{
|
||
for (int k = 0; k < p.values.Count; k++)
|
||
{
|
||
if (pc.from_name.Contains(p.values[k].value))
|
||
{
|
||
vid = (int)p.values[k].vid;
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
continue;
|
||
}
|
||
if (p.name.Contains("面料") && vid == 0)
|
||
{
|
||
if (po == null && p.values.Count > 0)
|
||
vid = (int)p.values[0].vid;
|
||
if (po != null && p.values.Count > 0)
|
||
{
|
||
for (int k = 0; k < p.values.Count; k++)
|
||
{
|
||
if (p.values[k].value == "其他" || p.values[k].value == "其它")
|
||
{
|
||
vid = (int)p.values[k].vid;
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
if (vid > 0)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
}
|
||
continue;
|
||
}
|
||
#endregion
|
||
if (po == null)
|
||
po = pc.Prop.Find(pr => pr.Value.Contains(p.name) || pr.Value.Contains(p.name_alias));
|
||
if (po == null)
|
||
continue;
|
||
properties.RemoveAt(i);
|
||
i--;
|
||
|
||
if (p.values == null || p.values.Count == 0)//输入型
|
||
{
|
||
if (!string.IsNullOrEmpty(p.value_unit) && !p.value_unit.Contains("—"))
|
||
value = po.Value.Replace(p.value_unit, "");
|
||
else
|
||
value = po.Value;
|
||
|
||
if (p.value_type == 1)//数值型
|
||
{
|
||
if (value.Contains("X"))
|
||
{
|
||
string[] bi = value.Split('X');
|
||
if (p.name == "长" && bi.Length > 0)
|
||
{
|
||
value = bi[0];
|
||
}
|
||
if (p.name == "宽" && bi.Length > 1)
|
||
{
|
||
value = bi[1];
|
||
}
|
||
if (p.name == "高" && bi.Length > 2)
|
||
{
|
||
value = bi[2];
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(p.value_unit))
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.Xx]+)");
|
||
if (value.Contains("(")||value.Contains("-"))
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.Xx-—]+)" + p.value_unit);//
|
||
if (value!=null&& !Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$"))
|
||
value = BaseRegex.GetMatchRegexString(value, @"([\d.]+)"+p.value_unit);//
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.Xx]+)[(]");
|
||
if (string.IsNullOrEmpty(p.value_unit))
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.Xx]+)");
|
||
if (p.name.Contains("年龄"))
|
||
p.value_unit = "岁";
|
||
if (p.name.Contains("定价"))
|
||
p.value_unit = "元";
|
||
if (p.name.Contains("年龄段"))
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.Xx-—]+)" + p.value_unit);//
|
||
value = value.Replace("—", ",");
|
||
}
|
||
if (string.IsNullOrEmpty(value))
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.Xx]+)");
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.]+)$");
|
||
}
|
||
if (!string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
p.value_unit = p.value_unit.Trim();
|
||
}
|
||
if (p.name == "酒精度数" && p.value_unit != "%vol.")
|
||
{
|
||
p.value_unit = "%vol.";
|
||
}
|
||
if (p.name == "保质期" && string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
p.value_unit = "天";
|
||
}
|
||
if (p.name == "保质期" && p.value_unit!="天")
|
||
{
|
||
if (string.IsNullOrEmpty(value))
|
||
value = "60";
|
||
if (p.value_unit.Contains("月"))
|
||
{
|
||
value = (int.Parse(value) * 30).ToString();
|
||
}
|
||
if (p.value_unit.Contains("年"))
|
||
{
|
||
value = "365";
|
||
}
|
||
p.value_unit = "天";
|
||
}
|
||
if (p.value_unit!=null&&p.value_unit.Contains("—"))
|
||
{
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.Xx—]+)");
|
||
}
|
||
|
||
if (po.Value.Contains("—"))
|
||
{
|
||
if (string.IsNullOrEmpty(value))
|
||
value = BaseRegex.GetMatchRegexString(po.Value, @"([\d.—X]+)" + p.value_unit);//
|
||
value = value.Replace("—", ",");
|
||
}
|
||
if (!string.IsNullOrEmpty(p.value_unit) && p.value_unit.Length > 10)
|
||
p.value_unit = BaseRegex.GetMatchRegexString(po.Value, @"([^\d.]+)");
|
||
if (catId == 10492 || catId == 10487)
|
||
{
|
||
p.value_unit = "cm";
|
||
value = (int.Parse(value) / 10).ToString();
|
||
}
|
||
if (catId == 18629 || (catId == 6606 && p.name.Contains("净含量")))
|
||
{
|
||
p.value_unit = "g";
|
||
}
|
||
if ((p.name_alias.Contains("包") || p.name.Contains("包")) && string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
p.value_unit = "包";
|
||
}
|
||
if (catId == 17378 || catId == 17377 && string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
p.value_unit = "包";
|
||
}
|
||
if (catId == 4668)
|
||
{
|
||
p.value_unit = "张";
|
||
}
|
||
if (catId == 6690 && p.name == "规格")
|
||
{
|
||
p.value_unit = "袋";
|
||
}
|
||
if (catId == 12007 && p.name == "照明时间")
|
||
{
|
||
p.value_unit = "h";
|
||
}
|
||
if (catId == 17360 && p.value_unit.Contains("L"))
|
||
{
|
||
decimal result = 0M;
|
||
decimal.TryParse(value, out result);
|
||
value = ((int)(result * 1000)).ToString();
|
||
p.value_unit = "mL";
|
||
}
|
||
if (!string.IsNullOrEmpty(p.value_unit))
|
||
{
|
||
if (p.value_unit.Contains("-") || p.value_unit.Contains("(") || p.value_unit.Contains(")"))
|
||
p.value_unit = p.value_unit.Replace("-", "").Replace("(", "").Replace(")", "");
|
||
}
|
||
if (p.name.Contains("年份"))
|
||
{
|
||
p.value_unit = "年";
|
||
}
|
||
if (p.name.Contains("产品重量")&& catId!= 7799&& !(p.value_unit != null&&(p.value_unit.Contains("mL")|| p.value_unit.Contains("L"))))
|
||
{
|
||
p.value_unit = "g";
|
||
}
|
||
if (catId == 7799 && p.value_unit.Contains("mL"))
|
||
p.value_unit = "mL";
|
||
if (p.name == "节数")
|
||
{
|
||
p.value_unit = "节";
|
||
if (int.Parse(value) > 10000)
|
||
value = "10000";
|
||
}
|
||
if (catId == 17068)
|
||
value =po.Value.Replace(p.value_unit, "").Replace("x", ",");
|
||
|
||
if (string.IsNullOrEmpty(value) && p.required == true)//必填强制指定
|
||
value = "1";
|
||
}
|
||
if (p.value_type == 5)
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(value, @"([\d]{4}-[\d]{1,2}-[\d]{1,2})");
|
||
if (string.IsNullOrEmpty(value))
|
||
value = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
|
||
}
|
||
if (!string.IsNullOrEmpty(value) && p.value_type != 0)
|
||
value = value.Replace("X", ",");
|
||
if (!string.IsNullOrEmpty(value) && p.value_type != 0)
|
||
value = value.Replace("x", ",");
|
||
if (string.IsNullOrEmpty(value) && p.name == "3C认证证书编号")
|
||
{
|
||
value = +Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999);
|
||
}
|
||
if (p.name.Contains("期") && p.value_unit == null)
|
||
p.value_unit = "天";
|
||
if (p.name.Contains("期") && p.value_unit != null)
|
||
p.value_unit = p.value_unit.Replace("个", "");
|
||
if (!string.IsNullOrEmpty(value) && p.name == "生产日期" && pc.main_cat_name == "食品保健" && pc.main_cid == 7)
|
||
value = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||
|
||
if (string.IsNullOrEmpty(value))
|
||
continue;
|
||
value = value.Replace(" ", "");
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
continue;
|
||
}
|
||
else if (p.is_sale == true && p.values.Count > 0)//复选多属性
|
||
{
|
||
continue;
|
||
string[] l = po.Value.Replace(" ", ",").Replace("、", ",").Split(',');
|
||
for (int j = 0; j < l.Length && j < 3; j++)
|
||
{
|
||
if (string.IsNullOrEmpty(l[j]))
|
||
continue;
|
||
var v = p.values.Find(va => va.value == l[j]);
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value.Contains(l[j]) || l[j].Contains(va.value));
|
||
if (v == null)
|
||
continue;
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + v.vid + ",\"parent_spec_id\":\"" + p.spec_id + "\",\"spec_id\":\"" + v.spec_id + "\",\"group_id\":\"" + v.group.id + "\",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
}
|
||
continue;
|
||
}
|
||
else if (p.values.Count > 0) //选择型
|
||
{
|
||
if (p.name == "型号")
|
||
{
|
||
string[] poValue = po.Value.Split('、');
|
||
for (int q = 0; q < poValue.Length; q++)
|
||
{
|
||
var vr = p.values.Find(va => va.value == poValue[q]);
|
||
if (vr == null)
|
||
vr = p.values.Find(va => va.value.Replace("其它", "其他") == po.Value.Replace("其它", "其他"));
|
||
if (vr == null && (bool)p.required == false)
|
||
continue;
|
||
if (vr == null)
|
||
vr = p.values.Find(va => va.value.Contains(po.Value) || po.Value.Contains(va.value));
|
||
if (vr == null)
|
||
{
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
if (!p.values[j].value.Contains("/") || !p.values[j].value.Contains("("))
|
||
continue;
|
||
if (!p.values[j].value.Contains("/"))
|
||
{
|
||
string[] px = p.values[j].value.Split('/');
|
||
if (!string.IsNullOrEmpty(px[0]) && po.Value.Contains(px[0]))
|
||
{
|
||
vr = p.values[j];
|
||
break;
|
||
}
|
||
}
|
||
if (!p.values[j].value.Contains("("))
|
||
{
|
||
string[] px = p.values[j].value.Split('(');
|
||
if (!string.IsNullOrEmpty(px[0]) && po.Value.Contains(px[0]))
|
||
{
|
||
vr = p.values[j];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (vr == null && p.required == true) //必填强制随机
|
||
vr = p.values[Randomx.GetId(p.values.Count)];
|
||
if (vr == null || vr.vid == null)
|
||
continue;
|
||
vid = (int)vr.vid;
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
continue;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string[] poValues = po.Value.Split('、');
|
||
for (int k = 0; k < poValues.Length; k++)
|
||
{
|
||
po.Value = poValues[k];
|
||
var v = p.values.Find(va => va.value == po.Value.Trim());
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value.Contains(po.Value.Trim()) || po.Value.Trim().Contains(va.value));
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value.Replace("其它", "其他") == po.Value.Replace("其它", "其他"));
|
||
if (v == null && (bool)p.required == false)
|
||
continue;
|
||
if (v == null)
|
||
v = p.values.Find(va => va.value.Contains(po.Value) || po.Value.Contains(va.value));
|
||
if (v == null)
|
||
{
|
||
for (int j = 0; j < p.values.Count; j++)
|
||
{
|
||
if (!p.values[j].value.Contains("/") || !p.values[j].value.Contains("("))
|
||
continue;
|
||
if (!p.values[j].value.Contains("/"))
|
||
{
|
||
string[] px = p.values[j].value.Split('/');
|
||
if (!string.IsNullOrEmpty(px[0]) && po.Value.Contains(px[0]))
|
||
{
|
||
v = p.values[j];
|
||
break;
|
||
}
|
||
}
|
||
if (!p.values[j].value.Contains("("))
|
||
{
|
||
string[] px = p.values[j].value.Split('(');
|
||
if (!string.IsNullOrEmpty(px[0]) && po.Value.Contains(px[0]))
|
||
{
|
||
v = p.values[j];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (v == null && p.required == true) //必填强制随机
|
||
v = p.values[Randomx.GetId(p.values.Count)];
|
||
if (v == null || v.vid == null)
|
||
continue;
|
||
vid = (int)v.vid;
|
||
if (p.name.Contains("特殊"))
|
||
{
|
||
if (code.Contains("国妆") || code.Contains("QB"))
|
||
{
|
||
vid = (int)p.values.Find(pt => pt.value == "是").vid;
|
||
}
|
||
}
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
if (p.required == true)
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
for (int i = 0; i < levelproperties.Count; i++)
|
||
{
|
||
if (flag && (levelproperties[i].name.Contains("材质") || levelproperties[i].name.Contains("成分含量") || levelproperties[i].name.Contains("面料")))
|
||
continue;
|
||
if (levelproperties[i].name.Contains("面料"))
|
||
{
|
||
var p = template.properties.Find(t => t.parent_id == levelproperties[i].id);
|
||
if (p != null)
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
string vidstr = mc[0].Groups[1].Value;
|
||
string item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
p = template.properties.Find(t => t.parent_id == p.id);
|
||
if (p != null)
|
||
{
|
||
mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + p.id + @",""vid"":([\d]+),[\w\W]+?}");
|
||
if (mc == null || mc.Count == 0) continue;
|
||
vidstr = mc[0].Groups[1].Value;
|
||
item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
}
|
||
}
|
||
}
|
||
if (vidParentIds.ContainsKey((int)levelproperties[i].id))//限制父节点取值
|
||
{
|
||
var lst = vidParentIds[(int)levelproperties[i].id];
|
||
var pxv = levelproperties[i].values.Find(s => s.value == "其他" || s.value == "其它");
|
||
if (pxv == null && !(bool)levelproperties[i].required)
|
||
{
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (KeyValuePair<int?, int?> kvp in dicPro)
|
||
{
|
||
if (kvp.Value == levelproperties[i].id)
|
||
{
|
||
vidxt = kvp.Key;
|
||
break;
|
||
}
|
||
}
|
||
if (code.Contains(vidxt.ToString()))
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + vidxt + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
}
|
||
vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == levelproperties[i].id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (code.Contains(vidxt.ToString()))
|
||
{
|
||
var mc = BaseRegex.GetMatchRegex(ref code, @",{""template_pid"":" + vidxt + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
code = code.Replace(item, "");
|
||
}
|
||
continue;
|
||
}
|
||
if (lst != null)
|
||
{
|
||
var v = lst[Randomx.GetId(lst.Count)];
|
||
if (code.Contains(levelproperties[i].id.ToString()))
|
||
continue;
|
||
pxv = levelproperties[i].values.Find(s => s.vid == v);
|
||
if (pxv == null)
|
||
continue;
|
||
code += ",{\"template_pid\":" + levelproperties[i].id + ",\"vid\":" + v + ",\"value\":\"\",\"value_unit\":\"" + levelproperties[i].value_unit + "\"}";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if ((bool)levelproperties[i].required)
|
||
{
|
||
properties.Add(levelproperties[i]);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
for (int i = 0; i < properties.Count; i++)//无数据且必填项目,强制随机取值
|
||
{
|
||
if (properties[i].required != true)
|
||
continue;
|
||
int vid = 0;
|
||
string value = "";
|
||
var p = properties[i];
|
||
if (catId == 3109 && (p.name == "电池容量" || p.name_alias == "电池容量"))
|
||
continue;
|
||
if ((catId == 15348 || catId == 15351) && p.name.Contains("3C"))
|
||
continue;
|
||
if (p.name.Contains("食品生产许可证编号") && code.Contains("SC"))
|
||
continue;
|
||
if (p.name.Contains("食品生产许可证编号") && code.Contains("保健食品"))
|
||
continue;
|
||
if (p.name.Contains("食品生产许可证编号") && code.Contains("海外膳食营养补充食品"))
|
||
continue;
|
||
if (p.values == null || p.values.Count == 0)//输入型
|
||
{
|
||
value = GetRandomChinese(8);//上传上家的商品,属性基本上不会出现在这里,这里用生成随机字符串的方式
|
||
if (catId == 8405)
|
||
continue;
|
||
if (p.name.Contains("证"))
|
||
value = Randomx.GetId(2000, 2019) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999);
|
||
if (p.name.Contains("工业产品生产许可证"))
|
||
value = Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(1000, 9999);
|
||
if (p.name == "生产日期" && pc.main_cat_name == "食品保健" && pc.main_cid == 7)
|
||
value = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||
if (p.name == "生产日期")
|
||
value = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||
//if (catId == 15172||catId== 15223 && p.name.Contains("证"))
|
||
// value = "2016010717879090";
|
||
if (catId == 14885)
|
||
value = "XK16-204-00364";
|
||
if (p.value_unit == "天")
|
||
value = "40";
|
||
if (p.name.Contains("保健品批准文号"))
|
||
continue;
|
||
if (p.name.Contains("化妆品批准文号")||p.name_alias.Contains("化妆品批准文号"))
|
||
continue;
|
||
if (p.name.Contains("食品生产许可证编号"))
|
||
value = "SC10635021200211";
|
||
if (p.name.Contains("ISBN"))
|
||
{
|
||
value = BaseRegex.GetMatchRegexString(pc.content_pinduoduo, @"ISBN编号\|([\d]+?)\|");
|
||
if (string.IsNullOrEmpty(value))
|
||
value = "9787540138240";
|
||
}
|
||
if (p.value_type == 5)
|
||
value = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value + "\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
}
|
||
else if (p.values.Count > 0) //选择型
|
||
{
|
||
vid = (int)p.values[Randomx.GetId(p.values.Count)].vid;
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + vid + ",\"value\":\"" + value +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
}
|
||
}
|
||
for (int i = 0; i < levelproperties.Count; i++)
|
||
{
|
||
var p = levelproperties[i];
|
||
int? vidxt = 0;//子节点ID
|
||
foreach (int key in dicPro.Keys)//父节点找子节点
|
||
{
|
||
if (key == p.id)
|
||
{
|
||
vidxt = dicPro[key];
|
||
break;
|
||
}
|
||
}
|
||
if (vidxt>0&&code.Contains(vidxt.ToString())|| code.Contains(p.id.ToString()))
|
||
continue;
|
||
//if (DefaultProperties.Count == 0)
|
||
//{
|
||
// GetDefaultProperties();
|
||
//}
|
||
if (DefaultProperties.ContainsKey(p.name) || DefaultProperties.ContainsKey(p.name_alias))
|
||
{
|
||
string value = "";
|
||
if (DefaultProperties.ContainsKey(p.name))
|
||
value = DefaultProperties[p.name];
|
||
if (string.IsNullOrEmpty(value))
|
||
value = DefaultProperties[p.name_alias];
|
||
if (p.name_alias!=p.name)
|
||
value = DefaultProperties[p.name_alias];
|
||
string[] vals = value.Split(',');
|
||
for (int j = 0; j < vals.Length; j++)
|
||
{
|
||
var item = vals[j];
|
||
if (p.values == null || p.values.Count == 0)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + 0 + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + 0 + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
}
|
||
else
|
||
{
|
||
bool ishas = false;
|
||
for (int k = 0; k < p.values.Count; k++)
|
||
{
|
||
if (item == p.values[k].value)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + p.values[k].vid + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + p.values[k].vid + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
ishas = true;
|
||
break;
|
||
}
|
||
}
|
||
if (ishas)
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//添加手动默认选项
|
||
for (int i = 0; i < properties.Count; i++)
|
||
{
|
||
var p = properties[i];
|
||
//if (DefaultProperties.Count == 0)
|
||
//{
|
||
// GetDefaultProperties();
|
||
//}
|
||
if (DefaultProperties.ContainsKey(p.name)|| DefaultProperties.ContainsKey(p.name_alias))
|
||
{
|
||
string value = "";
|
||
if (DefaultProperties.ContainsKey(p.name))
|
||
value=DefaultProperties[p.name];
|
||
if (string.IsNullOrEmpty(value))
|
||
value = DefaultProperties[p.name_alias];
|
||
string[] vals = value.Split(',');
|
||
for (int j = 0; j < vals.Length; j++)
|
||
{
|
||
var item = vals[j];
|
||
if (p.values == null || p.values.Count == 0)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + 0 + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + 0 + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
}
|
||
else
|
||
{
|
||
bool ishas = false;
|
||
for (int k = 0; k < p.values.Count; k++)
|
||
{
|
||
if (item == p.values[k].value)
|
||
{
|
||
code += ",{\"template_pid\":" + p.id + ",\"vid\":" + p.values[k].vid + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
mustCode += ",{\"template_pid\":" + p.id + ",\"vid\":" + p.values[k].vid + ",\"value\":\"" + item +
|
||
"\",\"value_unit\":\"" + p.value_unit + "\"}";
|
||
ishas = true;
|
||
break;
|
||
}
|
||
}
|
||
if (ishas)
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (cat1 == 6586)
|
||
code = code.Replace("克", "g");
|
||
if (catId == 14879)
|
||
{
|
||
if (code.Contains("10629"))
|
||
code = ",{\"template_pid\":95201,\"vid\":59036,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":95202,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":95203,\"vid\":0,\"value\":\"XK16-204-03833\",\"value_unit\":\"\"}";
|
||
}
|
||
if (catId == 14885)
|
||
{
|
||
if (code.Contains("10629"))
|
||
code = ",{\"template_pid\":95213,\"template_module_id\":21971,\"vid\":59036,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":95214,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":95215,\"vid\":0,\"value\":\"XK16-204-03833\",\"value_unit\":\"\"}";
|
||
}
|
||
if (catId == 7307 || catId == 8496)
|
||
{
|
||
if (code.Contains("10629"))
|
||
code = code.Replace(",{\"template_pid\":144155,\"vid\":14504,\"value\":\"\",\"value_unit\":\"\"}", "").Replace(",{\"template_pid\":144155,\"vid\":14499,\"value\":\"\",\"value_unit\":\"\"}", "");
|
||
}
|
||
if (catId == 8496)
|
||
{
|
||
if (code.Contains("10629"))
|
||
code = code.Replace(",{\"template_pid\":142793,\"vid\":14504,\"value\":\"\",\"value_unit\":\"\"}", "").Replace(",{\"template_pid\":142793,\"vid\":14499,\"value\":\"\",\"value_unit\":\"\"}", "");
|
||
}
|
||
if (code.Contains("10629"))
|
||
{
|
||
var m = BaseRegex.GetMatchRegex(ref code, @"{[^}]+?}");
|
||
int tid = 0;
|
||
int sid = 0;
|
||
int svid = 0;
|
||
for (int i = 0; m != null && i < m.Count; i++)
|
||
{
|
||
string item = m[i].Groups[0].Value;
|
||
tid = BaseRegex.GetIntJson(ref item, "template_pid");
|
||
svid = BaseRegex.GetIntJson(ref item, "vid");
|
||
if (svid == 10629)
|
||
break;
|
||
}
|
||
foreach (KeyValuePair<int?, int?> kvp in dicPro)
|
||
{
|
||
if ((int)kvp.Value == tid)
|
||
{
|
||
sid = (int)kvp.Key;
|
||
break;
|
||
}
|
||
}
|
||
bool ishas = false;
|
||
foreach (KeyValuePair<int, List<int>> kvp in vidParentIds)
|
||
{
|
||
if (kvp.Key == tid)
|
||
{
|
||
for (int i = 0; i < kvp.Value.Count; i++)
|
||
{
|
||
if (kvp.Value[i] == svid)
|
||
{
|
||
ishas = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!ishas)
|
||
{
|
||
string item = "";
|
||
for (int i = 0; m != null && i < m.Count; i++)
|
||
{
|
||
item = m[i].Groups[0].Value;
|
||
tid = BaseRegex.GetIntJson(ref item, "template_pid");
|
||
if (tid == sid)
|
||
break;
|
||
}
|
||
code = code.Replace("," + item + "", "");
|
||
}
|
||
|
||
}
|
||
return code;
|
||
}
|
||
public static string GetRandomChinese(int strlength)
|
||
{
|
||
// 获取GB2312编码页(表)
|
||
Encoding gb = Encoding.GetEncoding("gb2312");
|
||
|
||
object[] bytes = CreateRegionCode(strlength);
|
||
|
||
StringBuilder sb = new StringBuilder();
|
||
|
||
for (int i = 0; i < strlength; i++)
|
||
{
|
||
string temp = gb.GetString((byte[])Convert.ChangeType(bytes[i], typeof(byte[])));
|
||
sb.Append(temp);
|
||
}
|
||
|
||
return sb.ToString();
|
||
}
|
||
private static object[] CreateRegionCode(int strlength)
|
||
{
|
||
//定义一个字符串数组储存汉字编码的组成元素
|
||
string[] rBase = new String[16] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
|
||
|
||
Random rnd = new Random();
|
||
|
||
//定义一个object数组用来
|
||
object[] bytes = new object[strlength];
|
||
|
||
/**
|
||
每循环一次产生一个含两个元素的十六进制字节数组,并将其放入bytes数组中
|
||
每个汉字有四个区位码组成
|
||
区位码第1位和区位码第2位作为字节数组第一个元素
|
||
区位码第3位和区位码第4位作为字节数组第二个元素
|
||
**/
|
||
for (int i = 0; i < strlength; i++)
|
||
{
|
||
//区位码第1位
|
||
int r1 = rnd.Next(11, 14);
|
||
string str_r1 = rBase[r1].Trim();
|
||
|
||
//区位码第2位
|
||
rnd = new Random(r1 * unchecked((int)DateTime.Now.Ticks) + i); // 更换随机数发生器的 种子避免产生重复值
|
||
int r2;
|
||
if (r1 == 13)
|
||
{
|
||
r2 = rnd.Next(0, 7);
|
||
}
|
||
else
|
||
{
|
||
r2 = rnd.Next(0, 16);
|
||
}
|
||
string str_r2 = rBase[r2].Trim();
|
||
|
||
//区位码第3位
|
||
rnd = new Random(r2 * unchecked((int)DateTime.Now.Ticks) + i);
|
||
int r3 = rnd.Next(10, 16);
|
||
string str_r3 = rBase[r3].Trim();
|
||
|
||
//区位码第4位
|
||
rnd = new Random(r3 * unchecked((int)DateTime.Now.Ticks) + i);
|
||
int r4;
|
||
if (r3 == 10)
|
||
{
|
||
r4 = rnd.Next(1, 16);
|
||
}
|
||
else if (r3 == 15)
|
||
{
|
||
r4 = rnd.Next(0, 15);
|
||
}
|
||
else
|
||
{
|
||
r4 = rnd.Next(0, 16);
|
||
}
|
||
string str_r4 = rBase[r4].Trim();
|
||
|
||
// 定义两个字节变量存储产生的随机汉字区位码
|
||
byte byte1 = Convert.ToByte(str_r1 + str_r2, 16);
|
||
byte byte2 = Convert.ToByte(str_r3 + str_r4, 16);
|
||
// 将两个字节变量存储在字节数组中
|
||
byte[] str_r = new byte[] { byte1, byte2 };
|
||
|
||
// 将产生的一个汉字的字节数组放入object数组中
|
||
bytes.SetValue(str_r, i);
|
||
}
|
||
|
||
return bytes;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取必填项
|
||
/// </summary>
|
||
/// <param name="catId"></param>
|
||
/// <param name="pc"></param>
|
||
/// <returns></returns>
|
||
public static string Get(int catId, int cat1, ref ProductCollectBase pc)
|
||
{
|
||
string code = "";
|
||
if (catId == 14932)
|
||
{
|
||
code =
|
||
",{\"template_pid\":40870,\"template_module_id\":8747,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40871,\"template_module_id\":8747,\"pid\":9,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40872,\"template_module_id\":8747,\"pid\":55,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40874,\"template_module_id\":8747,\"pid\":316,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"},{\"template_pid\":40875,\"template_module_id\":8747,\"pid\":317,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"},{\"template_pid\":40876,\"template_module_id\":8747,\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"}," +
|
||
"{\"template_pid\":40877,\"template_module_id\":8747,\"pid\":351,\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(2000, 5017) + "/" + Randomx.GetId(10000, 50017) +
|
||
"\",\"value_unit\":\"\"},{\"template_pid\":40878,\"template_module_id\":8747,\"pid\":352,\"vid\":84120,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":40879,\"template_module_id\":8747,\"pid\":175,\"vid\":84126,\"value\":\"\",\"value_unit\":\"\"}";
|
||
return code;
|
||
}
|
||
if (catId == 17402) //卷筒纸
|
||
{
|
||
code =
|
||
",{\"template_pid\":45053,\"template_module_id\":9772,\"pid\":275,\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(20, 200) +
|
||
"\",\"value_unit\":\"g\"},{\"template_pid\":45054,\"template_module_id\":9772,\"pid\":162,\"vid\":0,\"value_unit\":\"卷\"},{\"template_pid\":45055,\"template_module_id\":9772,\"pid\":64,\"vid\":0,\"value\":\"100,100\",\"value_unit\":\"mm\"},{\"template_pid\":45056,\"template_module_id\":9772,\"pid\":336,\"vid\":83637,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45057,\"template_module_id\":9772,\"pid\":33,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45058,\"template_module_id\":9772,\"pid\":16,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45059,\"template_module_id\":9772,\"pid\":340,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45060,\"template_module_id\":9772,\"pid\":339,\"value\":\"\",\"value_unit\":\"\"}";
|
||
return code;
|
||
}
|
||
if (catId == 17399) //抽纸
|
||
{
|
||
code =
|
||
",{\"template_pid\":45017,\"template_module_id\":9766,\"pid\":336,\"vid\":83637,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":45018,\"template_module_id\":9766,\"pid\":191,\"vid\":0,\"value\":\"100\",\"value_unit\":\"抽\"},{\"template_pid\":45020,\"template_module_id\":9766,\"pid\":64,\"vid\":0,\"value\":\"100,100\",\"value_unit\":\"mm\"}";
|
||
return code;
|
||
}
|
||
if (catId == 8653) //国产腕表
|
||
{
|
||
code =
|
||
",{\"template_pid\":57869,\"template_module_id\":14217,\"pid\":133,\"vid\":0,\"value\":\"26\",\"value_unit\":\"mm\"}";
|
||
return code;
|
||
}
|
||
if (catId == 13924)
|
||
{
|
||
var no = pc.Prop.Find(p => p.Key == "注册证号");
|
||
string nox = no == null || string.IsNullOrEmpty(no.Value)
|
||
? "国食药监械(准)字2014第3" + Randomx.GetId(100000, 999999) + "号"
|
||
: no.Value;
|
||
code =
|
||
",{\"template_pid\":42782,\"template_module_id\":9175,\"pid\":234,\"vid\":0,\"value\":\"" + nox +
|
||
"\",\"value_unit\":\"\"}";
|
||
return code;
|
||
}
|
||
List<ModelBase> md = Properties.FindAll(m => m != null && m.cats.Contains(catId));
|
||
if (md == null || md.Count == 0)
|
||
{
|
||
if (
|
||
",14918,14932,14913,15540,14932,9647,9610,9559,9558,9551,6247,6167,6034,6028,6024,6006,5989,5982,5965,5963,5961,5959,5757,5671,5670,3030,657,"
|
||
.Contains("," + catId + ","))
|
||
{
|
||
code =
|
||
",{\"template_pid\":33051,\"template_module_id\":7185,\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"}";
|
||
var k = pc.Prop.Find(p => p.Key.Contains("证书编号"));
|
||
if (k != null)
|
||
code +=
|
||
",{\"template_pid\":33052,\"template_module_id\":7185,\"pid\":59,\"vid\":0,\"value\":\"" +
|
||
k.Value + "\",\"value_unit\":\"\"}";
|
||
else
|
||
code +=
|
||
",{\"template_pid\":33052,\"template_module_id\":7185,\"pid\":59,\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" +
|
||
Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}";
|
||
}
|
||
if (
|
||
",2,6586,6785,6883,6758,6536,6630,6398,,63,64,65,92,95,99,101,3853,3862,3867,3872,3876,3900,898,897,3993,1079,"
|
||
.Contains("," + cat1 + ","))
|
||
{
|
||
code += ",{\"template_pid\":5876,\"template_module_id\":1385,\"pid\":57,\"vid\":0,\"value\":\"" +
|
||
DateTime.Today.ToString("yyyy-MM-dd") +
|
||
"\",\"value_unit\":\"\"},{\"template_pid\":5877,\"template_module_id\":1385,\"pid\":58,\"vid\":0,\"value\":\"300\",\"value_unit\":\"天\"}";
|
||
}
|
||
if (",14931,".Contains("," + catId + ","))
|
||
{
|
||
code +=
|
||
",{\"template_pid\":55981,\"template_module_id\":13855,\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"}";
|
||
code +=
|
||
",{\"template_pid\":33052,\"template_module_id\":7185,\"pid\":59,\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" +
|
||
Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}";
|
||
}
|
||
|
||
return code;
|
||
}
|
||
ModelBase mdType = md.Find(m => m.name.Contains("面料俗称") || m.name.Contains("面料材质"));
|
||
List<ModelBase> mdType1 = md.FindAll(m => m.pid == 16);//材质
|
||
List<ModelBase> mdType2 = md.FindAll(m => m.pid == 56);//成分含量
|
||
|
||
for (int i = 0; i < mdType1.Count; i++)
|
||
{
|
||
md.Remove(mdType1[i]);
|
||
}
|
||
for (int i = 0; i < mdType2.Count; i++)
|
||
{
|
||
md.Remove(mdType2[i]);
|
||
}
|
||
if (mdType != null)
|
||
{
|
||
md.Remove(mdType);
|
||
string codeTemp = "";
|
||
bool ok = false;
|
||
for (int i = 0; i < mdType.Values.Count; i++)
|
||
{
|
||
if (ok)
|
||
break;
|
||
string name = mdType.Values[i].value;
|
||
if (name.Contains(" "))
|
||
name = mdType.Values[i].value.Substring(0, mdType.Values[i].value.IndexOf(" "));
|
||
if (name.Contains("("))
|
||
name = mdType.Values[i].value.Substring(0, mdType.Values[i].value.IndexOf("("));
|
||
var p = pc.Prop.Find(px => px.Value.Contains(name));
|
||
if (name == "其它" && p == null)
|
||
p = pc.Prop.Find(px => px.Value.Contains("其他"));
|
||
|
||
if (p == null)
|
||
continue;
|
||
if (!p.Value.Contains("%"))
|
||
p = pc.Prop.Find(px => px.Value.Contains("%"));
|
||
if (p == null)
|
||
p = new KeyValueBase("", "20%");
|
||
|
||
codeTemp += ",{\"template_pid\":" + mdType.template_pid + ",\"template_module_id\":" +
|
||
mdType.template_module_id + ",\"pid\":" + mdType.pid + ",\"vid\":" +
|
||
mdType.Values[i].vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
mdType.Values[i].p_unit + "\"}";
|
||
if (mdType1.Count > 0)
|
||
{
|
||
ModelBase mdType16 =
|
||
mdType1.Find(m => m.Values.Count > 0 && m.Values[0].value == mdType.Values[i].value);
|
||
if (mdType16 != null)
|
||
{
|
||
codeTemp += ",{\"template_pid\":" + mdType16.template_pid + ",\"template_module_id\":" +
|
||
mdType16.template_module_id + ",\"pid\":" + mdType16.pid + ",\"vid\":" +
|
||
mdType16.Values[0].vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
mdType16.Values[0].p_unit + "\"}";
|
||
}
|
||
}
|
||
string percent = BaseRegex.GetMatchRegexString(p.Value, @"([\d ]+)%");
|
||
if (string.IsNullOrEmpty(percent))
|
||
break;
|
||
int per = 0;
|
||
int.TryParse(percent, out per);
|
||
for (int j = 0; mdType2.Count > 0 && j < mdType2[0].Values.Count; j++)
|
||
{
|
||
var m = BaseRegex.GetMatchRegex(mdType2[0].Values[j].value, @"([\d]+)%");
|
||
int min = 0, max = 0;
|
||
if (m == null || m.Count == 0)
|
||
break;
|
||
if (m.Count == 1)
|
||
{
|
||
min = max = int.Parse(m[0].Groups[1].Value);
|
||
}
|
||
if (m.Count == 2)
|
||
{
|
||
min = int.Parse(m[0].Groups[1].Value);
|
||
max = int.Parse(m[1].Groups[1].Value);
|
||
}
|
||
if (per >= min && per <= max)
|
||
{
|
||
codeTemp += ",{\"template_pid\":" + mdType2[0].template_pid + ",\"template_module_id\":" +
|
||
mdType2[0].template_module_id + ",\"pid\":" + mdType2[0].pid + ",\"vid\":" +
|
||
mdType2[0].Values[j].vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
mdType2[0].Values[j].p_unit + "\"}";
|
||
ok = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (!ok)
|
||
{
|
||
if (mdType.name.Contains("面料俗称"))
|
||
{
|
||
codeTemp =
|
||
",{\"template_pid\":46543,\"template_module_id\":10053,\"pid\":7,\"vid\":10348,\"value\":\"\",\"value_unit\":\"\"}," +
|
||
"{\"template_pid\":46545,\"template_module_id\":10053,\"pid\":16,\"vid\":10571,\"value\":\"\",\"value_unit\":\"\"}," +
|
||
"{\"template_pid\":46546,\"pid\":56,\"vid\":14504,\"value\":\"\",\"value_unit\":\"\"}";
|
||
}
|
||
else
|
||
{
|
||
var m = mdType.Values.Find(mm => mm.value == "其他");
|
||
if (m == null)
|
||
{
|
||
m = mdType.Values.Find(mm => mm.value == "棉");
|
||
if (m == null && mdType.Values.Count > 0)
|
||
m = mdType.Values[0];
|
||
if (m == null)
|
||
{
|
||
codeTemp =
|
||
",{\"template_pid\":50936,\"template_module_id\":12662,\"pid\":16,\"vid\":10629,\"value\":\"\",\"value_unit\":\"\"}";
|
||
}
|
||
else
|
||
{
|
||
codeTemp =
|
||
",{\"template_pid\":" + mdType.template_pid + ",\"template_module_id\":" + mdType.template_module_id + ",\"pid\":" + mdType.pid + ",\"vid\":" + m.value + ",\"value\":\"\",\"value_unit\":\"\"}";
|
||
codeTemp +=
|
||
",{\"template_pid\":" + mdType.template_pid + ",\"template_module_id\":" + mdType.template_module_id + ",\"pid\":56,\"vid\":14504,\"value\":\"\",\"value_unit\":\"\"}";
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
codeTemp =
|
||
",{\"template_pid\":" + mdType.template_pid + ",\"template_module_id\":" + mdType.template_module_id + ",\"pid\":" + mdType.pid + ",\"vid\":" + m.value + ",\"value\":\"\",\"value_unit\":\"\"}";
|
||
}
|
||
|
||
}
|
||
}
|
||
code += codeTemp;
|
||
}
|
||
|
||
|
||
try
|
||
{
|
||
for (int i = 0; i < pc.Prop.Count; i++)
|
||
{
|
||
var p = pc.Prop[i];
|
||
if (p.Key.Contains("品牌") || p.Key.Contains("型号"))
|
||
continue;
|
||
for (int j = 0; j < md.Count; j++)
|
||
{
|
||
if (p.Key == md[j].name || p.Key == md[j].name_all ||
|
||
p.Key.Contains("证书编号") && (md[j].name.Contains("证书编号") || md[j].name.Contains("认证证书")))
|
||
{
|
||
bool get = false;
|
||
if (p.Key.Contains("证书编号"))
|
||
{
|
||
code += ",{\"template_pid\":" + md[j].template_pid + ",\"template_module_id\":" +
|
||
md[j].template_module_id + ",\"pid\":" + md[j].pid + ",\"vid\":0,\"value\":\"" +
|
||
p.Value + "\",\"value_unit\":\"\"}";
|
||
md.RemoveAt(j); //匹配成功则删除
|
||
j--;
|
||
continue;
|
||
}
|
||
if (md[j].template_pid == 53996)
|
||
md[j].value_type = 0;
|
||
if (md[j].value_type == 1) //文本型
|
||
{
|
||
if (",30419,28189,".Contains("," + md[j].template_pid + ","))
|
||
{
|
||
for (int k = 0; k < md[j].Values.Count; k++)
|
||
{
|
||
if (md[j].Values[k].value != p.Value)
|
||
continue;
|
||
code += ",{\"template_pid\":" + md[j].template_pid + ",\"template_module_id\":" +
|
||
md[j].template_module_id + ",\"pid\":" + md[j].pid + ",\"vid\":" +
|
||
md[j].Values[k].vid + ",\"value\":\"\",\"value_unit\":\"\"}";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (md[j].template_pid == 33103)
|
||
md[j].value_unit = "L";
|
||
if (md[j].template_pid == 33163)
|
||
md[j].value_unit = "W";
|
||
if (md[j].template_pid == 51489)
|
||
md[j].value_unit = "g";
|
||
code += ",{\"template_pid\":" + md[j].template_pid + ",\"template_module_id\":" +
|
||
md[j].template_module_id + ",\"pid\":" + md[j].pid +
|
||
",\"vid\":0,\"value\":\"" +
|
||
(string.IsNullOrEmpty(md[j].value_unit)
|
||
? p.Value
|
||
: p.Value.Replace(md[j].value_unit, ""))
|
||
+ "\",\"value_unit\":\"" + md[j].value_unit + "\"}";
|
||
}
|
||
|
||
get = true;
|
||
|
||
}
|
||
if (md[j].value_type == 0)
|
||
{
|
||
bool had = false;
|
||
for (int k = 0; k < md[j].Values.Count; k++)
|
||
{
|
||
if (md[j].Values[k].value.ToLower() == p.Value.ToLower())
|
||
{
|
||
code += ",{\"template_pid\":" + md[j].template_pid + ",\"template_module_id\":" +
|
||
md[j].template_module_id + ",\"pid\":" + md[j].pid + ",\"vid\":" +
|
||
md[j].Values[k].vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
md[j].Values[k].p_unit + "\"}";
|
||
had = true;
|
||
get = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!had && p.Value.Contains("、"))
|
||
{
|
||
string[] vs = p.Value.Split('、');
|
||
for (int l = 0; l < vs.Length; l++)
|
||
{
|
||
if (string.IsNullOrEmpty(vs[l]))
|
||
continue;
|
||
for (int k = 0; k < md[j].Values.Count; k++)
|
||
{
|
||
if (md[j].Values[k].value.ToLower() == vs[l].Trim().ToLower())
|
||
{
|
||
code += ",{\"template_pid\":" + md[j].template_pid +
|
||
",\"template_module_id\":" +
|
||
md[j].template_module_id + ",\"pid\":" + md[j].pid + ",\"vid\":" +
|
||
md[j].Values[k].vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
md[j].Values[k].p_unit + "\"}";
|
||
md[j].Values.RemoveAt(k);
|
||
get = true;
|
||
had = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!had)
|
||
{
|
||
int k = Randomx.GetId(0, md[j].Values.Count);
|
||
code += ",{\"template_pid\":" + md[j].template_pid + ",\"template_module_id\":" +
|
||
md[j].template_module_id + ",\"pid\":" + md[j].pid + ",\"vid\":" +
|
||
md[j].Values[k].vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
md[j].Values[k].p_unit + "\"}";
|
||
}
|
||
}
|
||
if (get)
|
||
{
|
||
md.RemoveAt(j); //匹配成功则删除
|
||
j--;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//未匹配成功的必填项
|
||
for (int i = 0; i < md.Count; i++)
|
||
{
|
||
if (!md[i].must || code.Contains(":" + md[i].pid + ","))
|
||
continue;
|
||
if (md[i].pid == 93) //产地
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 59) //3C证书
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":59,\"vid\":0,\"value\":\"" + Randomx.GetId(2000, 2017) +
|
||
"0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999) +
|
||
"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 40) //充电器
|
||
{
|
||
int vid = 78213;
|
||
if (md[i].Values.Count > 0)
|
||
vid = md[i].Values[Randomx.GetId(md[i].Values.Count)].vid;
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":40,\"vid\":" + vid +
|
||
",\"value\":\"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 67) //功率w
|
||
{
|
||
int vid = 78213;
|
||
if (md[i].Values.Count > 0)
|
||
vid = md[i].Values[Randomx.GetId(md[i].Values.Count)].vid;
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":67,\"vid\":\"" + vid +
|
||
"\",\"value\":\"\",\"value_unit\":\"W\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 95) //电流类型
|
||
{
|
||
int vid = 24825;
|
||
if (md[i].Values.Count > 0)
|
||
vid = md[i].Values[Randomx.GetId(md[i].Values.Count)].vid;
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":95,\"vid\":" + vid +
|
||
",\"value\":\"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 96) //个人护理
|
||
{
|
||
int vid = 28237;
|
||
if (md[i].Values.Count > 0)
|
||
vid = md[i].Values[Randomx.GetId(md[i].Values.Count)].vid;
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":96,\"vid\":" + vid +
|
||
",\"value\":\"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 316) //纸尿片
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":316,\"vid\":0,\"value\":\"其他\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 317) //纸尿片
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":317,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 40) //热水袋
|
||
{
|
||
int vid = 57495;
|
||
if (md[i].Values.Count > 0)
|
||
vid = md[i].Values[Randomx.GetId(md[i].Values.Count)].vid;
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":40,\"vid\":" + vid +
|
||
",\"value\":\"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 57) //食品生产日期
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":57,\"vid\":0,\"value\":\"" +
|
||
DateTime.Today.ToString("yyyy-MM-dd") +
|
||
"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 58) //食品保质期
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":58,\"vid\":0,\"value\":\"300\",\"value_unit\":\"天\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 59) //3C证书
|
||
{
|
||
code += ",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":" + md[i].pid + ",\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" +
|
||
Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 92) //医疗器械
|
||
{
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":92,\"vid\":0,\"value\":\"Z" +
|
||
Randomx.GetId(10000000, 99999999) + Randomx.GetId(1, 9) + "\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (md[i].pid == 0)
|
||
{
|
||
}
|
||
|
||
int vidx = 0;
|
||
if (md[i].Values.Count > 0)
|
||
vidx = md[i].Values[Randomx.GetId(md[i].Values.Count)].vid;
|
||
code +=
|
||
",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":" + md[i].pid + ",\"vid\":" + vidx +
|
||
",\"value\":\"\",\"value_unit\":\"\"}";
|
||
continue;
|
||
}
|
||
if (code.Contains("\"pid\":93,") && !code.Contains("\"pid\":59,"))
|
||
{
|
||
code +=
|
||
",{\"template_pid\":33052,\"template_module_id\":7185,\"pid\":59,\"vid\":0,\"value\":\"" +
|
||
Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" +
|
||
Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}";
|
||
}
|
||
for (int i = 0; i < md.Count; i++) //强制匹配可选项目
|
||
{
|
||
if (code.Contains(md[i].template_pid.ToString()))
|
||
continue;
|
||
var s =
|
||
md[i].Values.Find(
|
||
m => m.value == "其他" || m.value == "其它" || m.value == "通用" || m.value == "中国大陆");
|
||
if (s != null)
|
||
{
|
||
code += ",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":" + md[i].pid + ",\"vid\":" +
|
||
s.vid + ",\"value\":\"\",\"value_unit\":\"" +
|
||
s.p_unit + "\"}";
|
||
continue;
|
||
}
|
||
if (md[i].name == "化妆品批准文号")
|
||
{
|
||
code += ",{\"template_pid\":" + md[i].template_pid + ",\"template_module_id\":" +
|
||
md[i].template_module_id + ",\"pid\":" + md[i].pid + ",\"vid\":" +
|
||
0 + ",\"value\":\"国妆特字G201" + Randomx.GetId(10000, 99999) +
|
||
"\",\"value_unit\":\"\"}";
|
||
}
|
||
|
||
}
|
||
if (",8496,".Contains(catId.ToString()))//属性材质
|
||
{
|
||
if (!code.Contains("53201"))
|
||
code +=
|
||
",{\"template_pid\":53201,\"template_module_id\":13191,\"pid\":7,\"vid\":10348,\"value\":\"\",\"value_unit\":\"\"}";
|
||
code +=
|
||
",{\"template_pid\":53202,\"template_module_id\":13191,\"pid\":16,\"vid\":10571,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":53203,\"pid\":56,\"vid\":14499,\"value\":\"\",\"value_unit\":\"\"}";
|
||
}
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogSave.Add(e.Message);
|
||
}
|
||
return code;
|
||
}
|
||
|
||
public static void GetDefaultProperties()
|
||
{
|
||
string url = BaseClass.LoginApiUrl + "?obj=pinbaobao/config&act=get_default_properties&" + UserLogin.GetSignaturex("", "");
|
||
string html = GetHtml.PostUtf8(url, "");
|
||
if (html.Contains("Not Key"))
|
||
{
|
||
Thread.Sleep(3000);
|
||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/config&act=get_default_properties&" + UserLogin.GetSignaturex("", "");
|
||
html = GetHtml.PostUtf8(url, "");
|
||
}
|
||
var sm = BaseRegex.GetMatchRegex(ref html, @"{[^}]+?}");
|
||
for (int i = 0; sm != null && i < sm.Count; i++)
|
||
{
|
||
string orderItem = sm[i].Groups[0].Value;
|
||
string key = BaseRegex.GetStringJson(ref orderItem, "name");
|
||
string value = BaseRegex.GetStringJson(ref orderItem, "value");
|
||
DefaultProperties.Add(key,value);
|
||
}
|
||
}
|
||
public static string GetMonth()
|
||
{
|
||
string result = DateTime.Now.Year + "年冬季";
|
||
int mm = DateTime.Now.Month;
|
||
if (mm >= 3 && mm <= 5)
|
||
result= DateTime.Now.Year + "年春季";
|
||
if (mm >= 6 && mm <= 8)
|
||
result= DateTime.Now.Year + "年夏季";
|
||
if (mm >= 9 && mm <= 11)
|
||
result= DateTime.Now.Year + "年秋季";
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public class ModelBase
|
||
{
|
||
public List<int> cats = new List<int>();
|
||
public int template_pid;
|
||
public int template_module_id;
|
||
public int pid;
|
||
public int show_type;
|
||
public string name;
|
||
public string name_all;
|
||
public bool must;
|
||
public int choose_max_num;
|
||
public string value_unit;
|
||
public int value_type;
|
||
public List<ContentBase> Values = new List<ContentBase>();
|
||
public ModelBase Clone()
|
||
{
|
||
string html = JsonHelper.SerializeObject(this);
|
||
ModelBase tp = JsonHelper.DeserializeJsonToObject<ModelBase>(html);
|
||
return tp;
|
||
}
|
||
}
|
||
public class ContentBase
|
||
{
|
||
public int id;
|
||
public int vid;
|
||
public string value;
|
||
public string p_unit;
|
||
}
|
||
public class Node
|
||
{
|
||
public Node(int item)
|
||
{
|
||
this.id = item;
|
||
this.next = null;
|
||
}
|
||
public Node()
|
||
{
|
||
this.id = 0;
|
||
this.next = null;
|
||
}
|
||
public int id;
|
||
public Node next;
|
||
}
|
||
public class LinkList
|
||
{
|
||
public Node head { set; get; }
|
||
/// <summary>
|
||
/// 求单链表的长度
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public int GetLength()
|
||
{
|
||
Node p = head;
|
||
int length = 0;
|
||
while (p != null)
|
||
{
|
||
p = p.next;
|
||
length++;
|
||
}
|
||
return length;
|
||
}
|
||
public bool IsEmpty()
|
||
{
|
||
if (head == null)
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
public void Append(int item)
|
||
{
|
||
Node temp = new Node (item);
|
||
Node current= new Node();
|
||
if (head == null)
|
||
{
|
||
head = temp;
|
||
return;
|
||
}
|
||
current= head;
|
||
while (current.next != null)
|
||
{
|
||
current = current.next;
|
||
}
|
||
current.next = temp;
|
||
}
|
||
/// <summary>
|
||
/// 获得当前位置单链表中结点的值
|
||
/// </summary>
|
||
/// <param name="i">结点位置</param>
|
||
/// <returns></returns>
|
||
public Node GetNodeValue(int i)
|
||
{
|
||
if (IsEmpty() || i < 1 || i > GetLength())
|
||
{
|
||
return null;
|
||
}
|
||
|
||
Node A = new Node ();
|
||
A = head;
|
||
int j = 1;
|
||
while (A.next != null && j < i)
|
||
{
|
||
A = A.next;
|
||
j++;
|
||
}
|
||
return A;
|
||
}
|
||
public void Insert(int item, int n)
|
||
{
|
||
if (IsEmpty() || n < 1 || n > GetLength())
|
||
{
|
||
return;
|
||
}
|
||
if (n == 1) //增加到头部
|
||
{
|
||
Node H = new Node(item);
|
||
H.next = head;
|
||
head = H;
|
||
return;
|
||
}
|
||
|
||
Node A = new Node();
|
||
Node B = new Node();
|
||
B = head;
|
||
int j = 1;
|
||
while (B.next != null && j < n)
|
||
{
|
||
A = B;
|
||
B = B.next;
|
||
j++;
|
||
}
|
||
|
||
if (j == n)
|
||
{
|
||
Node C = new Node(item);
|
||
A.next = C;
|
||
C.next = B;
|
||
}
|
||
}
|
||
public void Dispaly()
|
||
{
|
||
Node A = new Node();
|
||
A = head;
|
||
while (A != null)
|
||
{
|
||
//Console.WriteLine(A.Data);
|
||
A = A.next;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|