微信上货支持选择随机曝光量

This commit is contained in:
wule committed 2026-08-04 15:03:27 +08:00
1 parent b1f76eb13c
commit 78e911c7cf
5 files changed
+221 -48

No files matched your search

@@ -1031,6 +1031,29 @@ namespace KJD_Web.BLL.BXX
}
mySql.Close();
}
if (prod.product_json.Contains(":null"))
{
mySql = new MysqlUtils(conn);
try
{
JObject jObj = JsonUtils.JObjectParse(prod.product_json);
RemoveNullProperties(jObj);
JsonSerializerSettings jsonIgnoreNullSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
var newProdJson = JsonUtils.SerializeObjectToString(jObj, jsonIgnoreNullSetting);
sql = "update " + tableName + " set product_json=@product_json where spu_id='" + prod.spu_id + "'";
paramLst = new List<MySqlParameter>();
paramLst.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "product_json", Value = newProdJson, });
mySql.ExecuteNonQuery(sql, paramLst.ToArray());
prod.product_json = newProdJson;
}
catch
{
}
mySql.Close();
}
}
if (!string.IsNullOrEmpty(get_select_count))
{
@@ -1058,6 +1081,93 @@ namespace KJD_Web.BLL.BXX
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
/// <summary>
/// 递归剔除JObject中值为null的字段 (修改为null才删除,empty不删除)
/// </summary>
public static void RemoveNullProperties(JToken token)
{
if (token.Type == JTokenType.Object)
{
var jObj = (JObject)token;
var propertiesToRemove = jObj.Properties()
//.Where(p =>
// p.Value == null ||
// p.Value.Type == JTokenType.Null ||
// (p.Value.Type == JTokenType.String && string.IsNullOrEmpty((string)p.Value)) ||
// (p.Value.Type == JTokenType.String && string.IsNullOrWhiteSpace((string)p.Value)) ||
// (p.Value.Type == JTokenType.Array && !p.Value.HasValues))
.Where(p =>
p.Value == null ||
p.Value.Type == JTokenType.Null)
.ToList();
foreach (var prop in propertiesToRemove)
prop.Remove();
foreach (var child in jObj.Children())
{
if (child.Children().Count() > 0)
{
RemoveNullProperties(child);
}
}
}
else if (token.Type == JTokenType.Property)
{
if (token.Children().Count() > 0)
{
var childs = token.Children()
//.Where(p =>
// p == null ||
// p.Type == JTokenType.Null ||
// (p.Type == JTokenType.String && string.IsNullOrEmpty((string)p)) ||
// (p.Type == JTokenType.String && string.IsNullOrWhiteSpace((string)p)) ||
// (p.Type == JTokenType.Array && !p.HasValues))
.Where(p =>
p == null ||
p.Type == JTokenType.Null)
.ToList();
foreach (var prop in childs)
prop.Remove();
foreach (var child in token.Children())
{
if (child.Children().Count() > 0)
{
RemoveNullProperties(child);
}
}
}
}
else if (token.Type == JTokenType.Array)
{
var jArray = (JArray)token;
// 清理数组内部的 null / ""
for (int i = jArray.Count - 1; i >= 0; i--)
{
var item = jArray[i];
//if (item.Type == JTokenType.Null ||
// (item.Type == JTokenType.String && string.IsNullOrWhiteSpace((string)item)))
if (item.Type == JTokenType.Null)
{
jArray.RemoveAt(i);
}
}
// 递归数组内对象/子数组
foreach (var child in jArray)
RemoveNullProperties(child);
//// 如果数组最后变空,也删除
//if (!jArray.HasValues)
//{
// if (jArray.Parent is JProperty prop)
// prop.Remove();
//}
}
}
/// <summary>
/// 回采微信小店属性等商品数据入库
/// </summary>
@@ -1924,6 +2034,9 @@ namespace KJD_Web.BLL.BXX
add_user_name = "admin";
var no_fission_words = RegexUtils.GetStringQuery(ref inputData, "no_fission_words").ParseToBool(); // 未裂变标题
var fission_words = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "fission_words"))?.Replace("'", "\\'");
var min_view_uv = HtmlUtils.UrlDecodeUtf8(RegexUtils.GetStringQuery(ref inputData, "min_view_uv"))?.ParseToNullableInt();
if (min_view_uv > 0 && min_view_uv < 100)
min_view_uv = 100;
int page = RegexUtils.GetStringQuery(ref inputData, "page").ParseToInt();
int page_size = RegexUtils.GetStringQuery(ref inputData, "page_size").ParseToInt(50);
@@ -2062,6 +2175,10 @@ namespace KJD_Web.BLL.BXX
{
where += " and fission_words LIKE '" + fission_words + "%'";
}
if (min_view_uv > 0)
{
where += " and view_uv >= " + min_view_uv + "";
}
sql += where;
int count = prod_count;
+11 -3
View File
@@ -70,12 +70,20 @@ namespace KJD_Web.Utils
}
}
public static JObject JObjectParse(string json)
public static JObject JObjectParse(string json, JsonLoadSettings settings = null)
{
try
{
JObject obj = JObject.Parse(json);
return obj;
if (settings == null)
{
JObject obj = JObject.Parse(json);
return obj;
}
else
{
JObject obj = JObject.Parse(json, settings);
return obj;
}
}
catch
{