5508 lines
287 KiB
C#
5508 lines
287 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Result;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net.Http;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.ToolForms;
|
||
using Work;
|
||
using TemuKJD.BLL;
|
||
using System.Text.RegularExpressions;
|
||
using TemuKJD.PDDForms.ProductSelectForms;
|
||
using TemuKJD.WXForms.ShopForms;
|
||
using AllBase.Model.Result.PDDResult;
|
||
using AllBase.Model.Param.WXParam;
|
||
using AllBase.Model.Result.WXResult;
|
||
using Newtonsoft.Json;
|
||
using NaiBa.Util;
|
||
using AllBase.Model.Config;
|
||
|
||
namespace TemuKJD.WXForms.ProductForms
|
||
{
|
||
public partial class WXDBProdUploadForm : BaseForm
|
||
{
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
public bool IsLoadComplate { get; set; } = false;
|
||
|
||
bool isInit = false;
|
||
CheckBox chkSelectAll = null;
|
||
ConcurrentList<AuthInfo> lstShopAuthInfo = new ConcurrentList<AuthInfo>();
|
||
ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
public NaiBa.Util.ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
|
||
NaiBa.Util.ConcurrentList<AddPriceRule> lstAddPriceRule = new NaiBa.Util.ConcurrentList<AddPriceRule>();
|
||
AddPriceRule defaultAddPriceRule = null;
|
||
WXUploadRule wxUploadRule = null;
|
||
//public Dictionary<string, List<string>> dicCheckedShopIdList = new Dictionary<string, List<string>>();
|
||
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
|
||
public Dictionary<string, WxShopUploadInfo> dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
|
||
public string pdd_product_cates = "";
|
||
public List<string> forceFilteKeyWords = new List<string>()
|
||
{
|
||
"顶级", "之王", "二手", "亏本", "冲量", "白菜价", "跳楼价", "xxx", "xx", "最大", "最小", "低价", "降价", "成本", "赔钱", "甩卖",
|
||
"真丝", "蚕丝", "香云纱", "羊绒", "羊毛", "羊羔绒", "羊羔毛", "羽绒", "皮草"
|
||
};
|
||
string DefaultAdultBrandId = "";
|
||
|
||
public WXDBProdUploadForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
|
||
{
|
||
this.splitContainer1.Dock = DockStyle.Fill;
|
||
this.panel1.Location = new Point(40, 30);
|
||
this.panel1.Width = this.Width - 80;
|
||
this.panel1.Height = this.Height - 60;
|
||
this.panel1.SendToBack();
|
||
|
||
lstShopAuthInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<AuthInfo>>("wx_shop_auth_list");
|
||
if (lstShopAuthInfo == null)
|
||
lstShopAuthInfo = new ConcurrentList<AuthInfo>();
|
||
|
||
lstWXShopTokenInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<WXShopTokenInfo>>("wx_shop_token_list");
|
||
if (lstWXShopTokenInfo == null)
|
||
lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
|
||
lstTemuDBProductSelect = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<TemuDBProductSelect>>("wx_db_prod_upload_list");
|
||
if (lstTemuDBProductSelect == null)
|
||
lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
|
||
|
||
lstAddPriceRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<ConcurrentList<AddPriceRule>>("wx_add_price_rules");
|
||
if (lstAddPriceRule == null)
|
||
{
|
||
lstAddPriceRule = new NaiBa.Util.ConcurrentList<AddPriceRule>();
|
||
lstAddPriceRule.Add(new AddPriceRule() { MoreThanPrice = 0, LessThanPrice = 10, AddPriceTimes = 2, AddMorePrice = 10, SinglePriceAdd = 1 });
|
||
lstAddPriceRule.Add(new AddPriceRule() { MoreThanPrice = 10, LessThanPrice = 20, AddPriceTimes = 2, AddMorePrice = 10, SinglePriceAdd = 1 });
|
||
lstAddPriceRule.Add(new AddPriceRule() { MoreThanPrice = 20, LessThanPrice = 999, AddPriceTimes = 2, AddMorePrice = 10, SinglePriceAdd = 1 });
|
||
}
|
||
this.fPnlPriceRule.Controls.Clear();
|
||
foreach (var priceItem in lstAddPriceRule)
|
||
{
|
||
var ucPrice = new UcAddPrice()
|
||
{
|
||
PriceEnd = priceItem.LessThanPrice,
|
||
PriceStart = priceItem.MoreThanPrice,
|
||
PriceAddTimes = priceItem.AddPriceTimes,
|
||
PriceAddMore = priceItem.AddMorePrice,
|
||
SinglePriceAdd = priceItem.SinglePriceAdd,
|
||
};
|
||
ucPrice.lblSinglePriceAdd.Visible = false;
|
||
ucPrice.txtSinglePriceAdd.Visible = false;
|
||
if (IsSetFontScaleNone)
|
||
{
|
||
Font of = ucPrice.Font;
|
||
Font nf = new Font(of.FontFamily, (of.Size * 96.0 / FormDpi).ParseToFloat(), of.Style, of.Unit, of.GdiCharSet, of.Bold);
|
||
ucPrice.Font = nf;
|
||
}
|
||
|
||
this.fPnlPriceRule.Controls.Add(ucPrice);
|
||
ucPrice.PriceChange += ucAddPrice_PriceChange;
|
||
}
|
||
|
||
dicCheckedShopId = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, bool>>("wx_checked_shop_dic");
|
||
if (dicCheckedShopId == null)
|
||
dicCheckedShopId = new Dictionary<string, bool>();
|
||
dicShopUpload = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, WxShopUploadInfo>>("wx_shop_upload_info");
|
||
if (dicShopUpload == null)
|
||
dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
|
||
|
||
defaultAddPriceRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<AddPriceRule>("wx_default_add_price_rule");
|
||
if (defaultAddPriceRule == null)
|
||
{
|
||
defaultAddPriceRule = new AddPriceRule() { AddPriceTimes = 1.3m, AddMorePrice = 1, SinglePriceAdd = 1 };
|
||
}
|
||
txtAddTimes.TextChanged -= txtAddPrice_TextChanged;
|
||
txtAddMorePrice.TextChanged -= txtAddPrice_TextChanged;
|
||
txtSinglePriceAdd.TextChanged -= txtAddPrice_TextChanged;
|
||
txtStockNum.TextChanged -= txtAddPrice_TextChanged;
|
||
txtShippingPriceTimes.TextChanged -= txtAddPrice_TextChanged;
|
||
chkAddMorePriceFirst.CheckedChanged -= chkAddMorePriceFirst_CheckedChanged;
|
||
chkStepAddPrice.CheckedChanged -= chkStepAddPrice_CheckedChanged;
|
||
|
||
this.txtAddTimes.Text = defaultAddPriceRule.AddPriceTimes.ToString();
|
||
this.txtAddMorePrice.Text = defaultAddPriceRule.AddMorePrice.ToString();
|
||
this.txtSinglePriceAdd.Text = defaultAddPriceRule.SinglePriceAdd.ToString();
|
||
this.txtStockNum.Text = defaultAddPriceRule.StockNum.ToString();
|
||
this.txtShippingPriceTimes.Text = defaultAddPriceRule.ShippingPriceTimes.ToString();
|
||
this.chkAddMorePriceFirst.Checked = defaultAddPriceRule.AddMorePriceFirst;
|
||
this.chkStepAddPrice.Checked = defaultAddPriceRule.IsStepAddPrice;
|
||
|
||
txtAddTimes.TextChanged += txtAddPrice_TextChanged;
|
||
txtAddMorePrice.TextChanged += txtAddPrice_TextChanged;
|
||
txtSinglePriceAdd.TextChanged += txtAddPrice_TextChanged;
|
||
txtStockNum.TextChanged += txtAddPrice_TextChanged;
|
||
txtShippingPriceTimes.TextChanged += txtAddPrice_TextChanged;
|
||
chkAddMorePriceFirst.CheckedChanged += chkAddMorePriceFirst_CheckedChanged;
|
||
chkStepAddPrice.CheckedChanged += chkStepAddPrice_CheckedChanged;
|
||
|
||
wxUploadRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<WXUploadRule>("wx_upload_rule");
|
||
if (wxUploadRule == null)
|
||
wxUploadRule = new WXUploadRule();
|
||
var filteWords = wxUploadRule.FilterWords.Split(new string[] { ",", ",", " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
filteWords.RemoveAll(w => forceFilteKeyWords.Contains(w));
|
||
filteWords.AddRange(forceFilteKeyWords);
|
||
wxUploadRule.FilterWords = string.Join(",", filteWords);
|
||
this.txtPreDays.TextChanged -= txtPreDays_TextChanged;
|
||
this.txtReplaceText.TextChanged -= txtReplaceText_TextChanged;
|
||
this.txtMinPrice.TextChanged -= txtMinPrice_TextChanged;
|
||
this.txtWaitSeconds.TextChanged -= txtWaitSeconds_TextChanged;
|
||
this.chkHighestPriceSku.CheckedChanged -= chkHighestPriceSku_CheckedChanged;
|
||
this.chkSameSpecPrice.CheckedChanged -= chkSameSpecPrice_CheckedChanged;
|
||
this.chkSkipUploaded.CheckedChanged -= chkSkipUploaded_CheckedChanged;
|
||
this.chkUpDraft.CheckedChanged -= chkUpDraft_CheckedChanged;
|
||
this.chkPreSale.CheckedChanged -= chkPreSale_CheckedChanged;
|
||
this.txtTitleHeadWord.TextChanged -= txtTitleHeadWord_TextChanged;
|
||
this.chkAiShortTitle.CheckedChanged -= chkAiShotTitle_CheckedChanged;
|
||
this.chkUseWXComplateProd.CheckedChanged -= chkUseWXComplateProd_CheckedChanged;
|
||
this.chkSaveBound.CheckedChanged -= chkSaveBound_CheckedChanged;
|
||
this.txtFilterBoundMin.TextChanged -= txtFilterBoundMin_TextChanged;
|
||
this.txtFilterBoundMax.TextChanged -= txtFilterBoundMax_TextChanged;
|
||
|
||
this.txtPreDays.Text = wxUploadRule.PreSaleDays.ParseToString();
|
||
this.txtReplaceText.Text = wxUploadRule.FilterWords.ParseToString();
|
||
this.txtMinPrice.Text = wxUploadRule.SkuMinPrice.ParseToString();
|
||
this.txtWaitSeconds.Text = wxUploadRule.WaitSeconds.ParseToString();
|
||
this.chkHighestPriceSku.Checked = wxUploadRule.OnlyHighestPriceSku.ParseToBool();
|
||
this.chkSameSpecPrice.Checked = wxUploadRule.SameSpecSamePrice.ParseToBool();
|
||
this.chkSkipUploaded.Checked = wxUploadRule.SkipUploaded.ParseToBool();
|
||
this.chkUpDraft.Checked = wxUploadRule.UpDraft.ParseToBool();
|
||
this.chkPreSale.Checked = wxUploadRule.IsPreSale.ParseToBool();
|
||
this.txtTitleHeadWord.Text = wxUploadRule.TitleHeadWords.ParseToString();
|
||
this.chkAiShortTitle.Checked = wxUploadRule.IsAiShortTitle;
|
||
this.chkUseWXComplateProd.Checked = wxUploadRule.IsUseWXComplateProd;
|
||
this.chkSaveBound.Checked = wxUploadRule.IsSaveBound;
|
||
if (wxUploadRule.IsSaveBound)
|
||
{
|
||
this.txtFilterBoundMin.Text = wxUploadRule.FilterBoundMinSave.ParseToString();
|
||
this.txtFilterBoundMax.Text = wxUploadRule.FilterBoundMaxSave.ParseToString();
|
||
}
|
||
|
||
this.txtPreDays.TextChanged += txtPreDays_TextChanged;
|
||
this.txtReplaceText.TextChanged += txtReplaceText_TextChanged;
|
||
this.txtMinPrice.TextChanged += txtMinPrice_TextChanged;
|
||
this.txtWaitSeconds.TextChanged += txtWaitSeconds_TextChanged;
|
||
this.chkHighestPriceSku.CheckedChanged += chkHighestPriceSku_CheckedChanged;
|
||
this.chkSameSpecPrice.CheckedChanged += chkSameSpecPrice_CheckedChanged;
|
||
this.chkSkipUploaded.CheckedChanged += chkSkipUploaded_CheckedChanged;
|
||
this.chkUpDraft.CheckedChanged += chkUpDraft_CheckedChanged;
|
||
this.chkPreSale.CheckedChanged += chkPreSale_CheckedChanged;
|
||
this.txtTitleHeadWord.TextChanged += txtTitleHeadWord_TextChanged;
|
||
this.chkAiShortTitle.CheckedChanged += chkAiShotTitle_CheckedChanged;
|
||
this.chkUseWXComplateProd.CheckedChanged += chkUseWXComplateProd_CheckedChanged;
|
||
this.chkSaveBound.CheckedChanged += chkSaveBound_CheckedChanged;
|
||
this.txtFilterBoundMin.TextChanged += txtFilterBoundMin_TextChanged;
|
||
this.txtFilterBoundMax.TextChanged += txtFilterBoundMax_TextChanged;
|
||
|
||
this.lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
|
||
int prodCount = 0;
|
||
pbSelectProd.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
GetRandomProductList(out prodCount, 1, 1);
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbSelectProd.Visible = false;
|
||
lblGoodsCount.Text = "产品库 " + prodCount + " 件";
|
||
}));
|
||
});
|
||
|
||
this.panel1.SendToBack();
|
||
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
|
||
dgvShop.Columns["colSelect"].HeaderText = "";
|
||
//chkSelectAll.Width = chkSelectAll.Height = 13;
|
||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
//chkSelectAll.Checked = true;
|
||
|
||
this.dgvSelectProduct.AddSelectorColumn("colCheck");
|
||
|
||
dgvSelectProduct.AddImgColumn("colProductSkcPic", "colImgUrl");
|
||
dgvSelectProduct.AddImgColumn("colSkuFakeImg", "colSkuFakeImgUrl");
|
||
|
||
dgvSelectProduct.Columns["colSkuFakeImg"].Visible = false;
|
||
|
||
upload_draft_product_lst = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<TemuDBProductSelect>>("wx_select_upload_draft_products");
|
||
if (upload_draft_product_lst == null)
|
||
upload_draft_product_lst = new ConcurrentList<TemuDBProductSelect>();
|
||
foreach (var selectProd in upload_draft_product_lst)
|
||
{
|
||
int rowIndex = 0;
|
||
this.dgvSelectProduct.Rows.Insert(rowIndex,
|
||
true,
|
||
selectProd.id,
|
||
selectProd.shop_id,
|
||
selectProd.shop_account,
|
||
"登录",
|
||
"进店",
|
||
BaseClass.SaLevel > 0 ? selectProd.spu_id : selectProd.spu_id.ParseToString().GetHashCode().ParseToString().Trim('-'),
|
||
selectProd.skc_id,
|
||
selectProd.main_img,
|
||
DataGridViewExtension.defaultBitmap,
|
||
"",
|
||
null,
|
||
selectProd.product_name, // 用户端显示商品原名
|
||
selectProd.cat_name,
|
||
BaseClass.SaLevel > 0 ? selectProd.ext_code : selectProd.ext_code.ParseToString().GetHashCode().ParseToString().Trim('-'),
|
||
selectProd.status,
|
||
selectProd.draft_id,
|
||
selectProd.notes,
|
||
(selectProd.user_notes + " 编辑").Trim(),
|
||
"删除",
|
||
selectProd.add_time.ToString("yy-MM-dd HH:mm:ss"),
|
||
"");
|
||
|
||
dgvSelectProduct.Rows[rowIndex].Height = 60;
|
||
|
||
int maxRowCount = 10000;
|
||
while (dgvSelectProduct.Rows.Count > maxRowCount)
|
||
{
|
||
dgvSelectProduct.Rows.RemoveAt(maxRowCount);
|
||
}
|
||
}
|
||
|
||
//#if DEBUG
|
||
if (BaseClass.SaLevel == 1)
|
||
{
|
||
//lblExtCodeFilter.Visible = true;
|
||
//txtExtCodeFilter.Visible = true;
|
||
|
||
lblIdFilter.Visible = true;
|
||
txtIdFilter.Visible = true;
|
||
lblSourceType.Visible = true;
|
||
cmbSourceType.Visible = true;
|
||
lblGroupFilter.Visible = true;
|
||
cmbGroupFilter.Visible = true;
|
||
lblJstInitSet.Visible = true;
|
||
cmbJstInitSet.Visible = true;
|
||
}
|
||
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("货源选择"))
|
||
{
|
||
cmbSourceType.Visible = true;
|
||
}
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采"))
|
||
{
|
||
chkWXComplateProd.Visible = true;
|
||
chkUseWXComplateProd.Visible = true;
|
||
}
|
||
//#endif
|
||
if (BaseClass.SaLevel == 1)
|
||
{
|
||
//chkImgRandomBlock.Visible = true;
|
||
}
|
||
|
||
IsLoadComplate = true;
|
||
}
|
||
|
||
private void btnRefreshAuthor_Click(object sender, EventArgs e)
|
||
{
|
||
updateAuthor(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 升级授权
|
||
/// </summary>
|
||
/// <param name="idRefreshTodayHasGet">今日取过的也取</param>
|
||
private void updateAuthor(bool idRefreshTodayHasGet = false)
|
||
{
|
||
this.pbLoadingShop.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
// 店铺Id
|
||
var updateIds = dgvShop.Rows.Cast<DataGridViewRow>().Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (idRefreshTodayHasGet == true)
|
||
updateIds = selectIds;
|
||
|
||
List<Task> tList = new List<Task>();
|
||
if (idRefreshTodayHasGet)
|
||
lstShopAuthInfo.RemoveAll(s => updateIds.Contains(s.ShopId));
|
||
foreach (var shop in GlobalConfig.ShopLoginList.Where(s => updateIds.Contains(s.ShopId)))
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, ""); }));
|
||
var t = Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
return;
|
||
}
|
||
|
||
var authInfo = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||
if (idRefreshTodayHasGet || authInfo == null || authInfo?.AddTime.Date != DateTime.Now.Date)
|
||
{
|
||
lstShopAuthInfo.RemoveAll(sa => sa.ShopId == shop.ShopId);
|
||
var rst = WXUpload.GetApiServiceList(shop);
|
||
if (!rst.Contains("\"code\":0"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
return;
|
||
}
|
||
|
||
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = DateTime.Now });
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "授权查询失败"); }));
|
||
return;
|
||
}
|
||
|
||
foreach (var itemObj in JsonHelper.JObjectParse(rst)["itemList"])
|
||
{
|
||
// 找到了指定服务
|
||
if (itemObj["serviceName"].ParseToString() == "店统领供应链-商品管理")
|
||
{
|
||
var expiresTick = itemObj["expireTime"].ParseToLong();
|
||
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = BaseClass.StampToDateTime(expiresTick.ParseToInt()) });
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
|
||
return;
|
||
}
|
||
}
|
||
// 没找到指定服务
|
||
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = DateTime.Now });
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
});
|
||
tList.Add(t);
|
||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 20) { Thread.Sleep(100); }
|
||
}
|
||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 1) { Thread.Sleep(100); }
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig( "wx_shop_auth_list", lstShopAuthInfo);
|
||
Invoke(new Action(() => { pbLoadingShop.Visible = false; }));
|
||
});
|
||
}
|
||
|
||
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!chkSelectAll.Checked)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//var list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus == "登录成功").Select(ss => ss.ShopId);
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
//if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
|
||
if(row.Visible == true)
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
|
||
foreach (var r in dgvShop.Rows.Cast<DataGridViewRow>())
|
||
{
|
||
dicCheckedShopId[r.Cells["colShopId"].Value.ParseToString()] = r.Cells["colSelect"].Value.ParseToBool();
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
|
||
}
|
||
|
||
private void btnRefreshShop_Click(object sender, EventArgs e)
|
||
{
|
||
pbLoadingShop.Visible = true;
|
||
RefreshDbProdGroupAndCate();
|
||
RefreshShopLogin();
|
||
}
|
||
|
||
private void UserSelectDbProductForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (Visible == true)
|
||
{
|
||
RefreshShopLogin();
|
||
updateAuthor();
|
||
RefreshDbProdGroupAndCate();
|
||
|
||
if (!isInit)
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||
{
|
||
//if (shop.LoginStatus == "登录成功")
|
||
//{
|
||
// var rst = WXPreSale.scanProductPreview(shop);
|
||
// if (!rst.Contains("\"code\":0") && !rst.Contains("\"success\":true"))
|
||
// {
|
||
// WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
// }
|
||
//}
|
||
}
|
||
|
||
});
|
||
}
|
||
|
||
isInit = true;
|
||
}
|
||
}
|
||
|
||
private void RefreshDbProdGroupAndCate()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
PDDDBProdListForm.GetPDDProductGroup(cmbGroupFilter); // 同时刷新下商品分组
|
||
GetPddProductCate();
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbLoadingShop.Visible = false;
|
||
}));
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取商品所有类目
|
||
/// </summary>
|
||
void GetPddProductCate()
|
||
{
|
||
var url = BaseClass.BuildObjString("product/get_pdd_product_cates");
|
||
var data = UserLogin.GetSignaturex();
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
BaseMsgForm.ShowError("商品类目获取失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
|
||
}
|
||
else
|
||
{
|
||
pdd_product_cates = BaseRegex.GetStringJson(ref html, "data");
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cmbSourceType.Text.Trim() != "厂商直采" && cmbSourceType.Text.Trim() != "微信店采")
|
||
{
|
||
fillPddCate();
|
||
}
|
||
else
|
||
{
|
||
fillWxCate();
|
||
}
|
||
}));
|
||
}
|
||
|
||
void fillPddCate()
|
||
{
|
||
cmbCateFilter1.Items.Clear();
|
||
cmbCateFilter2.Items.Clear();
|
||
cmbCateFilter3.Items.Clear();
|
||
cmbCateFilter1.Text = "";
|
||
cmbCateFilter2.Text = "";
|
||
cmbCateFilter3.Text = "";
|
||
foreach (var item in pdd_product_cates.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
|
||
{
|
||
cmbCateFilter1.Items.Add(item);
|
||
}
|
||
cmbCateFilter1.Items.Add("");
|
||
}
|
||
|
||
void fillWxCate()
|
||
{
|
||
cmbCateFilter1.Items.Clear();
|
||
cmbCateFilter2.Items.Clear();
|
||
cmbCateFilter3.Items.Clear();
|
||
cmbCateFilter1.Text = "";
|
||
cmbCateFilter2.Text = "";
|
||
cmbCateFilter3.Text = "";
|
||
foreach (var cate in GlobalConfig.WxCatList.Where(c => c.level == 1).ToList())
|
||
{
|
||
cmbCateFilter1.Items.Add(cate.name);
|
||
}
|
||
}
|
||
|
||
private void RefreshShopLogin()
|
||
{
|
||
// 店铺Id
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
// 获取被删除的店铺
|
||
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||
// 更新被删除的店铺列表
|
||
foreach (var row in dgvRowList)
|
||
{
|
||
dgvShop.Rows.Remove(row);
|
||
}
|
||
// 绑定其他店铺(含新导入的店铺)
|
||
foreach (ShopLoginInfo shopEntity in GlobalConfig.ShopLoginList)
|
||
{
|
||
if (!string.IsNullOrEmpty(shopEntity.ShopId))
|
||
BindShop(shopEntity, selectIds);
|
||
}
|
||
cmbFilterShopNotes.Items.Clear();
|
||
//cmbFilterShopNotes.Items.Add("");
|
||
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopNotes.Items.Add(note);
|
||
}
|
||
}
|
||
|
||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
|
||
{
|
||
if (shopEntity == null)
|
||
return;
|
||
if (selectShopId == null)
|
||
selectShopId = new List<string>();
|
||
|
||
bool canUse = shopEntity.LoginStatus == "登录成功";
|
||
//canUse = true; // 内部库不需要校验登录状态
|
||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
|
||
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
|
||
if (row == null)
|
||
{
|
||
this.dgvShop.Rows.Add(
|
||
//!isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse),
|
||
dicCheckedShopId.Keys.Contains(shopEntity.ShopId) && dicCheckedShopId[shopEntity.ShopId] == true,
|
||
shopEntity.LoginName,
|
||
shopEntity.ShopId,
|
||
shopEntity.ShopAccount,
|
||
shopEntity.Notes,
|
||
"选择商品",
|
||
canUse ? "在线" : "掉线",
|
||
lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
|
||
canUse,
|
||
dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
|
||
dicShopUpload[shopEntity.ShopId].DicDayUploadCount[day] : 0,
|
||
dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
|
||
dicShopUpload[shopEntity.ShopId].OnSaleCount : 0,
|
||
shopEntity.AddProductRemaining,
|
||
msg
|
||
);
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = !isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse);
|
||
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
|
||
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
|
||
row.Cells["colShopNotes"].Value = shopEntity.Notes;
|
||
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
|
||
row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
|
||
row.Cells["colCanUse"].Value = canUse;
|
||
row.Cells["colApi"].Value = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期";
|
||
row.Cells["colRemaining"].Value = shopEntity.AddProductRemaining;
|
||
row.Cells["colUploadCount"].Value = dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
|
||
dicShopUpload[shopEntity.ShopId].DicDayUploadCount[day] : 0;
|
||
row.Cells["colOnSaleNum"].Value = dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
|
||
dicShopUpload[shopEntity.ShopId].OnSaleCount : 0;
|
||
row.Cells["colMessage"].Value = msg;
|
||
}
|
||
|
||
displayAuthStatus(shopEntity);
|
||
}
|
||
|
||
void displayAuthStatus(ShopLoginInfo shop)
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ParseToString() == shop?.ShopId);
|
||
foreach (var row in rows)
|
||
{
|
||
bool canUse = row.Cells["colLoginStatus"].Value.ParseToString() == "在线";
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
|
||
canUse = row.Cells["colApi"].Value.ParseToString() == "可用";
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
|
||
}
|
||
}
|
||
|
||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
|
||
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
|
||
string shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
|
||
string shopAccount = dgvShop.Rows[e.RowIndex].Cells["colShopName"].Value.ToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
|
||
var row = dgvShop.Rows[e.RowIndex];
|
||
switch (columnName)
|
||
{
|
||
case "colSelect":
|
||
//if (row.Cells["colCanUse"].Value.ParseToBool())
|
||
{
|
||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
|
||
chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
|
||
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
|
||
chkSelectAll.Checked = true;
|
||
else
|
||
chkSelectAll.Checked = false;
|
||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
}
|
||
//else
|
||
{
|
||
//BaseMsgForm.ShowInfo("店铺未登录!");
|
||
}
|
||
|
||
dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
|
||
break;
|
||
case "colLoginStatus":
|
||
{
|
||
if (WXShopListForm.Instance == null)
|
||
WXShopListForm.Instance = new WXShopListForm();
|
||
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
//shopLoginForm.prodUserSelectForm = this;
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopLogin();
|
||
}
|
||
else
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.Show();
|
||
}
|
||
}
|
||
break;
|
||
case "colApi":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139";
|
||
shopLoginForm.Show();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (lstShopId.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择店铺!");
|
||
return;
|
||
}
|
||
}
|
||
|
||
private void dgvSelectProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvSelectProduct.Columns[e.ColumnIndex].HeaderText;
|
||
var dbId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSelectId"].Value.ParseToString();
|
||
var dbProduct = lstTemuDBProductSelect.FirstOrDefault(p => p.id.ToString() == dbId);
|
||
var shopId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
||
var draftId = dgvSelectProduct.Rows[e.RowIndex].Cells["colDraftId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
|
||
switch (headerText)
|
||
{
|
||
case "删除":
|
||
break;
|
||
case "登录":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
//shopLoginForm.prodUserSelectForm = this;
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopLogin();
|
||
}
|
||
break;
|
||
case "进店":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
//shopLoginForm.prodUserSelectForm = this;
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home";
|
||
shopLoginForm.Show();
|
||
}
|
||
break;
|
||
case "上传商品Id":
|
||
//if (!string.IsNullOrEmpty(draftId) && shop != null)
|
||
//{
|
||
// ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
|
||
// shopLoginForm.InitUrl = "https://seller.kuajingmaihuo.com/goods/product-create/product-edit?productDraftId=" +
|
||
// draftId + "&from=productDraftList";
|
||
// shopLoginForm.openType = EnumOpenType.manage;
|
||
// shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
// shopLoginForm.ShowDialog();
|
||
//}
|
||
break;
|
||
case "图片":
|
||
{
|
||
ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString());
|
||
imgFrom.ShowDialog();
|
||
break;
|
||
}
|
||
case "SKU替换图":
|
||
{
|
||
ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colSkuFakeImgUrl"].Value.ParseToString());
|
||
imgFrom.ShowDialog();
|
||
break;
|
||
}
|
||
case "":
|
||
dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
private void btnUpload_Click(object sender, EventArgs e)
|
||
{
|
||
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (shopIdLst.Count <= 0)
|
||
{
|
||
BaseMsgForm.ShowError("未勾选上传店铺!");
|
||
return;
|
||
}
|
||
|
||
if (lstTemuDBProductSelect.Count() > 0)
|
||
{
|
||
if (WXShopLoginForm.shopLoginInstance != null && WXShopLoginForm.shopLoginInstance.IsDisposed != true)
|
||
WXShopLoginForm.shopLoginInstance.Dispose();
|
||
|
||
this.btnUpload.Enabled = false;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
AddProductArr(shopIdLst);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.btnUpload.Enabled = true;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
else
|
||
{
|
||
BaseMsgForm.ShowError("请选择要上传的商品!");
|
||
}
|
||
}
|
||
|
||
void AddProductArr(List<string> shopIdLst)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在上传" + "...".Substring(0, DateTime.Now.Second % 4);
|
||
this.statusBar.pgbTaskProgress.Maximum = lstTemuDBProductSelect.Count;
|
||
this.statusBar.UpdateProgressBar(0);
|
||
}));
|
||
|
||
// 随机厂商商品
|
||
var url = BaseClass.BuildObjString("product/get_random_company_product_config");
|
||
var data = UserLogin.GetSignaturex();
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
chkRandomCompanyProd.Checked = BaseRegex.GetStringJson(ref html, "is_on") == "1";
|
||
int randomComProdInterval = Math.Max(1, BaseRegex.GetIntJson(ref html, "product_interval"));
|
||
string randomComProdGroup = BaseRegex.GetStringJson(ref html, "product_group");
|
||
int waitCompanyProdCnt = 0;
|
||
ConcurrentList<TemuDBProductSelect> CompanyProdLst = new ConcurrentList<TemuDBProductSelect>();
|
||
|
||
ConcurrentList<ShopLoginInfo> currentShopList = new ConcurrentList<ShopLoginInfo>();
|
||
while (lstTemuDBProductSelect.Count > 0)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (shopIdLst.Count <= 0)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "请至少勾选一个店铺";
|
||
}));
|
||
Thread.Sleep(500);
|
||
continue;
|
||
}
|
||
var randomShopLst = new ConcurrentList<ShopLoginInfo>();
|
||
randomShopLst.AddRange(GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId) && s.LoginStatus == "登录成功"));
|
||
if (randomShopLst.Count <= 0)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "所有店铺都已掉线,请登录店铺";
|
||
}));
|
||
Thread.Sleep(500);
|
||
continue;
|
||
}
|
||
if (currentShopList.Count >= 20) // 最多20店同传
|
||
{
|
||
Thread.Sleep(500);
|
||
continue;
|
||
}
|
||
|
||
var randomShop = randomShopLst.Where(s => !currentShopList.Contains(s)).ToList().OrderBy(x => Randomx.GetId(999999)).FirstOrDefault();
|
||
if (randomShop == null)
|
||
{
|
||
Thread.Sleep(500);
|
||
continue;
|
||
}
|
||
currentShopList.Add(randomShop);
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
// 每次挑选列表第一件商品
|
||
var selectProd = lstTemuDBProductSelect.FirstOrDefault();
|
||
selectProd.shop_id = randomShop.ShopId;
|
||
selectProd.shop_account = randomShop.ShopAccount;
|
||
|
||
// 每若干个个商品插一件黄总商品包或其他组商品
|
||
waitCompanyProdCnt++;
|
||
if (chkRandomCompanyProd.Checked && waitCompanyProdCnt > randomComProdInterval)
|
||
{
|
||
waitCompanyProdCnt = 0;
|
||
if (CompanyProdLst.Count == 0)
|
||
{
|
||
int dbCompanyProdCount;
|
||
var dbComProdLst = GetRandomCompanyProductList(out dbCompanyProdCount, randomComProdGroup);
|
||
foreach (var comProd in dbComProdLst)
|
||
{
|
||
var comSelectProd = JsonHelper.DeserializeJsonToObject<TemuDBProductSelect>(JsonHelper.SerializeObject(comProd));
|
||
comSelectProd.out_product_Id = comProd.id.ToString();
|
||
comSelectProd.id = 1;
|
||
if (CompanyProdLst.Count > 0)
|
||
comSelectProd.id = CompanyProdLst.Max(p => p.id).ParseToInt() + 1;
|
||
CompanyProdLst.Add(comSelectProd);
|
||
}
|
||
}
|
||
selectProd = CompanyProdLst.FirstOrDefault();
|
||
selectProd.shop_id = randomShop.ShopId;
|
||
selectProd.shop_account = randomShop.ShopAccount;
|
||
CompanyProdLst.Remove(selectProd);
|
||
}
|
||
else
|
||
{
|
||
lstTemuDBProductSelect.Remove(selectProd);
|
||
}
|
||
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}));
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在上传" + "...".Substring(0, DateTime.Now.Second % 4);
|
||
this.statusBar.pgbTaskProgress.Maximum = lstTemuDBProductSelect.Count + this.statusBar.pgbTaskProgress.Value + 1;
|
||
this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1);
|
||
}));
|
||
|
||
if (selectProd == null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
BaseMsgForm.ShowError("商品为空,将为您跳过该商品!");
|
||
}));
|
||
currentShopList.Remove(randomShop);
|
||
continue;
|
||
}
|
||
|
||
// 过滤标题
|
||
var lstTitleReplaceText = new List<string>();
|
||
if (!txtReplaceText.Text.Trim().IsNullOrEmpty())
|
||
lstTitleReplaceText.AddRange(txtReplaceText.Text.Trim().Split(new string[] { ",", ",", " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
|
||
// 过滤标题内指定词语
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
selectProd.product_name = selectProd.product_name.Replace(txt, "");
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
int rowIndex = 0;
|
||
this.dgvSelectProduct.Rows.Insert(rowIndex,
|
||
true,
|
||
selectProd.id,
|
||
selectProd.shop_id,
|
||
selectProd.shop_account,
|
||
"登录",
|
||
"进店",
|
||
BaseClass.SaLevel > 0 ? selectProd.spu_id : selectProd.spu_id.ParseToString().GetHashCode().ParseToString().Trim('-'),
|
||
selectProd.skc_id,
|
||
selectProd.main_img,
|
||
DataGridViewExtension.defaultBitmap,
|
||
"",
|
||
null,
|
||
selectProd.product_name, // 用户端显示商品原名
|
||
selectProd.cat_name,
|
||
BaseClass.SaLevel > 0 ? selectProd.ext_code : selectProd.ext_code.ParseToString().GetHashCode().ParseToString().Trim('-'),
|
||
selectProd.status,
|
||
selectProd.draft_id,
|
||
selectProd.notes,
|
||
(selectProd.user_notes + " 编辑").Trim(),
|
||
"删除",
|
||
"",
|
||
"");
|
||
|
||
dgvSelectProduct.Rows[rowIndex].Height = 60;
|
||
|
||
int maxRowCount = 10000;
|
||
while (dgvSelectProduct.Rows.Count > maxRowCount)
|
||
{
|
||
dgvSelectProduct.Rows.RemoveAt(maxRowCount);
|
||
}
|
||
}));
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = false;
|
||
}));
|
||
|
||
Task.Run(() =>
|
||
{
|
||
DateTime startTime = DateTime.Now;
|
||
for (int j = 0; j < 1; j++)
|
||
{
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == selectProd.shop_id);
|
||
if (shop == null)
|
||
continue;
|
||
|
||
var row = dgvSelectProduct.Rows.Cast<DataGridViewRow>().FirstOrDefault(r =>
|
||
r.Cells["colSelectId"]?.Value.ToString() == selectProd.id.ToString());
|
||
double duration = 0;
|
||
if (row == null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
BaseMsgForm.ShowError("商品已被清除,将为您跳过该商品!");
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
KJDDBProduct kjdDbProd = selectProd.kjdDbProduct;
|
||
string errStr = "";
|
||
if (kjdDbProd == null)
|
||
kjdDbProd = GetProductDetail(selectProd.out_product_Id.ToString(), out errStr);
|
||
if (kjdDbProd == null || kjdDbProd.id == 0)
|
||
{
|
||
if (kjdDbProd?.id == 0)
|
||
{
|
||
selectProd.status = "已清除";
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (row.Index >= 0)
|
||
{
|
||
row.Cells["colOpResult"].Value = "选品数据库商品已被清除";
|
||
if (kjdDbProd?.id == 0)
|
||
row.Cells["colStatus"].Value = "已清除";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
var result = "";
|
||
try
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (row.Index >= 0)
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺掉线";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
//将商品上传
|
||
KJDDBProduct kjdDbProdTmp = null;
|
||
try
|
||
{
|
||
kjdDbProdTmp = JsonHelper.DeserializeJsonToObject<KJDDBProduct>(JsonHelper.SerializeObject(kjdDbProd));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = "{\"success\":false,\"status\":\"未上传\",\"errMsg\":\"商品初始化失败:" + ex.Message + "\"}";
|
||
goto endUploadProduct;
|
||
}
|
||
|
||
result = UploadProduct(shop, kjdDbProdTmp, selectProd, row.Cells["colOpResult"], startTime);
|
||
if (result.Contains("今日提审次数已用尽,请明日再试") || result.Contains("如需上架请先缴纳足额保证金"))
|
||
{
|
||
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||
if (shopRow != null)
|
||
Invoke(new Action(() => { shopRow.Cells["colSelect"].Value = false; }));
|
||
}
|
||
// 图片重复的,修改图片缓存为空再传一次
|
||
if (result.Contains("10020225") || result.Contains("10020226"))
|
||
{
|
||
kjdDbProdTmp = JsonHelper.DeserializeJsonToObject<KJDDBProduct>(JsonHelper.SerializeObject(kjdDbProd));
|
||
kjdDbProdTmp.wx_img_map_json = null;
|
||
result = UploadProduct(shop, kjdDbProdTmp, selectProd, row.Cells["colOpResult"], startTime);
|
||
}
|
||
|
||
if (!result.Contains("success"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
}
|
||
endUploadProduct:;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = "{\"success\":false,\"status\":\"未上传\",\"errMsg\":\"内部错误:" + ex.Message + " " + ex.InnerException?.Message + "\"}";
|
||
}
|
||
Thread.Sleep(Randomx.GetId(100, 300));
|
||
|
||
// 记录失败商品
|
||
if (!result.Contains("success\":true"))
|
||
{
|
||
selectProd.wxDraftProduct = null;
|
||
selectProd.draft_id = BaseRegex.GetStringJson(ref result, "draftId");
|
||
selectProd.status = "上传失败";
|
||
selectProd.add_time = DateTime.Now;
|
||
upload_draft_product_lst.Add(selectProd);
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
}
|
||
|
||
//额外等待时间(无论失败与否)
|
||
var waitTime = 0;
|
||
Invoke(new Action(() => { waitTime = txtWaitSeconds.Text.Trim().ParseToInt(); }));
|
||
if (waitTime > 0)
|
||
Thread.Sleep(Randomx.GetId(waitTime * 1000, (waitTime + 2) * 1000));
|
||
|
||
selectProd.status = BaseRegex.GetStringJson(ref result, "status");
|
||
if (string.IsNullOrWhiteSpace(selectProd.status))
|
||
selectProd.status = "待上传";
|
||
var productDraftId = BaseRegex.GetStringJson(ref result, "draftId");
|
||
|
||
var timeSpan = DateTime.Now - startTime;
|
||
duration = timeSpan.TotalSeconds;
|
||
// 至少3秒才完成一件商品
|
||
while (duration < 3)
|
||
{
|
||
Thread.Sleep(1000);
|
||
timeSpan = DateTime.Now - startTime;
|
||
duration = timeSpan.TotalSeconds;
|
||
}
|
||
|
||
var error = BaseRegex.GetStringJson(ref result, "errMsg");
|
||
error = GetHtml.UrlDecode(error);
|
||
// 上传失败
|
||
if (!result.Contains("\"success\":true") && !result.Contains("上传成功"))
|
||
{
|
||
if (string.IsNullOrWhiteSpace(error))
|
||
error = result;
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (row.Index >= 0)
|
||
{
|
||
row.Cells["colDraftId"].Value = productDraftId; // 草稿箱id
|
||
row.Cells["colOpResult"].Value = error + " " + duration.ParseToInt() + "秒";
|
||
}
|
||
}));
|
||
}
|
||
// 上传成功/上传到草稿箱
|
||
else
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (row.Index >= 0)
|
||
{
|
||
row.Cells["colDraftId"].Value = productDraftId; // 草稿箱id
|
||
row.Cells["colAddTime"].Value = DateTime.Now.ToString("yy-MM-dd HH:mm:ss");
|
||
row.Cells["colOpResult"].Value = (selectProd.status == "已上传" ? "已成功上传" : "已上传 注意:") + (" " + error).TrimEnd(' ') + " " + duration.ParseToInt() + "秒";
|
||
row.Cells["colMsg"].Value = selectProd.status;
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
currentShopList.Remove(randomShop);
|
||
});
|
||
}
|
||
|
||
for (int i = 0; i < 300 && currentShopList.Count > 0; i++)
|
||
{
|
||
Thread.Sleep(1000);
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
BaseMsgForm.ShowInfo("上传停止!");
|
||
else
|
||
BaseMsgForm.ShowInfo("上传完成!");
|
||
}));
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = false;
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
this.statusBar.lblTaskStatus.Text = "上传停止";
|
||
else
|
||
this.statusBar.lblTaskStatus.Text = "上传完成";
|
||
//this.statusBar.UpdateProgressBar(lstTemuDBProductSelect.Count);
|
||
}));
|
||
}
|
||
|
||
public static KJDDBProduct GetProductDetail(string prodDbId, out string errMsg, bool noViolationProduct = false)
|
||
{
|
||
errMsg = "";
|
||
|
||
if (string.IsNullOrEmpty(prodDbId))
|
||
{
|
||
errMsg = "产品编号为空";
|
||
return new KJDDBProduct();
|
||
}
|
||
|
||
List<KJDDBProduct> list = new List<KJDDBProduct>();
|
||
|
||
var url = BaseClass.BuildObjString("product/get_pdd_product_detail_list");
|
||
var data = UserLogin.GetSignaturex() + "&search_db_ids=" + prodDbId;
|
||
if (noViolationProduct)
|
||
data += "&wx_safe_status=安全商品,未校验";
|
||
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
return null;
|
||
}
|
||
|
||
var jArr = JObject.Parse(html)["data"];
|
||
if (jArr.Count() == 0)
|
||
return null;
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
|
||
try
|
||
{
|
||
list = JsonHelper.DeserializeJsonToList<KJDDBProduct>(sProd);
|
||
var item = list.FirstOrDefault();
|
||
if (item == null)
|
||
item = new KJDDBProduct();
|
||
return item;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public static WXGetEditProductInfoLite GetProductWXComplate(string secret_spu_id, out string errMsg)
|
||
{
|
||
errMsg = "";
|
||
|
||
if (string.IsNullOrEmpty(secret_spu_id))
|
||
{
|
||
errMsg = "产品编码为空";
|
||
return null;
|
||
}
|
||
|
||
List<WXGetEditProductInfoLite> list = new List<WXGetEditProductInfoLite>();
|
||
|
||
var url = BaseClass.BuildObjString("product/get_pdd_prod_wx_complate_list");
|
||
var data = UserLogin.GetSignaturex() + "&search_secret_spu_ids=" + secret_spu_id;
|
||
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
errMsg = BaseRegex.GetStringJson(ref html, "msg");
|
||
if (errMsg.IsNullOrEmpty())
|
||
errMsg = html;
|
||
errMsg = "取回采数据失败 " + errMsg;
|
||
return null;
|
||
}
|
||
|
||
var jArr = JObject.Parse(html)["data"];
|
||
if (jArr.Count() == 0)
|
||
{
|
||
errMsg = "产品不存在";
|
||
return null;
|
||
}
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
|
||
try
|
||
{
|
||
var item = jArr.FirstOrDefault()["wx_edit_prod_json"];
|
||
if (item == null)
|
||
return null;
|
||
|
||
var editProd = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(((JValue)item).Value.ParseToString());
|
||
return editProd;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errMsg = "回采数据转换失败 " + ex.Message;
|
||
return null;
|
||
}
|
||
}
|
||
|
||
string UploadProduct(ShopLoginInfo shop, KJDDBProduct dbProd, TemuDBProductSelect selectProd, DataGridViewCell cell, DateTime startTime)
|
||
{
|
||
Thread.Sleep(Randomx.GetId(100, 300));
|
||
if (shop == null || string.IsNullOrEmpty(shop.ShopId) || shop.LoginStatus != "登录成功")
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"店铺为空或未登录!\"}";
|
||
}
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在初始化上传";
|
||
}));
|
||
}
|
||
|
||
#region 跳过已上传商品
|
||
if (chkSkipUploaded.Checked)
|
||
{
|
||
var searchExtCode = "EC1" + dbProd.spu_id + "A";
|
||
if (dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId"))
|
||
{
|
||
var sku_secret_json = dbProd.sku_secret_json;
|
||
searchExtCode = BaseRegex.GetStringJson(ref sku_secret_json, "goodsId");
|
||
}
|
||
var searchRst = WXUpload.searchProduct(shop, searchExtCode);
|
||
if (!searchRst.Contains("\"code\":0") && !searchRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref searchRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = searchRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + error + "\"}";
|
||
}
|
||
try
|
||
{
|
||
var num = JObject.Parse(searchRst)["totalNum"].ParseToInt();
|
||
if (num > 0)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品已存在,选择跳过\"}";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
WXGetEditProductInfoLite wxEditProdInfo = null;
|
||
if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
try
|
||
{
|
||
wxEditProdInfo = JsonHelper.DeserializeJsonToObject<WXGetEditProductInfoLite>(dbProd.product_json);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"微信商品格式获取失败" + ex.Message + "\"}";
|
||
}
|
||
}
|
||
|
||
#region 将聚水潭产品数据格式进行转换成pdd格式统一上传,匹配加密的spuCode和skuCoke 微信小店的货号spuCode和外部商品编号outProductId/out_product_id对应加密的聚水潭goodsId
|
||
if (dbProd.product_get_type_text == "厂商直采" && dbProd.sku_secret_json != null && dbProd.sku_secret_json.Contains("goodsId"))
|
||
{
|
||
string convertRst = "";
|
||
var pInfo = new PDDProdFormConverter().JstPddProdToPddConvert(out convertRst, dbProd);
|
||
if (!string.IsNullOrEmpty(convertRst))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 微信格式转换
|
||
if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
string convertRst = "";
|
||
var pInfo = new PDDProdFormConverter().WXProdToPddConvert(out convertRst, dbProd);
|
||
if (!string.IsNullOrEmpty(convertRst))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 1688格式转换
|
||
if (dbProd.product_get_type_text == "1688厂家")
|
||
{
|
||
string convertRst = "";
|
||
var pInfo = new PDDProdFormConverter()._1688ClientToPddConvert(out convertRst, dbProd);
|
||
if (!string.IsNullOrEmpty(convertRst))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 微信小店app
|
||
if (dbProd.product_get_type_text == "微信小店")
|
||
{
|
||
string convertRst = "";
|
||
var pInfo = new PDDProdFormConverter().WXClientToPddConvert(out convertRst, dbProd);
|
||
if (!string.IsNullOrEmpty(convertRst))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 将产品数据初始化成微信小店支持的参数
|
||
JObject prodJObj = new JObject();
|
||
try
|
||
{
|
||
prodJObj = JObject.Parse(dbProd.product_json);
|
||
|
||
var lstTitleReplaceText = new List<string>();
|
||
if (!txtReplaceText.Text.Trim().IsNullOrEmpty())
|
||
lstTitleReplaceText.AddRange(txtReplaceText.Text.Trim().Split(new string[] { ",", ",", " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
|
||
// 过滤标题敏感词
|
||
if (lstTitleReplaceText.Count > 0)
|
||
{
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
dbProd.product_name = dbProd.product_name.Replace(txt, "");
|
||
}
|
||
|
||
var goods_name = prodJObj["detail"]["goods_name"].ParseToString();
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
goods_name = goods_name.Replace(txt, "");
|
||
}
|
||
prodJObj["detail"]["goods_name"] = goods_name;
|
||
|
||
var tiny_name = prodJObj["detail"]["tiny_name"].ParseToString();
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
tiny_name = tiny_name.Replace(txt, "");
|
||
}
|
||
prodJObj["detail"]["tiny_name"] = tiny_name;
|
||
|
||
var goods_desc = prodJObj["detail"]["goods_desc"].ParseToString();
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
goods_desc = goods_desc.Replace(txt, "");
|
||
}
|
||
prodJObj["detail"]["goods_desc"] = goods_desc;
|
||
|
||
var share_desc = prodJObj["detail"]["share_desc"].ParseToString();
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
share_desc = share_desc.Replace(txt, "");
|
||
}
|
||
prodJObj["detail"]["share_desc"] = share_desc;
|
||
}
|
||
// 替换货号
|
||
if (!string.IsNullOrEmpty(dbProd.ext_code))
|
||
prodJObj["detail"]["out_goods_sn"] = dbProd.ext_code;
|
||
// 替换编辑过的sku
|
||
if (!string.IsNullOrEmpty(dbProd.sku_edit_json))
|
||
prodJObj["detail"]["sku"] = JArray.Parse(JsonHelper.SerializeObject(JsonHelper.DeserializeJsonToList<sku_item>(dbProd.sku_edit_json)));
|
||
// 过滤sku敏感词
|
||
if (lstTitleReplaceText.Count> 0)
|
||
{
|
||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||
try
|
||
{
|
||
foreach (var skuJObj in skuJArr)
|
||
{
|
||
var specJArr = skuJObj["spec"] as JArray;
|
||
for (int i = 0; i < specJArr.Count; i++)
|
||
{
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
specJArr[i]["spec_name"] = specJArr[i]["spec_name"].ParseToString().Replace(txt, "");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品数据初始化失败" + ex.Message + "\"}";
|
||
}
|
||
}
|
||
if (chkSameSpecPrice.Checked)
|
||
{
|
||
var priceTextLst = dbProd.price_text.Split('-');
|
||
if (priceTextLst.Length != 2 || priceTextLst[0] != priceTextLst[1])
|
||
{
|
||
Dictionary<string, int> specPriceDic = new Dictionary<string, int>();
|
||
Dictionary<string, int> specMultiPriceDic = new Dictionary<string, int>();
|
||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||
try
|
||
{
|
||
// 计算主spec的最高价
|
||
foreach (var skuJObj in skuJArr)
|
||
{
|
||
var specJArr = skuJObj["spec"] as JArray;
|
||
if (!specPriceDic.ContainsKey(specJArr[0]["spec_name"].ParseToString()) || skuJObj["price"].ParseToInt() > specPriceDic[specJArr[0]["spec_name"].ParseToString()])
|
||
{
|
||
specPriceDic[specJArr[0]["spec_name"].ParseToString()] = skuJObj["price"].ParseToInt();
|
||
}
|
||
if (!specMultiPriceDic.ContainsKey(specJArr[0]["spec_name"].ParseToString()) || skuJObj["multi_price"].ParseToInt() > specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()])
|
||
{
|
||
specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()] = skuJObj["multi_price"].ParseToInt();
|
||
}
|
||
}
|
||
// 统一按最高价设置
|
||
foreach (var skuJObj in skuJArr)
|
||
{
|
||
var specJArr = skuJObj["spec"] as JArray;
|
||
skuJObj["price"] = specPriceDic[specJArr[0]["spec_name"].ParseToString()];
|
||
skuJObj["multi_price"] = specMultiPriceDic[specJArr[0]["spec_name"].ParseToString()];
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品数据初始化失败" + ex.Message + "\"}";
|
||
}
|
||
}
|
||
}
|
||
if (chkHighestPriceSku.Checked)
|
||
{
|
||
int price = 0;
|
||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||
try
|
||
{
|
||
// 计算主spec的最高价
|
||
foreach (var skuJObj in skuJArr)
|
||
{
|
||
if (price < skuJObj["multi_price"].ParseToInt())
|
||
price = skuJObj["multi_price"].ParseToInt();
|
||
}
|
||
|
||
var product_json_tmp = JsonHelper.SerializeObject(prodJObj);
|
||
|
||
// 移除第一组所有sku
|
||
skuJArr.RemoveAll();
|
||
|
||
// 序列化第二组,从组中挑选符合价格条件的sku往第一组内填写
|
||
var prodJObj2 = JObject.Parse(product_json_tmp);
|
||
var skuJArr2 = prodJObj2["detail"]["sku"] as JArray;
|
||
foreach (var skuJObj2 in skuJArr2)
|
||
{
|
||
if (skuJObj2["multi_price"].ParseToInt() >= price)
|
||
skuJArr.Add(skuJObj2);
|
||
}
|
||
if (skuJArr.Count == 0)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品sku差价不满足上货条件,跳过\"}";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品数据初始化失败" + ex.Message + "\"}";
|
||
}
|
||
}
|
||
// 过滤低价sku,如果所有sku都不达标,跳过商品
|
||
if (!string.IsNullOrEmpty(txtMinPrice.Text))
|
||
{
|
||
var product_json_tmp = JsonHelper.SerializeObject(prodJObj);
|
||
|
||
// 移除第一组所有sku
|
||
var skuJArr = prodJObj["detail"]["sku"] as JArray;
|
||
skuJArr.RemoveAll();
|
||
|
||
// 序列化第二组,从组中挑选符合价格条件的sku往第一组内填写
|
||
var prodJObj2 = JObject.Parse(product_json_tmp);
|
||
var skuJArr2 = prodJObj2["detail"]["sku"] as JArray;
|
||
foreach (var skuJObj2 in skuJArr2)
|
||
{
|
||
var limitPrice = this.txtMinPrice.Text.Trim().ParseToDecimal() * 100;
|
||
// 供应商价加价10%(最低1元)赚取差价 先加价后过滤,过滤条件也要相应增加10%
|
||
//if (dbProd.product_get_type_text == "厂商直采")
|
||
// limitPrice += Math.Max(100m, limitPrice * 0.1m);
|
||
if (skuJObj2["multi_price"].ParseToInt() >= limitPrice)
|
||
skuJArr.Add(skuJObj2);
|
||
}
|
||
if (skuJArr.Count == 0)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品sku价格不满足上货条件,跳过\"}";
|
||
}
|
||
}
|
||
dbProd.product_json = JsonHelper.SerializeObject(prodJObj);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品数据初始化失败" + ex.Message + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1")
|
||
{
|
||
string errMsg = "";
|
||
wxEditProdInfo = GetProductWXComplate(dbProd.secret_spu_id, out errMsg);
|
||
|
||
if (wxEditProdInfo == null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = errMsg;
|
||
}));
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + errMsg + "\"}";
|
||
}
|
||
}
|
||
|
||
#region 图片盗链映射
|
||
bool isChangeImgDic = false;
|
||
Dictionary<string, string> wxImgMapDic = new Dictionary<string, string>();
|
||
if (!string.IsNullOrEmpty(dbProd.wx_img_map_json))
|
||
{
|
||
try
|
||
{
|
||
wxImgMapDic = JsonHelper.DeserializeJsonToObject<Dictionary<string, string>>(dbProd.wx_img_map_json);
|
||
}
|
||
catch
|
||
{
|
||
isChangeImgDic = true;
|
||
wxImgMapDic = new Dictionary<string, string>();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 暂时不上传视频
|
||
var prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(dbProd.product_json);
|
||
prodInfo.detail.galleries.RemoveAll(g => g.type == 6); // 视频暂时移除,以后再视情况加上
|
||
#endregion
|
||
|
||
#region 主图不够详情图补充
|
||
int mainImgCount = (prodInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt();
|
||
if (mainImgCount > 0 && mainImgCount < 3)
|
||
{
|
||
var gallery1 = prodInfo?.detail?.galleries?.Where(g => g.type == 2).FirstOrDefault();
|
||
// 先补一张
|
||
if (gallery1 != null)
|
||
{
|
||
prodInfo.detail.galleries.Add(new gallery_item()
|
||
{
|
||
type = 1,
|
||
url = gallery1.url,
|
||
width = gallery1.width,
|
||
height = gallery1.height,
|
||
});
|
||
}
|
||
// 如果补了只有两张再补一张
|
||
if (mainImgCount == 1 && (prodInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt() > 1)
|
||
{
|
||
var gallery2 = prodInfo?.detail?.galleries?[1];
|
||
if (gallery2 != null)
|
||
{
|
||
prodInfo.detail.galleries.Add(new gallery_item()
|
||
{
|
||
type = 1,
|
||
url = gallery2.url,
|
||
width = gallery2.width,
|
||
height = gallery2.height,
|
||
});
|
||
}
|
||
}
|
||
}
|
||
if ((prodInfo?.detail?.galleries?.Where(g => g.type == 1).Count()).ParseToInt() < 3)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "主图数量少于三张";
|
||
}));
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"主图数量少于三张\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 过滤重复图片 无论是否打码
|
||
bool needAddRandomBlock = false;
|
||
bool wantAddRandomBlock = chkImgRandomBlock.Checked && (/*upProdParam.product.info.category.FirstOrDefault()?.name == "图书" ||*/
|
||
prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸" || dbProd.main_cat_name == "图书" || dbProd.main_cat_name == "书籍/杂志/报纸");
|
||
{
|
||
List<gallery_item> galls = new List<gallery_item>();
|
||
foreach (var gall in prodInfo.detail.galleries.Where(g => g.type == 1).ToList())
|
||
{
|
||
if (!galls.Any(g => g.url == gall.url)/* && !prodInfo.detail.sku.Any(s => s.thumb_url == gall.url)*/)
|
||
galls.Add(gall);
|
||
}
|
||
foreach (var gall in prodInfo.detail.galleries.Where(g => g.type == 2).ToList())
|
||
{
|
||
if (!galls.Any(g => g.url == gall.url)/* && !prodInfo.detail.sku.Any(s => s.thumb_url == gall.url)*/)
|
||
galls.Add(gall);
|
||
}
|
||
prodInfo.detail.galleries.Clear();
|
||
prodInfo.detail.galleries.AddRange(galls);
|
||
int repeatSn = 0;
|
||
while (prodInfo.detail.galleries.Where(g => g.type == 1).Count() > 0 && prodInfo.detail.galleries.Where(g => g.type == 1).Count() < 3)
|
||
{
|
||
repeatSn++;
|
||
var gallOld = prodInfo.detail.galleries.LastOrDefault(g => g.type == 1);
|
||
var gallNew = JsonHelper.DeserializeJsonToObject<gallery_item>(JsonHelper.SerializeObject(gallOld));
|
||
// 如果有 替换掉之前附加的后缀
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
gallNew.url = gallNew.url.Replace("?re_sn1=" + i, "");
|
||
gallNew.url = gallNew.url.Replace("?re_sn1=" + i, "");
|
||
}
|
||
if (gallNew.url.Contains("?"))
|
||
gallNew.url += "&re_sn1=" + repeatSn;
|
||
else
|
||
gallNew.url += "?re_sn1=" + repeatSn;
|
||
prodInfo.detail.galleries.Add(gallNew);
|
||
needAddRandomBlock = true;
|
||
}
|
||
if (prodInfo.detail.galleries.Where(g => g.type == 1).Count() > 0 && prodInfo.detail.galleries.Where(g => g.type == 2).Count() <= 0)
|
||
{
|
||
var gallOld = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1);
|
||
var gallNew = JsonHelper.DeserializeJsonToObject<gallery_item>(JsonHelper.SerializeObject(gallOld));
|
||
if (gallNew.url.Contains("?"))
|
||
gallNew.url += "&re_sn2=" + 1;
|
||
else
|
||
gallNew.url += "?re_sn2=" + 1;
|
||
gallNew.type = 2;
|
||
prodInfo.detail.galleries.Add(gallNew);
|
||
needAddRandomBlock = true;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
// 生成初始化上传商品对象
|
||
var upProdInitParam = new WXUploadProductInitParam();
|
||
// 生成上传商品对象
|
||
var upProdParam = new WXUploadProductParam();
|
||
|
||
// 获取店铺的accessToken
|
||
WXShopTokenInfo token = lstWXShopTokenInfo.FirstOrDefault(t => t.shopId == shop.ShopId);
|
||
if (token == null)
|
||
token = new WXShopTokenInfo();
|
||
if (token.isExpire || string.IsNullOrEmpty(token.accessToken))
|
||
{
|
||
AuthInfo auth = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||
if (auth != null && auth.ExpiresTime > DateTime.Now.AddMinutes(5))
|
||
{
|
||
token = new WxApiBLL().GetShopWxToken(shop);
|
||
|
||
if (!string.IsNullOrEmpty(token.accessToken))
|
||
{
|
||
lstWXShopTokenInfo.RemoveAll(t => t.shopId == shop.ShopId);
|
||
lstWXShopTokenInfo.Add(token);
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_token_list", lstWXShopTokenInfo);
|
||
}
|
||
}
|
||
}
|
||
// 如果店铺token不可用,随机获取一个上传图片的accessToken
|
||
if (token == null || token.isExpire || string.IsNullOrEmpty(token.accessToken))
|
||
token = new WxApiBLL().GetRandomWxToken();
|
||
|
||
#region 设置标题
|
||
string prodTitle = dbProd.product_name.IsNullOrEmpty() ? prodInfo.detail.goods_name : dbProd.product_name;
|
||
upProdInitParam.product.info.title = prodTitle;
|
||
upProdParam.product.info.title = prodTitle;
|
||
upProdParam.sessionInfo.sessionId = upProdInitParam.product.sessionId;
|
||
#endregion
|
||
|
||
#region 设置货号
|
||
var extCode = dbProd.ext_code.IsNullOrEmpty() ? prodInfo.detail.out_goods_sn : dbProd.ext_code;
|
||
if (extCode.IsNullOrEmpty())
|
||
{
|
||
//extCode = "EC" + Randomx.GetId(1000).ToString().PadLeft(3, '0') + dbProd.spu_id + "C";
|
||
extCode = "EC1" + dbProd.spu_id + "A";
|
||
}
|
||
upProdParam.product.info.spuCode = extCode;
|
||
upProdParam.product.info.outProductId = extCode;
|
||
upProdParam.product.info.out_product_id = extCode;
|
||
upProdParam.product.productKey.outProductId = extCode;
|
||
#endregion
|
||
|
||
#region 上传主图
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成主图并识别商品";
|
||
}));
|
||
}
|
||
Thread.Sleep(Randomx.GetId(100, 300));
|
||
var mainGalleries = prodInfo.detail.galleries.Where(g => g.type == 1).Take(9).ToList();
|
||
foreach (var gallery_item in mainGalleries) // 9张主图
|
||
{
|
||
try
|
||
{
|
||
if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
upProdInitParam.product.info.headImg.Add(gallery_item.url);
|
||
upProdParam.product.info.headImg.Add(gallery_item.url);
|
||
continue;
|
||
}
|
||
|
||
// 获取缓存盗链 主图
|
||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||
{
|
||
upProdInitParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||
upProdParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||
continue;
|
||
}
|
||
|
||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||
{
|
||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||
}
|
||
else
|
||
{
|
||
// 使用接口链接传主图
|
||
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
|
||
var upDate = UserLogin.GetSignaturex();
|
||
upDate += "&token=" + token.accessToken;
|
||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + gallery_item.url.Replace("https://", "http://") + "\"}");
|
||
|
||
var sTime = DateTime.Now;
|
||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成主图并识别商品 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||
}));
|
||
}
|
||
|
||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||
{
|
||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||
token = new WxApiBLL().GetRandomWxToken();
|
||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
}
|
||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||
{
|
||
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||
isChangeImgDic = true;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
// api上传图片文件 主图
|
||
if (1 == 1)
|
||
{
|
||
try
|
||
{
|
||
string errMsg = "";
|
||
var imgBase64 = GetImgBase64ForApi(out errMsg, gallery_item.url, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
return errMsg;
|
||
}
|
||
|
||
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=" + gallery_item.url;
|
||
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");
|
||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||
{
|
||
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||
isChangeImgDic = true;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"修改主图失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
|
||
// 模拟上传图片
|
||
if (1 == 1)
|
||
{
|
||
var upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
|
||
for (int i = 0; i < 10 && upImgAuthRst.Contains("LogicError"); i++)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "图片提报失败,正在重试。" + (i + 1);
|
||
}));
|
||
Thread.Sleep(Randomx.GetId(3000, 6000));
|
||
upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
|
||
}
|
||
if (!upImgAuthRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref upImgAuthRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = upImgAuthRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"申请上传主图失败 " + GetHtml.UrlEncodeUtf8(error) + "\"}";
|
||
}
|
||
string disK = BaseRegex.GetStringJson(ref upImgAuthRst, "disK");
|
||
long disT = BaseRegex.GetLongJson(ref upImgAuthRst, "disT");
|
||
string ext = BaseRegex.GetStringJson(ref upImgAuthRst, "ext");
|
||
string imgBase64 = "";
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
//生成主图base64字符串
|
||
string getImgError;
|
||
var image = GetHtml.GetUrlImg(gallery_item.url.Replace("https://", "http://"), out getImgError);
|
||
var imageBg = new Bitmap(800, 800);
|
||
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);
|
||
if (needAddRandomBlock || wantAddRandomBlock)
|
||
{
|
||
g.FillRectangle(new SolidBrush(Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256))),
|
||
new Rectangle(Randomx.GetId(imageBg.Width - 30), Randomx.GetId(imageBg.Height - 30), 30, 30));
|
||
}
|
||
}
|
||
using (MemoryStream memoryStream = new MemoryStream())
|
||
{
|
||
imageBg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
byte[] imageBytes = memoryStream.ToArray();
|
||
imgBase64 = Convert.ToBase64String(imageBytes);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"修改主图失败 " + ex.Message + "\"}";
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
//上传主图获取路径
|
||
var upImgRst = WXUpload.adtimageupload(shop, imgBase64, disK, disT, ext).ParseToString();
|
||
var location = BaseRegex.GetStringJson(ref upImgRst, "Location");
|
||
if (string.IsNullOrEmpty(location))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref upImgAuthRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = upImgAuthRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"主图上传失败 " + error + "\"}";
|
||
}
|
||
upProdInitParam.product.info.headImg.Add(location);
|
||
upProdParam.product.info.headImg.Add(location);
|
||
//wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = location;
|
||
//isChangeImgDic = true;
|
||
Thread.Sleep(Randomx.GetId(10, 50));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存缓存盗链图片
|
||
if (isChangeImgDic)
|
||
{
|
||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&spu_id=" + dbProd.spu_id;
|
||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
isChangeImgDic = false;
|
||
}
|
||
#endregion
|
||
|
||
#region 识别类目
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成类目属性";
|
||
}));
|
||
}
|
||
List<long> aiCateIdLst = new List<long>();
|
||
// 聚水潭商品已识别类目使用类目缓存
|
||
// 微信商品使用类目缓存
|
||
if (!dbProd.wx_cat_leaf.IsNullOrZero())
|
||
{
|
||
if (!dbProd.wx_cat_1.IsNullOrZero())
|
||
aiCateIdLst.Add(dbProd.wx_cat_1.ParseToLong());
|
||
if (!dbProd.wx_cat_2.IsNullOrZero())
|
||
aiCateIdLst.Add(dbProd.wx_cat_2.ParseToLong());
|
||
if (!dbProd.wx_cat_3.IsNullOrZero())
|
||
aiCateIdLst.Add(dbProd.wx_cat_3.ParseToLong());
|
||
if (!dbProd.wx_cat_leaf.IsNullOrZero())
|
||
aiCateIdLst.Add(dbProd.wx_cat_leaf.ParseToLong());
|
||
aiCateIdLst = aiCateIdLst.Distinct().ToList();
|
||
}
|
||
else
|
||
{
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
// ai识别类目暂存主图位置
|
||
int imgId = 0;
|
||
string tempImgPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower();
|
||
List<string> tempImgFullPathLst = new List<string>();
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
// 生成ai识别类目所需图片
|
||
var aiGalleries = prodInfo.detail.galleries.Where(g => g.type == 1).Take(3).ToList();
|
||
foreach (var gallery_item in aiGalleries) // 9张主图
|
||
{
|
||
string getImgError;
|
||
var image = GetHtml.GetUrlImg(gallery_item.url.Replace("https://", "http://"), out getImgError);
|
||
var imageBg = new Bitmap(800, 800);
|
||
if (!string.IsNullOrEmpty(getImgError) || image == null)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"初始化主图上传失败\"}";
|
||
}
|
||
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);
|
||
}
|
||
|
||
// 取前三张图片保存到系统temp路径,配合商品标题获取商品类目
|
||
if (imgId <= 3)
|
||
{
|
||
if (!Directory.Exists(tempImgPath))
|
||
Directory.CreateDirectory(tempImgPath);
|
||
string imgFullPath = tempImgPath + "\\图片" + imgId + ".jpg";
|
||
tempImgFullPathLst.Add(imgFullPath);
|
||
if (imgId == 1)
|
||
image.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
else
|
||
{
|
||
// 只需要传一张真实图像即可
|
||
int fileSize = Randomx.GetId(1024, 10240);
|
||
using (BinaryWriter writer = new BinaryWriter(File.Create(imgFullPath)))
|
||
{
|
||
for (int i = 0; i < fileSize; i++)
|
||
{
|
||
writer.Write((byte)Randomx.GetId(256)); // 生成0到255之间的随机字节
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
Thread.Sleep(Randomx.GetId(100, 300));
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
// 根据Ai分类,获取类目信息
|
||
//{"code":0,"predInfo":{"firstCatRes":[{"catId":10000111,"catName":"服饰内衣","level":1},{"catId":10000111,"catName":"服饰内衣","level":1},{"catId":10000111,"catName":"服饰内衣","level":1}],"secondCatRes":[{"catId":10000113,"catName":"女装","level":2},{"catId":10000113,"catName":"女装","level":2},{"catId":10000113,"catName":"女装","level":2}],"thirdCatRes":[{"catId":547705,"catName":"牛仔裤","level":3,"modelVersion":""},{"catId":547704,"catName":"加绒裤","level":3,"modelVersion":"商品标题含'加绒加厚、保暖'等关键词,这表示裤子具备加绒保暖功能。主图展示了加绒内衬,也符合【服饰内衣:女装:裤子:加绒裤】类目特征。"},{"catId":547701,"catName":"休闲裤","level":3,"modelVersion":""}],"singleSecondCatRes":[],"singleFirstCatRes":[],"isSupportedCate":1},"aiCategoryList":[{"id":547705,"paths":[{"id":"10000111","name":"服饰内衣","sonIdList":["10000397","10000115","10000112","10000113","10000114"],"fId":"0","level":1,"leaf":false},{"id":"10000113","name":"女装","sonIdList":["546810","546811","530041","547706","6090","6089","6088","6087","6083","6076","6073","6070","6065","6063","6058","10000672","10000671","10000670","10000669","10000668","10000667","10000666","10000665","10000664","10000663","10000662","10000661","10000660","10000659","10000658","10000657","10000656","10000655"],"fId":"10000111","level":2,"leaf":false},{"id":"10000672","name":"裤子","sonIdList":["547699","547700","547701","547702","547703","547704","547705"],"fId":"10000113","level":3,"leaf":false},{"id":"547705","name":"牛仔裤","fId":"10000672","level":4,"leaf":true,"state":0,"hasTrialCategory":false,"isTrialCategory":false,"isLocalLife":false}],"depositAmount":0,"catAuth":true,"limitSubjectTypes":[]},{"id":547704,"paths":[{"id":"10000111","name":"服饰内衣","sonIdList":["10000397","10000115","10000112","10000113","10000114"],"fId":"0","level":1,"leaf":false},{"id":"10000113","name":"女装","sonIdList":["546810","546811","530041","547706","6090","6089","6088","6087","6083","6076","6073","6070","6065","6063","6058","10000672","10000671","10000670","10000669","10000668","10000667","10000666","10000665","10000664","10000663","10000662","10000661","10000660","10000659","10000658","10000657","10000656","10000655"],"fId":"10000111","level":2,"leaf":false},{"id":"10000672","name":"裤子","sonIdList":["547699","547700","547701","547702","547703","547704","547705"],"fId":"10000113","level":3,"leaf":false},{"id":"547704","name":"加绒裤","fId":"10000672","level":4,"leaf":true,"state":0,"hasTrialCategory":false,"isTrialCategory":false,"isLocalLife":false}],"depositAmount":0,"catAuth":true,"limitSubjectTypes":[]},{"id":547701,"paths":[{"id":"10000111","name":"服饰内衣","sonIdList":["10000397","10000115","10000112","10000113","10000114"],"fId":"0","level":1,"leaf":false},{"id":"10000113","name":"女装","sonIdList":["546810","546811","530041","547706","6090","6089","6088","6087","6083","6076","6073","6070","6065","6063","6058","10000672","10000671","10000670","10000669","10000668","10000667","10000666","10000665","10000664","10000663","10000662","10000661","10000660","10000659","10000658","10000657","10000656","10000655"],"fId":"10000111","level":2,"leaf":false},{"id":"10000672","name":"裤子","sonIdList":["547699","547700","547701","547702","547703","547704","547705"],"fId":"10000113","level":3,"leaf":false},{"id":"547701","name":"休闲裤","fId":"10000672","level":4,"leaf":true,"state":0,"hasTrialCategory":false,"isTrialCategory":false,"isLocalLife":false}],"depositAmount":0,"catAuth":true,"limitSubjectTypes":[]}],"version":"ProductClsRAG","noQualificationCatIds":[547705,547704,547701],"depositCatInfos":[{"catId":547705,"amountToPay":0,"error":false},{"catId":547704,"amountToPay":0,"error":false},{"catId":547701,"amountToPay":0,"error":false}],"visionCallMethod":"ProductClsRAG"}
|
||
var productClassifyRst = WXUpload.getProductClassify(shop, upProdInitParam.product.info.title, tempImgFullPathLst);
|
||
if (!productClassifyRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref productClassifyRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = productClassifyRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"获取类目失败 " + error + "\"}";
|
||
}
|
||
WXGetProdCateInfo cateInfo = new WXGetProdCateInfo();
|
||
try
|
||
{
|
||
cateInfo = JsonHelper.DeserializeJsonToObject<WXGetProdCateInfo>(productClassifyRst);
|
||
foreach (var catePath in cateInfo.aiCategoryList.FirstOrDefault().paths)
|
||
{
|
||
aiCateIdLst.Add(catePath.id.ParseToLong());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + "根据图片获取类目失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 生成类目模板
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成类目模板";
|
||
}));
|
||
}
|
||
string getCateRst = WXUpload.getCategoryOnShelf(shop, aiCateIdLst);
|
||
if (!getCateRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getCateRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getCateRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"获取类目模板失败" + error + "\"}";
|
||
}
|
||
|
||
JObject jCateRst = JObject.Parse(getCateRst);
|
||
upProdParam.product.info.category = JsonHelper.DeserializeJsonToList<categoryParam>(JsonHelper.SerializeObject(jCateRst["category"]));
|
||
// 这里用了ai获取类目,如下填写
|
||
upProdParam.product.info.recommendCategory = new recommendCategoryParam()
|
||
{
|
||
isAccepted = true,
|
||
categoryNames = new List<string>(),
|
||
recommendSource = "ai",
|
||
interfaceName = "ProductClsRAG",
|
||
useNewInterface = 1,
|
||
};
|
||
foreach (var cateParam in upProdParam.product.info.category)
|
||
{
|
||
upProdParam.product.info.recommendCategory.categoryNames.Add(cateParam.name);
|
||
}
|
||
|
||
// 获取叶子类目id
|
||
long leafCatId = (upProdParam.product.info.category.LastOrDefault()?.catId).ParseToLong(); //哲学经典著作
|
||
var bound = GlobalConfig.WxCatBoundList.FirstOrDefault(b => b.leaf_id == leafCatId);
|
||
if (bound == null)
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"获取类目保证金失败\"}";
|
||
var maxBount = txtFilterBoundMax.Text.Trim().ParseToInt();
|
||
var minBount = txtFilterBoundMin.Text.Trim().ParseToInt();
|
||
if (bound.cat_bound < minBount || bound.cat_bound > maxBount )
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目保证金(" + bound.cat_bound + ")超过过滤限制(" + minBount + "-" + maxBount + ")\"}";
|
||
|
||
// 检测是否有类目上传权限
|
||
var cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId);
|
||
//"{\"code\":0,\"list\":[{\"category_id\":\"1427\",\"result\":0,\"no_auth_reason_type\":0}]}"
|
||
//"{\"code\":0,\"list\":[{\"category_id\":\"7486\",\"result\":0,\"no_auth_reason_type\":0}]}"
|
||
if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref cateUpCheckRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = cateUpCheckRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目校验错误 " + error + "\"}";
|
||
}
|
||
if (!cateUpCheckRst.Contains("\"result\":1"))
|
||
{
|
||
if (aiCateIdLst.FirstOrDefault() == 10000215)
|
||
{
|
||
//@"{""categoryInfo"":{""categories"":[{""id"":10000215},{""id"":10000222},{""id"":7483}],""categoryDeposit"":""1000.00"",""isNewApplyCat"":true,""licenseGroupList"":[{""licenseGroupId"":""1"",""license"":{""licenseId"":""4"",""cosIdList"":[""1771897594802-oM5657FQAaKYlf2uP300NBgx9HYY-0581""],""licenseFieldList"":[{""key"":""audit_license_registration_no"",""value"":""YB23509020049441""},{""key"":""search_url"",""value"":""""}],""isReuse"":true}}],""ruleVersion"":5234,""certificate"":[]},""brandIdList"":[],""leafCategoryId"":7483,""reuse"":0,""applyType"":""normalApply""}";
|
||
var getCatDataRst = WXUpload.getSingleCategoryData(shop, leafCatId, aiCateIdLst);
|
||
if (!getCatDataRst.Contains("\"code\":0") && !getCatDataRst.Contains("\"success\":true"))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 查询类目资质文件失败" + "\"}";
|
||
}
|
||
|
||
WXCateAuthParam wxCateAuthParam = new WXCateAuthParam();
|
||
wxCateAuthParam.leafCategoryId = leafCatId;
|
||
wxCateAuthParam.categoryInfo.categoryDeposit = bound.cat_bound.ToString("0.00");
|
||
wxCateAuthParam.categoryInfo.ruleVersion = BaseRegex.GetIntJson(ref getCatDataRst, "ruleVersion");
|
||
foreach (var cateId in aiCateIdLst)
|
||
{
|
||
wxCateAuthParam.categoryInfo.categories.Add(new WXCateId() { id = cateId });
|
||
}
|
||
try
|
||
{
|
||
if (!JsonHelper.JObjectParse(getCatDataRst)["reuseApplyData"].IsJTokenNullOrEmpty())
|
||
{
|
||
var jlicenseGroupList = JsonHelper.JObjectParse(getCatDataRst)["reuseApplyData"]["catInfo"]["licenseGroupList"];
|
||
var licenseGroupListStr = JsonHelper.SerializeObject(jlicenseGroupList);
|
||
wxCateAuthParam.categoryInfo.licenseGroupList = JsonHelper.DeserializeJsonToList<licenseGroup>(licenseGroupListStr);
|
||
}
|
||
else
|
||
{
|
||
var licenseGroup = new licenseGroup();
|
||
wxCateAuthParam.categoryInfo.licenseGroupList.Add(licenseGroup);
|
||
licenseGroup.license.licenseId = "4";
|
||
var cosIdList = "[" + BaseRegex.GetMatchRegexString(ref getCatDataRst, "\"cosIdList\":\\[([\\s\\S]*?)\\]") + "]";
|
||
licenseGroup.license.cosIdList = JsonHelper.DeserializeJsonToList<string>(cosIdList);
|
||
var licenseFieldList = "[" + BaseRegex.GetMatchRegexString(ref getCatDataRst, "\"licenseFieldList\":\\[([\\s\\S]*?)\\]") + "]";
|
||
licenseGroup.license.licenseFieldList = JsonHelper.DeserializeJsonToList<KeyValueParam>(licenseFieldList);
|
||
}
|
||
var authCateRst = WXUpload.wxCateAuth(shop, aiCateIdLst, wxCateAuthParam);
|
||
if (!authCateRst.Contains("\"code\":0") && !authCateRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref authCateRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = BaseRegex.GetStringJson(ref authCateRst, "errmsg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = authCateRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 " + error + "\"}";
|
||
}
|
||
Thread.Sleep(Randomx.GetId(5000, 7000));
|
||
cateUpCheckRst = WXUpload.batchCheckCategoryRelation(shop, leafCatId);
|
||
if (!cateUpCheckRst.Contains("\"code\":0") && !cateUpCheckRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref cateUpCheckRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = cateUpCheckRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请校验错误 " + error + "\"}";
|
||
}
|
||
if (!cateUpCheckRst.Contains("\"result\":1"))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请审核中 请稍后再试\"}";
|
||
}
|
||
catch
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 复用资质文件失败,请重新提交资质文件" + "\"}";
|
||
}
|
||
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请失败 请手动申请资质类目" + "\"}";
|
||
}
|
||
else
|
||
{
|
||
Thread.Sleep(Randomx.GetId(1000, 2000));
|
||
var cateAuthorRst = WXUpload.addFinderCategoryV2(shop, leafCatId);
|
||
if (!cateAuthorRst.Contains("\"code\":0") && !cateAuthorRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref cateAuthorRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = BaseRegex.GetStringJson(ref cateAuthorRst, "errmsg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = cateAuthorRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"类目申请错误 " + error + "\"}";
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region ai短标题 // ai获取短标题
|
||
if (wxUploadRule.IsAiShortTitle)
|
||
{
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成短标题";
|
||
}));
|
||
}
|
||
|
||
WXGetShortTitleParam titleParam = new WXGetShortTitleParam()
|
||
{
|
||
categories = new List<categorieParam>(),
|
||
headImgUrls = upProdParam.product.info.headImg,
|
||
productTitle = upProdParam.product.info.title,
|
||
};
|
||
foreach (var cate in upProdParam.product.info.category)
|
||
{
|
||
titleParam.categories.Add(new categorieParam() { catId = cate.catId, catName = cate.name });
|
||
}
|
||
var shortTitleRst = WXUpload.genProductShortTitle(shop, titleParam);
|
||
if (!shortTitleRst.Contains("\"code\":0") && !shortTitleRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref shortTitleRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = shortTitleRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"短标题获取失败 " + error + "\"}";
|
||
}
|
||
upProdParam.product.info.shortTitle = BaseRegex.GetStringJson(ref shortTitleRst, "shortTitle");
|
||
upProdParam.product.info.aiGenShortTitle = upProdParam.product.info.shortTitle;
|
||
upProdParam.product.info.title = upProdParam.product.info.shortTitle + upProdParam.product.info.title;
|
||
}
|
||
#endregion
|
||
|
||
#region 标题前缀,加在最前面
|
||
if (!string.IsNullOrWhiteSpace(wxUploadRule.TitleHeadWords))
|
||
upProdParam.product.info.title = wxUploadRule.TitleHeadWords + upProdParam.product.info.title;
|
||
#endregion
|
||
|
||
#region 售后信息
|
||
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在选取售后属性";
|
||
}));
|
||
}
|
||
|
||
var afterSaleAddress = "";
|
||
var afterSaleDetail = "";
|
||
// 厂商直采获取售后地址用于处理售后单
|
||
if (dbProd.product_get_type_text == "厂商直采" && dbProd.wx_cat_leaf != null)
|
||
{
|
||
|
||
var urlAfterSale = BaseClass.BuildObjString("product/wx_get_after_sale");
|
||
var dataAfterSale = Work.UserLogin.GetSignaturex();
|
||
if (!string.IsNullOrEmpty(dbProd.real_coid))
|
||
dataAfterSale += "&coid=" + dbProd.skc_id + "->" + dbProd.real_coid;
|
||
else
|
||
dataAfterSale += "&coid=" + dbProd.skc_id;
|
||
var htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
if (htmlAfterSale.Contains("\"data\":\"\""))
|
||
{
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlAfterSale)["data"]);
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//{"address_id":null,"user_name":"退货","postal_code":null,"province_name":"广东省","city_name":"揭阳市","county_name":"榕城区","street_name":"东兴街道","detail_info":"建阳路万泰华庭二期对面眼镜","tel_number":"13024622251","number":"10431013","name":"麦多多供应链"}
|
||
//{"address_id":null,"user_name":"退货","postal_code":null,"province_name":"广东省","city_name":"揭阳市","county_name":"榕城区","street_name":"东兴街道","detail_info":"建阳路万泰华庭二期对面眼镜","tel_number":"13024622251","number":"10431013","name":"麦多多供应链"}
|
||
if (string.IsNullOrEmpty(afterSaleAddress))
|
||
{
|
||
// 获取推单售后地址
|
||
var urlAfter = BaseClass.BuildObjString("product/e57_after_sale");
|
||
var dataAfter = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id;
|
||
var afterRst = GetHtml.PostUtf8(urlAfter, dataAfter);
|
||
try
|
||
{
|
||
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(afterRst)["data"]);
|
||
if (afterRst.Contains("\"code\":0") && !string.IsNullOrEmpty(afterSaleAddress))
|
||
{
|
||
urlAfterSale = BaseClass.BuildObjString("product/wx_add_mdy_after_sale");
|
||
dataAfterSale = Work.UserLogin.GetSignaturex() +
|
||
"&coid=" + dbProd.skc_id +
|
||
"&after_sale_json=" + afterSaleAddress;
|
||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(afterSaleAddress))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"售后地址信息获取失败\"}";
|
||
}
|
||
}
|
||
|
||
if (dbProd.product_get_type_text == "1688厂家")
|
||
{
|
||
var urlAfterSale = BaseClass.BuildObjString("product/wx_get_after_sale");
|
||
var dataAfterSale = Work.UserLogin.GetSignaturex();
|
||
dataAfterSale += "&coid=" + dbProd.from_shop_id;
|
||
var htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||
htmlAfterSale = GetHtml.PostUtf8(urlAfterSale, dataAfterSale);
|
||
if (string.IsNullOrEmpty(htmlAfterSale) || !htmlAfterSale.Contains("\"code\":200"))
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
if (htmlAfterSale.Contains("\"data\":\"\""))
|
||
{
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
afterSaleAddress = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlAfterSale)["data"]);
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(afterSaleAddress))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"售后地址信息获取失败\"}";
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(afterSaleAddress))
|
||
{
|
||
afterSaleDetail = BaseRegex.GetStringJson(ref afterSaleAddress, "detail_info");
|
||
if (string.IsNullOrEmpty(afterSaleDetail))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"售后地址详细信息获取失败\"}";
|
||
}
|
||
}
|
||
|
||
var addressRst = WXUpload.getAddress(shop, afterSaleDetail);
|
||
if (!addressRst.Contains("\"code\":0") && !addressRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref addressRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = addressRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"售后地址获取失败 " + error + "\"}";
|
||
}
|
||
if (addressRst.Contains("\"totalNum\":0") && !string.IsNullOrEmpty(afterSaleDetail))
|
||
{
|
||
string provinceName = BaseRegex.GetStringJson(ref afterSaleAddress, "province_name");
|
||
string cityName = BaseRegex.GetStringJson(ref afterSaleAddress, "city_name");
|
||
string countyName = BaseRegex.GetStringJson(ref afterSaleAddress, "county_name");
|
||
string detailInfo = afterSaleDetail;
|
||
string userName = BaseRegex.GetStringJson(ref afterSaleAddress, "user_name");
|
||
string telNumber = BaseRegex.GetStringJson(ref afterSaleAddress, "tel_number");
|
||
var addAddRst = WXUpload.addAddress(shop, provinceName, cityName, countyName, detailInfo, userName, telNumber);
|
||
|
||
Thread.Sleep(Randomx.GetId(500, 1000));
|
||
|
||
addressRst = WXUpload.getAddress(shop, afterSaleDetail);
|
||
if (!addressRst.Contains("\"code\":0") && !addressRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref addressRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = addressRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"售后地址获取失败 " + error + "\"}";
|
||
}
|
||
}
|
||
|
||
if (addressRst.Contains("\"totalNum\":0"))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"售后地址获取失败\"}";
|
||
}
|
||
|
||
upProdParam.product.info.afterSaleInfo = new afterSaleInfoParam();
|
||
upProdParam.product.info.afterSaleInfo.afterSaleAddressId = BaseRegex.GetStringJson(ref addressRst, "addressId");
|
||
#endregion
|
||
|
||
// 厂商直采获取推单运费模板
|
||
#region 获取推单运费模板,计算运费加价。
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在选取运费模板";
|
||
}));
|
||
}
|
||
|
||
var shippingTemplateJson = "";
|
||
var shipPrice = 0;
|
||
|
||
if (dbProd.product_get_type_text == "厂商直采" && dbProd.wx_cat_leaf != null)
|
||
{
|
||
var urlShipping = BaseClass.BuildObjString("product/wx_get_shipping_template");
|
||
var dataShipping = Work.UserLogin.GetSignaturex() +
|
||
"&coid=" + dbProd.skc_id;
|
||
var htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
||
if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200"))
|
||
htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
||
if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200"))
|
||
{
|
||
}
|
||
else
|
||
{
|
||
if (htmlShipping.Contains("\"data\":\"\""))
|
||
{
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
shippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(htmlShipping)["data"]);
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(shippingTemplateJson))
|
||
{
|
||
// 获取运费模板
|
||
var urlShip = BaseClass.BuildObjString("product/e57_get_freight_template");
|
||
var dataShip = Work.UserLogin.GetSignaturex() + "&coid=" + dbProd.skc_id;
|
||
var shipRst = GetHtml.PostUtf8(urlShip, dataShip);
|
||
if (string.IsNullOrEmpty(shipRst) || !shipRst.Contains("\"code\":0"))
|
||
shipRst = GetHtml.PostUtf8(urlShipping, dataShipping);
|
||
if (!shipRst.Contains("\"code\":0"))
|
||
{
|
||
var errMsg = BaseRegex.GetStringJson(ref shipRst, "msg");
|
||
if (string.IsNullOrEmpty(errMsg))
|
||
errMsg = shipRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 " + errMsg + "\"}";
|
||
}
|
||
try
|
||
{
|
||
//[{"id":"204","warehouseNum":"15016108","freightType":0,"provinces":"香港特别行政区,台湾省,澳门特别行政区","freightPrice":9999900,"createBy":"vmslin","createTime":"2026-01-30T16:45:03+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:03+08:00"},{"id":"205","warehouseNum":"15016108","freightType":3,"provinces":"海南省,新疆维吾尔自治区,西藏自治区,内蒙古自治区","freightPrice":1530,"createBy":"vmslin","createTime":"2026-01-30T16:45:51+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:45:51+08:00"},{"id":"206","warehouseNum":"15016108","freightType":1,"provinces":"北京市,上海市","freightPrice":410,"createBy":"vmslin","createTime":"2026-01-30T16:46:04+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:04+08:00"},{"id":"207","warehouseNum":"15016108","freightType":1,"provinces":"安徽省,重庆市,福建省,广东省,甘肃省,广西壮族自治区,贵州省,河北省,湖北省,黑龙江省,河南省,湖南省,吉林省,江苏省,江西省,辽宁省,宁夏回族自治区,青海省,四川省,山东省,山西省,陕西省,天津市,云南省,浙江省","freightPrice":310,"createBy":"vmslin","createTime":"2026-01-30T16:46:17+08:00","updateBy":"vmslin","updateTime":"2026-01-30T16:46:17+08:00"}]
|
||
shippingTemplateJson = JsonHelper.SerializeObject(JsonHelper.JObjectParse(shipRst)["data"]);
|
||
if (shipRst.Contains("\"code\":0") && !string.IsNullOrEmpty(shippingTemplateJson))
|
||
{
|
||
urlShipping = BaseClass.BuildObjString("product/wx_add_mdy_shipping_template");
|
||
dataShipping = Work.UserLogin.GetSignaturex() +
|
||
"&coid=" + dbProd.skc_id +
|
||
"&shipping_template_json=" + shippingTemplateJson;
|
||
htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
||
if (string.IsNullOrEmpty(htmlShipping) || !htmlShipping.Contains("\"code\":200"))
|
||
htmlShipping = GetHtml.PostUtf8(urlShipping, dataShipping);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板解析失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(shippingTemplateJson))
|
||
{
|
||
try
|
||
{
|
||
int count = 0;
|
||
var shipObjs = JArray.Parse(shippingTemplateJson);
|
||
foreach (var shipObj in shipObjs)
|
||
{
|
||
var provincesStr = shipObj["provinces"].ParseToString();
|
||
if (provincesStr.Split(',').Length > count)
|
||
{
|
||
count = provincesStr.Split(',').Length;
|
||
shipPrice = shipObj["freightPrice"].ParseToInt();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
if (shipPrice <=0)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 未获取到\"}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 运费模板
|
||
var expressRst = WXUpload.getFreightTemplate(shop);
|
||
if (!expressRst.Contains("\"code\":0") && !expressRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref expressRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = expressRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 " + error + "\"}";
|
||
}
|
||
upProdParam.product.info.expressInfo = new expressInfoParam();
|
||
upProdParam.product.info.expressInfo.templateId = BaseRegex.GetStringJson(ref expressRst, "templateId");
|
||
#endregion
|
||
|
||
#region 详情图
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成商品详情";
|
||
}));
|
||
}
|
||
Thread.Sleep(Randomx.GetId(100, 300));
|
||
upProdParam.product.info.detail = new productDetailParam(); // 详情图
|
||
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)
|
||
{
|
||
try
|
||
{
|
||
if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
upProdParam.product.info.detail.detailImg.Add(gallery_item.url);
|
||
continue;
|
||
}
|
||
|
||
// 获取缓存盗链 详情图
|
||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||
{
|
||
upProdParam.product.info.detail.detailImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||
continue;
|
||
}
|
||
|
||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||
{
|
||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||
}
|
||
else
|
||
{
|
||
// 使用接口链接传详情图
|
||
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
|
||
var upDate = UserLogin.GetSignaturex();
|
||
upDate += "&token=" + token.accessToken;
|
||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + gallery_item.url.Replace("https://", "http://") + "\"}");
|
||
|
||
var sTime = DateTime.Now;
|
||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成商品详情图 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||
}));
|
||
}
|
||
|
||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||
{
|
||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||
token = new WxApiBLL().GetRandomWxToken();
|
||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
}
|
||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||
{
|
||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||
isChangeImgDic = true;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
|
||
// api上传图片文件 详情图
|
||
if (1 == 1)
|
||
{
|
||
try
|
||
{
|
||
string errMsg = "";
|
||
var imgBase64 = GetImgBase64ForApi(out errMsg, gallery_item.url, needAddRandomBlock, wantAddRandomBlock);
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
return errMsg;
|
||
}
|
||
|
||
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=" + gallery_item.url;
|
||
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");
|
||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||
{
|
||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||
isChangeImgDic = true;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"修改详情图失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
|
||
// 模拟上传图片
|
||
bool randomDrawBlock = false;
|
||
if (needAddRandomBlock || wantAddRandomBlock)
|
||
randomDrawBlock = true;
|
||
var locationStr = UploadImg(shop, gallery_item.url, cell, randomDrawBlock);
|
||
if (!locationStr.Contains("\"success\":true"))
|
||
return locationStr;
|
||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||
upProdParam.product.info.detail.detailImg.Add(location);
|
||
//wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = location;
|
||
//isChangeImgDic = true;
|
||
Thread.Sleep(Randomx.GetId(10, 50));
|
||
}
|
||
#endregion
|
||
|
||
#region 保存缓存盗链图片
|
||
if (isChangeImgDic)
|
||
{
|
||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&spu_id=" + dbProd.spu_id;
|
||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
isChangeImgDic = false;
|
||
}
|
||
#endregion
|
||
|
||
#region 匹配产品属性
|
||
//真丝、蚕丝、香云纱、羊绒、羊毛、羊羔毛、羽绒、皮草
|
||
upProdParam.product.info.param = new List<wxPropParam>(); // 商品属性值
|
||
var productAttr = upProdParam.product.info.category.LastOrDefault().catInfo.productAttr;
|
||
|
||
// 直接转换微信回采
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1" && wxEditProdInfo != null)
|
||
{
|
||
foreach(var wxEditPropParam in wxEditProdInfo.product.info.param)
|
||
{
|
||
var wxPropParam = new wxPropParam();
|
||
upProdParam.product.info.param.Add(wxPropParam);
|
||
foreach (var wxEditCategoryParam in wxEditPropParam.categorys)
|
||
{
|
||
var wxCategoryParam = new categoryPropParam()
|
||
{
|
||
catType = wxEditCategoryParam.catType,
|
||
name = wxEditCategoryParam.name,
|
||
catInfo = new catInfoParam()
|
||
{
|
||
inputType = wxEditCategoryParam.catInfo.inputType,
|
||
isRequired = wxEditCategoryParam.catInfo.isRequired,
|
||
isCustomize = wxEditCategoryParam.catInfo.isCustomize,
|
||
}
|
||
};
|
||
wxPropParam.categorys.Add(wxCategoryParam);
|
||
}
|
||
}
|
||
}
|
||
// 直接转换微信店采
|
||
else if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
foreach (var wxEditPropParam in wxEditProdInfo.product.info.param)
|
||
{
|
||
var wxPropParam = new wxPropParam();
|
||
upProdParam.product.info.param.Add(wxPropParam);
|
||
foreach (var wxEditCategoryParam in wxEditPropParam.categorys)
|
||
{
|
||
var wxCategoryParam = new categoryPropParam()
|
||
{
|
||
catType = wxEditCategoryParam.catType,
|
||
name = wxEditCategoryParam.name,
|
||
catInfo = new catInfoParam()
|
||
{
|
||
inputType = wxEditCategoryParam.catInfo.inputType,
|
||
isRequired = wxEditCategoryParam.catInfo.isRequired,
|
||
isCustomize = wxEditCategoryParam.catInfo.isCustomize,
|
||
}
|
||
};
|
||
wxPropParam.categorys.Add(wxCategoryParam);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var propInfo in prodInfo.property.goods_properties)
|
||
{
|
||
if (propInfo.name == "容量")
|
||
{
|
||
|
||
}
|
||
if (propInfo.values.Count == 0)
|
||
continue;
|
||
|
||
var attr = productAttr.attr.FirstOrDefault(r => r.name == propInfo.name);
|
||
if (propInfo.name == "生产日期" && propInfo.values.Count > 0)
|
||
{
|
||
propInfo.values.FirstOrDefault().value = DateTime.Now.Date.AddDays(-15).ToString("yyyy-MM-dd");
|
||
propInfo.values.FirstOrDefault().raw_value = propInfo.values.FirstOrDefault().value;
|
||
}
|
||
if (attr == null)
|
||
{
|
||
if (propInfo.name.Contains("面料俗称"))
|
||
{
|
||
attr = productAttr.attr.FirstOrDefault(r => r.name == "面料材质");
|
||
}
|
||
if (propInfo.name.Contains("适用年龄"))
|
||
{
|
||
attr = productAttr.attr.FirstOrDefault(r => r.name == "适用年龄" || r.name == "适用年龄段");
|
||
}
|
||
if (propInfo.name.Contains("填充物"))
|
||
{
|
||
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 (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||
{
|
||
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)
|
||
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)
|
||
{
|
||
continue;
|
||
}
|
||
var attrValueLst = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
var attrValue = attrValueLst.FirstOrDefault(v => v == propInfo.values.FirstOrDefault()?.value);
|
||
if (propInfo.name == "保质期")
|
||
{
|
||
attrValue = "30 天";
|
||
if (propInfo.values.Count > 0)
|
||
{
|
||
if (propInfo.values.FirstOrDefault().value.Contains("年") || propInfo.values.FirstOrDefault().value.Contains("月")
|
||
|| propInfo.values.FirstOrDefault().value.Contains("日") || propInfo.values.FirstOrDefault().value.Contains("天")
|
||
|| propInfo.values.FirstOrDefault().value.Contains("见包装"))
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault().value;
|
||
}
|
||
if (attrValue.Contains("天") && attrValue.Replace("天", "").ParseToInt() < 30)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品保质期小于30天,跳过上传\"}";
|
||
}
|
||
}
|
||
}
|
||
|
||
if (propInfo.name == "产品重量")
|
||
{
|
||
attrValue = "10g";
|
||
if (propInfo.values.FirstOrDefault().value.Contains("g") || propInfo.values.FirstOrDefault().value.Contains("kg"))
|
||
attrValue = propInfo.values.FirstOrDefault().value;
|
||
}
|
||
if (propInfo.name == "风格" && attrValue == null)
|
||
{
|
||
attrValue = attrValueLst.FirstOrDefault(v => v == propInfo.values.FirstOrDefault().value + "风");
|
||
}
|
||
if (attr.type == "string")
|
||
{
|
||
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("其他"))
|
||
attrValue = "其他";
|
||
else if (attrValueLst.Contains("常规"))
|
||
attrValue = "常规";
|
||
else if (attrValueLst.Contains("通用"))
|
||
attrValue = "通用";
|
||
else if (attrValueLst.Contains("国产"))
|
||
attrValue = "国产";
|
||
else if (attr.value.Contains("绒丝;羽毛;白鸭绒;白鹅绒;灰鸭绒;灰鹅绒;鸭毛片;鹅毛片"))
|
||
{
|
||
attrValue = "绒丝";
|
||
}
|
||
else if (attr.name == "是否进口")
|
||
{
|
||
attrValue = "非进口";
|
||
if (attr.value == "是;否")
|
||
attrValue = "否";
|
||
}
|
||
else if (attr.name == "商品产地")
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
else if (attr.name == "产地")
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
else if (attrValueLst.Any(v => v.Contains("%")))
|
||
{
|
||
attrValue = attrValueLst.FirstOrDefault();
|
||
}
|
||
else
|
||
attrValue = attrValueLst.Where(v => !"真丝、蚕丝、香云纱、羊绒、羊毛、羊羔绒、羊羔毛、羽绒、皮草".Contains(v)).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||
}
|
||
if (attrValue.IsNullOrEmpty())
|
||
{
|
||
if (attrValueLst.Contains("其他"))
|
||
attrValue = "其他";
|
||
else if (attrValueLst.Contains("通用"))
|
||
attrValue = "通用";
|
||
}
|
||
if (attrValue.IsNullOrEmpty() && attr.type == "string")
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||
}
|
||
if (attr.type == "decimal4_unit" || attr.type == "integer_unit")
|
||
{
|
||
if (attr.value == "%")
|
||
attrValue = "10 %";
|
||
else if (attr.value == "g;kg")
|
||
attrValue = "50 g";
|
||
else if (attr.value == "g")
|
||
attrValue = "10 g";
|
||
else if (attr.value == "kg")
|
||
attrValue = "1 kg";
|
||
//else if (attr.value == "g;kg;ml;L")
|
||
// attrValue = "100 g";
|
||
//else if (attr.value == "cm")
|
||
// attrValue = "20 cm";
|
||
//else if (attr.value.Contains("岁以上") && attr.value.Contains("个月以上"))
|
||
// attrValue = "7 岁以上";
|
||
else if (attr.value == "只;个")
|
||
{
|
||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith("只") || (propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith("个"))
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||
if (attrValue.TrimEnd('只', '个').ParseToInt() == 0)
|
||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + (attrValue.Contains("只") ? " 只" : " 个");
|
||
if (attrValue.TrimEnd('只', '个').ParseToInt() == 0)
|
||
attrValue = "1 个";
|
||
}
|
||
else
|
||
attrValue = "1 个";
|
||
}
|
||
else if (attr.value == "ml")
|
||
{
|
||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith(attr.value))
|
||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||
else
|
||
attr.value = "100 ml";
|
||
}
|
||
else if (attr.value == "L")
|
||
{
|
||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith(attr.value))
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||
if (attrValue.TrimEnd('L').ParseToInt() == 0)
|
||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + " L";
|
||
if (attrValue.TrimEnd('L').ParseToInt() == 0)
|
||
attrValue = "1 L";
|
||
}
|
||
else
|
||
attr.value = "1 L";
|
||
}
|
||
else if (attr.value == "g;kg;ml;L")
|
||
{
|
||
var propInfoValue = (propInfo.values.FirstOrDefault()?.value).ParseToString();
|
||
if (propInfoValue.EndsWith("g") || propInfoValue.EndsWith("kg") || propInfoValue.EndsWith("ml") || propInfoValue.EndsWith("L"))
|
||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||
else
|
||
attr.value = "100 g";
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(attrValue))
|
||
continue;
|
||
|
||
var wxPropParam = new wxPropParam();
|
||
upProdParam.product.info.param.Add(wxPropParam);
|
||
var wxCategoryParam1 = new categoryPropParam()
|
||
{
|
||
catType = 7,
|
||
name = attr.name,
|
||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||
};
|
||
var wxCategoryParam2 = new categoryPropParam()
|
||
{
|
||
catType = 7,
|
||
name = attrValue,
|
||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||
};
|
||
wxPropParam.categorys.Add(wxCategoryParam1);
|
||
wxPropParam.categorys.Add(wxCategoryParam2);
|
||
}
|
||
}
|
||
foreach (var attr in productAttr.attr)
|
||
{
|
||
if (attr.isRequired != true)
|
||
continue;
|
||
// 已填写内没有但是必填属性
|
||
if (upProdParam.product.info.param.Any(p => p.categorys.FirstOrDefault()?.name == attr.name))
|
||
continue;
|
||
|
||
var attrValueLst = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
string attrValue = "";
|
||
if (attrValue.IsNullOrEmpty() && attr.isRequired == true)
|
||
{
|
||
if (attrValueLst.Contains("其他"))
|
||
attrValue = "其他";
|
||
else if (attrValueLst.Contains("常规"))
|
||
attrValue = "常规";
|
||
else if (attrValueLst.Contains("通用"))
|
||
attrValue = "通用";
|
||
else if (attrValueLst.Contains("国产"))
|
||
attrValue = "国产";
|
||
else if (attr.value.Contains("绒丝;羽毛;白鸭绒;白鹅绒;灰鸭绒;灰鹅绒;鸭毛片;鹅毛片"))
|
||
{
|
||
attrValue = "绒丝";
|
||
}
|
||
else if (attr.name == "是否进口")
|
||
{
|
||
attrValue = "非进口";
|
||
if (attr.value == "是;否")
|
||
attrValue = "否";
|
||
}
|
||
else if (attr.name == "商品产地")
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
else if (attr.name == "产地")
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
else if (attrValueLst.Any(v => v.Contains("%")))
|
||
{
|
||
attrValue = attrValueLst.FirstOrDefault();
|
||
}
|
||
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 == "ISBN版号/CN刊号")
|
||
// attrValue = "9787922575016";
|
||
if (attr.name == "书名")
|
||
attrValue = prodTitle;
|
||
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 (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||
{
|
||
if (attr.name == "食品名称")
|
||
attrValue = prodTitle;
|
||
if (attr.name == "生产企业名称")
|
||
attrValue = "见包装";
|
||
if (attr.name == "食品生产许可证编号")
|
||
{
|
||
attrValue = "SC10241162100670";
|
||
attrValue = "见包装";
|
||
}
|
||
if (attr.name == "产品标准号")
|
||
{
|
||
attrValue = "GB 2726";
|
||
attrValue = "见包装";
|
||
}
|
||
if (attr.name == "生产日期")
|
||
attrValue = DateTime.Now.Date.AddDays(-15).ToString("yyyy-MM-dd");
|
||
if (attr.name == "净含量")
|
||
attrValue = "见包装";
|
||
if (attr.name == "单件净含量")
|
||
{
|
||
attrValue = "见包装";
|
||
}
|
||
if (attr.name == "包装方式")
|
||
attrValue = "袋装";
|
||
if (attr.name == "配料表")
|
||
attrValue = "水";
|
||
if (attr.name == "联系方式")
|
||
attrValue = "无";
|
||
if (attr.name == "地址")
|
||
attrValue = "见包装";
|
||
if (attr.name == "贮存条件")
|
||
attrValue = "常温";
|
||
if (attr.name == "保质期")
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品属性不含保质期,跳过上传\"}";
|
||
}
|
||
}
|
||
}
|
||
if (attrValue.IsNullOrEmpty() && attr.type == "string")
|
||
{
|
||
attrValue = "其他";
|
||
}
|
||
if (attr.type == "decimal4_unit" || attr.type == "integer_unit")
|
||
{
|
||
if (attr.value == "%")
|
||
attrValue = "10 %";
|
||
else if (attr.value == "g;kg")
|
||
attrValue = "50 g";
|
||
else if (attr.value == "g")
|
||
attrValue = "10 g";
|
||
else if (attr.value == "kg")
|
||
attrValue = "1 kg";
|
||
else if (attr.value == "g;kg;ml;L")
|
||
attrValue = "100 g";
|
||
else if (attr.value == "cm")
|
||
attrValue = "20 cm";
|
||
else if (attr.value.Contains("岁以上") && attr.value.Contains("个月以上"))
|
||
attrValue = "7 岁以上";
|
||
else if (attr.value == "只;个")
|
||
attrValue = "1 个";
|
||
else if (attr.value == "ml")
|
||
attrValue = "100 ml";
|
||
else if (attr.value == "L")
|
||
attrValue = "1 L";
|
||
}
|
||
|
||
var wxPropParam = new wxPropParam();
|
||
upProdParam.product.info.param.Add(wxPropParam);
|
||
var wxCategoryParam1 = new categoryPropParam()
|
||
{
|
||
catType = 7,
|
||
name = attr.name,
|
||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||
};
|
||
var wxCategoryParam2 = new categoryPropParam()
|
||
{
|
||
catType = 7,
|
||
name = attrValue,
|
||
catInfo = new catInfoParam() { inputType = attr.normalRelease.ruleType, isRequired = attr.isRequired == true ? 1 : 0, isCustomize = 0 }
|
||
};
|
||
wxPropParam.categorys.Add(wxCategoryParam1);
|
||
wxPropParam.categorys.Add(wxCategoryParam2);
|
||
}
|
||
#endregion
|
||
|
||
#region sku规格属性
|
||
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成sku";
|
||
}));
|
||
}
|
||
Thread.Sleep(Randomx.GetId(100, 300));
|
||
|
||
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 (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||
{
|
||
if (selectProd.cat_name == "坚果炒货" || selectProd.cat_name == "果干")
|
||
{
|
||
if (!prodInfo.detail.sku.FirstOrDefault().spec.Any(s => s.parent_name == "规格/净含量"))
|
||
{
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
sku.spec.FirstOrDefault().parent_name = "规格/净含量";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!prodInfo.detail.sku.FirstOrDefault().spec.Any(s => s.parent_name == "规格"))
|
||
{
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
sku.spec.FirstOrDefault().parent_name = "规格";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (prodInfo.detail.sku.FirstOrDefault()?.spec?.Count > 0)
|
||
{
|
||
productSaleAttrParam attrParam = new productSaleAttrParam()
|
||
{
|
||
key = prodInfo.detail.sku.FirstOrDefault()?.spec[0].parent_name,
|
||
hasImg = true,
|
||
items = new List<productSaleAttrItemParam>()
|
||
};
|
||
upProdParam.product.info.productSaleAttrs.Add(attrParam);
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
var spec = sku.spec[0];
|
||
if (!attrParam.items.Any(it => it.value == spec.spec_name) && !string.IsNullOrEmpty(sku.thumb_url))
|
||
{
|
||
if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = sku.thumb_url, });
|
||
continue;
|
||
}
|
||
|
||
// 获取缓存盗链 sku图
|
||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(sku.thumb_url)))
|
||
{
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)], });
|
||
continue;
|
||
}
|
||
// 使用接口链接传sku图
|
||
if (1 == 1 && !sku.thumb_url.Contains("wst.wxapp.tc.qq.com"))
|
||
{
|
||
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
|
||
var upDate = UserLogin.GetSignaturex();
|
||
upDate += "&token=" + token.accessToken;
|
||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + sku.thumb_url.Replace("https://", "http://") + "\"}");
|
||
|
||
var sTime = DateTime.Now;
|
||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成sku " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||
}));
|
||
}
|
||
|
||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||
{
|
||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||
token = new WxApiBLL().GetRandomWxToken();
|
||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
}
|
||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||
{
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
||
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl;
|
||
isChangeImgDic = true;
|
||
continue; // 传图成功跳过模拟上传
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
|
||
// api上传图片文件 sku图
|
||
if (1 == 1)
|
||
{
|
||
try
|
||
{
|
||
string errMsg = "";
|
||
var imgBase64 = GetImgBase64ForApi(out errMsg, sku.thumb_url, false, false);
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
return errMsg;
|
||
}
|
||
|
||
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=" + sku.thumb_url;
|
||
upDate += "&img_base64=" + imgBase64;
|
||
|
||
var sTime = DateTime.Now;
|
||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在上传商品sku图文件 " + (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");
|
||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||
{
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
||
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl;
|
||
isChangeImgDic = true;
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"修改详情图失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
|
||
// 上传sku图
|
||
var locationStr = UploadImg(shop, sku.thumb_url, cell);
|
||
if (!locationStr.Contains("\"success\":true"))
|
||
return locationStr;
|
||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = location, });
|
||
Thread.Sleep(Randomx.GetId(10, 50));
|
||
|
||
//wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = location;
|
||
//isChangeImgDic = true;
|
||
}
|
||
}
|
||
}
|
||
if (prodInfo.detail.sku.FirstOrDefault()?.spec?.Count > 1)
|
||
{
|
||
productSaleAttrParam attrParam = new productSaleAttrParam()
|
||
{
|
||
key = prodInfo.detail.sku.FirstOrDefault()?.spec[1].parent_name,
|
||
hasImg = false,
|
||
items = new List<productSaleAttrItemParam>()
|
||
};
|
||
upProdParam.product.info.productSaleAttrs.Add(attrParam);
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
var spec = sku.spec[1];
|
||
if (!attrParam.items.Any(it => it.value == spec.spec_name))
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name });
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存缓存盗链图片
|
||
if (isChangeImgDic)
|
||
{
|
||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&spu_id=" + dbProd.spu_id;
|
||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
isChangeImgDic = false;
|
||
}
|
||
#endregion
|
||
|
||
#region sku信息
|
||
upProdParam.product.productSkus = new List<productSkuParam>();
|
||
int skuIndex = 0;
|
||
int id = 3;
|
||
long catId = 200000000003;
|
||
long fCatId = 200000000003;
|
||
long valueCatId = (17 + Randomx.GetNumber(11)).ParseToLong();
|
||
Dictionary<string, long> dicSpecParentNameId = new Dictionary<string, long>();
|
||
Dictionary<string, long> dicSpecParentNameCatId = new Dictionary<string, long>();
|
||
Dictionary<string, long> dicSpecNamefCatId = new Dictionary<string, long>();
|
||
Dictionary<string, long> dicSpecNameCatId = new Dictionary<string, long>();
|
||
foreach (var skuInfo in prodInfo.detail.sku)
|
||
{
|
||
foreach (var spec in skuInfo.spec)
|
||
{
|
||
if (!dicSpecParentNameId.Keys.Contains(spec.parent_name))
|
||
{
|
||
dicSpecParentNameId[spec.parent_name] = id++;
|
||
dicSpecParentNameCatId[spec.parent_name] = catId++;
|
||
}
|
||
if (!dicSpecNamefCatId.Keys.Contains(spec.spec_name))
|
||
{
|
||
dicSpecNamefCatId[spec.spec_name] = fCatId++;
|
||
dicSpecNameCatId[spec.spec_name] = valueCatId++;
|
||
}
|
||
}
|
||
}
|
||
if (dbProd.product_get_type_text == "厂商直采" && !prodInfo.detail.sku.Any(s => s.quantity.ParseToInt() > 0))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"源商品库存为0\"}";
|
||
}
|
||
foreach (var skuInfo in prodInfo.detail.sku)
|
||
{
|
||
productSkuParam skuParam = new productSkuParam();
|
||
upProdParam.product.productSkus.Add(skuParam);
|
||
for (int i = skuInfo.spec.Count - 1; i >= 0; i--)
|
||
{
|
||
var specInfo = skuInfo.spec[i];
|
||
skuParam.__skuKey = specInfo.parent_name + "." + specInfo.spec_name + "_";
|
||
skuParam.__skuKey += specInfo.spec_name;
|
||
}
|
||
skuParam.__skuKey.TrimEnd('_');
|
||
skuParam.index = skuIndex++;
|
||
skuParam.productSkuInfo = new productSkuInfoParam();
|
||
// 加价
|
||
skuParam.productSkuInfo.salePrice = (skuInfo.multi_price * defaultAddPriceRule.AddPriceTimes + defaultAddPriceRule.AddMorePrice * 100).ParseToInt();
|
||
if (defaultAddPriceRule.AddMorePriceFirst)
|
||
skuParam.productSkuInfo.salePrice = ((skuInfo.multi_price + defaultAddPriceRule.AddMorePrice * 100) * defaultAddPriceRule.AddPriceTimes).ParseToInt();
|
||
// 阶梯式加价,如果命中则按阶梯式加价进行
|
||
if (defaultAddPriceRule.IsStepAddPrice)
|
||
{
|
||
foreach (var addPrice in lstAddPriceRule)
|
||
{
|
||
if (skuInfo.multi_price > addPrice.MoreThanPrice * 100 && skuInfo.multi_price <= addPrice.LessThanPrice * 100)
|
||
{
|
||
if (defaultAddPriceRule.AddMorePriceFirst) // 先加后乘
|
||
skuParam.productSkuInfo.salePrice = ((skuInfo.multi_price + addPrice.AddMorePrice * 100) * addPrice.AddPriceTimes).ParseToInt();
|
||
else
|
||
skuParam.productSkuInfo.salePrice = (skuInfo.multi_price * addPrice.AddPriceTimes + addPrice.AddMorePrice * 100).ParseToInt();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
// 聚水潭上微信小店,加运费(其他平台shipPrice默认为0)
|
||
skuParam.productSkuInfo.salePrice += (shipPrice * defaultAddPriceRule.ShippingPriceTimes).ParseToInt();
|
||
// sku图
|
||
skuParam.productSkuInfo.thumbImg = upProdParam.product.info.productSaleAttrs[0].items.FirstOrDefault(a => a.value == skuInfo.spec[0].spec_name)?.imgUrl;
|
||
skuParam.productSkuInfo.skuCode = skuInfo.out_sku_sn;
|
||
skuParam.productSkuInfo.outSkuId = skuInfo.out_sku_sn;
|
||
skuParam.productSkuInfo.out_sku_id = skuInfo.out_sku_sn;
|
||
//skuParam.productSkuInfo.barCode = skuInfo.out_sku_sn; // 条形码
|
||
skuParam.skuKey.outSkuId = skuInfo.out_sku_sn;
|
||
skuParam.skuKey.productKey = new productKeyParam();
|
||
skuParam.skuKey.productKey.outProductId = upProdParam.product.info.spuCode;
|
||
// 库存
|
||
skuParam.productSkuInfo.stockInfo = new stockInfoParam() { stockNum = defaultAddPriceRule.StockNum };
|
||
// 厂商直采上家库存为0则按0上架
|
||
if (dbProd.product_get_type_text == "厂商直采" && skuInfo.quantity.IsNullOrZero())
|
||
skuParam.productSkuInfo.stockInfo.stockNum = 0;
|
||
skuParam.productSkuInfo.saleParam = new List<saleParamParam>();
|
||
foreach (var specInfo in skuInfo.spec)
|
||
{
|
||
saleParamParam saleParam = new saleParamParam();
|
||
skuParam.productSkuInfo.saleParam.Add(saleParam);
|
||
saleParam.categorys = new List<object>();
|
||
|
||
// specKey
|
||
categoryKeyParam skuCateKeyParam = new categoryKeyParam();
|
||
saleParam.categorys.Add(skuCateKeyParam);
|
||
skuCateKeyParam.isCustomize = true;
|
||
skuCateKeyParam.isMainSale = true;
|
||
skuCateKeyParam.name = specInfo.parent_name;
|
||
skuCateKeyParam.id = dicSpecParentNameId[specInfo.parent_name].ParseToInt(); // 3;
|
||
skuCateKeyParam.catId = dicSpecParentNameCatId[specInfo.parent_name];
|
||
skuCateKeyParam.label = "自定义规格";
|
||
skuCateKeyParam.catInfo = new skuCatInfoParam() { isCustomize = 1 };
|
||
skuCateKeyParam.catType = 8;
|
||
|
||
// specValue
|
||
categoryValueParam skuCateValueParam = new categoryValueParam();
|
||
saleParam.categorys.Add(skuCateValueParam);
|
||
skuCateValueParam.fCatId = dicSpecNamefCatId[specInfo.spec_name];
|
||
skuCateValueParam.catId = dicSpecNameCatId[specInfo.spec_name];
|
||
skuCateValueParam.name = specInfo.spec_name;
|
||
skuCateValueParam.skuNameValue = specInfo.spec_name;
|
||
skuCateValueParam.desc = "";
|
||
skuCateValueParam.catInfo = new categoryValueCatInfo() { editByUser = 1 };
|
||
skuCateValueParam.thumbImg = "";
|
||
var specIndex = skuInfo.spec.IndexOf(specInfo);
|
||
skuCateValueParam.priority = prodInfo.detail.sku.Select(s => s.spec[specIndex].spec_name).Distinct().ToList().IndexOf(specInfo.spec_name);
|
||
skuCateValueParam.selected = false;
|
||
}
|
||
skuParam.productSkuInfo.skuDeliverInfo = new skuDeliverInfoParam();
|
||
skuParam.productSkuInfo.stockDiff = new stockDiffParam() { diffType = 1, num = defaultAddPriceRule.StockNum };
|
||
// 厂商直采上家库存为0则按0上架
|
||
if (dbProd.product_get_type_text == "厂商直采" && skuInfo.quantity.IsNullOrZero())
|
||
skuParam.productSkuInfo.stockDiff.num = 0;
|
||
skuParam.status = 5;
|
||
}
|
||
#endregion
|
||
|
||
#region 预售信息
|
||
if (chkPreSale.Checked)
|
||
{
|
||
upProdParam.product.deliverInfo = new productDeliverInfoParam();
|
||
upProdParam.product.deliverInfo.deliverType = 1;
|
||
int preSaleDays = Math.Max(3, wxUploadRule.PreSaleDays);
|
||
preSaleDays = Math.Min(45, preSaleDays);
|
||
upProdParam.product.deliverInfo.skuDeliverInfo = new skuDeliverInfoParam()
|
||
{
|
||
stockType = 1,
|
||
fullPaymentPresaleDeliveryTime = preSaleDays.ParseToString()
|
||
};
|
||
}
|
||
#endregion
|
||
|
||
// 资质信息
|
||
// 微信回采直接复制
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked && dbProd.has_wx_format == "1" && wxEditProdInfo != null)
|
||
{
|
||
upProdParam.product.info.qualificationList.Clear();
|
||
if (wxEditProdInfo.product?.info?.qualificationList?.Count > 0)
|
||
{
|
||
foreach (var editQualification in wxEditProdInfo.product.info.qualificationList)
|
||
{
|
||
upProdParam.product.info.qualificationList.Add(new qualificationParam()
|
||
{
|
||
qualificationId = editQualification.qualificationId,
|
||
qualificationUrl = editQualification.qualificationUrl,
|
||
});
|
||
}
|
||
}
|
||
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||
{
|
||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||
DefaultAdultBrandId = wxEditProdInfo.product.info.brandId;
|
||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||
upProdParam.product.info.brandId = wxEditProdInfo.product.info.brandId.ParseToLong();
|
||
}
|
||
}
|
||
// 微信店采直接复制
|
||
else if (dbProd.product_get_type_text == "微信店采")
|
||
{
|
||
upProdParam.product.info.qualificationList.Clear();
|
||
if (wxEditProdInfo.product?.info?.qualificationList?.Count > 0)
|
||
{
|
||
foreach (var editQualification in wxEditProdInfo.product.info.qualificationList)
|
||
{
|
||
upProdParam.product.info.qualificationList.Add(new qualificationParam()
|
||
{
|
||
qualificationId = editQualification.qualificationId,
|
||
qualificationUrl = editQualification.qualificationUrl,
|
||
});
|
||
}
|
||
}
|
||
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||
{
|
||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||
DefaultAdultBrandId = wxEditProdInfo.product.info.brandId;
|
||
if (wxEditProdInfo.product.info.brandId.ParseToLong() > 0)
|
||
upProdParam.product.info.brandId = wxEditProdInfo.product.info.brandId.ParseToLong();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
#region 标签图 书籍类生成书籍图片
|
||
//qualificationList
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||
{
|
||
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).ToString("yyyy年MM月dd日");
|
||
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;
|
||
propParam.categorys[1].name = bookPrice;
|
||
}
|
||
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
|
||
|
||
#region 标签图 食品类生成食品图片
|
||
//qualificationList
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料")
|
||
{
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成食品饮料专有信息";
|
||
}));
|
||
}
|
||
|
||
|
||
string foodName = "食品名称:" + prodTitle;
|
||
string companyName = "生产商名称:中国地区食品厂";
|
||
string SCID = "食品生产许可证编号:SC10241162100670";
|
||
string GBID = "产品标准号:GB 2726";
|
||
string ExpDate = "保质期:30天";
|
||
string MakeDate = "生产日期:" + DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd");
|
||
string NetContent = "净含量:见包装";
|
||
string Pack = "包装方式:袋装";
|
||
string inList = "配料表:水";
|
||
string contact = "联系方式:无";
|
||
string address = "地址:见包装";
|
||
string Storage = "贮存条件:常温";
|
||
|
||
foreach (var propParam in upProdParam.product.info.param)
|
||
{
|
||
if (propParam.categorys[0].name.Contains("食品名称"))
|
||
foodName = "食品名称:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("生产企业名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装"))
|
||
companyName = "生产商名称:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("食品生产许可证编号") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装"))
|
||
SCID = "食品生产许可证编号:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("产品标准号") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装"))
|
||
GBID = "产品标准号:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("保质期"))
|
||
ExpDate = "保质期:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("生产日期"))
|
||
MakeDate = "生产日期:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("净含量"))
|
||
NetContent = "净含量:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("包装方式"))
|
||
Pack = "包装方式:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("配料表"))
|
||
inList = "配料表:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("联系方式"))
|
||
contact = "联系方式:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("地址"))
|
||
address = "地址:" + propParam.categorys[1].name;
|
||
else if (propParam.categorys[0].name.Contains("贮存条件"))
|
||
Storage = "贮存条件:" + propParam.categorys[1].name;
|
||
}
|
||
|
||
var bookStr = foodName + "\r\n" + "\r\n";
|
||
bookStr += companyName + "\r\n" + "\r\n";
|
||
bookStr += SCID + "\r\n" + "\r\n";
|
||
bookStr += GBID + "\r\n" + "\r\n";
|
||
bookStr += ExpDate + "\r\n" + "\r\n";
|
||
bookStr += MakeDate + "\r\n" + "\r\n";
|
||
bookStr += NetContent + "\r\n" + "\r\n";
|
||
bookStr += Pack + "\r\n" + "\r\n";
|
||
bookStr += inList + "\r\n" + "\r\n";
|
||
bookStr += contact + "\r\n" + "\r\n";
|
||
bookStr += address + "\r\n" + "\r\n";
|
||
bookStr += Storage + "\r\n" + "\r\n";
|
||
|
||
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 = "50000057", qualificationUrl = new List<string>() { location }, });
|
||
}
|
||
#endregion
|
||
|
||
#region 标签图 成人用品
|
||
//qualificationList
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||
{
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成成人用品专有信息";
|
||
}));
|
||
}
|
||
|
||
string prodName = "产品名称:" +
|
||
(upProdParam.product.info.category.Count > 2 ? upProdParam.product.info.category[2].name : upProdParam.product.info.category.LastOrDefault()?.name);
|
||
string company = "生产企业:浙江邦臣医药有限公司";
|
||
string address = "制造商地址:浙江省金华市婺城区神丽路1399号6号厂房";
|
||
string model = "产品型号:见包装";
|
||
string material = "材质:其他";
|
||
string user = "适用人群:18岁以上成年人";
|
||
|
||
foreach (var propParam in upProdParam.product.info.param)
|
||
{
|
||
//if (propParam.categorys[0].name.Contains("产品名称"))
|
||
// prodName = "产品名称:" + propParam.categorys[1].name;
|
||
}
|
||
|
||
var bookStr = prodName + "\r\n" + "\r\n" +
|
||
company + "\r\n" + "\r\n" +
|
||
address + "\r\n" + "\r\n" +
|
||
model + "\r\n" + "\r\n" +
|
||
material + "\r\n" + "\r\n" +
|
||
user;
|
||
|
||
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 = "50000089", qualificationUrl = new List<string>() { location }, });
|
||
}
|
||
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||
{
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成成人用品专有信息";
|
||
}));
|
||
}
|
||
|
||
string prodName = (upProdParam.product.info.category.Count > 2 ? upProdParam.product.info.category[2].name : upProdParam.product.info.category.LastOrDefault()?.name);
|
||
|
||
var baseImg = TemuKJD.Properties.Resources.qingqu;
|
||
var newImg = new Bitmap(baseImg.Width, baseImg.Height);
|
||
using (Graphics g = Graphics.FromImage(newImg))
|
||
{
|
||
//g.Clear(Color.White);
|
||
g.DrawImage(baseImg, new Rectangle(0, 0, newImg.Width, newImg.Height), 0, 0, baseImg.Width, baseImg.Height, GraphicsUnit.Pixel);
|
||
|
||
g.FillRectangle(Brushes.White, 860.ParseToInt(), (1024 - 4).ParseToInt(), 500, 120);
|
||
|
||
//Font font = new Font("宋体", txtSize.Text.Trim().ParseToInt(), FontStyle.Bold);
|
||
Font font = new Font("宋体", 44.ParseToInt(), FontStyle.Regular);
|
||
//Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||
Brush textBrush = Brushes.Black;
|
||
textBrush = new SolidBrush(Color.FromArgb(0, 0, 0));
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||
RectangleF rectF = new RectangleF(860, 1024, baseImg.Width - 80, baseImg.Height - 80);
|
||
if (!string.IsNullOrWhiteSpace(prodName.Trim()))
|
||
g.DrawString(prodName.Trim(), font, textBrush, rectF);
|
||
}
|
||
|
||
Thread.Sleep(Randomx.GetId(500, 800));
|
||
var locationStr = UploadImg(shop, newImg, cell);
|
||
if (!locationStr.Contains("\"success\":true"))
|
||
return locationStr;
|
||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||
upProdParam.product.info.qualificationList.Add(new qualificationParam() { qualificationId = "50000115", qualificationUrl = new List<string>() { location }, });
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
// 直接使用微信回采情趣商品品牌
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked &&
|
||
upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||
{
|
||
if (DefaultAdultBrandId.ParseToLong() > 0)
|
||
upProdParam.product.info.brandId = DefaultAdultBrandId.ParseToLong();
|
||
}
|
||
// 情趣内衣类禁止设置运费险
|
||
if (upProdParam.product.info.category[1].name == "情趣内衣")
|
||
{
|
||
upProdParam.product.info.extraService.freightInsurance = 0;
|
||
}
|
||
if (upProdParam.product.info.category[0].name == "珠宝首饰" || upProdParam.product.info.category[1].name == "时尚饰品")
|
||
{
|
||
upProdParam.product.info.extraService.fakeOnePayFour = 1;
|
||
}
|
||
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在提交商品";
|
||
}));
|
||
}
|
||
Thread.Sleep(Randomx.GetId(1000, 2000));
|
||
|
||
var uploadDraftRst = WXUpload.uploadProductDraft(shop, upProdParam);
|
||
if (!uploadDraftRst.Contains("\"code\":0") && !uploadDraftRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref uploadDraftRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = uploadDraftRst;
|
||
var draftId = BaseRegex.GetStringJson(ref uploadDraftRst, "productId").ParseToLong();
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"草稿保存失败 " + GetHtml.UrlEncodeUtf8(error) + "\"}";
|
||
}
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var timeSpan = DateTime.Now - startTime;
|
||
var duration = timeSpan.TotalSeconds;
|
||
cell.Value = "商品已保存草稿,正在提交上架" + " " + duration.ParseToInt() + "秒";
|
||
}));
|
||
}
|
||
|
||
#region 保存缓存盗链图片
|
||
if (isChangeImgDic)
|
||
{
|
||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&spu_id=" + dbProd.spu_id;
|
||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
isChangeImgDic = false;
|
||
}
|
||
#endregion
|
||
|
||
upProdParam.product.productKey.productId = BaseRegex.GetLongJson(ref uploadDraftRst, "productId").ParseToString();
|
||
if (chkUpDraft.Checked)
|
||
{
|
||
selectProd.wxDraftProduct = upProdParam;
|
||
selectProd.draft_id = upProdParam.product.productKey.productId;
|
||
selectProd.status = "草稿箱";
|
||
selectProd.add_time = DateTime.Now;
|
||
upload_draft_product_lst.Add(selectProd);
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
|
||
return "{\"success\":true,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"草稿箱\",\"errMsg\":\"指定上传到草稿箱\"}";
|
||
}
|
||
|
||
// 提交商品上架
|
||
if (!chkTestNoAuditUpload.Checked)
|
||
{
|
||
var uploadProdRst = WXUpload.upProductV2(shop, upProdParam);
|
||
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 = BaseRegex.GetStringJson(ref uploadProdRst, "errcode");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = uploadProdRst;
|
||
return "{\"success\":false,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"草稿箱\",\"errMsg\":\"上架失败 " + error + "\"}";
|
||
}
|
||
if (upProdParam.product.productKey.productId.IsNullOrEmpty())
|
||
upProdParam.product.productKey.productId = BaseRegex.GetLongJson(ref uploadProdRst, "productId").ParseToString();
|
||
}
|
||
else
|
||
{
|
||
#region 尝试免审接口提交 未成功 作废
|
||
var getEditProd = WXUpload.getEditProductV2(shop, upProdParam.product.productKey.productId);
|
||
//getEditProd = getEditProd.Replace("8388275713", "33333333");
|
||
//getEditProd = getEditProd.Replace("33333333", "8387633147");
|
||
|
||
string productJson = "";
|
||
try
|
||
{
|
||
// 获取免审编辑回传数据
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(upProdParam, jsonSetting);
|
||
JObject jObj = JsonHelper.JObjectParse(prodStr);
|
||
|
||
JObject jObjTmp = JsonHelper.JObjectParse(getEditProd);
|
||
jObj["product"] = jObjTmp["product"];
|
||
|
||
//productJson = productJson.Replace("999", "1005");
|
||
jObj["product"]["status"] = 1; //默认为5
|
||
foreach(var sku in jObj["product"]["productSkus"])
|
||
{
|
||
sku["productSkuInfo"]["stockInfo"]["stockNum"] = "1000";
|
||
sku["productSkuInfo"]["stockInfo"]["totalNum"] = "1000";
|
||
//sku["productSkuInfo"]["realStockInfo"]["stockNum"] = "1000";
|
||
//sku["productSkuInfo"]["realStockInfo"]["totalNum"] = "1000";
|
||
|
||
var realStockInfo = new realStockInfoParam() { stockNum = 999, totalNum = 999 };
|
||
sku["productSkuInfo"]["realStockInfo"] = JsonHelper.JObjectParse(JsonHelper.SerializeObject(realStockInfo));
|
||
}
|
||
productJson = JsonHelper.SerializeObject(jObj);
|
||
|
||
// 提交上架
|
||
//var uploadProdRst = WXUpload.upProductJObjectV2(shop, productJson);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
|
||
string submitJson = "{\"name\":\"goods/" + upProdParam.product.productKey.productId + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" +
|
||
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now) + "/submit.json\"}";
|
||
var initFileName = BaseRegex.GetStringJson(ref submitJson, "name");
|
||
DateTime tickTime = DateTime.Now.AddSeconds(0 - Randomx.GetId(10, 30));
|
||
int time1 = BaseClass.DateTimeToTimestampSeconds(tickTime) - Randomx.GetId(80, 150);
|
||
int time2 = BaseClass.DateTimeToTimestampSeconds(tickTime);
|
||
|
||
var uploadPartRst = WXUpload.initUploadPart(shop, submitJson, upProdParam.product.productKey.productId, time1, time2);
|
||
string uploadPartId = BaseRegex.GetStringJson(ref uploadPartRst, "uploadId");
|
||
|
||
//upProdParam.product.status = 5;
|
||
//upProdParam.product.editStatus = 0;
|
||
//upProdParam.product.auditReason = "";
|
||
//upProdParam.product.info.skuIdList = new skuIdListParam();
|
||
//upProdParam.product.info.skuList = new skuListParam();
|
||
//upProdParam.product.info.skuList.skuInfo = new List<skuInfoParam>();
|
||
//var listingAuditFreeRst = WXUpload.listingAuditFree(shop, upProdParam, upProdParam.product.productKey.productId, time1, time2);
|
||
// 提交免审修改(实际生效接口)
|
||
var listingAuditFreeRst = WXUpload.listingAuditFree(shop, productJson, upProdParam.product.productKey.productId, time1, time2);
|
||
|
||
string tempBlobPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower();
|
||
if (!Directory.Exists(tempBlobPath))
|
||
Directory.CreateDirectory(tempBlobPath);
|
||
string blobFullPath = tempBlobPath + "\\blob"; // C:\Users\Administrator\AppData\Local\Temp\3mer3k21\blob
|
||
using (StreamWriter sw = new StreamWriter(blobFullPath))
|
||
{
|
||
//skuParam.productSkuInfo.realStockInfo = new realStockInfoParam() { stockNum = 1005, totalNum = 1005 };
|
||
|
||
|
||
var jObj = JsonHelper.JObjectParse(productJson);
|
||
foreach(JObject skuObj in jObj["product"]["productSkus"])
|
||
{
|
||
skuObj["productSkuInfo"]["stockInfo"]["stockNum"] = 1005;
|
||
|
||
var realStockInfo = new realStockInfoParam() { stockNum = 999, totalNum = 999 };
|
||
skuObj["productSkuInfo"]["realStockInfo"] = JsonHelper.JObjectParse(JsonHelper.SerializeObject(realStockInfo));
|
||
}
|
||
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
foreach (var sku in upProdParam.product.productSkus)
|
||
{
|
||
sku.productSkuInfo.stockInfo.stockNum = 1005;
|
||
}
|
||
var prodStr = JsonConvert.SerializeObject(upProdParam, jsonSetting);
|
||
prodStr = JsonHelper.SerializeObject(jObj["product"]);
|
||
sw.Write(prodStr);
|
||
}
|
||
uploadPartRst = WXUpload.uploadPartBinary(shop, initFileName, blobFullPath, uploadPartId, upProdParam.product.productKey.productId, time1, time2);
|
||
//{"code":0,"etag":"18e3f73046378472219641ef181d3232"}
|
||
//C:\Users\Administrator\AppData\Local\Temp\9uaeiplr\blob
|
||
|
||
var eTag = BaseRegex.GetStringJson(ref uploadPartRst, "etag");
|
||
string rstParmStr = @"{""name"":""" + initFileName + @""",""uploadId"":""" + uploadPartId + @""",""etagList"":[""" + eTag + @"""],""partSeqList"":[1]}";
|
||
var complateRst = WXUpload.completeUploadPart(shop, rstParmStr, upProdParam.product.productKey.productId, time1, time2);
|
||
|
||
#endregion
|
||
}
|
||
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var timeSpan = DateTime.Now - startTime;
|
||
var duration = timeSpan.TotalSeconds;
|
||
cell.Value = "商品已上传" + " " + duration.ParseToInt() + "秒";
|
||
}));
|
||
}
|
||
|
||
// 已传的商品保存为安全商品
|
||
if (dbProd.wx_safe_status == "未校验")
|
||
{
|
||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&spu_id=" + dbProd.spu_id;
|
||
data += "&wx_safe_status=安全商品";
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
}
|
||
//add_secret_spu_id_shop_id_map //测试id "2017522348787531778" FC4C8B7F3C6E4B029AD2A12D4D323B41
|
||
if (!string.IsNullOrEmpty(dbProd.secret_spu_id))
|
||
{
|
||
var url = BaseClass.BuildObjString("product/wx_add_secret_id_up_map");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&up_secret_spu_id=" + dbProd.secret_spu_id;
|
||
data += "&up_spu_id=" + dbProd.spu_id;
|
||
data += "&shop_id=" + shop.ShopId;
|
||
data += "&index=" + Math.Abs(dbProd.secret_spu_id.GetHashCode()) % 1024;
|
||
data += "&price_max=" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice);
|
||
data += "&price_min=" + upProdParam.product.productSkus.Min(s => s.productSkuInfo.salePrice);
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
}
|
||
|
||
//colUploadCount
|
||
var dgvShopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(row => row.Cells["colShopId"]?.Value.ParseToString() == shop.ShopId);
|
||
if (dgvShopRow != null)
|
||
{
|
||
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
|
||
if (!dicShopUpload.ContainsKey(shop.ShopId))
|
||
dicShopUpload[shop.ShopId] = new WxShopUploadInfo();
|
||
if (!dicShopUpload[shop.ShopId].DicDayUploadCount.ContainsKey(day))
|
||
dicShopUpload[shop.ShopId].DicDayUploadCount[day] = 0;
|
||
dicShopUpload[shop.ShopId].DicDayUploadCount[day] += 1;
|
||
// 删除45天前的记录
|
||
var removeKeys = dicShopUpload[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt()).ToList();
|
||
foreach (var key in removeKeys)
|
||
{
|
||
dicShopUpload[shop.ShopId].DicDayUploadCount.Remove(key);
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", dicShopUpload);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvShopRow.Cells["colUploadCount"].Value = dicShopUpload[shop.ShopId].DicDayUploadCount[day];
|
||
}));
|
||
}
|
||
|
||
return "{\"success\":true,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"已上传\",\"msg\":\"上传成功\"}";
|
||
}
|
||
|
||
|
||
public static string GetImgBase64ForApi(out string errorMsg, string img_url, bool needAddRandomBlock, bool wantAddRandomBlock, int imgWidth = 0, int imgHeight = 0)
|
||
{
|
||
errorMsg = "";
|
||
string imgBase64 = "";
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
//生成主图base64字符串
|
||
string getImgError;
|
||
if (!img_url.Contains("wst.wxapp.tc.qq.com"))
|
||
img_url = img_url.Replace("https://", "http://");
|
||
var image = GetHtml.GetUrlImg(img_url, out getImgError);
|
||
if (image == null)
|
||
image = new Bitmap(800, 800);
|
||
if (imgWidth == 0 || imgHeight == 0)
|
||
{
|
||
imgWidth = image.Width;
|
||
imgHeight = image.Height;
|
||
}
|
||
var imageBg = new Bitmap(imgWidth, imgHeight);
|
||
if (image == null || !string.IsNullOrEmpty(getImgError))
|
||
{
|
||
errorMsg = "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"初始化图片上传失败 " + getImgError + "\"}";
|
||
return "";
|
||
}
|
||
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);
|
||
if (needAddRandomBlock || wantAddRandomBlock)
|
||
{
|
||
g.FillRectangle(new SolidBrush(Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256))),
|
||
new Rectangle(Randomx.GetId(imageBg.Width - 30), Randomx.GetId(imageBg.Height - 30), 30, 30));
|
||
}
|
||
}
|
||
using (MemoryStream memoryStream = new MemoryStream())
|
||
{
|
||
imageBg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
byte[] imageBytes = memoryStream.ToArray();
|
||
imgBase64 = Convert.ToBase64String(imageBytes);
|
||
return imgBase64;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errorMsg = "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"修改图片失败 " + ex.Message + "\"}";
|
||
return "";
|
||
}
|
||
}
|
||
|
||
public string UploadImg(ShopLoginInfo shop, string img_url, DataGridViewCell cell = null, bool randomBlock = false)
|
||
{
|
||
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);
|
||
if (randomBlock)
|
||
g.FillRectangle(new SolidBrush(Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256))),
|
||
new Rectangle(Randomx.GetId(imageBg.Width - 30), Randomx.GetId(imageBg.Height - 30), 30, 30));
|
||
}
|
||
}
|
||
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 < 20 && upImgAuthRst.Contains("LogicError"); i++)
|
||
{
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "图片提报失败,正在重试。" + (i + 1);
|
||
}));
|
||
}
|
||
Thread.Sleep(Randomx.GetId(3000, 6000));
|
||
upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
|
||
}
|
||
if (!upImgAuthRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref upImgAuthRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = upImgAuthRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"申请上传图片失败 " + GetHtml.UrlEncodeUtf8(error) + "\"}";
|
||
}
|
||
string disK = BaseRegex.GetStringJson(ref upImgAuthRst, "disK");
|
||
long disT = BaseRegex.GetLongJson(ref upImgAuthRst, "disT");
|
||
string ext = BaseRegex.GetStringJson(ref upImgAuthRst, "ext");
|
||
string imgBase64 = "";
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
//生成图片base64字符串
|
||
try
|
||
{
|
||
using (MemoryStream memoryStream = new MemoryStream())
|
||
{
|
||
img.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
byte[] imageBytes = memoryStream.ToArray();
|
||
imgBase64 = Convert.ToBase64String(imageBytes);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + "修改图片失败 " + ex.Message + "\"}";
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
//上传图片,获取图片路径
|
||
var upImgRst = WXUpload.adtimageupload(shop, imgBase64, disK, disT, ext).ParseToString();
|
||
var location = BaseRegex.GetStringJson(ref upImgRst, "Location");
|
||
if (string.IsNullOrEmpty(location))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref upImgAuthRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = upImgAuthRst;
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"图片上传失败 " + error + "\"}";
|
||
}
|
||
return "{\"success\":true,\"location\":\"" + location + "\"}";
|
||
}
|
||
|
||
private void btnStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.cancellationTokenSource != null)
|
||
this.cancellationTokenSource.Cancel();
|
||
}
|
||
|
||
CancellationTokenSource getProdTokenSource = null;
|
||
private void pbSelectProd_Click(object sender, EventArgs e)
|
||
{
|
||
if (getProdTokenSource != null)
|
||
getProdTokenSource.Cancel();
|
||
}
|
||
private void btnRandomAdd_Click(object sender, EventArgs e)
|
||
{
|
||
btnRandomAdd.Enabled = false;
|
||
Task.Run(() =>
|
||
{
|
||
Thread.Sleep(5000);
|
||
Invoke(new Action(() =>
|
||
{
|
||
btnRandomAdd.Enabled = true;
|
||
}));
|
||
});
|
||
|
||
pbSelectProd.Visible = true;
|
||
int addCount = txtAddCount.Text.Trim().ParseToInt();
|
||
if (getProdTokenSource != null)
|
||
getProdTokenSource.Cancel();
|
||
getProdTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
List<KJDDBProduct> prodLst = new List<KJDDBProduct>();
|
||
int index = 0;
|
||
int pageSize = 50;
|
||
int prodCount = 99999999;
|
||
while (addCount > 0)
|
||
{
|
||
if (getProdTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
index++;
|
||
// 如果产品数量在0到50之间,说明数据库商品数量不足,无需再重复筛选,直接随机打乱
|
||
if (prodLst.Count == 0 || prodCount > pageSize)
|
||
{
|
||
if (prodCount != 99999999)
|
||
{
|
||
//不重复筛选
|
||
prodLst = GetRandomProductList(out prodCount, 1, Math.Min(pageSize, addCount), true, prodCount);
|
||
}
|
||
else
|
||
{
|
||
prodLst = GetRandomProductList(out prodCount, 1, Math.Min(pageSize, addCount));
|
||
}
|
||
//Thread.Sleep(Randomx.GetId(50, 100));
|
||
Thread.Sleep(Randomx.GetId(250, 500));
|
||
}
|
||
else
|
||
{
|
||
prodLst = prodLst.OrderBy(x => Guid.NewGuid()).ToList();
|
||
Thread.Sleep(Randomx.GetId(10, 30));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblGoodsCount.Text = "产品库 " + prodCount + " 件";
|
||
}));
|
||
if (prodLst.Count == 0) // 等于0要么库里没数据要么出错了,跳出
|
||
break;
|
||
foreach (var prod in prodLst)
|
||
{
|
||
var selectProd = JsonHelper.DeserializeJsonToObject<TemuDBProductSelect>(JsonHelper.SerializeObject(prod));
|
||
selectProd.out_product_Id = prod.id.ToString();
|
||
selectProd.id = 1;
|
||
if (lstTemuDBProductSelect.Count > 0)
|
||
selectProd.id = lstTemuDBProductSelect.Max(p => p.id) + 1;
|
||
this.lstTemuDBProductSelect.Add(selectProd);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}));
|
||
addCount--;
|
||
if (addCount <= 0)
|
||
break;
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbSelectProd.Visible = false;
|
||
}));
|
||
}, getProdTokenSource.Token);
|
||
}
|
||
|
||
public List<KJDDBProduct> GetRandomProductList(out int totalCount, int page = 1, int pageSize = 50, bool isNotCount = false, int totalProdCount = 0)
|
||
{
|
||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
|
||
List<KJDDBProduct> list = new List<KJDDBProduct>();
|
||
int pageCount = 1;
|
||
totalCount = 0;
|
||
|
||
var url = BaseClass.BuildObjString("product/get_pdd_product_list_random");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex() +
|
||
"&page=" + 1 +
|
||
"&page_size=" + pageSize;
|
||
if (isNotCount)
|
||
{
|
||
data += "&is_not_count=" + true;
|
||
data += "&prod_count=" + totalProdCount;
|
||
}
|
||
data += "&in_ext_codes=" + txtExtCodeFilter.Text;
|
||
data += "&in_spu_ids=" + txtIdFilter.Text;
|
||
data += "&in_groups=" + cmbGroupFilter.Text;
|
||
|
||
if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
data += "&in_cates=" + (cmbCateFilter1.Text == "全部" ? "" : cmbCateFilter1.Text);
|
||
else
|
||
{
|
||
//var selectCate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCateFilter1.Text.Trim());
|
||
//var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == selectCate1?.cat_id).ToList();
|
||
//var selectCate2 = cates2.FirstOrDefault(c => c.level == 2 && c.name == cmbCateFilter2.Text.Trim());
|
||
//var cates3 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == selectCate2?.cat_id).ToList();
|
||
//var selectCate3 = cates3.FirstOrDefault(c => c.level == 3 && c.name == cmbCateFilter3.Text.Trim());
|
||
|
||
//if (!string.IsNullOrEmpty(cmbCateFilter1.Text) && selectCate1 != null)
|
||
// data += "&wx_cat_1=" + selectCate1.cat_id;
|
||
//else if (chkSkipQualification.Checked)
|
||
//{
|
||
// // 厂商直采普通店铺不要随特殊商品
|
||
// data += "&wx_cat_1=" + string.Join(",", GlobalConfig.WxCatList.Where(c=>c.level == 1 && !(c.name == "图书" || c.name == "食品饮料" || c.name == "成人用品"))
|
||
// .Select(c => c.cat_id));
|
||
//}
|
||
//if (!string.IsNullOrEmpty(cmbCateFilter2.Text) && selectCate2 != null)
|
||
// data += "&wx_cat_2=" + selectCate2.cat_id;
|
||
//if (!string.IsNullOrEmpty(cmbCateFilter3.Text) && selectCate3 != null)
|
||
// data += "&wx_cat_3=" + selectCate3.cat_id;
|
||
|
||
var selectCate1 = GlobalConfig.WxCatList.Where(c => c.level == 1 && (";" + cmbCateFilter1.Text.Trim() + ";").Contains(";" + c.name + ";")).ToList();
|
||
var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList();
|
||
var selectCate2 = cates2.Where(c => c.level == 2 && (";" + cmbCateFilter2.Text.Trim() + ";").Contains(";" + c.name + ";")).ToList();
|
||
var cates3 = GlobalConfig.WxCatList.Where(c => selectCate2.Any(c2 => c.f_cat_id == c2.cat_id)).ToList();
|
||
var selectCate3 = cates3.Where(c => c.level == 3 && (";" + cmbCateFilter3.Text.Trim() + ";").Contains(";" + c.name + ";")).ToList();
|
||
|
||
if (selectCate1?.Count == 0 && chkSkipQualification.Checked)
|
||
{
|
||
// 厂商直采普通店铺不要随特殊商品
|
||
data += "&wx_cat_1=" + string.Join(",", GlobalConfig.WxCatList.Where(c => c.level == 1 && !(c.name == "图书" || c.name == "食品饮料" || c.name == "成人用品"))
|
||
.Select(c => c.cat_id));
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(cmbCateFilter1.Text) && selectCate1?.Count > 0)
|
||
data += "&wx_cat_1=" + string.Join(",", selectCate1.Select(c => c.cat_id).ToList());
|
||
if (!string.IsNullOrEmpty(cmbCateFilter2.Text) && selectCate2?.Count > 0)
|
||
data += "&wx_cat_2=" + string.Join(",", selectCate2.Select(c => c.cat_id).ToList());
|
||
if (!string.IsNullOrEmpty(cmbCateFilter3.Text) && selectCate3?.Count > 0)
|
||
data += "&wx_cat_3=" + string.Join(",", selectCate3.Select(c => c.cat_id).ToList());
|
||
}
|
||
data += "&product_get_type=" + cmbSourceType.Text.Trim();
|
||
data += "&wx_safe_status=" + cmbWxSafe.Text.Trim().Replace("安全+未校验", "安全商品,未校验");
|
||
data += "&is_supplier_prod_ok=" + cmbJstInitSet.Text.Trim();
|
||
data += "&product_name=" + txtSearchGoodsName.Text.Trim();
|
||
|
||
if (chkSevenDays.Checked)
|
||
data += "&add_days_less=21";
|
||
|
||
if (chkWXComplateProd.Checked)
|
||
data += "&has_wx_format=1";
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
BaseMsgForm.ShowError("获取商品失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
|
||
}));
|
||
return new List<KJDDBProduct>();
|
||
}
|
||
|
||
int count = BaseRegex.GetIntJson(ref html, "count");
|
||
totalCount = count;
|
||
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
|
||
pageCount = Math.Max(pageCount, 1);
|
||
|
||
var jArr = JObject.Parse(html)["data"];
|
||
if (jArr.Count() == 0)
|
||
return list;
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
|
||
try
|
||
{
|
||
list = JsonHelper.DeserializeJsonToList<KJDDBProduct>(sProd).OrderBy(x => Randomx.GetId(999999)).ToList();
|
||
return list;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new List<KJDDBProduct>();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 随机添加黄总厂商商品(或其他指定分组产品,由服务端控制)
|
||
/// </summary>
|
||
/// <param name="totalCount"></param>
|
||
/// <param name="page"></param>
|
||
/// <param name="pageSize"></param>
|
||
/// <returns></returns>
|
||
public List<KJDDBProduct> GetRandomCompanyProductList(out int totalCount, string groupName = "黄总数据包", int page = 1, int pageSize = 200)
|
||
{
|
||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
|
||
List<KJDDBProduct> list = new List<KJDDBProduct>();
|
||
int pageCount = 1;
|
||
totalCount = 0;
|
||
|
||
var url = BaseClass.BuildObjString("product/get_pdd_product_list_random");
|
||
var data = "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
data = UserLogin.GetSignaturex() +
|
||
"&page=" + 1 +
|
||
"&page_size=" + pageSize;
|
||
data += "&in_groups=" + groupName;
|
||
}));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
BaseMsgForm.ShowError("获取商品失败,请重试!" + BaseRegex.GetStringJson(ref html, "msg"));
|
||
}));
|
||
return new List<KJDDBProduct>();
|
||
}
|
||
|
||
int count = BaseRegex.GetIntJson(ref html, "count");
|
||
totalCount = count;
|
||
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
|
||
pageCount = Math.Max(pageCount, 1);
|
||
|
||
var jArr = JObject.Parse(html)["data"];
|
||
if (jArr.Count() == 0)
|
||
return list;
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
|
||
try
|
||
{
|
||
list = JsonHelper.DeserializeJsonToList<KJDDBProduct>(sProd).OrderBy(x => Randomx.GetId(999999)).ToList();
|
||
return list;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new List<KJDDBProduct>();
|
||
}
|
||
}
|
||
|
||
private void btnClearUpload_Click(object sender, EventArgs e)
|
||
{
|
||
if (BaseMsgForm.ShowConfirm("确定清空待上传商品吗?清空后不可恢复!").DialogResult == DialogResult.Cancel)
|
||
return;
|
||
|
||
this.lstTemuDBProductSelect.Clear();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}
|
||
|
||
private void lblNewAddPrice_Click(object sender, EventArgs e)
|
||
{
|
||
var ucPrice = new UcAddPrice();
|
||
if (IsSetFontScaleNone)
|
||
{
|
||
Font of = ucPrice.Font;
|
||
Font nf = new Font(of.FontFamily, (of.Size * 96.0 / FormDpi).ParseToFloat(), of.Style, of.Unit, of.GdiCharSet, of.Bold);
|
||
ucPrice.Font = nf;
|
||
}
|
||
ucPrice.PriceChange += ucAddPrice_PriceChange;
|
||
this.fPnlPriceRule.Controls.Add(ucPrice);
|
||
ucPrice.lblSinglePriceAdd.Visible = false;
|
||
ucPrice.txtSinglePriceAdd.Visible = false;
|
||
}
|
||
|
||
private void ucAddPrice_PriceChange(object obj)
|
||
{
|
||
List<AddPriceRule> priceRuleLst = new List<AddPriceRule>();
|
||
foreach (var ucItem in fPnlPriceRule.Controls)
|
||
{
|
||
var ucPrice = ucItem as UcAddPrice;
|
||
if (ucPrice != null)
|
||
{
|
||
priceRuleLst.Add(new AddPriceRule()
|
||
{
|
||
AddMorePrice = ucPrice.PriceAddMore,
|
||
AddPriceTimes = ucPrice.PriceAddTimes,
|
||
LessThanPrice = ucPrice.PriceEnd,
|
||
MoreThanPrice = ucPrice.PriceStart,
|
||
SinglePriceAdd = ucPrice.SinglePriceAdd,
|
||
});
|
||
}
|
||
}
|
||
this.lstAddPriceRule.Clear();
|
||
this.lstAddPriceRule.AddRange(priceRuleLst);
|
||
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_add_price_rules", lstAddPriceRule);
|
||
}
|
||
|
||
private void txtAddPrice_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (IsLoadComplate)
|
||
{
|
||
defaultAddPriceRule.AddPriceTimes = txtAddTimes.Text.Trim().ParseToDecimal();
|
||
defaultAddPriceRule.AddMorePrice = txtAddMorePrice.Text.Trim().ParseToDecimal();
|
||
defaultAddPriceRule.SinglePriceAdd = txtSinglePriceAdd.Text.Trim().ParseToDecimal();
|
||
defaultAddPriceRule.StockNum = txtStockNum.Text.Trim().ParseToInt();
|
||
defaultAddPriceRule.ShippingPriceTimes = txtShippingPriceTimes.Text.Trim().ParseToDecimal();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig<AddPriceRule>("wx_default_add_price_rule", defaultAddPriceRule);
|
||
}
|
||
}
|
||
|
||
private void chkStepAddPrice_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
defaultAddPriceRule.IsStepAddPrice = this.chkStepAddPrice.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig<AddPriceRule>("wx_default_add_price_rule", defaultAddPriceRule);
|
||
}
|
||
|
||
private void btnClearDgv_Click(object sender, EventArgs e)
|
||
{
|
||
//this.dgvSelectProduct.Rows.Clear();
|
||
var rows = this.dgvSelectProduct.Rows.Cast<DataGridViewRow>().ToList(); //Cast后Rows做foreach循环时仍会夹花跳过,所以要ToList转一个新的数组。
|
||
foreach (var row in rows)
|
||
{
|
||
if (row.Cells["colCheck"].Value.ParseToBool() == true)
|
||
{
|
||
var draft_id = row.Cells["colDraftId"].Value.ParseToString();
|
||
var add_time = row.Cells["colAddTime"].Value.ParseToString().ParseToDateTime();
|
||
upload_draft_product_lst.RemoveAll(p => p.draft_id.ParseToString() == draft_id && p.add_time.ToString("yyyyMMddHHmmss") == add_time.ToString("yyyyMMddHHmmss"));
|
||
|
||
this.dgvSelectProduct.Rows.Remove(row);
|
||
}
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
}
|
||
|
||
private void chkAddMorePriceFirst_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (IsLoadComplate)
|
||
{
|
||
defaultAddPriceRule.AddMorePriceFirst = chkAddMorePriceFirst.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_default_add_price_rule", defaultAddPriceRule);
|
||
}
|
||
}
|
||
|
||
private void lblGoodsCount_Click(object sender, EventArgs e)
|
||
{
|
||
//PDDDBProdListForm f = new PDDDBProdListForm();
|
||
//f.Width = 1366;
|
||
//f.Height = 768;
|
||
//f.ShowMaximizeBox = true;
|
||
//f.ShowDialog();
|
||
}
|
||
|
||
private void lblWaitToUp_Click(object sender, EventArgs e)
|
||
{
|
||
PDDDBProdUserSelectCacheForm selectCacheForm = new PDDDBProdUserSelectCacheForm(lstTemuDBProductSelect);
|
||
selectCacheForm.ShowDialog();
|
||
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}
|
||
|
||
private void btnClearFilter_Click(object sender, EventArgs e)
|
||
{
|
||
txtIdFilter.Text = "";
|
||
txtExtCodeFilter.Text = "";
|
||
txtSearchGoodsName.Text = "";
|
||
cmbGroupFilter.Text = "";
|
||
cmbCateFilter1.Text = "";
|
||
cmbWxSafe.Text = "安全+未校验";
|
||
cmbSourceType.Text = "厂商直采";
|
||
chkSkipQualification.Checked = false;
|
||
|
||
int prodCount;
|
||
pbSelectProd.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
GetRandomProductList(out prodCount, 1, 1);
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbSelectProd.Visible = false;
|
||
lblGoodsCount.Text = "产品库 " + prodCount + " 件";
|
||
}));
|
||
});
|
||
}
|
||
|
||
private void 并发上传_Click(object sender, EventArgs e)
|
||
{
|
||
var draftIdLst = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colDraftId"]?.Value.ToString()).ToList();
|
||
|
||
var lst = upload_draft_product_lst.Select(p => p.wxDraftProduct).ToList();
|
||
|
||
var upLst = lst.Where(l => draftIdLst.Contains(l.product.productKey.productId)).ToList();
|
||
DateTime startTime = DateTime.Now;
|
||
Task.Run(() =>
|
||
{
|
||
List<Task> tLst = new List<Task>();
|
||
foreach (var prodParam in upLst)
|
||
{
|
||
var row = this.dgvSelectProduct.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colDraftId"].Value.ParseToString() == prodParam.product.productKey.productId);
|
||
if (row == null)
|
||
continue;
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == row.Cells["colSupplierId"].Value.ParseToString());
|
||
if (shop == null)
|
||
continue;
|
||
var t =Task.Run(() =>
|
||
{
|
||
UploadSameTime(shop, prodParam, row.Cells["colOpResult"]);
|
||
});
|
||
tLst.Add(t);
|
||
}
|
||
Task.WaitAll(tLst.ToArray());
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
var duration = DateTime.Now - startTime;
|
||
Invoke(new Action(() => { BaseMsgForm.ShowInfo("并发上传完成,耗时:" + duration.TotalSeconds + " 秒"); }));
|
||
});
|
||
}
|
||
|
||
//public ConcurrentList<WXUploadProductParam> upload_draft_products = new ConcurrentList<WXUploadProductParam>();
|
||
public ConcurrentList<TemuDBProductSelect> upload_draft_product_lst = new ConcurrentList<TemuDBProductSelect>();
|
||
void UploadSameTime(ShopLoginInfo shop, WXUploadProductParam upProdParam, DataGridViewCell cell)
|
||
{
|
||
|
||
var uploadProdRst = WXUpload.upProductV2(shop, upProdParam);
|
||
int retryTimes = 0;
|
||
while (!uploadProdRst.Contains("\"code\":0") && !uploadProdRst.Contains("\"success\":true"))
|
||
{
|
||
retryTimes++;
|
||
uploadProdRst = WXUpload.upProductV2(shop, upProdParam);
|
||
if (retryTimes >= 5)
|
||
break;
|
||
if (uploadProdRst.Contains("今日提审次数已用尽,请明日再试"))
|
||
break;
|
||
}
|
||
if (!uploadProdRst.Contains("\"code\":0") && !uploadProdRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref uploadProdRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = uploadProdRst;
|
||
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "商品上传失败 " + error;
|
||
}));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (cell != null)
|
||
{
|
||
upload_draft_product_lst.RemoveAll(p => p.wxDraftProduct == upProdParam);
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "商品已上传,重试次数 " + retryTimes;
|
||
}));
|
||
}
|
||
|
||
var dgvShopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(row => row.Cells["colShopId"]?.Value.ParseToString() == shop.ShopId);
|
||
if (dgvShopRow != null)
|
||
{
|
||
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
|
||
if (!dicShopUpload.ContainsKey(shop.ShopId))
|
||
dicShopUpload[shop.ShopId] = new WxShopUploadInfo();
|
||
if (!dicShopUpload[shop.ShopId].DicDayUploadCount.ContainsKey(day))
|
||
dicShopUpload[shop.ShopId].DicDayUploadCount[day] = 0;
|
||
dicShopUpload[shop.ShopId].DicDayUploadCount[day] += 1;
|
||
// 删除45天前的记录
|
||
var removeKeys = dicShopUpload[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt());
|
||
foreach (var key in removeKeys)
|
||
{
|
||
dicShopUpload[shop.ShopId].DicDayUploadCount.Remove(key);
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", dicShopUpload);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvShopRow.Cells["colUploadCount"].Value = dicShopUpload[shop.ShopId].DicDayUploadCount[day];
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void txtPreDays_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.PreSaleDays = txtPreDays.Text.Trim().ParseToInt();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void txtReplaceText_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.FilterWords = txtReplaceText.Text.Trim();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void txtMinPrice_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.SkuMinPrice = txtMinPrice.Text.Trim().ParseToInt();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void txtWaitSeconds_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.WaitSeconds = txtWaitSeconds.Text.Trim().ParseToInt();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkHighestPriceSku_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.OnlyHighestPriceSku = chkHighestPriceSku.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkSameSpecPrice_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.SameSpecSamePrice = chkSameSpecPrice.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkSkipUploaded_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.SkipUploaded = chkSkipUploaded.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkUpDraft_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.UpDraft = chkUpDraft.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkPreSale_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.IsPreSale = chkPreSale.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void btnRefreshNum_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void cmbSourceType_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
fillPddCate();
|
||
else
|
||
fillWxCate();
|
||
|
||
|
||
if (!string.IsNullOrWhiteSpace(cmbSourceType.Text) && cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家")
|
||
{
|
||
cmbJstInitSet.Text = "";
|
||
}
|
||
else
|
||
{
|
||
cmbJstInitSet.Text = "已设置";
|
||
}
|
||
}
|
||
|
||
private void cmbSourceType_TextChanged(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void cmbCateFilter1_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "微信店采")
|
||
// return;
|
||
|
||
//cmbCateFilter2.Text = "";
|
||
//cmbCateFilter2.Items.Clear();
|
||
//var cate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCateFilter1.Text.Trim());
|
||
//var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate1?.cat_id).ToList();
|
||
//foreach (var cate2 in cates2)
|
||
//{
|
||
// cmbCateFilter2.Items.Add(cate2.name);
|
||
//}
|
||
}
|
||
|
||
private void cmbCateFilter2_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "微信店采")
|
||
// return;
|
||
|
||
//cmbCateFilter3.Text = "";
|
||
//cmbCateFilter3.Items.Clear();
|
||
//var cate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCateFilter1.Text.Trim());
|
||
//var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate1?.cat_id).ToList();
|
||
//var cate2 = cates2.FirstOrDefault(c => c.level == 2 && c.name == cmbCateFilter2.Text.Trim());
|
||
//var cates3 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate2?.cat_id).ToList();
|
||
//foreach (var cate3 in cates3)
|
||
//{
|
||
// cmbCateFilter3.Items.Add(cate3.name);
|
||
//}
|
||
}
|
||
|
||
private void cmbCateFilter3_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
//var cate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCateFilter1.Text.Trim());
|
||
//var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate1?.cat_id).ToList();
|
||
//var cate2 = cates2.FirstOrDefault(c => c.level == 2 && c.name == cmbCateFilter2.Text.Trim());
|
||
//var cates3 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate2?.cat_id).ToList();
|
||
//var cate3 = cates3.FirstOrDefault(c => c.level == 3 && c.name == cmbCateFilter3.Text.Trim());
|
||
}
|
||
|
||
private void cmbCateFilter1_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
return;
|
||
|
||
cmbCateFilter2.Text = "";
|
||
cmbCateFilter2.Items.Clear();
|
||
cmbCateFilter3.Text = "";
|
||
cmbCateFilter3.Items.Clear();
|
||
var selectCate1 = GlobalConfig.WxCatList
|
||
.Where(c => c.level == 1 && (cmbCateFilter1.Text.Trim() == cmbCateFilter1.DefaultText || (";" + cmbCateFilter1.Text.Trim() + ";")
|
||
.Contains(";" + c.name + ";"))).ToList();
|
||
var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList();
|
||
//foreach (var cate2 in cates2)
|
||
//{
|
||
// cmbCat2.Items.Add(cate2.name);
|
||
//}
|
||
cmbCateFilter2.Items.AddRange(cates2.Select(c => c.name).ToArray());
|
||
}
|
||
|
||
private void cmbCateFilter2_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
return;
|
||
|
||
cmbCateFilter3.Text = "";
|
||
cmbCateFilter3.Items.Clear();
|
||
var selectCate1 = GlobalConfig.WxCatList
|
||
.Where(c => c.level == 1 && (cmbCateFilter1.Text.Trim() == cmbCateFilter1.DefaultText || (";" + cmbCateFilter1.Text.Trim() + ";")
|
||
.Contains(";" + c.name + ";"))).ToList();
|
||
var cates2 = GlobalConfig.WxCatList.Where(c => selectCate1.Any(c1 => c.f_cat_id == c1.cat_id)).ToList();
|
||
var selectCate2 = cates2
|
||
.Where(c => c.level == 2 && (cmbCateFilter2.Text.Trim() == cmbCateFilter1.DefaultText || (";" + cmbCateFilter2.Text.Trim() + ";")
|
||
.Contains(c.name))).ToList();
|
||
var cates3 = GlobalConfig.WxCatList.Where(c => selectCate2.Any(c2 => c.f_cat_id == c2.cat_id)).ToList();
|
||
//foreach (var cate3 in cates3)
|
||
//{
|
||
// cmbCat3.Items.Add(cate3.name);
|
||
//}
|
||
cmbCateFilter3.Items.AddRange(cates3.Select(c => c.name).ToArray());
|
||
}
|
||
|
||
private void cmbCateFilter3_TextChanged(object sender, EventArgs e)
|
||
{
|
||
//var cate1 = GlobalConfig.WxCatList.FirstOrDefault(c => c.level == 1 && c.name == cmbCat1.Text.Trim());
|
||
//var cates2 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate1?.cat_id).ToList();
|
||
//var cate2 = cates2.FirstOrDefault(c => c.level == 2 && c.name == cmbCat1.Text.Trim());
|
||
//var cates3 = GlobalConfig.WxCatList.Where(c => c.f_cat_id == cate2?.cat_id).ToList();
|
||
//var cate3 = cates3.FirstOrDefault(c => c.level == 3 && c.name == cmbCat1.Text.Trim());
|
||
}
|
||
|
||
|
||
private void btnFilterBound_Click(object sender, EventArgs e)
|
||
{
|
||
var boundMax = txtFilterBoundMax.Text.Trim().ParseToInt();
|
||
var boundMin = txtFilterBoundMin.Text.Trim().ParseToInt();
|
||
var cates = GlobalConfig.WxCatBoundList.Where(b => b.cat_bound <= boundMax && b.cat_bound >= boundMin);
|
||
lstTemuDBProductSelect.RemoveAll(p => !cates.Any(c => c.leaf_id.ParseToString() == p.wx_cat_leaf));
|
||
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}
|
||
|
||
private void btnFilterShop_Click(object sender, EventArgs e)
|
||
{
|
||
foreach(DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
{
|
||
row.Visible = false;
|
||
row.Cells["colSelect"].Value = false;
|
||
continue;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
{
|
||
row.Visible = false;
|
||
row.Cells["colSelect"].Value = false;
|
||
continue;
|
||
}
|
||
row.Visible = true;
|
||
}
|
||
}
|
||
|
||
private void btnEmptyShop_Click(object sender, EventArgs e)
|
||
{
|
||
txtFilterShopName.Text = "";
|
||
cmbFilterShopNotes.Text = "全部";
|
||
btnFilterShop_Click(null, null);
|
||
}
|
||
|
||
private void btnReverse_Click(object sender, EventArgs e)
|
||
{
|
||
foreach(DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
}
|
||
}
|
||
|
||
private void btnAddSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
|
||
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnAddUnSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
|
||
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectOnline_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colLoginStatus"].Value.ParseToString() == "在线")
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectOffline_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colLoginStatus"].Value.ParseToString() != "在线")
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void txtTitleHeadWord_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.TitleHeadWords = txtTitleHeadWord.Text.Trim();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkSaveBound_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.IsSaveBound = chkSaveBound.Checked;
|
||
if (chkSaveBound.Checked)
|
||
{
|
||
wxUploadRule.FilterBoundMinSave = txtFilterBoundMin.Text.ParseToInt();
|
||
wxUploadRule.FilterBoundMaxSave = txtFilterBoundMax.Text.ParseToInt();
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void txtFilterBoundMin_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (wxUploadRule.IsSaveBound)
|
||
{
|
||
wxUploadRule.FilterBoundMinSave = txtFilterBoundMin.Text.ParseToInt();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
}
|
||
private void txtFilterBoundMax_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (wxUploadRule.IsSaveBound)
|
||
{
|
||
wxUploadRule.FilterBoundMaxSave = txtFilterBoundMax.Text.ParseToInt();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
}
|
||
|
||
private void chkAiShotTitle_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.IsAiShortTitle = chkAiShortTitle.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkUseWXComplateProd_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.IsUseWXComplateProd = chkUseWXComplateProd.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void btnProdDb_Click(object sender, EventArgs e)
|
||
{
|
||
WXUserProdListForm.Instance.lstTemuDBProductSelect = this.lstTemuDBProductSelect;
|
||
WXUserProdListForm.Instance.SaveComplete -= dbProdList_SaveComplete;
|
||
WXUserProdListForm.Instance.SaveComplete += dbProdList_SaveComplete;
|
||
WXUserProdListForm.Instance.Show();
|
||
WXUserProdListForm.Instance.BringToFront();
|
||
}
|
||
|
||
private void dbProdList_SaveComplete(object obj)
|
||
{
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}));
|
||
}
|
||
}
|
||
|
||
public class WXUpload
|
||
{
|
||
public static string searchProduct(ShopLoginInfo shop, string extCode, string extCode2 = "")
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/searchProduct?" +
|
||
"token=&lang=zh_CN&pageSize=20&productStatus[]=-1&productSource=[1,16,32]&searchSource=1&useNew=true&pageNum=1&status[]=5&spuCode=" + extCode;
|
||
if (!string.IsNullOrEmpty(extCode2))
|
||
url += "," + extCode2;
|
||
string refere = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_ON";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, refere);
|
||
return result;
|
||
}
|
||
|
||
public static string searchProductWithTitle(ShopLoginInfo shop, string urlEncodeTitle)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/searchProduct?" +
|
||
"token=&lang=zh_CN&pageSize=20&productStatus[]=-1&productSource=[1,16,32]&searchSource=1&useNew=true&pageNum=1&status[]=-1&title=" + urlEncodeTitle;
|
||
string refere = "https://store.weixin.qq.com/shop/goods/list";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, refere);
|
||
return result;
|
||
}
|
||
|
||
public static string getUploadTempImgAuth(ShopLoginInfo shop, int uploadScene = 3)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecchannelspicture/cgi/getUploadTempImgAuth?token=&lang=zh_CN&uploadScene=" + uploadScene;
|
||
string refere = "https://store.weixin.qq.com/shop/goods/entry";
|
||
//{"code":0,"disK":"538c14e950da7b678ce9f5a12658c8acddd09e4b","disT":1767870926,"ext":"23aa0ecfb792a","url":"https://westore.video.qq.com/adtimageupload"}
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, refere);
|
||
return result;
|
||
}
|
||
|
||
public static string adtimageupload(ShopLoginInfo shop, string imgBase64, string dis_k, long dis_t, string ext)
|
||
{
|
||
string url = "https://westorealpha.video.qq.com/adtimageupload";
|
||
string referer = "https://store.weixin.qq.com/";
|
||
string body = imgBase64;
|
||
var result = WXHttpResponseBLL.WeiXinImgPostResponse(shop, url, body, dis_k, dis_t, ext, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getProductClassify(ShopLoginInfo shop, string goodsName, List<string> goodImgUrlsLst)
|
||
{
|
||
string boundaryLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||
string boundaryStr = "----WebKitFormBoundary";
|
||
for (int i = 0; i < 16; i++)
|
||
{
|
||
boundaryStr += boundaryLetters[Randomx.GetId(boundaryLetters.Length)];
|
||
}
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/cgi/common/productClassify?from=B&title=" + GetHtml.UrlEncodeUtf8(goodsName) + "&token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
|
||
string body = @"--" + boundaryStr + @"
|
||
";
|
||
foreach (var imgFullPath in goodImgUrlsLst)
|
||
{
|
||
string fileName = imgFullPath.Split('\\').LastOrDefault();
|
||
body += @"Content-Disposition: form-data; name=""file""; filename=""" + fileName + @"""
|
||
Content-Type: image/jpeg
|
||
|
||
<!>" + imgFullPath + @"<!>
|
||
--" + boundaryStr;
|
||
}
|
||
body += @"--
|
||
";
|
||
var result = WXHttpResponseBLL.WeiXinUploadResponse(shop, url, body, boundaryStr, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getCategoryOnShelf(ShopLoginInfo shop, List<long> catIdLst)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/product/getCategoryOnShelfV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = @"{""catIdList"":[" + string.Join(",", catIdLst) + @"],""brandId"":2100000000}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string batchCheckCategoryRelation(ShopLoginInfo shop, long catId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/product/batchCheckCategoryRelation?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = @"{""categoryIdList"":[" + catId + "]}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string addFinderCategoryV2(ShopLoginInfo shop, long catId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/addFinderCategoryV2?token=&lang=zh_CN";
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 申请资质类目前获取类目信息
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="catId"></param>
|
||
/// <returns></returns>
|
||
public static string getSingleCategoryData(ShopLoginInfo shop, long catId, List<long> catIdLst)
|
||
{
|
||
var catIds = "[\"" + string.Join("\",\"", catIdLst) + "\"]";
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/getSingleCategoryData?token=&lang=zh_CN&categoryId=" + catId;
|
||
string referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=" + GetHtml.UrlEncodeUtf8(catIds) + "&source=goods&type=apply";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
|
||
return result;
|
||
}
|
||
|
||
public static string wxCateAuth(ShopLoginInfo shop, List<long> catIdLst, WXCateAuthParam wxCateAuthParam)
|
||
{
|
||
var catIds = "[\"" + string.Join("\",\"", catIdLst) + "\"]";
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/addFinderCategoryV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=" + GetHtml.UrlEncodeUtf8(catIds) + "&source=goods&type=apply";
|
||
string data = JsonHelper.SerializeObject(wxCateAuthParam);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
public static string genProductShortTitle(ShopLoginInfo shop, WXGetShortTitleParam getShortTitleParam)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/common/cgi/goods/genProductShortTitle?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = JsonHelper.SerializeObject(getShortTitleParam);
|
||
//{"productTitle":"妈妈老年中年阔脚裤冬季秋季时尚牛仔裤","headImgUrls":["https://wst.wxapp.tc.qq.com/160/20304/snscosdownload/SH/reserved/6xykWLEnztKEVU0iahAM7HQ28puCia87zPkvSbFT8Fcia99g2ZNWRdy8licxD6qwsqV4bCicoxwQF9e6jh3qwibgzxuA?token=x5Y29zUxcibCe0pFyoSA8zb1aYVKnIBLkQ8ZUXMcwEq3qYHsko3TDzv2rsL2AfJPd&idx=1&expire=1768211170","https://wst.wxapp.tc.qq.com/160/20304/snscosdownload/SH/reserved/6xykWLEnztKEVU0iahAM7Hbwaw1AboTKxjGsLhJgVreuYNxwyQxrk9RtvCv3XsXSnic9WfBFMAIZYpNgYkWd7VDQ?token=x5Y29zUxcibCe0pFyoSA8zb1aYVKnIBLk4qWUsS2WZiaCjXhZLj0D6PYyddX71qNiat&idx=1&expire=1768211170","https://wst.wxapp.tc.qq.com/160/20304/snscosdownload/SH/reserved/6xykWLEnztKEVU0iahAM7HTa1Ej2xJpy6Ej84arVO7A3vxIDD1XP6ZRVw43OficKLXPcXPUvDNmc8A4lMHCgbic3A?token=x5Y29zUxcibCe0pFyoSA8zb1aYVKnIBLkhejArCiaiaLIEKtvOicA5chibIj1tfELV0Mm&idx=1&expire=1768211170"],"categories":[{"catId":"10000111","catName":"服饰内衣"},{"catId":"10000113","catName":"女装"},{"catId":"10000672","catName":"裤子"},{"catId":"547705","catName":"牛仔裤"}]}
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getFreightTemplate(ShopLoginInfo shop)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/express/cgi/goods/getFreightTemplate?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取售后地址
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <returns></returns>
|
||
public static string getAddress(ShopLoginInfo shop, string searchText="")
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/cgi/getAddress?token=&lang=zh_CN";
|
||
if (!string.IsNullOrEmpty(searchText))
|
||
url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/cgi/getAddress?searchStr=" + GetHtml.UrlEncodeUtf8(searchText) + "&token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getAddressById(ShopLoginInfo shop, string AddressId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/cgi/getAddress?offset=0&limit=20&includeBlock=1&addressId=" + AddressId +
|
||
"&token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/address/expressAddressMgmt";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string uploadProductDraft(ShopLoginInfo shop, WXUploadProductParam prodParam)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/common/cgi/goods/uploadProductDraft?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string upProductV2(ShopLoginInfo shop, WXUploadProductParam prodParam)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/upProductV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
public static string upProductJObjectV2(ShopLoginInfo shop, string prodStr)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/upProductV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
//JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
//var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 尝试免审 失败
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="productId"></param>
|
||
/// <returns></returns>
|
||
public static string getEditProductV2(ShopLoginInfo shop, string productId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/getEditProductV2?token=&lang=zh_CN&productKey=%7B%22productId%22:" +
|
||
productId + "%7D&needRealStock=true&preview=false&release=false";
|
||
//url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/getEditProductV2?token=&lang=zh_CN&productKey=%7B%22productId%22:" +
|
||
// productId + "%7D&needRealStock=true&preview=false&release=true";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + productId + "&isUpdateAuditFree=0&source=list_edit&continueEditInfo={%22isEditingContinued%22:false,%22lastEditDraftTime%22:0,%22listingTime%22:0}";
|
||
//referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + productId + "&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo={%22isEditingContinued%22:true,%22lastEditDraftTime%22:0,%22listingTime%22:0}";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string initUploadPart(ShopLoginInfo shop, string submitJson, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodefiletransfer/filecos/initUploadPart?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
string body = submitJson; //@"{""name"":""goods/10000456038253/2026-01-20/1768887306422/submit.json""}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string listingAuditFree(ShopLoginInfo shop, WXUploadProductParam prodParam, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/listingAuditFree?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string listingAuditFree(ShopLoginInfo shop, string prodStr, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/listingAuditFree?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string uploadPartBinary(ShopLoginInfo shop, string initFileName, string blobPath, string uploadId, string prodId, int time1, int time2)
|
||
{
|
||
string boundaryLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||
string boundaryStr = "----WebKitFormBoundary";
|
||
for (int i = 0; i < 16; i++)
|
||
{
|
||
boundaryStr += boundaryLetters[Randomx.GetId(boundaryLetters.Length)];
|
||
}
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodefiletransfer/filecos/uploadPartBinary?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
string body = @"--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""name""
|
||
|
||
" + initFileName + @"
|
||
--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""uploadId""
|
||
|
||
" + uploadId + @"
|
||
--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""partSeq""
|
||
|
||
1
|
||
--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""file""; filename=""blob""
|
||
Content-Type: application/octet-stream
|
||
|
||
<!>" + blobPath + @"<!>
|
||
--" + boundaryStr + @"--
|
||
";
|
||
var result = WXHttpResponseBLL.WeiXinUploadResponse(shop, url, body, boundaryStr, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
public static string completeUploadPart(ShopLoginInfo shop, string completeJson, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodefiletransfer/filecos/completeUploadPart?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
string body = completeJson; //{"name":"goods/10000466857488/2026-01-20/1768907711117/submit.json","uploadId":"176890774759894589c6096cab2210e0793688fb68b482b766a0387c8667d3280a36385109","etagList":["ade9671ce546efb4cb209f5aa7e5d597"],"partSeqList":[1]}
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加售后地址
|
||
/// </summary>
|
||
public static string addAddress(ShopLoginInfo shop, string provinceName, string cityName, string countyName,
|
||
string detailInfo, string userName, string telNumber)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/address/addAddress?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/address/expressAddressMgmt";
|
||
string address = "{\"addressInfo\":{\"provinceName\":\"" + provinceName +
|
||
"\",\"cityName\":\"" + cityName + "\",\"countyName\":\"" + countyName +
|
||
"\",\"detailInfo\":\"" + detailInfo + "\",\"userName\":\"" + userName +
|
||
"\",\"telNumber\":\"" + telNumber + "\",\"location\":{}},\"defaultSend\":0,\"defaultRecv\":0}";
|
||
|
||
JObject obj = new JObject();
|
||
obj["data"] = address;
|
||
string body = JsonHelper.SerializeObject(obj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取服务接口到期时间
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <returns></returns>
|
||
public static string GetApiServiceList(ShopLoginInfo shop)
|
||
{
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeservicemarket/service/GetMyServiceList?offset=0&limit=20&status=2&token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/servicemarket/myServices?status=2";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public class AddPriceRule
|
||
{
|
||
/// <summary>
|
||
/// 加价金额区间大于 不包含
|
||
/// </summary>
|
||
public decimal MoreThanPrice { get; set; }
|
||
/// <summary>
|
||
/// 加价金额区间小于 包含
|
||
/// </summary>
|
||
public decimal LessThanPrice { get; set; }
|
||
/// <summary>
|
||
/// 加价倍数
|
||
/// </summary>
|
||
public decimal AddPriceTimes { get; set; } = 2m;
|
||
/// <summary>
|
||
/// 额外加价金额
|
||
/// </summary>
|
||
public decimal AddMorePrice { get; set; } = 10m;
|
||
/// <summary>
|
||
/// 单买加价
|
||
/// </summary>
|
||
public decimal SinglePriceAdd { get; set; } = 1m;
|
||
/// <summary>
|
||
/// 先加后乘
|
||
/// </summary>
|
||
public bool AddMorePriceFirst { get; set; } = false;
|
||
/// <summary>
|
||
/// 上货库存量设置
|
||
/// </summary>
|
||
public int StockNum { get; set; } = 999;
|
||
public bool IsStepAddPrice { get; set; } = false;
|
||
/// <summary>
|
||
/// 运费倍率
|
||
/// </summary>
|
||
public decimal ShippingPriceTimes { get; set; } = 1.0m;
|
||
}
|
||
|
||
public class WXUploadRule
|
||
{
|
||
public int PreSaleDays { get; set; } = 5;
|
||
|
||
public string FilterWords { get; set; } = "顶级,之王,二手,亏本,冲量,白菜价,跳楼价,xx,xxx,最大,最小,低价,降价,成本,赔钱,甩卖,真丝,蚕丝,香云纱,羊绒,羊毛,羊羔绒,羊羔毛,羽绒,皮草";
|
||
|
||
public int SkuMinPrice { get; set; } = 10;
|
||
|
||
public int WaitSeconds { get; set; } = 10;
|
||
|
||
public bool OnlyHighestPriceSku { get; set; } = true;
|
||
public bool SameSpecSamePrice { get; set; } = true;
|
||
public bool SkipUploaded { get; set; } = true;
|
||
public bool UpDraft { get; set; } = false;
|
||
public bool IsPreSale { get; set; } = false;
|
||
public string TitleHeadWords { get; set; } = "";
|
||
|
||
public bool IsSaveBound { get; set; } = false;
|
||
public int FilterBoundMinSave { get; set; } = 1000;
|
||
public int FilterBoundMaxSave { get; set; } = 1000;
|
||
public bool IsAiShortTitle { get; set; } = false;
|
||
public bool IsUseWXComplateProd { get; set; }
|
||
}
|
||
}
|