书籍类目上传

This commit is contained in:
wule_5900x committed 2026-01-18 20:40:11 +08:00
1 parent dbc954a200
commit 2ae38c8105
10 files changed
+339 -89

No files matched your search

@@ -1286,7 +1286,7 @@ namespace TemuKJD.WXForms.ProductForms
}
// 检测是否有类目上传权限
long leafCatId = (upProdParam.product.info.category.LastOrDefault()?.catId).ParseToLong();
long leafCatId = (upProdParam.product.info.category.LastOrDefault()?.catId).ParseToLong(); //哲学经典著作
var cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId);
if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true"))
{
@@ -1333,7 +1333,6 @@ namespace TemuKJD.WXForms.ProductForms
upProdParam.product.info.aiGenShortTitle = upProdParam.product.info.shortTitle;
#endregion
#region 售后信息
var addressRst = WXUpload.getAddress(shop);
if (!addressRst.Contains("\"code\":0") && !addressRst.Contains("\"success\":true"))
@@ -1360,6 +1359,7 @@ namespace TemuKJD.WXForms.ProductForms
upProdParam.product.info.expressInfo.templateId = BaseRegex.GetStringJson(ref expressRst, "templateId");
#endregion
#region 详情图
if (cell != null)
{
Invoke(new Action(() =>
@@ -1368,9 +1368,11 @@ namespace TemuKJD.WXForms.ProductForms
}));
}
Thread.Sleep(Randomx.GetId(500, 800));
#region 详情图
upProdParam.product.info.detail = new productDetailParam(); // 详情图
foreach (var gallery_item in prodInfo.detail.galleries.Where(g => g.type == 2))
var detailGalleries = prodInfo.detail.galleries.Where(g => g.type == 2).ToList();
if (detailGalleries.Count == 0)
detailGalleries.Add(new gallery_item() { type = 2, url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
foreach (var gallery_item in detailGalleries)
{
var locationStr = UploadImg(shop, gallery_item.url, cell);
if (!locationStr.Contains("\"success\":true"))
@@ -1402,6 +1404,29 @@ namespace TemuKJD.WXForms.ProductForms
{
attr = productAttr.attr.FirstOrDefault(r => r.name == "填充物种类" || r.name == "填充物");
}
// 书籍类目匹配
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
{
if (propInfo.name == "出版社名称")
attr = productAttr.attr.FirstOrDefault(r => r.name == "出版社名称");
else if (propInfo.name == "ISBN编号")
attr = productAttr.attr.FirstOrDefault(r => r.name == "ISBN版号/CN刊号");
else if (propInfo.name == "书名")
attr = productAttr.attr.FirstOrDefault(r => r.name == "书名");
else if (propInfo.name == "定价")
attr = productAttr.attr.FirstOrDefault(r => r.name == "定价");
else if (propInfo.name == "作者")
attr = productAttr.attr.FirstOrDefault(r => r.name == "作者");
else if (propInfo.name == "出版时间")
attr = productAttr.attr.FirstOrDefault(r => r.name == "出版时间");
else if (propInfo.name == "版次")
attr = productAttr.attr.FirstOrDefault(r => r.name == "版次");
else if (propInfo.name == "装帧类型")
attr = productAttr.attr.FirstOrDefault(r => r.name == "包装");
else if (propInfo.name == "包册数")
attr = productAttr.attr.FirstOrDefault(r => r.name == "图书册数");
}
}
if (attr == null)
{
@@ -1417,6 +1442,18 @@ namespace TemuKJD.WXForms.ProductForms
{
attrValue = propInfo.values.FirstOrDefault()?.value;
}
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
{
if (attrValue.IsNullOrEmpty() && attr.type == "integer_unit" && (propInfo.values.FirstOrDefault()?.value).IsNumber())
{
attrValue = propInfo.values.FirstOrDefault()?.value + " " + attr.value.Split(';').FirstOrDefault();
}
if (attrValue.IsNullOrEmpty() && attr.name == "包装")
{
if (propInfo.values.FirstOrDefault()?.value == "平装-胶订")
attrValue = "平装";
}
}
if (attrValue.IsNullOrEmpty() && attr.isRequired == true)
{
if (attrValueLst.Contains("其他"))
@@ -1481,10 +1518,6 @@ namespace TemuKJD.WXForms.ProductForms
var attrValueLst = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
string attrValue = "";
if (attr.type == "string")
{
attrValue = "其他";
}
if (attrValue.IsNullOrEmpty() && attr.isRequired == true)
{
if (attrValueLst.Contains("其他"))
@@ -1503,6 +1536,25 @@ namespace TemuKJD.WXForms.ProductForms
}
else
attrValue = attrValueLst.Where(v => !"真丝、蚕丝、香云纱、羊绒、羊毛、羊羔绒、羊羔毛、羽绒、皮草".Contains(v)).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
//书籍属性处理
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
{
if (attr.name == "是否为单一书号丛书")
attrValue = "是";
if (attr.name == "图书册数")
attrValue = "1 册";
if (attr.name == "出版社名称")
attrValue = new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
if (attr.name == "作者")
attrValue = new List<string>() { "李老师", "张老师", "王老师" }[Randomx.GetId(3)];
if (attr.name == "包装")
attrValue = "平装";
}
}
if (attrValue.IsNullOrEmpty() && attr.type == "string")
{
attrValue = "其他";
}
if (attr.type == "decimal4_unit" || attr.type == "integer_unit")
{
@@ -1535,6 +1587,7 @@ namespace TemuKJD.WXForms.ProductForms
}
#endregion
#region sku规格属性
if (cell != null)
{
@@ -1545,8 +1598,17 @@ namespace TemuKJD.WXForms.ProductForms
}
Thread.Sleep(1000);
#region sku规格属性
upProdParam.product.info.productSaleAttrs = new List<productSaleAttrParam>();
if (prodInfo.detail.sku == null)
prodInfo.detail.sku = new List<sku_item>();
if (prodInfo.detail.sku.Count == 0)
prodInfo.detail.sku.Add(new sku_item() { spec = new List<spec_item>() });
if (prodInfo.detail.sku.FirstOrDefault().spec == null)
prodInfo.detail.sku.FirstOrDefault().spec = new List<spec_item>();
if (prodInfo.detail.sku.FirstOrDefault().spec.Count == 0)
prodInfo.detail.sku.FirstOrDefault().spec.Add(new spec_item() { parent_name = "规格", spec_name = "默认" });
if (prodInfo.detail.sku.FirstOrDefault().thumb_url.IsNullOrEmpty())
prodInfo.detail.sku.FirstOrDefault().thumb_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url;
if (prodInfo.detail.sku.FirstOrDefault()?.spec?.Count > 0)
{
productSaleAttrParam attrParam = new productSaleAttrParam()
@@ -1692,6 +1754,76 @@ namespace TemuKJD.WXForms.ProductForms
}
#endregion
#region 书籍类生成书籍图片
//qualificationList
if (1 == 1)
{
if (cell != null)
{
Invoke(new Action(() =>
{
cell.Value = "正在生成图书专有信息";
}));
}
string publisher = "出版社:" + new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
string isbn = "ISBN:";
string bookName = "书名:";
string bookPrice = "定价:" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice) * 0.01;
string author = "作者:王老师";
string publishTime = "出版时间:" + DateTime.Now.AddMonths(-3);
string edition = "版次:1";
string binding = "装帧:平装";
foreach (var propParam in upProdParam.product.info.param)
{
if (propParam.categorys[0].name.Contains("出版社名称"))
publisher = "出版社:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("ISBN版号/CN刊号"))
isbn = "ISBN:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("书名"))
bookName = "书名:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("定价"))
bookPrice = "定价:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("作者"))
author = "作者:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("出版时间"))
publishTime = "出版时间:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("版次"))
edition = "版次:" + propParam.categorys[1].name;
else if (propParam.categorys[0].name.Contains("包装"))
binding = "装帧:" + propParam.categorys[1].name;
}
var bookStr = publisher + "\r\n" + "\r\n" +
isbn + "\r\n" + "\r\n" +
bookName + "\r\n" + "\r\n" +
bookPrice + "\r\n" + "\r\n" +
author + "\r\n" + "\r\n" +
publishTime + "\r\n" + "\r\n" +
edition + "\r\n" + "\r\n" +
binding;
var bookImg = new Bitmap(800, 800);
using (Graphics g = Graphics.FromImage(bookImg))
{
g.Clear(Color.White);
//Font font = new Font("宋体", 15, FontStyle.Bold);
Font font = new Font("微软雅黑", 15, FontStyle.Regular);
Brush textBrush = Brushes.Black;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
RectangleF rectF = new RectangleF(80, 80, 800 - 80, 800 - 80);
g.DrawString(bookStr, font, textBrush, rectF);
}
Thread.Sleep(Randomx.GetId(500, 800));
var locationStr = UploadImg(shop, bookImg, cell);
if (!locationStr.Contains("\"success\":true"))
return locationStr;
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "1111485", qualificationUrl = new List<string>() { location }, });
}
#endregion
if (cell != null)
{
@@ -1738,6 +1870,8 @@ namespace TemuKJD.WXForms.ProductForms
if (!uploadProdRst.Contains("\"code\":0") && !uploadProdRst.Contains("\"success\":true"))
{
var error = BaseRegex.GetStringJson(ref uploadProdRst, "msg");
if (string.IsNullOrEmpty(error))
error = BaseRegex.GetStringJson(ref uploadProdRst, "errmsg");
if (string.IsNullOrEmpty(error))
error = uploadProdRst;
return "{\"success\":false,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"草稿箱\",\"errMsg\":\"上架失败 " + error + "\"}";
@@ -1782,11 +1916,36 @@ namespace TemuKJD.WXForms.ProductForms
return "{\"success\":true,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"已上传\",\"msg\":\"上传成功\"}";
}
public string UploadImg(ShopLoginInfo shop, string img_url, DataGridViewCell cell = null)
{
string getImgError;
var image = GetHtml.GetUrlImg(img_url.Replace("https://", "http://"), out getImgError);
if (image == null)
image = new Bitmap(800, 800);
var imageBg = new Bitmap(image.Width, image.Height);
if (!string.IsNullOrEmpty(getImgError) || image == null)
{
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"初始化图片上传失败\"}";
}
try
{
using (Graphics g = Graphics.FromImage(imageBg))
{
g.DrawImage(image, new Rectangle(0, 0, imageBg.Width, imageBg.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
}
}
catch (Exception ex)
{
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + "修改图片失败 " + ex.Message + "\"}";
}
return UploadImg(shop, imageBg, cell);
}
public string UploadImg(ShopLoginInfo shop, Bitmap img, DataGridViewCell cell = null)
{
var upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
for (int i = 0; i < 10 && upImgAuthRst.Contains("LogicError"); i++)
@@ -1814,23 +1973,12 @@ namespace TemuKJD.WXForms.ProductForms
string imgBase64 = "";
//-------------------------------------------------------------------------------------------------------------------------------------
//生成详情图base64字符串
string getImgError;
var image = GetHtml.GetUrlImg(img_url.Replace("https://", "http://"), out getImgError);
var imageBg = new Bitmap(image.Width, image.Height);
if (!string.IsNullOrEmpty(getImgError) || image == null)
{
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"初始化图片上传失败\"}";
}
//生成图片base64字符串
try
{
using (Graphics g = Graphics.FromImage(imageBg))
{
g.DrawImage(image, new Rectangle(0, 0, imageBg.Width, imageBg.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
}
using (MemoryStream memoryStream = new MemoryStream())
{
imageBg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imageBytes = memoryStream.ToArray();
imgBase64 = Convert.ToBase64String(imageBytes);
}
@@ -1841,7 +1989,7 @@ namespace TemuKJD.WXForms.ProductForms
}
//-------------------------------------------------------------------------------------------------------------------------------------
//上传详情图,获取图片路径
//上传图片,获取图片路径
var upImgRst = WXUpload.adtimageupload(shop, imgBase64, disK, disT, ext).ParseToString();
var location = BaseRegex.GetStringJson(ref upImgRst, "Location");
if (string.IsNullOrEmpty(location))
@@ -2270,6 +2418,11 @@ Content-Type: image/jpeg
string referer = "https://store.weixin.qq.com/shop/goods/entry";
string body = @"{""categoryInfo"":{""categories"":[{""id"":""" + catId + @"""}]},""brandIdList"":[],""leafCategoryId"":""" + catId + @""",""reuse"":0,""applyType"":1}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
//{"categoryInfo":{"categories":[{"id":10000257},{"id":10000245},{"id":112888}],"categoryDeposit":"10000.00","isNewApplyCat":true,"licenseGroupList":[{"licenseGroupId":"17","license":{"licenseId":"5","cosIdList":["1768635607165-orc0V2WjFHdNvjNnk967_g14awFw-7487"],"licenseFieldList":[{"key":"audit_license_no","value":"新出发皖字第1027号"},{"key":"audit_license_validty_period","value":"2029-04-30"}],"isReuse":true}}],"ruleVersion":5234,"certificate":[]},"brandIdList":[],"leafCategoryId":112888,"reuse":0,"applyType":"normalApply"}
//{"code":0,"baseResp":{"errcode":0,"errmsg":"ok"},"auditId":"8362856529"}
//string body = @"{""categoryInfo"":{""categories"":[{""id"":10000257},{""id"":10000245},{""id"":112888}],""categoryDeposit"":""10000.00"",""isNewApplyCat"":true,""licenseGroupList"":[{""licenseGroupId"":""17"",""license"":{""licenseId"":""5"",""cosIdList"":[""1768635607165-orc0V2WjFHdNvjNnk967_g14awFw-7487""],""licenseFieldList"":[{""key"":""audit_license_no"",""value"":""新出发皖字第1027号""},{""key"":""audit_license_validty_period"",""value"":""2029-04-30""}],""isReuse"":true}}],""ruleVersion"":5234,""certificate"":[]},""brandIdList"":[],""leafCategoryId"":112888,""reuse"":0,""applyType"":""normalApply""}";
// request.Referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=%5B%2210000257%22%2C%2210000245%22%2C%22112888%22%5D&source=goods&type=apply";
return result;
}