ai图片随机作为sku图或者主图上传商品
This commit is contained in:
1 parent
0d3ab6321e
commit
ec8736b8f9
31 files changed
+3169
-75
No files matched your search
@@ -30,6 +30,7 @@
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DbProductEditNotesForm));
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.btnSkuAi = new TemuKJD.UserControls.ButtonEx();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.txtFissionWords = new DevComponents.DotNetBar.Controls.TextBoxX();
|
||||
this.txtEndWords = new System.Windows.Forms.TextBox();
|
||||
@@ -55,6 +56,7 @@
|
||||
// panel2
|
||||
//
|
||||
this.panel2.BackColor = System.Drawing.Color.White;
|
||||
this.panel2.Controls.Add(this.btnSkuAi);
|
||||
this.panel2.Controls.Add(this.label7);
|
||||
this.panel2.Controls.Add(this.txtFissionWords);
|
||||
this.panel2.Controls.Add(this.txtEndWords);
|
||||
@@ -79,6 +81,23 @@
|
||||
this.panel2.Size = new System.Drawing.Size(464, 686);
|
||||
this.panel2.TabIndex = 1;
|
||||
//
|
||||
// btnSkuAi
|
||||
//
|
||||
this.btnSkuAi.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnSkuAi.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255)))));
|
||||
this.btnSkuAi.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnSkuAi.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btnSkuAi.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnSkuAi.ForeColor = System.Drawing.Color.White;
|
||||
this.btnSkuAi.Location = new System.Drawing.Point(90, 640);
|
||||
this.btnSkuAi.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.btnSkuAi.Name = "btnSkuAi";
|
||||
this.btnSkuAi.Size = new System.Drawing.Size(77, 26);
|
||||
this.btnSkuAi.TabIndex = 404;
|
||||
this.btnSkuAi.Text = "SKU AI图";
|
||||
this.btnSkuAi.UseVisualStyleBackColor = false;
|
||||
this.btnSkuAi.Click += new System.EventHandler(this.btnSkuAi_Click);
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.AutoSize = true;
|
||||
@@ -318,5 +337,6 @@
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.TextBox txtHeadWords;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private UserControls.ButtonEx btnSkuAi;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AllBase;
|
||||
using Work;
|
||||
using TemuKJD.ToolForms;
|
||||
|
||||
namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
{
|
||||
@@ -73,5 +74,11 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSkuAi_Click(object sender, EventArgs e)
|
||||
{
|
||||
DouBaoImgCefForm doubaoForm = new DouBaoImgCefForm(dbProd);
|
||||
doubaoForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
-16
@@ -39,6 +39,7 @@
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DbProductSelectListManageForm));
|
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||
this.chkAiSkuAndMainImg = new TemuKJD.UserComponent.UcCheckBox(this.components);
|
||||
this.chkLongTitle = new TemuKJD.UserComponent.UcCheckBox(this.components);
|
||||
this.chkSameExtcodeRandomMainImg = new TemuKJD.UserComponent.UcCheckBox(this.components);
|
||||
this.lblSkuRandomLetterNotes = new System.Windows.Forms.Label();
|
||||
@@ -112,7 +113,7 @@
|
||||
this.chkAddPrice = new TemuKJD.UserComponent.UcCheckBox(this.components);
|
||||
this.chkEnglishProdName = new TemuKJD.UserComponent.UcCheckBox(this.components);
|
||||
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
|
||||
this.pnlError = new System.Windows.Forms.Panel();
|
||||
this.pnlError = new DevComponents.DotNetBar.PanelEx();
|
||||
this.lblError = new System.Windows.Forms.Label();
|
||||
this.pbLoading = new System.Windows.Forms.PictureBox();
|
||||
this.lblCustomImgNum = new System.Windows.Forms.Label();
|
||||
@@ -189,6 +190,7 @@
|
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.Controls.Add(this.chkAiSkuAndMainImg);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.chkLongTitle);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.chkSameExtcodeRandomMainImg);
|
||||
this.splitContainer1.Panel1.Controls.Add(this.lblSkuRandomLetterNotes);
|
||||
@@ -226,14 +228,26 @@
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.splitContainer2);
|
||||
this.splitContainer1.Size = new System.Drawing.Size(1558, 638);
|
||||
this.splitContainer1.SplitterDistance = 100;
|
||||
this.splitContainer1.SplitterDistance = 125;
|
||||
this.splitContainer1.TabIndex = 2;
|
||||
//
|
||||
// chkAiSkuAndMainImg
|
||||
//
|
||||
this.chkAiSkuAndMainImg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.chkAiSkuAndMainImg.AutoSize = true;
|
||||
this.chkAiSkuAndMainImg.Location = new System.Drawing.Point(1410, 98);
|
||||
this.chkAiSkuAndMainImg.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
|
||||
this.chkAiSkuAndMainImg.Name = "chkAiSkuAndMainImg";
|
||||
this.chkAiSkuAndMainImg.Size = new System.Drawing.Size(152, 21);
|
||||
this.chkAiSkuAndMainImg.TabIndex = 680;
|
||||
this.chkAiSkuAndMainImg.Text = "sku随机AI图+随机转主";
|
||||
this.chkAiSkuAndMainImg.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// chkLongTitle
|
||||
//
|
||||
this.chkLongTitle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.chkLongTitle.AutoSize = true;
|
||||
this.chkLongTitle.Location = new System.Drawing.Point(1276, 73);
|
||||
this.chkLongTitle.Location = new System.Drawing.Point(1126, 98);
|
||||
this.chkLongTitle.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
|
||||
this.chkLongTitle.Name = "chkLongTitle";
|
||||
this.chkLongTitle.Size = new System.Drawing.Size(96, 21);
|
||||
@@ -245,7 +259,7 @@
|
||||
//
|
||||
this.chkSameExtcodeRandomMainImg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.chkSameExtcodeRandomMainImg.AutoSize = true;
|
||||
this.chkSameExtcodeRandomMainImg.Location = new System.Drawing.Point(1372, 73);
|
||||
this.chkSameExtcodeRandomMainImg.Location = new System.Drawing.Point(1222, 98);
|
||||
this.chkSameExtcodeRandomMainImg.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
|
||||
this.chkSameExtcodeRandomMainImg.Name = "chkSameExtcodeRandomMainImg";
|
||||
this.chkSameExtcodeRandomMainImg.Size = new System.Drawing.Size(188, 21);
|
||||
@@ -256,12 +270,12 @@
|
||||
// lblSkuRandomLetterNotes
|
||||
//
|
||||
this.lblSkuRandomLetterNotes.AutoSize = true;
|
||||
this.lblSkuRandomLetterNotes.Font = new System.Drawing.Font("微软雅黑", 8F);
|
||||
this.lblSkuRandomLetterNotes.Font = new System.Drawing.Font("微软雅黑", 9F);
|
||||
this.lblSkuRandomLetterNotes.ForeColor = System.Drawing.SystemColors.MenuHighlight;
|
||||
this.lblSkuRandomLetterNotes.Location = new System.Drawing.Point(959, 75);
|
||||
this.lblSkuRandomLetterNotes.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
|
||||
this.lblSkuRandomLetterNotes.Name = "lblSkuRandomLetterNotes";
|
||||
this.lblSkuRandomLetterNotes.Size = new System.Drawing.Size(138, 16);
|
||||
this.lblSkuRandomLetterNotes.Size = new System.Drawing.Size(150, 17);
|
||||
this.lblSkuRandomLetterNotes.TabIndex = 641;
|
||||
this.lblSkuRandomLetterNotes.Text = "备注:当前特殊字符包括--";
|
||||
//
|
||||
@@ -1302,7 +1316,7 @@
|
||||
//
|
||||
this.chkEnglishProdName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.chkEnglishProdName.AutoSize = true;
|
||||
this.chkEnglishProdName.Location = new System.Drawing.Point(1203, 73);
|
||||
this.chkEnglishProdName.Location = new System.Drawing.Point(1053, 98);
|
||||
this.chkEnglishProdName.Margin = new System.Windows.Forms.Padding(6, 0, 0, 0);
|
||||
this.chkEnglishProdName.Name = "chkEnglishProdName";
|
||||
this.chkEnglishProdName.Size = new System.Drawing.Size(75, 21);
|
||||
@@ -1335,19 +1349,28 @@
|
||||
//
|
||||
this.splitContainer2.Panel2.Controls.Add(this.ucSplitPage1);
|
||||
this.splitContainer2.Panel2.Controls.Add(this.statusBar);
|
||||
this.splitContainer2.Size = new System.Drawing.Size(1558, 534);
|
||||
this.splitContainer2.SplitterDistance = 505;
|
||||
this.splitContainer2.Size = new System.Drawing.Size(1558, 509);
|
||||
this.splitContainer2.SplitterDistance = 480;
|
||||
this.splitContainer2.TabIndex = 0;
|
||||
//
|
||||
// pnlError
|
||||
//
|
||||
this.pnlError.Anchor = System.Windows.Forms.AnchorStyles.Top;
|
||||
this.pnlError.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(244)))), ((int)(((byte)(224)))));
|
||||
this.pnlError.CanvasColor = System.Drawing.SystemColors.Control;
|
||||
this.pnlError.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
|
||||
this.pnlError.Controls.Add(this.lblError);
|
||||
this.pnlError.Location = new System.Drawing.Point(650, 95);
|
||||
this.pnlError.DisabledBackColor = System.Drawing.Color.Empty;
|
||||
this.pnlError.Location = new System.Drawing.Point(650, 91);
|
||||
this.pnlError.Name = "pnlError";
|
||||
this.pnlError.Size = new System.Drawing.Size(259, 120);
|
||||
this.pnlError.TabIndex = 488;
|
||||
this.pnlError.Size = new System.Drawing.Size(259, 118);
|
||||
this.pnlError.Style.Alignment = System.Drawing.StringAlignment.Center;
|
||||
this.pnlError.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground;
|
||||
this.pnlError.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(227)))), ((int)(((byte)(239)))), ((int)(((byte)(255)))));
|
||||
this.pnlError.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
|
||||
this.pnlError.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
|
||||
this.pnlError.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText;
|
||||
this.pnlError.Style.GradientAngle = 90;
|
||||
this.pnlError.TabIndex = 492;
|
||||
this.pnlError.Visible = false;
|
||||
//
|
||||
// lblError
|
||||
@@ -1363,7 +1386,7 @@
|
||||
//
|
||||
this.pbLoading.Anchor = System.Windows.Forms.AnchorStyles.None;
|
||||
this.pbLoading.Image = global::TemuKJD.Properties.Resources.loading_blue;
|
||||
this.pbLoading.Location = new System.Drawing.Point(754, 227);
|
||||
this.pbLoading.Location = new System.Drawing.Point(754, 215);
|
||||
this.pbLoading.Name = "pbLoading";
|
||||
this.pbLoading.Size = new System.Drawing.Size(50, 50);
|
||||
this.pbLoading.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
@@ -1497,7 +1520,7 @@
|
||||
this.dgvSelectProduct.ReadOnly = true;
|
||||
this.dgvSelectProduct.RowHeadersWidth = 40;
|
||||
this.dgvSelectProduct.RowTemplate.Height = 23;
|
||||
this.dgvSelectProduct.Size = new System.Drawing.Size(1550, 505);
|
||||
this.dgvSelectProduct.Size = new System.Drawing.Size(1550, 480);
|
||||
this.dgvSelectProduct.TabIndex = 189;
|
||||
this.dgvSelectProduct.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvSelectProduct_CellContentClick);
|
||||
this.dgvSelectProduct.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dgvSelectProduct_Scroll);
|
||||
@@ -1896,7 +1919,8 @@
|
||||
private UserComponent.UcCheckBox chkSameExtcodeRandomMainImg;
|
||||
private UserComponent.UcCheckBox chkLongTitle;
|
||||
private UserComponent.UcCheckBox chkEnglishProdName;
|
||||
private System.Windows.Forms.Panel pnlError;
|
||||
private System.Windows.Forms.Label lblError;
|
||||
private UserComponent.UcCheckBox chkAiSkuAndMainImg;
|
||||
private DevComponents.DotNetBar.PanelEx pnlError;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ using System.Text.RegularExpressions;
|
||||
using TemuKJD.BLL;
|
||||
using TemuKJD.ToolForms;
|
||||
using AllBase.Model.Result.TemuResult.TemuSizeConfigResult;
|
||||
using AllBase.Model.Result.TemuResult;
|
||||
|
||||
namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
{
|
||||
@@ -980,6 +981,8 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
prodParam.carouselImageUrls = prodInfo.carouselImageUrls;
|
||||
|
||||
List<ProductSkuReqsItem> realSkuItems = new List<ProductSkuReqsItem>();
|
||||
Dictionary<string, AiSkuImgInfo> aiImgInfoDic = new Dictionary<string, AiSkuImgInfo>();
|
||||
List<AiSkuImgInfo> aiImgInfoList = new List<AiSkuImgInfo>();
|
||||
List<string> realCarouselImageUrls = new List<string>();
|
||||
realCarouselImageUrls.AddRange(prodInfo.carouselImageUrls);
|
||||
|
||||
@@ -999,8 +1002,8 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
{
|
||||
var sameExtCodeDBProdLst = GetProductSameExtCodeDetailList(dbProd.ext_code);
|
||||
var sameExtCodeProdInfoLst = new List<TemuDetailProductInfo>();
|
||||
var sameExtCodeMainImgUrlLst = new List<string>();
|
||||
var sameExtCodeSkuImgUrlLst = new List<string>();
|
||||
var sameExtCodeMainImgUrlLst = new List<string>(); // 同货号商品主图
|
||||
var sameExtCodeSkuImgUrlLst = new List<string>(); // 同货号商品sku图
|
||||
try
|
||||
{
|
||||
foreach(var sameExtCodeDbProd in sameExtCodeDBProdLst)
|
||||
@@ -1410,7 +1413,7 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
}));
|
||||
}
|
||||
|
||||
#region 随机打乱sku顺序
|
||||
#region 按顺序抽取sku或抽取随机打乱顺序的sku
|
||||
int id = 0;
|
||||
if (chkRandomSkuOrder.Checked)
|
||||
id = Randomx.GetId(0, skuListTmp.Count);
|
||||
@@ -1606,6 +1609,61 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
skuItem.thumbUrl = imgUrlRst;
|
||||
Thread.Sleep(Randomx.GetId(50, 100));
|
||||
}
|
||||
//自定义ai图(ai图sku)
|
||||
if (chkAiSkuAndMainImg.Checked)
|
||||
{
|
||||
var skuCopy = JsonHelper.DeserializeJsonToObject<ProductSkuReqsItem>(JsonHelper.SerializeObject(skuItem));
|
||||
realSkuItems.Add(skuCopy);
|
||||
|
||||
AiSkuImgInfo aiSkuImgInfo = null;
|
||||
// 把每次随出来的图片暂存起来,相同颜色规格的sku直接获取图片地址即可
|
||||
if (aiImgInfoDic.Keys.Contains(skuInfo.productSkuSpecList[0].specId.ParseToString()))
|
||||
aiSkuImgInfo = aiImgInfoDic[skuInfo.productSkuSpecList[0].specId.ParseToString()];
|
||||
else
|
||||
{
|
||||
var aiSkuImgLst = DouBaoImgCefForm.GetSkuImgList(prodInfo.productId.ParseToString(), skuInfo.productSkuSpecList[0].specId.ParseToString());
|
||||
if (aiSkuImgLst.Count > 0)
|
||||
{
|
||||
aiImgInfoList.AddRange(aiSkuImgLst);
|
||||
|
||||
int index = Randomx.GetId(aiSkuImgLst.Count + 1);
|
||||
if (index == aiSkuImgLst.Count)
|
||||
{
|
||||
aiSkuImgInfo = new AiSkuImgInfo()
|
||||
{
|
||||
product_id = prodInfo.productId.ParseToString(),
|
||||
spec_id = skuInfo.productSkuSpecList[0].specId.ParseToString(),
|
||||
spec_name = skuInfo.productSkuSpecList[0].specName,
|
||||
img_url = skuInfo.thumbUrl,
|
||||
original_img_url = skuInfo.thumbUrl,
|
||||
};
|
||||
}
|
||||
else
|
||||
aiSkuImgInfo = aiSkuImgLst[index];
|
||||
aiImgInfoDic[skuInfo.productSkuSpecList[0].specId.ParseToString()] = aiSkuImgInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (aiSkuImgInfo != null)
|
||||
{
|
||||
var imgUrlRst = aiSkuImgInfo.img_url;
|
||||
if (string.IsNullOrEmpty(imgUrlRst))
|
||||
{
|
||||
imgUrlRst = UploadAiSkuImg(shop, prodParam.productDraftId.ParseToString(), aiSkuImgInfo.img_base64, aiSkuImgInfo.img_md5);
|
||||
if (imgUrlRst.Contains("\"success\":false"))
|
||||
return imgUrlRst;
|
||||
aiSkuImgInfo.img_url = imgUrlRst;
|
||||
|
||||
var url = BaseClass.BuildObjString("product/mdy_base64_img_url");
|
||||
var data = UserLogin.GetSignaturex() +
|
||||
"&db_id=" + aiSkuImgInfo.img_base64_db_id;
|
||||
data += "&img_url=" + imgUrlRst;
|
||||
var rst = GetHtml.PostUtf8(url, data);
|
||||
}
|
||||
skuItem.thumbUrl = imgUrlRst;
|
||||
Thread.Sleep(Randomx.GetId(50, 100));
|
||||
}
|
||||
}
|
||||
|
||||
skcItem.productSkuReqs.Add(skuItem);
|
||||
}
|
||||
@@ -1613,6 +1671,51 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
prodParam.productSkcReqs.Add(skcItem);
|
||||
}
|
||||
|
||||
// aisku图转主,放在sku处理完之后,这样少读取一次
|
||||
if (chkAiSkuAndMainImg.Checked)
|
||||
{
|
||||
if (aiImgInfoList.Count > 0)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
return "{\"success\":false,\"status\":\"未上传\"," +
|
||||
@@ -2046,6 +2149,104 @@ namespace TemuKJD.KJDForms.ProductSelectForms
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传主图或sku等的Ai图片
|
||||
/// </summary>
|
||||
/// <param name="shop"></param>
|
||||
/// <param name="productDraftId"></param>
|
||||
/// <param name="imgBase64"></param>
|
||||
/// <param name="imgMd5"></param>
|
||||
/// <returns></returns>
|
||||
string UploadAiSkuImg(ShopLoginInfo shop, string productDraftId, string imgBase64, string imgMd5)
|
||||
{
|
||||
var md5CheckRst = CheckImgMd5(shop, productDraftId, "", imgMd5);
|
||||
if (!md5CheckRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref md5CheckRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref md5CheckRst, "error_msg");
|
||||
return "{\"success\":false,\"status\":\"未上传\"," +
|
||||
"\"productDraftId\":\"" + productDraftId + "\"," +
|
||||
"\"errMsg\":\"草稿箱上传失败 " + error + "\"}";
|
||||
}
|
||||
var materialId = BaseRegex.GetStringJson(ref md5CheckRst, "id");
|
||||
if (string.IsNullOrEmpty(materialId))
|
||||
{
|
||||
var imgUpSignRst = GetImgUpSign(shop, productDraftId);
|
||||
string signature = BaseRegex.GetStringJson(ref imgUpSignRst, "signature");
|
||||
if (string.IsNullOrEmpty(signature))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref imgUpSignRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref imgUpSignRst, "error_msg");
|
||||
return "{\"success\":false,\"status\":\"未上传\"," +
|
||||
"\"productDraftId\":\"" + productDraftId + "\"," +
|
||||
"\"errMsg\":\"草稿箱上传失败,获取图片上传signature失败 " + error + "\"}";
|
||||
}
|
||||
// 创建临时图片路径
|
||||
string sImgPath = "";
|
||||
if (DriveInfo.GetDrives().Any(drive => drive.Name.Equals("D:\\", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
sImgPath = "D:\\tmp_img";
|
||||
}
|
||||
else if (DriveInfo.GetDrives().Any(drive => drive.Name.Equals("E:\\", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
sImgPath = "E:\\tmp_img";
|
||||
}
|
||||
else
|
||||
{
|
||||
sImgPath = "C:\\tmp_img";
|
||||
}
|
||||
if (!Directory.Exists(sImgPath))
|
||||
{
|
||||
Directory.CreateDirectory(sImgPath);
|
||||
}
|
||||
string imgName = "\\图片" + Randomx.GetId(1000, 9999) + ".jpg";
|
||||
sImgPath += imgName;
|
||||
// 使用MemoryStream创建图片对象
|
||||
byte[] imageBytes = Convert.FromBase64String(imgBase64);
|
||||
using (MemoryStream ms = new MemoryStream(imageBytes))
|
||||
{
|
||||
Image image = Image.FromStream(ms);
|
||||
// 保存图片到文件系统
|
||||
try
|
||||
{
|
||||
image.Save(sImgPath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
}
|
||||
catch (Exception ex) { return "存图失败 " + ex.Message; }
|
||||
}
|
||||
var uploadImgRst = UploadImage(shop, productDraftId, sImgPath, signature);
|
||||
var imgUrl = BaseRegex.GetStringJson(ref uploadImgRst, "url");
|
||||
|
||||
if (string.IsNullOrEmpty(signature))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref uploadImgRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref uploadImgRst, "error_msg");
|
||||
return "{\"success\":false,\"status\":\"未上传\"," +
|
||||
"\"productDraftId\":\"" + productDraftId + "\"," +
|
||||
"\"errMsg\":\"草稿箱上传失败,上传图片失败 " + error + "\"}";
|
||||
}
|
||||
|
||||
return imgUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
var existImgRst = this.GetExistImg(shop, productDraftId, materialId);
|
||||
string imgUrl = BaseRegex.GetStringJson(ref existImgRst, "imgUrl");
|
||||
if (string.IsNullOrEmpty(materialId))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref existImgRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = BaseRegex.GetStringJson(ref existImgRst, "error_msg");
|
||||
return "{\"success\":false,\"status\":\"未上传\"," +
|
||||
"\"productDraftId\":\"" + productDraftId + "\"," +
|
||||
"\"errMsg\":\"草稿箱上传失败,获取已存在图片失败 " + error + "\"}";
|
||||
}
|
||||
return imgUrl;
|
||||
}
|
||||
}
|
||||
|
||||
private string AddDraft(ShopLoginInfo shop, string catId)
|
||||
{
|
||||
//string url = "https://seller.kuajingmaihuo.com/bg-visage-mms/product/draft/add";
|
||||
|
||||
Reference in new issue
Block a user