详情图使用随机ai图片

This commit is contained in:
wule committed 2025-10-31 22:44:14 +08:00
1 parent ec8736b8f9
commit dc95bd8621
5 files changed
+184 -40

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ namespace AllBase
/// <summary>
/// 版本ID
/// </summary>
public static int VersionCount = 657;
public static int VersionCount = 658;
//public static int VersionCount = 613;
/// <summary>
@@ -20,5 +20,13 @@ namespace AllBase.Model.Result.TemuResult
public DateTime mdy_time { get; set; }
public DateTime base64_mdy_time { get; set; }
public string img_base64 { get; set; }
public int use_count { get; set; }
/// <summary>
/// 记录上货过程中是否被使用,在同一个商品上货一次过程中同一张图使用多少次都算1次
/// </summary>
public bool is_use { get; set; } = false;
public int width { get; set; } = 800;
public int height { get; set; } = 800;
}
}
@@ -1099,7 +1099,39 @@ namespace KJD_Web.BLL
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "update kjd.sku_img_base64 set img_url=\'" + img_url + "\' where id='" + id + "'";
string sql = "update kjd.sku_img_base64 set img_url=\'" + img_url + "\' where id='" + id + "';";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
if (rst)
{
return "{\"code\":200,\"msg\":\"success\"}";
}
else
return "{\"code\":500,\"msg\":\"保存失败:" + mySql.Message + "\"}";
}
return "{\"code\":19999,\"msg\":\"输入为空\"}";
}
public string MdyBase64ImgUseCount(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
var time = RegexUtils.GetStringQuery(ref inputData, "time").ParseToInt();
string time1 = RegexUtils.GetStringQuery(ref inputData, "code");
if (time1 != EncrypUtil.Encryption(time))
return "{\"code\":50000,\"msg\":\"校验失败\"}";
var user_name = RegexUtils.GetStringQuery(ref inputData, "user_name")?.Replace("'", "\\'");
var ids = RegexUtils.GetStringQuery(ref inputData, "db_ids")?.Replace("'", "\\'");
if (string.IsNullOrEmpty(ids))
{
return "{\"code\":500,\"msg\":\"保存失败:缺少图片编号\"}";
}
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
MysqlUtils mySql = new MysqlUtils(conn);
string sql = "update kjd.sku_img_base64 set use_count=use_count+1 where id in (" + ids + ");";
var rst = mySql.ExecuteNonQuery(sql);
mySql.Close();
@@ -273,5 +273,16 @@ namespace KJD_Web
Context.Response.Write(result);
Context.Response.End();
}
[WebMethod]
public void mdy_base64_img_use_count()
{
string jsontext = GetRequestJsonString();
var result = jsontext;
result = new ProductManage().MdyBase64ImgUseCount(jsontext);
Context.Response.Write(result);
Context.Response.End();
}
}
}
@@ -1042,6 +1042,8 @@ namespace TemuKJD.KJDForms.ProductSelectForms
prodParam.goodsAdvantageLabelTypes = prodInfo.goodsAdvantageLabelVOList != null ?
prodInfo.goodsAdvantageLabelVOList : new List<object>();
prodParam.goodsLayerDecorationCustomizeI18nReqs = prodInfo.goodsLayerDecorationCustomizeI18nVOList;
//详情图
prodParam.goodsLayerDecorationReqs = new List<GoodsLayerDecorationReqsItem>();
foreach (var goodsLayerDecorationVOInfo in (prodInfo.goodsLayerDecorationVOList == null ?
new List<TemuGoodsLayerDecorationVO>() : prodInfo.goodsLayerDecorationVOList))
@@ -1661,6 +1663,11 @@ namespace TemuKJD.KJDForms.ProductSelectForms
var rst = GetHtml.PostUtf8(url, data);
}
skuItem.thumbUrl = imgUrlRst;
if(aiSkuImgInfo.img_base64_db_id > 0)
{
// 使用次数+1
aiSkuImgInfo.is_use = true;
}
Thread.Sleep(Randomx.GetId(50, 100));
}
}
@@ -1672,55 +1679,141 @@ namespace TemuKJD.KJDForms.ProductSelectForms
}
// aisku图转主,放在sku处理完之后,这样少读取一次
if (chkAiSkuAndMainImg.Checked)
if (chkAiSkuAndMainImg.Checked && aiImgInfoList.Count > 0)
{
if (aiImgInfoList.Count > 0)
var randomImgLst = new List<AiSkuImgInfo>();
foreach (var url in prodParam.carouselImageUrls)
{
var randomImgLst = new List<AiSkuImgInfo>();
foreach(var url in prodParam.carouselImageUrls)
randomImgLst.Add(new AiSkuImgInfo() { img_url = url });
}
randomImgLst.AddRange(aiImgInfoList);
randomImgLst = randomImgLst.OrderBy(x => Guid.NewGuid()).Take(prodParam.carouselImageUrls.Count).ToList();
foreach (var imgInfo in randomImgLst)
{
if (string.IsNullOrEmpty(imgInfo.img_url))
{
randomImgLst.Add(new AiSkuImgInfo() { img_url = url });
}
randomImgLst.AddRange(aiImgInfoList);
randomImgLst = randomImgLst.OrderBy(x => Guid.NewGuid()).Take(prodParam.carouselImageUrls.Count).ToList();
var imgUrlRst = UploadAiSkuImg(shop, prodParam.productDraftId.ParseToString(), imgInfo.img_base64, imgInfo.img_md5);
if (imgUrlRst.Contains("\"success\":false"))
return imgUrlRst;
imgInfo.img_url = imgUrlRst;
foreach (var imgInfo in randomImgLst)
var url = BaseClass.BuildObjString("product/mdy_base64_img_url");
var data = UserLogin.GetSignaturex() +
"&db_id=" + imgInfo.img_base64_db_id;
data += "&img_url=" + imgUrlRst;
var rst = GetHtml.PostUtf8(url, data);
Thread.Sleep(Randomx.GetId(100, 300));
}
if (imgInfo.img_base64_db_id > 0)
{
if (string.IsNullOrEmpty(imgInfo.img_url))
{
var imgUrlRst = UploadAiSkuImg(shop, prodParam.productDraftId.ParseToString(), imgInfo.img_base64, imgInfo.img_md5);
if (imgUrlRst.Contains("\"success\":false"))
return imgUrlRst;
imgInfo.img_url = imgUrlRst;
var url = BaseClass.BuildObjString("product/mdy_base64_img_url");
var data = UserLogin.GetSignaturex() +
"&db_id=" + imgInfo.img_base64_db_id;
data += "&img_url=" + imgUrlRst;
var rst = GetHtml.PostUtf8(url, data);
Thread.Sleep(Randomx.GetId(100, 300));
}
// 使用次数+1
imgInfo.is_use = true;
}
prodParam.carouselImageUrls = randomImgLst.Select(r => r.img_url).ToList();
prodParam.materialImgUrl = prodParam.carouselImageUrls[Randomx.GetId(prodParam.carouselImageUrls.Count)];
}
prodParam.carouselImageUrls = randomImgLst.Select(r => r.img_url).ToList();
prodParam.materialImgUrl = prodParam.carouselImageUrls[Randomx.GetId(prodParam.carouselImageUrls.Count)];
try
{
prodParam.productSkcReqs[0].previewImgUrls[0] = prodParam.carouselImageUrls[0];
}
catch
{
try
{
prodParam.productSkcReqs[0].previewImgUrls[0] = prodParam.carouselImageUrls[0];
}
catch
{
}
}
}
}
if (cancellationTokenSource.IsCancellationRequested)
// aisku图转详情图
if (chkAiSkuAndMainImg.Checked && aiImgInfoList.Count > 0)
{
return "{\"success\":false,\"status\":\"未上传\"," +
"\"productDraftId\":\"" + prodParam.productDraftId.ParseToString() + "\"," +
"\"errMsg\":\"上传停止\"}";
var randomImgLst = new List<AiSkuImgInfo>();
var decorationImgs = prodParam.goodsLayerDecorationReqs.Where(d => d.type == "image" && d.contentList.Count > 0).ToList();
foreach (var decoration in decorationImgs)
{
randomImgLst.Add(new AiSkuImgInfo()
{
img_url = decoration.contentList[0].imgUrl,
width = decoration.contentList[0].width.ParseToInt(),
height = decoration.contentList[0].height.ParseToInt(),
});
prodParam.goodsLayerDecorationReqs.Remove(decoration);
}
randomImgLst.AddRange(aiImgInfoList);
int takeCount = decorationImgs.Count > 0 ? decorationImgs.Count : Randomx.GetId(6, 11);
randomImgLst = randomImgLst.OrderBy(x => Guid.NewGuid()).Take(takeCount).ToList();
foreach (var imgInfo in randomImgLst)
{
if (string.IsNullOrEmpty(imgInfo.img_url))
{
var imgUrlRst = UploadAiSkuImg(shop, prodParam.productDraftId.ParseToString(), imgInfo.img_base64, imgInfo.img_md5);
if (imgUrlRst.Contains("\"success\":false"))
return imgUrlRst;
imgInfo.img_url = imgUrlRst;
var url = BaseClass.BuildObjString("product/mdy_base64_img_url");
var data = UserLogin.GetSignaturex() +
"&db_id=" + imgInfo.img_base64_db_id;
data += "&img_url=" + imgUrlRst;
var rst = GetHtml.PostUtf8(url, data);
Thread.Sleep(Randomx.GetId(100, 300));
}
if (imgInfo.img_base64_db_id > 0)
{
// 使用次数+1
imgInfo.is_use = true;
}
}
foreach(var imgInfo in randomImgLst)
{
var decorationImg = decorationImgs.FirstOrDefault(d => d.contentList[0].imgUrl == imgInfo.img_url);
if (decorationImg == null)
{
decorationImg = new GoodsLayerDecorationReqsItem()
{
floorId = null,
lang = "zh",
key = "DecImage",
type = "image",
priority = 0,
contentList = new List<ContentListItem>(),
};
decorationImg.contentList.Add(new ContentListItem()
{
height = 800,
width = 800,
imgUrl = imgInfo.img_url,
});
}
if (decorationImg != null)
{
prodParam.goodsLayerDecorationReqs.Add(decorationImg);
}
}
for (int i = 0; i < prodParam.goodsLayerDecorationReqs.Count; i++)
{
prodParam.goodsLayerDecorationReqs[i].priority = i;
}
}
// aisku图转详情图
if (chkAiSkuAndMainImg.Checked && aiImgInfoList.Count > 0)
{
var img_base64_db_ids = aiImgInfoList.Where(img => img.is_use == true).Select(img => img.img_base64_db_id);
var url = BaseClass.BuildObjString("product/mdy_base64_img_use_count");
var data = UserLogin.GetSignaturex() +
"&db_ids=" + string.Join(",", img_base64_db_ids);
var rst = GetHtml.PostUtf8(url, data);
if (cancellationTokenSource.IsCancellationRequested)
{
return "{\"success\":false,\"status\":\"未上传\"," +
"\"productDraftId\":\"" + prodParam.productDraftId.ParseToString() + "\"," +
"\"errMsg\":\"上传停止\"}";
}
}
#region 尺码表