添加商品改价回滚功能,优化图书上传
This commit is contained in:
1 parent
8f5debb85c
commit
5467acadc0
7 files changed
+476
-140
No files matched your search
@@ -3163,10 +3163,10 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
foreach (var wxEditCategoryParam in wxEditPropParam.categorys)
|
||||
{
|
||||
// 修改书名
|
||||
//if (wxEditPropParam.categorys.FirstOrDefault().name == "书名" && wxEditCategoryParam == wxEditPropParam.categorys.LastOrDefault())
|
||||
//{
|
||||
// wxEditCategoryParam.name = prodTitle;
|
||||
//}
|
||||
if (wxEditPropParam.categorys.FirstOrDefault().name == "书名" && wxEditCategoryParam == wxEditPropParam.categorys.LastOrDefault())
|
||||
{
|
||||
wxEditCategoryParam.name = prodTitle;
|
||||
}
|
||||
var wxCategoryParam = new categoryPropParam()
|
||||
{
|
||||
catType = wxEditCategoryParam.catType,
|
||||
@@ -3320,14 +3320,15 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
// 修改书名 作者
|
||||
//if (attr.name == "书名" /*&& dbProd.product_get_type_text == "微信小店"*/)
|
||||
//{
|
||||
// attrValue = prodTitle;
|
||||
//}
|
||||
//if (attr.name == "作者" && attrValue == "无")
|
||||
//{
|
||||
// attrValue = new List<string>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
//}
|
||||
if (attr.name == "书名" /*&& dbProd.product_get_type_text == "微信小店"*/)
|
||||
{
|
||||
attrValue = prodTitle;
|
||||
}
|
||||
if (attr.name == "作者" && attrValue == "无")
|
||||
{
|
||||
attrValue = new List<string>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
attrValue = "无";
|
||||
}
|
||||
|
||||
if (attrValue.IsNullOrEmpty() && attr.type == "integer_unit" && (propInfo.values.FirstOrDefault()?.value).IsNumber())
|
||||
{
|
||||
@@ -3603,7 +3604,10 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
if (attr.name == "出版社名称")
|
||||
attrValue = new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||||
if (attr.name == "作者")
|
||||
{
|
||||
attrValue = new List<string>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||||
attrValue = "无";
|
||||
}
|
||||
if (attr.name == "包装")
|
||||
attrValue = "平装";
|
||||
if (attr.name == "出版时间")
|
||||
@@ -3723,6 +3727,19 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
wxPropParam.categorys.Add(wxCategoryParam1);
|
||||
wxPropParam.categorys.Add(wxCategoryParam2);
|
||||
}
|
||||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||||
{
|
||||
foreach (var param in upProdParam.product.info.param.ToList())
|
||||
{
|
||||
if (param.categorys.FirstOrDefault()?.name == "作者" && param.categorys.LastOrDefault()?.name == "无")
|
||||
{
|
||||
param.categorys.LastOrDefault().name = upProdParam.product.info.param.FirstOrDefault(p => p.categorys.FirstOrDefault()?.name == "出版社名称")?.categorys?.LastOrDefault()?.name;
|
||||
if (param.categorys.LastOrDefault().name.IsNullOrEmpty())
|
||||
param.categorys.LastOrDefault().name = "无";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region sku规格属性
|
||||
@@ -4160,7 +4177,7 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
}
|
||||
// 微信店采直接复制
|
||||
else if (dbProd.product_get_type_text == "微信店采") //&& upProdParam.product.info.category.FirstOrDefault()?.name != "图书")
|
||||
else if (dbProd.product_get_type_text == "微信店采" && upProdParam.product.info.category.FirstOrDefault()?.name != "图书")
|
||||
{
|
||||
upProdParam.product.info.qualificationList.Clear();
|
||||
if (wxEditProdInfo.product?.info?.qualificationList?.Count > 0)
|
||||
@@ -4198,9 +4215,10 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
}
|
||||
|
||||
string publisher = "出版社名称:" + new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||||
string isbn = "ISBN:";
|
||||
string bookName = "书名:";
|
||||
//string bookName = "图书名称:";
|
||||
//string isbn = "ISBN:";
|
||||
string isbn = "ISBN/CN刊号:";
|
||||
//string bookName = "书名:";
|
||||
string bookName = "图书名称:";
|
||||
string bookPrice = "定价:" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice) * 0.01;
|
||||
string author = "作者:王老师";
|
||||
string publishTime = "出版时间:" + DateTime.Now.AddMonths(-3).ToString("yyyy年MM月dd日");
|
||||
@@ -4212,10 +4230,20 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
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;
|
||||
{
|
||||
//isbn = "ISBN:" + propParam.categorys[1].name;
|
||||
isbn = "ISBN/CN刊号:" + propParam.categorys[1].name;
|
||||
if (propParam.categorys[1].name.Length == 13)
|
||||
{
|
||||
var isbnStr = propParam.categorys[1].name;
|
||||
isbn = "ISBN/CN刊号:" + isbnStr[0] + isbnStr[1] + isbnStr[2] + "-" + isbnStr[3] + "-" + isbnStr[4] + isbnStr[5] + isbnStr[6] + isbnStr[7] + "-" + isbnStr[8] + isbnStr[9] + isbnStr[10] + isbnStr[11] + "-" + isbnStr[12];
|
||||
}
|
||||
}
|
||||
else if (propParam.categorys[0].name.Contains("书名"))
|
||||
//bookName = "图书名称:" + propParam.categorys[1].name;
|
||||
bookName = "书名:" + propParam.categorys[1].name;
|
||||
{
|
||||
//bookName = "书名:" + propParam.categorys[1].name;
|
||||
bookName = "图书名称:" + propParam.categorys[1].name;
|
||||
}
|
||||
else if (propParam.categorys[0].name.Contains("定价"))
|
||||
{
|
||||
//bookPrice = "定价:" + propParam.categorys[1].name;
|
||||
@@ -4240,17 +4268,58 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
edition + "\r\n" + "\r\n" +
|
||||
binding;
|
||||
|
||||
var bookImg = new Bitmap(800, 800);
|
||||
int imgW = 800; int imgH = 800; int textImgH = 0;
|
||||
string getImgError;
|
||||
var img_url = upProdParam.product.info.headImg[0];
|
||||
if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||||
img_url = img_url.Replace("https://", "http://");
|
||||
var imageMain = GetHtml.GetUrlImg(img_url, out getImgError);
|
||||
if (imageMain == null)
|
||||
imageMain = new Bitmap(800, 800);
|
||||
using (Bitmap bitmap = new Bitmap(1, 1)) // 尺寸不重要,只是为了使用Graphics对象
|
||||
using (Graphics g = Graphics.FromImage(bitmap)) // 获取Graphics对象
|
||||
{
|
||||
// 定义字体
|
||||
Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
// 定义要测量的字符串
|
||||
string text = bookStr;
|
||||
// 测量字符串大小
|
||||
SizeF size = g.MeasureString(text, font, imgW - 120);
|
||||
// 输出高度信息
|
||||
//Console.WriteLine("Text Height: " + size.Height);
|
||||
textImgH = size.Height.ParseToInt() + 180;
|
||||
}
|
||||
|
||||
//var bookImg = new Bitmap(imgW, imgH);
|
||||
//using (Graphics g = Graphics.FromImage(bookImg))
|
||||
//{
|
||||
// g.Clear(Color.White);
|
||||
// //Font font = new Font("宋体", 15, FontStyle.Bold);
|
||||
// //Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
// Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||||
// //Font font = new Font("宋体", 17, FontStyle.Bold);
|
||||
// Brush textBrush = Brushes.Black;
|
||||
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
// RectangleF rectF = new RectangleF(60, 80, imgW - 120, imgH - 180);
|
||||
// g.DrawString(bookStr, font, textBrush, rectF);
|
||||
//}
|
||||
|
||||
// 绘制一张带主图的商品详情页
|
||||
var bookImg = new Bitmap(imgW, imgH + textImgH);
|
||||
using (Graphics g = Graphics.FromImage(bookImg))
|
||||
{
|
||||
g.Clear(Color.White);
|
||||
g.Clear(Color.FromArgb(248, 239, 244));
|
||||
|
||||
g.DrawImage(imageMain, new Rectangle(0, 0, imgW, imgH), 0, 0, imageMain.Width, imageMain.Height, GraphicsUnit.Pixel);
|
||||
|
||||
//Font font = new Font("宋体", 15, FontStyle.Bold);
|
||||
Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
//Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||||
//Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||||
Font font = new Font("微软雅黑", 18, FontStyle.Regular);
|
||||
//Font font = new Font("宋体", 17, FontStyle.Bold);
|
||||
Brush textBrush = Brushes.Black;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
RectangleF rectF = new RectangleF(80, 80, 800 - 80, 800 - 80);
|
||||
RectangleF rectF = new RectangleF(60, imgH + 80, imgW - 120, textImgH - 180);
|
||||
g.DrawString(bookStr, font, textBrush, rectF);
|
||||
}
|
||||
|
||||
@@ -4260,6 +4329,44 @@ namespace TemuKJD.WXForms.ProductForms
|
||||
return locationStr;
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "1111485", qualificationUrl = new List<string>() { location }, });
|
||||
|
||||
#region 将资质图作为主图的最后一张。
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
bookImg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
byte[] imageBytes = memoryStream.ToArray();
|
||||
var imgBase64 = Convert.ToBase64String(imageBytes);
|
||||
|
||||
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
upDate += "&img_url=" + location;
|
||||
upDate += "&img_base64=" + imgBase64;
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传资质图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
upProdParam.product.info.headImg = upProdParam.product.info.headImg.Take(8).ToList();
|
||||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in new issue
Block a user