8479 lines
352 KiB
C#
8479 lines
352 KiB
C#
using AllBase;
|
||
using AllBase.Extension;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Config;
|
||
using AllBase.Model.DBModel;
|
||
using AllBase.Model.Param.WXParam;
|
||
using AllBase.Model.Result;
|
||
using AllBase.Model.Result.PDDResult;
|
||
using AllBase.Model.Result.WXResult;
|
||
using CefSharp;
|
||
using NaiBa.Util;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.Drawing;
|
||
using System.Drawing.Printing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net.Http;
|
||
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.BLL;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.KJDForms.SystemForms;
|
||
using TemuKJD.PDDForms.ProductSelectForms;
|
||
using TemuKJD.ToolForms;
|
||
using TemuKJD.UserControls;
|
||
using TemuKJD.WXForms.ShopForms;
|
||
using Work;
|
||
using Work.BLL.Tools;
|
||
using Work.Services;
|
||
using static System.Net.Mime.MediaTypeNames;
|
||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
|
||
|
||
namespace TemuKJD.WXForms.ProductForms
|
||
{
|
||
public partial class WXDBProdUploadForm : BaseForm
|
||
{
|
||
public static WXDBProdUploadForm Instance { get; set; } = null;
|
||
public static ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
public static ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new ConcurrentList<TemuDBProductSelect>();
|
||
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
public bool IsWxNotUseSoftwareDefaultAddressOnce { get; set; } = false;
|
||
|
||
ConcurrentList<AddPriceRule> lstAddPriceRule = new ConcurrentList<AddPriceRule>();
|
||
|
||
bool isInit = false;
|
||
CheckBox chkSelectAll = null;
|
||
|
||
AddPriceRule defaultAddPriceRule = null;
|
||
WXUploadRule wxUploadRule = null;
|
||
|
||
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
|
||
|
||
public string pdd_product_cates = "";
|
||
|
||
public List<string> forceFilteKeyWords = new List<string>()
|
||
{
|
||
"顶级", "之王", "二手", "亏本", "冲量", "白菜价", "跳楼价", "xxx", "xx", "最大", "最小", "低价", "降价", "成本", "赔钱", "甩卖",
|
||
"真丝", "蚕丝", "香云纱", "羊绒", "羊毛", "羊羔绒", "羊羔毛", "羽绒", "皮草"
|
||
};
|
||
|
||
string DefaultAdultBrandId = "";
|
||
public bool RejectSevenDayReturn { get; set; } = false;
|
||
|
||
// 微信带货助手cookie
|
||
List<Cookie> lstWxSaleAssistantCookie = new List<Cookie>();
|
||
|
||
List<wx_qualification_image_info> lstQulificationImage = new List<wx_qualification_image_info>();
|
||
|
||
public WXDBProdUploadForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
DataContext<WaitingProductConfig> _bs;
|
||
|
||
WaitingProductConfig waiting_product_config = new WaitingProductConfig();
|
||
private UserConfig UserConfig { get; set; } = new();
|
||
void InitUserConfig()
|
||
{
|
||
Task.Run(async () =>
|
||
{
|
||
UserConfig = await SystemUploadConfigForm.LoadConfigAsync();
|
||
|
||
if (UserConfig != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (UserConfig.TryGetConfig(UserConfig.UseOrderReturnWarehouseAddressKey, out UserConfig.ConfigItem addItem))
|
||
{
|
||
chkUseShanghaiReturnOrderAddress.Enabled = addItem.Policy != UserConfig.InheritPolicy.Locked;
|
||
chkUseShanghaiReturnOrderAddress.Checked = addItem.Value.ParseToBool(false);
|
||
}
|
||
|
||
if (UserConfig.TryGetConfig(UserConfig.SensitiveWordsKey, out UserConfig.ConfigItem filterItem))
|
||
{
|
||
txtReplaceText.Enabled = filterItem.Policy != UserConfig.InheritPolicy.Locked;
|
||
|
||
if (filterItem.Policy == UserConfig.InheritPolicy.Locked)
|
||
{
|
||
txtReplaceText.Enabled = false;
|
||
txtReplaceText.Text = filterItem.Value;
|
||
}
|
||
else if (filterItem.Policy == UserConfig.InheritPolicy.AppendOnly)
|
||
{
|
||
txtReplaceText.Enabled = false;
|
||
txtReplaceText.Text += filterItem.Value;
|
||
}
|
||
else if (filterItem.Policy == UserConfig.InheritPolicy.Free)
|
||
{
|
||
if (string.IsNullOrEmpty(txtReplaceText.Text))
|
||
{
|
||
txtReplaceText.Text = filterItem.Value;
|
||
}
|
||
}
|
||
}
|
||
|
||
}));
|
||
}
|
||
});
|
||
}
|
||
void InitWaitingProductConfigBinding()
|
||
{
|
||
InitUserConfig();
|
||
|
||
|
||
Debug.WriteLine($"初始化配置");
|
||
Invoke(new Action(() =>
|
||
{
|
||
waiting_product_config = NaiBa.Util.Helper.ConfigHelper.LoadConfig<WaitingProductConfig>(nameof(waiting_product_config));
|
||
if (waiting_product_config == null)
|
||
{
|
||
waiting_product_config = new WaitingProductConfig();
|
||
}
|
||
_bs = new DataContext<WaitingProductConfig>(waiting_product_config);
|
||
//NaiBa.Util.Helper.ConfigHelper.SaveConfig<AddPriceRule>("wx_default_add_price_rule", defaultAddPriceRule);
|
||
////txtIdFilter.Bind<wx_qualification_image_info>(_bs,a=>a.)
|
||
txtIdFilter.Bind(_bs, a => a.Text, a => a.IdFilter);
|
||
txtSearchGoodsName.Bind(_bs, a => a.Text, a => a.SearchGoodsName);
|
||
cmbSourceType.Bind(_bs, a => a.Text, a => a.SourceType);
|
||
cmbGroupFilter.Bind(_bs, a => a.Text, a => a.GroupFilter);
|
||
cmbHot.Bind(_bs, a => a.Text, a => a.Hot);
|
||
cmbWxSafe.Bind(_bs, a => a.Text, a => a.WxSafe);
|
||
cmbCateFilter1.Bind(_bs, a => a.Text, a => a.CateFilter1);
|
||
cmbCateFilter2.Bind(_bs, a => a.Text, a => a.CateFilter2);
|
||
cmbCateFilter3.Bind(_bs, a => a.Text, a => a.CateFilter3);
|
||
cmbNotes.Bind(_bs, a => a.Text, a => a.Notes);
|
||
cmbJstInitSet.Bind(_bs, a => a.Text, a => a.JstInitSet);
|
||
txtAddCount.Bind(_bs, a => a.Text, a => a.AddCount);
|
||
chkSkipQualification.Bind(_bs, a => a.Checked, a => a.SkipQualification);
|
||
chkRandomFissionProduct.Bind(_bs, a => a.Checked, a => a.RandomFissionProduct);
|
||
txtRandomFissionProductCount.Bind(_bs, a => a.Text, a => a.RandomFissionProductCount);
|
||
chkWXComplateProd.Bind(_bs, a => a.Checked, a => a.WXComplateProd);
|
||
chkUpdateInDays.Bind(_bs, a => a.Checked, a => a.UpdateInDaysChecked);
|
||
txtUpdateInDays.Bind(_bs, a => a.Text, a => a.UpdateInDays);
|
||
cmbUpdateInDays.Bind(_bs, a => a.Text, a => a.UpdateInDaysType);
|
||
chkFilterViewUv.Bind(_bs, a => a.Checked, a => a.FilterViewUvChecked);
|
||
numFilterViewUv.Bind(_bs, a => a.Value, a => a.FilterViewUv);
|
||
chkFilterSaleCountNum.Bind(_bs, a => a.Checked, a => a.FilterSaleCountNumChecked);
|
||
numFilterSaleCountNum.Bind(_bs, a => a.Value, a => a.FilterSaleCountNum);
|
||
}));
|
||
Debug.WriteLine($"初始化配置END");
|
||
}
|
||
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
|
||
{
|
||
Instance = this;
|
||
|
||
if (!BaseClass.UserAuthority.Contains("定向品牌"))
|
||
{
|
||
cmbSpBrandName.Visible = lblSpBrand.Visible = false;
|
||
this.ucTabControlMetro1.TabPages.Remove(特殊参数);
|
||
}
|
||
else
|
||
cmbSpBrandName.Visible = lblSpBrand.Visible = true;
|
||
|
||
if (!BaseClass.UserAuthority.Contains("佣金上货"))
|
||
this.ucTabControlMetro1.TabPages.Remove(佣金上货);
|
||
else
|
||
{
|
||
lstWxSaleAssistantCookie = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<Cookie>>("wx_sale_assistant_cookies");
|
||
if (lstWxSaleAssistantCookie == null)
|
||
lstWxSaleAssistantCookie = new List<Cookie>();
|
||
}
|
||
|
||
GlobalConfig.lstWxShopAuthInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<AuthInfo>>("wx_shop_auth_list");
|
||
if (GlobalConfig.lstWxShopAuthInfo == null)
|
||
GlobalConfig.lstWxShopAuthInfo = 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>();
|
||
|
||
GlobalConfig.dicWxShopUploadInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, WxShopUploadInfo>>("wx_shop_upload_info");
|
||
if (GlobalConfig.dicWxShopUploadInfo == null)
|
||
GlobalConfig.dicWxShopUploadInfo = 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 };
|
||
}
|
||
|
||
//this.txtFissionTitle.Text = NaiBa.Util.Helper.ConfigHelper.LoadConfig<string>("wx_prod_fission_title").ParseToString();
|
||
try
|
||
{
|
||
if (File.Exists("data\\config\\wx_prod_fission_title"))
|
||
this.txtFissionTitle.Text = File.ReadAllText("data\\config\\wx_prod_fission_title");
|
||
}
|
||
catch { }
|
||
|
||
|
||
|
||
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.txtMaxPrice.TextChanged -= txtMaxPrice_TextChanged;
|
||
this.txtWaitSeconds.TextChanged -= txtWaitSeconds_TextChanged;
|
||
this.chkHighestPriceSku.CheckedChanged -= chkHighestPriceSku_CheckedChanged;
|
||
this.chkLowestPriceSku.CheckedChanged -= chkLowestPriceSku_CheckedChanged;
|
||
this.chkSameSpecPriceUp.CheckedChanged -= chkSameSpecPriceUp_CheckedChanged;
|
||
this.chkSameSpecPriceDown.CheckedChanged -= chkSameSpecPriceDown_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.chkSkipReplaceText.Checked = wxUploadRule.IsSkipHasFilterWordsProd.ParseToBool();
|
||
this.txtMinPrice.Text = wxUploadRule.SkuMinPrice.ParseToString();
|
||
this.txtWaitSeconds.Text = wxUploadRule.WaitSeconds.ParseToString();
|
||
this.chkHighestPriceSku.Checked = wxUploadRule.OnlyHighestPriceSku.ParseToBool();
|
||
this.chkLowestPriceSku.Checked = wxUploadRule.OnlyLowestPriceSku.ParseToBool();
|
||
this.chkSameSpecPriceUp.Checked = wxUploadRule.SameSpecSamePriceUp.ParseToBool();
|
||
this.chkSameSpecPriceDown.Checked = wxUploadRule.SameSpecSamePriceDown.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.chkUseShanghaiReturnOrderAddress.Checked = wxUploadRule.IsUseShanghaiReturnOrderAddress;
|
||
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();
|
||
}
|
||
chkNotUploadShopProdMoreThan.Checked = wxUploadRule.IsNotUploadShopProdMoreThan;
|
||
numNotUploadShopProdMoreThan.Value = wxUploadRule.NotUploadShopProdMoreThan;
|
||
colOnSaleNum.Visible = wxUploadRule.IsNotUploadShopProdMoreThan;
|
||
|
||
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.chkLowestPriceSku.CheckedChanged += chkLowestPriceSku_CheckedChanged;
|
||
this.chkSameSpecPriceUp.CheckedChanged += chkSameSpecPriceUp_CheckedChanged;
|
||
this.chkSameSpecPriceDown.CheckedChanged += chkSameSpecPriceDown_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 + " 件";
|
||
}));
|
||
});
|
||
|
||
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>();
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var selectProd in upload_draft_product_lst.Reverse().ToList())
|
||
{
|
||
int maxRowCount = 10000;
|
||
if (dgvSelectProduct.Rows.Count >= maxRowCount)
|
||
{
|
||
break;
|
||
}
|
||
if (dgvSelectProduct.Rows.Count % 100 == 0)
|
||
Thread.Sleep(1);
|
||
Invoke(new Action(() =>
|
||
{
|
||
int rowIndex = this.dgvSelectProduct.Rows.Add(
|
||
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;
|
||
}));
|
||
}
|
||
});
|
||
|
||
//#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;
|
||
lblHot.Visible = true;
|
||
cmbHot.Visible = true;
|
||
}
|
||
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("货源选择"))
|
||
{
|
||
lblSourceType.Visible = true;
|
||
cmbSourceType.Visible = true;
|
||
//if (!string.IsNullOrWhiteSpace(cmbSourceType.Text))
|
||
{
|
||
lblGroupFilter.Visible = true;
|
||
cmbGroupFilter.Visible = true;
|
||
}
|
||
}
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采"))
|
||
{
|
||
chkWXComplateProd.Visible = true;
|
||
chkUseWXComplateProd.Visible = true;
|
||
}
|
||
if (BaseClass.UserAuthority.ParseToString().Contains("爆款数据"))
|
||
{
|
||
lblHot.Visible = true;
|
||
cmbHot.Visible = true;
|
||
chkFilterViewUv.Visible = true;
|
||
//numFilterViewUv.Visible = true;
|
||
pnlFilterViewUv.Visible = true;
|
||
chkFilterSaleCountNum.Visible = true;
|
||
pnlFilterSaleCountNum.Visible = true;
|
||
if (!string.IsNullOrWhiteSpace(cmbSourceType.Text))
|
||
{
|
||
//lblGroupFilter.Visible = true;
|
||
//cmbGroupFilter.Visible = true;
|
||
}
|
||
cmbUpdateInDays.Visible = true;
|
||
chkUpdateInDays.Visible = true;
|
||
txtUpdateInDays.Visible = true;
|
||
lblUpdateInDays.Visible = true;
|
||
}
|
||
if (BaseClass.UserAuthority.Contains("商品采集") || BaseClass.ParentAuthority.Contains("商品采集"))
|
||
{
|
||
if (BaseClass.UserAuthority.Contains("学员数据") || BaseClass.ParentAuthority.Contains("学员数据"))
|
||
{
|
||
cmbSourceType.Items.Insert(1, "--------");
|
||
cmbSourceType.Items.Insert(1, "学员数据");
|
||
}
|
||
cmbSourceType.Items.Insert(1, "--------");
|
||
cmbSourceType.Items.Insert(1, "微信商品");
|
||
cmbSourceType.Items.Insert(1, "1688商品");
|
||
cmbSourceType.Items.Insert(1, "多多商品");
|
||
|
||
if (!BaseClass.UserAuthority.ParseToString().Contains("货源选择"))
|
||
{
|
||
this.lblSourceType.Visible = true;
|
||
this.cmbSourceType.Visible = true;
|
||
this.cmbSourceType.Items.Clear();
|
||
cmbSourceType.Items.Add("");
|
||
if (BaseClass.UserAuthority.Contains("学员数据") || BaseClass.ParentAuthority.Contains("学员数据"))
|
||
{
|
||
cmbSourceType.Items.Add("学员数据");
|
||
cmbSourceType.Items.Add("--------");
|
||
}
|
||
this.cmbSourceType.Items.Add("多多商品,1688商品,微信商品");
|
||
this.cmbSourceType.Items.Add("多多商品");
|
||
this.cmbSourceType.Items.Add("1688商品");
|
||
this.cmbSourceType.Items.Add("微信商品");
|
||
}
|
||
|
||
chkRandomFissionProduct.Visible = true;
|
||
txtRandomFissionProductCount.Visible = true;
|
||
|
||
lblNotes.Visible = true;
|
||
cmbNotes.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
string addUserName = BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName;
|
||
PDDDBProdListForm.GetPDDProductNotes(new List<ComboBox> { cmbNotes }, addUserName);
|
||
});
|
||
}
|
||
cmbHot_TextChanged(null, null);
|
||
|
||
if (BaseClass.UserAuthority.Contains("裂变调试"))
|
||
{
|
||
chkRandomFissionProduct.Visible = true;
|
||
txtRandomFissionProductCount.Visible = true;
|
||
}
|
||
else
|
||
{
|
||
ucTabControlMetro1.TabPages.Remove(裂变调试);
|
||
}
|
||
|
||
List<Control> ctrlLst = new List<Control>()
|
||
{
|
||
lblSourceType, cmbSourceType, lblGroupFilter, cmbGroupFilter, lblHot, cmbHot, lblIdFilter, txtIdFilter,
|
||
chkFilterViewUv, pnlFilterViewUv, chkFilterSaleCountNum, pnlFilterSaleCountNum,
|
||
/*chkRandomFissionProduct, txtRandomFissionProductCount, lblNotes, cmbNotes*//*, lblJstInitSet, cmbJstInitSet*/
|
||
};
|
||
for (int i = 0; i < ctrlLst.Count - 2; i += 2)
|
||
{
|
||
if (ctrlLst[i].Visible == false)
|
||
{
|
||
for (int j = ctrlLst.Count - 2; j > i; j -= 2)
|
||
{
|
||
ctrlLst[j].Parent = ucGroupBoxEx4;
|
||
ctrlLst[j].Location = new Point(ctrlLst[j - 2].Location.X + ctrlLst[j - 2].Width - ctrlLst[j].Width, ctrlLst[j - 2].Location.Y);
|
||
if (ctrlLst[j] is CheckBox) // 额外减去一个像素
|
||
ctrlLst[j].Location = new Point(ctrlLst[j].Location.X - 1, ctrlLst[j].Location.Y);
|
||
ctrlLst[j + 1].Location = new Point(ctrlLst[j].Location.X + ctrlLst[j].Width - 3, ctrlLst[j - 1].Location.Y);
|
||
ctrlLst[j + 1].Width = ctrlLst[j - 1].Width;
|
||
ctrlLst[j + 1].BringToFront();
|
||
}
|
||
}
|
||
}
|
||
if (cmbNotes.Visible == false)
|
||
{
|
||
txtSearchGoodsName.Width = 229;
|
||
}
|
||
if (chkWXComplateProd.Visible == false)
|
||
{
|
||
//chkRandomFissionProduct.Location = new Point(chkRandomFissionProduct.Location.X + 54, chkRandomFissionProduct.Location.Y);
|
||
//txtRandomFissionProductCount.Location = new Point(txtRandomFissionProductCount.Location.X + 54, txtRandomFissionProductCount.Location.Y);
|
||
}
|
||
|
||
IsFormLoad = 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)
|
||
GlobalConfig.lstWxShopAuthInfo.RemoveAll(s => updateIds.Contains(s.ShopId));
|
||
foreach (var shop in GlobalConfig.ValidShopLoginList.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 = GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||
if (idRefreshTodayHasGet || authInfo == null || authInfo?.UpdateTime.Date != DateTime.Now.Date)
|
||
{
|
||
GlobalConfig.lstWxShopAuthInfo.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;
|
||
}
|
||
|
||
GlobalConfig.lstWxShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = 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();
|
||
var WxShopAuthInfo = new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = BaseClass.StampToDateTime(expiresTick.ParseToInt()) };
|
||
if (WxShopAuthInfo.ExpiresTime > DateTime.Now)
|
||
{
|
||
GlobalConfig.lstWxShopAuthInfo.Add(WxShopAuthInfo);
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
|
||
return;
|
||
}
|
||
}
|
||
if (itemObj["serviceName"].ParseToString() == "东内部" || itemObj["serviceName"].ParseToString() == "29ERP")
|
||
{
|
||
var expiresTick = itemObj["expireTime"].ParseToLong();
|
||
var WxShopAuthInfo = new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = BaseClass.StampToDateTime(expiresTick.ParseToInt()) };
|
||
if (WxShopAuthInfo.ExpiresTime > DateTime.Now)
|
||
{
|
||
GlobalConfig.lstWxShopAuthInfo.Add(WxShopAuthInfo);
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
// 没找到指定服务
|
||
GlobalConfig.lstWxShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = 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", GlobalConfig.lstWxShopAuthInfo);
|
||
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.ValidShopLoginList.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 async void btnRefreshShop_Click(object sender, EventArgs e)
|
||
{
|
||
pbLoadingShop.Visible = true;
|
||
RefreshDbProdGroupAndCate();
|
||
RefreshShopLogin();
|
||
}
|
||
|
||
private async void UserSelectDbProductForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (Visible == true)
|
||
{
|
||
RefreshShopLogin();
|
||
updateAuthor();
|
||
RefreshDbProdGroupAndCate();
|
||
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
|
||
if (!isInit)
|
||
{
|
||
InitWaitingProductConfigBinding();
|
||
foreach (var item in dgvShop.Rows.Cast<DataGridViewRow>())
|
||
{
|
||
var shopId = item.Cells["colShopId"]?.Value.ToString();
|
||
|
||
item.Cells["colSelect"].Value = wxUploadRule.SelectedShopIds.Contains(shopId);
|
||
}
|
||
|
||
}
|
||
isInit = true;
|
||
}
|
||
}
|
||
|
||
private async void RefreshDbProdGroupAndCate()
|
||
{
|
||
// 同时刷新下商品分组
|
||
//string addUserName = BaseClass.UserAuthority.Contains("商品采集") ? ("admin," + BaseClass.UserName) : "admin";
|
||
//if (BaseClass.GroupId != 3)
|
||
// addUserName = BaseClass.ParentAuthority.Contains("商品采集") ? ("admin," + BaseClass.ParentUserName) : "admin";
|
||
//PDDDBProdListForm.GetPDDProductGroup(cmbGroupFilter, sourceType, "", addUserName); // 同时刷新下商品分组
|
||
PDDDBProdListForm.GetPDDProductGroup(new List<ComboBox> { cmbGroupFilter, }, "", "", "admin");
|
||
if (BaseClass.UserAuthority.Contains("商品采集") || BaseClass.ParentAuthority.Contains("商品采集"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
//cmbGroupFilter.Items.Remove("用户" + mainUserName);
|
||
cmbGroupFilter.Items.Remove("--------");
|
||
cmbGroupFilter.Items.Remove("我的商品");
|
||
cmbGroupFilter.Items.Insert(0, "--------");
|
||
cmbGroupFilter.Items.Insert(0, "我的商品");
|
||
}));
|
||
}
|
||
await GetPddProductCate();
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.btnSwitchCatType.Text = "P";
|
||
btnSwitchCatType_Click(null, null);
|
||
pbLoadingShop.Visible = false;
|
||
|
||
}));
|
||
waiting_product_config.Assign(NaiBa.Util.Helper.ConfigHelper.LoadConfig<WaitingProductConfig>(nameof(waiting_product_config)));
|
||
|
||
//call?.Invoke();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取商品所有类目
|
||
/// </summary>
|
||
async Task GetPddProductCate()
|
||
{
|
||
var pddMainCats = GlobalConfig.PddCatList.Where(c => c.level == 1);
|
||
var mainCatsText = string.Join(",", pddMainCats.Select(c => c.cat_name)) + "," + string.Join(",", pddMainCats.Select(c => c.cat_id));
|
||
|
||
|
||
|
||
var url = BaseClass.BuildObjString("product/get_pdd_product_cates");
|
||
var data = UserLogin.GetSignaturex();
|
||
var html = await GetHtml.PostUtf8Async(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = await GetHtml.PostUtf8Async(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");
|
||
}
|
||
}
|
||
|
||
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.ValidShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||
// 更新被删除的店铺列表
|
||
foreach (var row in dgvRowList)
|
||
{
|
||
dgvShop.Rows.Remove(row);
|
||
}
|
||
// 绑定其他店铺(含新导入的店铺)
|
||
foreach (ShopLoginInfo shopEntity in GlobalConfig.ValidShopLoginList)
|
||
{
|
||
if (!string.IsNullOrEmpty(shopEntity.ShopId))
|
||
BindShop(shopEntity, selectIds);
|
||
}
|
||
cmbFilterShopNotes.Items.Clear();
|
||
foreach (var note in GlobalConfig.ValidShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopNotes.Items.Add(note);
|
||
}
|
||
cmbFilterShopGroup.Items.Clear();
|
||
foreach (var note in GlobalConfig.ValidShopLoginList.Select(s => s.GroupName).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopGroup.Items.Add(note);
|
||
}
|
||
}
|
||
|
||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
|
||
{
|
||
if (shopEntity == null)
|
||
return;
|
||
if (shopEntity.is_point_shop_expire)
|
||
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,
|
||
shopEntity.GroupName,
|
||
"选择商品",
|
||
canUse ? "在线" : "掉线",
|
||
GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
|
||
canUse,
|
||
GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].DicDayUploadCount[day] : 0,
|
||
GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].OnSaleCount.ParseToString() : "-",
|
||
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 = GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期";
|
||
row.Cells["colRemaining"].Value = shopEntity.AddProductRemaining;
|
||
row.Cells["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].DicDayUploadCount[day] : 0;
|
||
row.Cells["colOnSaleNum"].Value = GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[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;
|
||
var row = dgvShop.Rows[e.RowIndex];
|
||
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.ValidShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
|
||
if (shop == null)
|
||
{
|
||
BaseMsgForm.ShowError("店铺不存在或已过期");
|
||
return;
|
||
}
|
||
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.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=4431685489938137094";
|
||
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;
|
||
var row = dgvShop.Rows[e.RowIndex];
|
||
var 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.ValidShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null && !string.IsNullOrEmpty(headerText))
|
||
{
|
||
BaseMsgForm.ShowError("店铺不存在或已过期");
|
||
return;
|
||
}
|
||
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)
|
||
{
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig<WaitingProductConfig>(nameof(waiting_product_config), waiting_product_config);
|
||
|
||
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;
|
||
}
|
||
|
||
wxUploadRule.SelectedShopIds = shopIdLst;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
|
||
|
||
if (lstTemuDBProductSelect.Count() > 0)
|
||
{
|
||
if (WXShopLoginForm.shopLoginInstance != null && WXShopLoginForm.shopLoginInstance.IsDisposed != true)
|
||
WXShopLoginForm.shopLoginInstance.Dispose();
|
||
|
||
this.btnUpload.Enabled = false;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
if (GlobalConfig.GlobalSettings.IsWxUseSoftwareDefaultAddress == true && !IsWxNotUseSoftwareDefaultAddressOnce &&
|
||
lstTemuDBProductSelect.Any(p => p.product_get_type_text != "厂商直采" && p.product_get_type_text != "1688厂家"))
|
||
{
|
||
if (shopIdLst.Any(a => !GlobalConfig.WXShopDefaultAddressList.Any(aa => aa.shop_id == a)))
|
||
WXShopDefaultAddressListForm.GetShopDefaultAddress();
|
||
var addressLst = GlobalConfig.WXShopDefaultAddressList.Where(s => shopIdLst.Contains(s.shop_id)).ToList();
|
||
foreach (var add in addressLst)
|
||
{
|
||
if (!add.isFullAddress)
|
||
{
|
||
string msg = "未设置店铺售后地址!\r\n" +
|
||
"\r\n部分商品无默认售后地址信息,需要设置店铺售后地址,";
|
||
if (BaseClass.GroupId == 3)
|
||
msg += "\r\n将自动跳转 店铺管理-店铺地址管理 界面设置,";
|
||
else
|
||
msg += "\r\n请使用主账号进行设置,";
|
||
msg += "\r\n或者点击 取消 按钮,本次使用店铺后台默认地址。\r\n" +
|
||
"\r\n可在系统设置选项卡更改配置永久使用店铺后台地址。\r\n\r\n";
|
||
var rst = BaseMsgForm.ShowConfirm(msg, "注意", FormLevel.LARGE, true);
|
||
if (rst.DialogResult == DialogResult.OK)
|
||
{
|
||
if (BaseClass.GroupId == 3)
|
||
Invoke(new Action(() =>
|
||
{
|
||
btnUpload.Enabled = true;
|
||
MainForm.instance.pnlShop_Click(MainForm.instance.pnlShop, null);
|
||
WXShopForm.instance.ClickShopAddress();
|
||
}));
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
IsWxNotUseSoftwareDefaultAddressOnce = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
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.ValidShopLoginList.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", 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.ValidShopLoginList.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)
|
||
{
|
||
if (selectProd.db_type == "云端数据")
|
||
kjdDbProd = GetCloudProductDetail(selectProd, out errStr, true, true);
|
||
else
|
||
kjdDbProd = GetProductDetail(selectProd.out_product_Id.ToString(), out errStr, true, true);
|
||
if (kjdDbProd != null)
|
||
kjdDbProd.db_type = selectProd?.db_type;
|
||
}
|
||
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;
|
||
|
||
// 店铺上架数超过一定数量
|
||
if (wxUploadRule.IsNotUploadShopProdMoreThan)
|
||
{
|
||
string nextKey = "";
|
||
int pageSize = 20, page = 1, onSaleStatusCode = 5;
|
||
var getProdOnSaleRst = WXProdNoCheckEditHelper.scanProductPreview(shop, page, nextKey, pageSize, onSaleStatusCode);
|
||
if (!getProdOnSaleRst.Contains("\"success\":true"))
|
||
{
|
||
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; }));
|
||
|
||
result = "{\"success\":false,\"status\":\"未上传\",\"errMsg\":\"商品初始化失败:" + BaseRegex.GetStringJson(ref getProdOnSaleRst, "msg") + "\"}";
|
||
goto endUploadProduct;
|
||
}
|
||
var totalNum = JsonHelper.JObjectParse(getProdOnSaleRst)["totalNum"].ParseToInt();
|
||
|
||
// 初始化店铺上货/在售信息
|
||
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
|
||
if (!GlobalConfig.dicWxShopUploadInfo.ContainsKey(shop.ShopId))
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId] = new WxShopUploadInfo();
|
||
if (!GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.ContainsKey(day))
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] = 0;
|
||
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].OnSaleCount = totalNum;
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].OnSaleRefreshDay = day;
|
||
// 删除45天前的记录
|
||
var removeKeys = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt()).ToList();
|
||
foreach (var key in removeKeys)
|
||
{
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Remove(key);
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", GlobalConfig.dicWxShopUploadInfo);
|
||
BindShop(shop, new List<string>() { shop.ShopId });
|
||
if (totalNum > wxUploadRule.NotUploadShopProdMoreThan)
|
||
{
|
||
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; }));
|
||
|
||
result = "{\"success\":false,\"status\":\"未上传\",\"errMsg\":\"超过设定的店铺最大在售商品数,设定:" +
|
||
wxUploadRule.NotUploadShopProdMoreThan + " 已上架:" + totalNum + "\"}";
|
||
goto endUploadProduct;
|
||
}
|
||
}
|
||
|
||
//将商品上传
|
||
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("如需上架请先缴纳足额保证金") || result.Contains("在架商品数已达到上限") ||
|
||
result.Contains("提审次数已达上限") || result.Contains("拥金上货失败:需要开通优选联盟") || result.Contains("本店铺近期提审失败比例较高,已被限"))
|
||
{
|
||
shop.upLimitRetryCount++;
|
||
if (shop.upLimitRetryCount >= globalShopUploadCntLimitRetryTimes)
|
||
{
|
||
shop.upLimitRetryCount = 0;
|
||
|
||
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; }));
|
||
}
|
||
}
|
||
else if (result.Contains("\"success\":true"))
|
||
{
|
||
shop.upLimitRetryCount = Math.Max(0, shop.upLimitRetryCount - 1);
|
||
}
|
||
// 图片重复的,修改图片缓存为空再传一次
|
||
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);
|
||
}));
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="prodDbId"></param>
|
||
/// <param name="errMsg"></param>
|
||
/// <param name="noViolationProduct">校验违规商品</param>
|
||
/// <param name="noBanWx">校验微信禁售商品</param>
|
||
/// <returns></returns>
|
||
public static KJDDBProduct GetProductDetail(string prodDbId, out string errMsg, bool noViolationProduct = false, bool noBanWx = false)
|
||
=> ComplianceProductReader.GetProductDetail(prodDbId, out errMsg, noViolationProduct, noBanWx);
|
||
|
||
public static KJDDBProduct GetCloudProductDetail(TemuDBProductSelect selectProd, out string errMsg, bool noViolationProduct = false, bool noBanWx = false)
|
||
{
|
||
errMsg = "";
|
||
|
||
if (string.IsNullOrEmpty(selectProd?.spu_id))
|
||
{
|
||
errMsg = "产品编号为空";
|
||
return new KJDDBProduct();
|
||
}
|
||
|
||
var html = CloudGoodsService.GetGoodsDetail(selectProd.spu_id.ParseToLong());
|
||
if (string.IsNullOrEmpty(html) || html.Length < 100)
|
||
html = CloudGoodsService.GetGoodsDetail(selectProd.spu_id.ParseToLong());
|
||
if (string.IsNullOrEmpty(html) || html.Length < 100)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
try
|
||
{
|
||
KJDDBProduct item = JsonHelper.DeserializeJsonToObject<KJDDBProduct>(JsonHelper.SerializeObject(selectProd));
|
||
item.product_json = html;
|
||
item.id = 29;
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
public static string GetEC1ExtCode(string spu_id)
|
||
{
|
||
if (spu_id.IsNullOrEmpty())
|
||
throw new Exception("货号指定失败,值不能为空!");
|
||
if (!spu_id.StartsWith("EC1") && !spu_id.EndsWith("A"))
|
||
return "EC1" + spu_id + "A";
|
||
return spu_id;
|
||
}
|
||
public static string GetNewExtCode(string spu_id)
|
||
{
|
||
if (spu_id.IsNullOrEmpty())
|
||
throw new Exception("货号指定失败,值不能为空!");
|
||
if (!spu_id.StartsWith("P1-"))
|
||
return "P1-" + spu_id;
|
||
return spu_id;
|
||
}
|
||
|
||
string UploadProduct(ShopLoginInfo shop, KJDDBProduct dbProd, TemuDBProductSelect selectProd, DataGridViewCell cell, DateTime startTime)
|
||
{
|
||
PlatformType Platform = (dbProd.product_get_type_text.Contains("多多")
|
||
? PlatformType.PDD :
|
||
dbProd.product_get_type_text.Contains("微信")
|
||
? PlatformType.WX :
|
||
PlatformType.None);
|
||
|
||
|
||
#region 初始化上传商品对象
|
||
// 生成初始化上传商品对象
|
||
var upProdInitParam = new WXUploadProductInitParam();
|
||
// 生成上传商品对象
|
||
var upProdParam = new WXUploadProductParam();
|
||
#endregion
|
||
|
||
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 = "正在初始化上传";
|
||
}));
|
||
}
|
||
|
||
// 开启上货自动剔除时,上传前检测违规状态;仅服务端明确返回违规时禁止上传。
|
||
if (GlobalConfig.GlobalSettings.AutoExcludeViolationProductsOnUpload)
|
||
{
|
||
if (cell != null)
|
||
Invoke(new Action(() => cell.Value = "商品违规检测..."));
|
||
try
|
||
{
|
||
long goodsId = 0;
|
||
if ((!long.TryParse(dbProd.spu_id, out goodsId) || goodsId <= 0) &&
|
||
(!long.TryParse(dbProd.skc_id, out goodsId) || goodsId <= 0))
|
||
throw new Exception("商品ID无效");
|
||
|
||
var statuses = CloudGoodsService.GetViolationStatus(new List<long> { goodsId });
|
||
var status = statuses.FirstOrDefault(item => item.GoodsId == goodsId);
|
||
if (status == null)
|
||
throw new Exception("未返回当前商品的违规状态");
|
||
if (status.IsViolation)
|
||
{
|
||
var shopId = shop.ShopId;
|
||
_ = Task.Run(async () =>
|
||
{
|
||
try
|
||
{
|
||
await CloudGoodsService.RecordShopActionLogs(shopId, status, ViolationLogAction.AutoListingExcluded);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.WriteLine("剔除违规商品日志记录失败:" + ex.Message);
|
||
}
|
||
});
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"当前商品违规,禁止上传\"}";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.WriteLine("商品违规检测失败,继续上传:" + ex.Message);
|
||
if (cell != null)
|
||
Invoke(new Action(() => cell.Value = "商品违规检测失败,继续上传"));
|
||
}
|
||
}
|
||
|
||
#region 裂变标题
|
||
if (BaseClass.UserAuthority.Contains("裂变调试") && chkFissionGoodsName.Checked)
|
||
{
|
||
bool isFinish = false;
|
||
Invoke(new Action(() =>
|
||
{
|
||
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
if (titles.Count == 0)
|
||
{
|
||
cancellationTokenSource.Cancel();
|
||
if (cell != null)
|
||
cell.Value = "裂变标题数量不足,将暂停上传";
|
||
BaseMsgForm.ShowError("裂变标题数量不足,将暂停上传");
|
||
isFinish = true;
|
||
}
|
||
selectProd.product_name = titles[0];
|
||
selectProd.is_fission_title = true;
|
||
titles.RemoveAt(0);
|
||
txtFissionTitle.Text = string.Join("\r\n", titles);
|
||
cell.Value = "标题裂变成功,更改为:" + selectProd.product_name;
|
||
}));
|
||
if (isFinish)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"裂变标题数量不足,将暂停上传\"}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 跳过已上传商品,默认按商品货号,裂变商品按标题。
|
||
if (chkSkipUploaded.Checked)
|
||
{
|
||
// 裂变按标题名称
|
||
if (selectProd.is_fission_title)
|
||
{
|
||
var searchRst = WXUpload.searchProductWithTitle(shop, GetHtml.UrlEncodeUtf8(selectProd?.product_name));
|
||
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 + "\"}";
|
||
}
|
||
}
|
||
// 非裂变商品按商品Id
|
||
else
|
||
{
|
||
var searchExtCode = dbProd.ext_code;
|
||
if (dbProd.db_type == "云端数据")
|
||
{
|
||
searchExtCode = GetNewExtCode(dbProd.spu_id);
|
||
}
|
||
else
|
||
{
|
||
if (searchExtCode.ParseToString().Length < 10)
|
||
searchExtCode = GetEC1ExtCode(dbProd.spu_id);
|
||
}
|
||
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
|
||
|
||
#region 处理佣金上传
|
||
int commissionRate = 0;
|
||
int minCommissionRate = 0;
|
||
int maxCommissionRate = 0;
|
||
int commissionRateChange = 0;
|
||
int? fromCommissionRate = 0;
|
||
if (BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||
{
|
||
if (dbProd.special_prod_type != "爆款数据" && dbProd.product_get_type_text != "微信小店")
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"拥金上货失败:仅爆款微信小店数据支持佣金上传!\"}";
|
||
|
||
var rst = WXUpload.GetAndUpdateWebStatus(shop);
|
||
if (!rst.Contains("\"isOpenLeague\":true"))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"拥金上货失败:需要开通优选联盟!\"}";
|
||
}
|
||
|
||
var url = BaseClass.BuildObjString("product/wx_get_commission_rate");
|
||
var date = UserLogin.GetSignaturex();
|
||
date += "&spu_ids=" + dbProd.spu_id;
|
||
|
||
var prodCommissionRst = GetHtml.PostUtf8(url, date);
|
||
if (!prodCommissionRst.Contains("\"code\":200"))
|
||
{
|
||
var errMsg = BaseRegex.GetStringJsonByRegs(ref prodCommissionRst, prodCommissionRst, "msg");
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"拥金上货失败:" + errMsg + "\"}";
|
||
}
|
||
fromCommissionRate = BaseRegex.GetStringJson(ref prodCommissionRst, "commission_rate").ParseToNullableInt();
|
||
if (fromCommissionRate == null)
|
||
fromCommissionRate = -1;
|
||
if (prodCommissionRst.Contains("\"data\":[]") || BaseRegex.GetStringJson(ref prodCommissionRst, "mdy_time").ParseToString().ParseToDateTime() < DateTime.Now.AddDays(-30))
|
||
{
|
||
var assistantShop = new ShopLoginInfo();
|
||
assistantShop.Cookies = JsonHelper.SerializeObject(lstWxSaleAssistantCookie);
|
||
var result = WxGetAssistant.wxGetAssistant(assistantShop, dbProd.spu_id);
|
||
Thread.Sleep(Randomx.GetId(500, 1500));
|
||
if (result.Contains("mcn magic invalid"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
BaseMsgForm.ShowError("拥金上货失败:请先登录上货助手");
|
||
btnLoginAssistant_Click(null, null);
|
||
}));
|
||
assistantShop.Cookies = JsonHelper.SerializeObject(lstWxSaleAssistantCookie);
|
||
result = WxGetAssistant.wxGetAssistant(assistantShop, dbProd.spu_id);
|
||
if (result.Contains("mcn magic invalid"))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"拥金上货失败:请先登录上货助手\"}";
|
||
}
|
||
fromCommissionRate = BaseRegex.GetStringJson(ref result, "commissionRate").ParseToNullableInt();
|
||
var prodName = BaseRegex.GetStringJson(ref result, "name");
|
||
if (fromCommissionRate == null)
|
||
fromCommissionRate = -1;
|
||
if (prodName.IsNullOrEmpty())
|
||
prodName = dbProd.product_name;
|
||
//if (fromCommissionRate != null && !string.IsNullOrEmpty(prodName))
|
||
{
|
||
url = BaseClass.BuildObjString("product/wx_add_mdy_commission_rate");
|
||
date = UserLogin.GetSignaturex();
|
||
date += "&spu_id=" + dbProd.spu_id;
|
||
date += "&commission_rate=" + fromCommissionRate;
|
||
date += "&product_name=" + prodName;
|
||
var addCommissionRateRst = GetHtml.PostUtf8(url, date);
|
||
}
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
minCommissionRate = this.txtMinUpCommission.Text.Trim().ParseToInt() * 10000;
|
||
maxCommissionRate = this.txtMaxUpCommission.Text.Trim().ParseToInt() * 10000;
|
||
commissionRateChange = this.txtCommissionChangeValue.Text.Trim().ParseToInt() * 10000;
|
||
if (cmbCommissionAddOrReduce.Text != "增加")
|
||
commissionRateChange = -commissionRateChange;
|
||
commissionRate = fromCommissionRate.ParseToInt() + commissionRateChange;
|
||
}));
|
||
if (fromCommissionRate < minCommissionRate || fromCommissionRate > maxCommissionRate)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"拥金上货失败:原商品佣金比例 " + fromCommissionRate * 0.0001 + "% 超过设置的佣金范围!\"}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 将聚水潭产品数据格式进行转换成pdd格式统一上传,匹配加密的spuCode和skuCoke 微信小店的货号spuCode和外部商品编号outProductId/out_product_id对应加密的聚水潭goodsId
|
||
if (dbProd.product_get_type_text == "厂商直采")
|
||
{
|
||
if (dbProd.sku_secret_json.IsNullOrEmpty() || !dbProd.sku_secret_json.Contains("goodsId"))
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询格式错误\"}";
|
||
}
|
||
if (dbProd.wx_cat_leaf.IsNullOrZero() || dbProd.send_to_out_server != 1 || dbProd.distribution_set != 1)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询校验错误\"}";
|
||
}
|
||
|
||
string convertRst = "";
|
||
var pInfo = new PDDProdFormConverter().JstPddProdToPddConvert(out convertRst, dbProd);
|
||
if (!string.IsNullOrEmpty(convertRst))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 微信店采原始格式还原
|
||
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 + "\"}";
|
||
}
|
||
}
|
||
#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 微信回采转换
|
||
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 + "\"}";
|
||
}
|
||
}
|
||
#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 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 + "\"}";
|
||
}
|
||
if (dbProd.product_get_type_text == "1688外部数据")
|
||
{
|
||
string convertRst = "";
|
||
var pInfo = new PDDProdFormConverter()._1688OutToPddConvert(out convertRst, dbProd);
|
||
if (!string.IsNullOrEmpty(convertRst))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
}
|
||
#endregion
|
||
|
||
#region 云端数据格式转换
|
||
if (dbProd.db_type == "云端数据" && dbProd.product_get_type_text == "多多")
|
||
{
|
||
string convertRst = "";
|
||
|
||
var content = dbProd.product_json;
|
||
if (content.Contains("\"spec_keys\"") && content.Contains("\"spec_values\"") && content.Contains("\"is_sku_pre_sale\""))
|
||
{
|
||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true, false);
|
||
}
|
||
else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") &&
|
||
content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"goods_property\"") &&
|
||
(content.Contains("\"ref_pid\"") || content.Contains("\"goods_property\":[]")) && content.Contains("\"sku_id\"") && content.Contains("\"quantity\"") &&
|
||
content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") &&
|
||
content.Contains("\"group_price\"") && content.Contains("img.pddpic.com"))
|
||
{
|
||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true, false);
|
||
}
|
||
else if (content.Contains("\"mallId\"") && content.Contains("\"mallName\"") && content.Contains("\"goodsId\"") && content.Contains("\"goodsName\"") &&
|
||
content.Contains("\"catID\"") && content.Contains("\"catID4\"") && content.Contains("\"topGallery\"") && content.Contains("\"detailGallery\"") &&
|
||
content.Contains("\"shareDesc\"") && content.Contains("\"maxOnSaleGroupPriceInCent\"") && content.Contains("\"shareDesc\"") &&
|
||
content.Contains("\"specs\"") && content.Contains("\"spec_key\"") && content.Contains("\"spec_value\"") &&
|
||
content.Contains("\"groupPrice\"") && content.Contains("img.pddpic.com"))
|
||
{
|
||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true, false);
|
||
}
|
||
else if (content.Contains("\"商品编号\"") && content.Contains("\"商品链接\"") && content.Contains("\"标题\""))
|
||
{
|
||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(content, true, null, true, false);
|
||
}
|
||
else
|
||
{
|
||
convertRst = new PDDProdFormConverter().PddFrontToPddBackConvertFactory("", true, null, true, false, content);
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(convertRst) && !convertRst.StartsWith("success"))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品查询错误 " + convertRst + "\"}";
|
||
|
||
if (convertRst.StartsWith("success"))
|
||
convertRst = convertRst.Substring("success".Length);
|
||
dbProd.product_json = 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)
|
||
{
|
||
if (chkSkipReplaceText.Checked)
|
||
{
|
||
if (lstTitleReplaceText.Any(t => selectProd.product_name.Contains(t)))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"命中敏感词\"}";
|
||
if (lstTitleReplaceText.Any(t => dbProd.product_name.Contains(t)))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"命中敏感词\"}";
|
||
|
||
var goods_name = prodJObj["detail"]["goods_name"].ParseToString();
|
||
if (lstTitleReplaceText.Any(t => goods_name.Contains(t)))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"命中敏感词\"}";
|
||
var tiny_name = prodJObj["detail"]["tiny_name"].ParseToString();
|
||
if (lstTitleReplaceText.Any(t => tiny_name.Contains(t)))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"命中敏感词\"}";
|
||
var goods_desc = prodJObj["detail"]["goods_desc"].ParseToString();
|
||
if (lstTitleReplaceText.Any(t => goods_desc.Contains(t)))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"命中敏感词\"}";
|
||
var share_desc = prodJObj["detail"]["share_desc"].ParseToString();
|
||
if (lstTitleReplaceText.Any(t => share_desc.Contains(t)))
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"命中敏感词\"}";
|
||
}
|
||
else
|
||
{
|
||
foreach (var txt in lstTitleReplaceText)
|
||
{
|
||
dbProd.product_name = dbProd.product_name.Replace(txt, "");
|
||
selectProd.product_name = selectProd.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 (chkRemoveSpecialChar.Checked)
|
||
{
|
||
var chLst = new List<char> { ']', '】', ')', ')', '}', };
|
||
foreach (var ch in chLst)
|
||
{
|
||
if (dbProd.product_name.Contains(ch) && dbProd.product_name.IndexOf(ch) < dbProd.product_name.Length / 2 && dbProd.product_name.Length > 10)
|
||
dbProd.product_name = dbProd.product_name.Substring(dbProd.product_name.IndexOf(ch)).Trim(ch);
|
||
|
||
if (selectProd.product_name.Contains(ch) && selectProd.product_name.IndexOf(ch) < selectProd.product_name.Length / 2 && selectProd.product_name.Length > 10)
|
||
selectProd.product_name = selectProd.product_name.Substring(selectProd.product_name.IndexOf(ch)).Trim(ch);
|
||
|
||
var goods_name = prodJObj["detail"]["goods_name"].ParseToString();
|
||
if (goods_name.Contains(ch) && goods_name.IndexOf(ch) < goods_name.Length / 2 && goods_name.Length > 10)
|
||
prodJObj["detail"]["goods_name"] = goods_name.Substring(goods_name.IndexOf(ch)).Trim(ch);
|
||
}
|
||
|
||
}
|
||
// 替换货号
|
||
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 (chkSameSpecPriceUp.Checked)
|
||
{
|
||
var priceTextLst = dbProd.price_text.ParseToString().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 (chkSameSpecPriceDown.Checked)
|
||
{
|
||
var priceTextLst = dbProd.price_text.ParseToString().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 + "\"}";
|
||
}
|
||
}
|
||
// 只保留最低价
|
||
if (chkLowestPriceSku.Checked)
|
||
{
|
||
int price = 99999999;
|
||
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 limitMinPrice = 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() >= limitMinPrice)
|
||
skuJArr.Add(skuJObj2);
|
||
}
|
||
if (skuJArr.Count == 0)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"商品sku价格不满足上货条件,跳过\"}";
|
||
}
|
||
}
|
||
// 过滤高价sku,如果所有sku都不达标,跳过商品
|
||
if (!string.IsNullOrEmpty(txtMaxPrice.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 limitMaxPrice = this.txtMaxPrice.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() <= limitMaxPrice)
|
||
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
|
||
|
||
var prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(dbProd.product_json);
|
||
|
||
#region 图片盗链映射生成字典(如果有)
|
||
Dictionary<string, ImageCache> wxImgMapDic = new Dictionary<string, ImageCache>(StringComparer.OrdinalIgnoreCase);
|
||
bool isChangeImgDic = false;
|
||
wxImgMapDic = ImageCacheService.GetImageCaches(prodInfo);
|
||
|
||
// 旧盗链
|
||
Dictionary<string, string> wxImgMapOldDic = new Dictionary<string, string>();
|
||
if (!string.IsNullOrEmpty(dbProd.wx_img_map_json))
|
||
{
|
||
try
|
||
{
|
||
wxImgMapOldDic = JsonHelper.DeserializeJsonToObject<Dictionary<string, string>>(dbProd.wx_img_map_json);
|
||
}
|
||
catch
|
||
{
|
||
isChangeImgDic = true;
|
||
wxImgMapOldDic = new Dictionary<string, string>();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 提取源商品详情,根据需要生成sku货号
|
||
// 如果没有货号或有相同货号无法区分sku,自定义货号
|
||
if (dbProd.db_type == "云端数据")
|
||
{
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
var skuId = sku.sku_id;
|
||
if (skuId.IsNullOrZero())
|
||
skuId = BaseClass.GetLong(string.Join(";", sku.spec.Select(s => s.spec_name)));
|
||
sku.out_sku_sn = GetNewExtCode(skuId.ParseToString());
|
||
}
|
||
}
|
||
else if (dbProd.product_get_type_text != "厂商直采")
|
||
{
|
||
if (prodInfo.detail.sku.Any(s => s.out_sku_sn.IsNullOrEmpty()) ||
|
||
prodInfo.detail.sku.Select(s => s.out_sku_sn).ToList().Count > prodInfo.detail.sku.Select(s => s.out_sku_sn).Distinct().ToList().Count)
|
||
{
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
sku.out_sku_sn = string.Join(";", sku.spec.Select(s => s.spec_name));
|
||
sku.out_sku_sn = "EC1" + Math.Abs(BaseClass.GetLong(sku.out_sku_sn)) + "A";
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 上传视频
|
||
if (prodInfo.detail.galleries.Any(a => a.type == 6))
|
||
{
|
||
List<gallery_item> videos = prodInfo.detail.galleries.Where(a => a.type == 6).ToList();
|
||
//下载视频保存
|
||
foreach (var item in videos)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "开始下载视频";
|
||
}));
|
||
byte[] files;
|
||
bool d_ret = GetHtml.DownloadFile(item.url, out files);
|
||
if (d_ret == false)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "视频下载失败";
|
||
}));
|
||
return JsonConvert.SerializeObject(new
|
||
{
|
||
success = false,
|
||
draftId = 0,
|
||
status = "未上传",
|
||
errMsg = "视频下载失败"
|
||
});
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "开始上传视频";
|
||
}));
|
||
var uploader = new WXVideoUploader();
|
||
var video = uploader.Upload(shop, selectProd.id.ToString(), files);
|
||
upProdParam.product.info.headVideoInfo.Add(new
|
||
{
|
||
videoUrl = video.DownloadUrl,
|
||
videoHeadImg = video.VideoImgUrl,
|
||
videoLen = video.VideoDuration,
|
||
videoSize = 0,
|
||
videoSource = 0,
|
||
videoFormat = 0,
|
||
playableVideoUrl = video.DownloadUrl
|
||
});
|
||
}
|
||
}
|
||
//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
|
||
|
||
|
||
|
||
#region 获取店铺 Api Token
|
||
// 获取店铺的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 = GlobalConfig.lstWxShopAuthInfo.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();
|
||
#endregion
|
||
|
||
#region 设置标题
|
||
string prodTitle = selectProd.product_name;
|
||
if (prodTitle.IsNullOrEmpty())
|
||
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 (dbProd.db_type == "云端数据")
|
||
{
|
||
extCode = GetNewExtCode(dbProd.spu_id);
|
||
}
|
||
if (extCode.IsNullOrEmpty() || extCode.Length <= 10)
|
||
{
|
||
//extCode = "EC" + Randomx.GetId(1000).ToString().PadLeft(3, '0') + dbProd.spu_id + "C";
|
||
extCode = GetEC1ExtCode(dbProd.spu_id);
|
||
}
|
||
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)))
|
||
{
|
||
Debug.WriteLine("主图:缓存");
|
||
var image = wxImgMapDic[BaseClass.GetMd5(gallery_item.url)];
|
||
upProdInitParam.product.info.headImg.Add(image.PlatformUrl);
|
||
upProdParam.product.info.headImg.Add(image.PlatformUrl);
|
||
continue;
|
||
}
|
||
if (wxImgMapOldDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||
{
|
||
upProdInitParam.product.info.headImg.Add(wxImgMapOldDic[BaseClass.GetMd5(gallery_item.url)]);
|
||
upProdParam.product.info.headImg.Add(wxImgMapOldDic[BaseClass.GetMd5(gallery_item.url)]);
|
||
continue;
|
||
}
|
||
|
||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||
{
|
||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||
}
|
||
else
|
||
{
|
||
Debug.WriteLine("主图:上传");
|
||
// 使用接口链接传主图
|
||
var urlImg = BaseClass.BuildWXImgObjString("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)] = new ImageCache
|
||
{
|
||
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||
PlatformUrl = upImgUrl,
|
||
};
|
||
|
||
wxImgMapOldDic[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.BuildWXImgObjString("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)] = new ImageCache
|
||
{
|
||
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||
PlatformUrl = upImgUrl,
|
||
};
|
||
|
||
wxImgMapOldDic[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)
|
||
{
|
||
ImageCacheService.SaveImageCaches(Platform, wxImgMapDic.Values);
|
||
|
||
SaveImageCacheOld(dbProd.spu_id, wxImgMapOldDic);
|
||
isChangeImgDic = false;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 识别类目
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在生成类目属性";
|
||
}));
|
||
}
|
||
List<long> aiCateIdLst = new List<long>();
|
||
// 聚水潭商品已识别类目使用类目缓存
|
||
if (dbProd.product_get_type_text == "厂商直采" && dbProd.wx_cat_leaf == null)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"该商品类目信息不完整\"}";
|
||
}
|
||
bool isRetryCat = false;
|
||
retryCat:
|
||
|
||
// 微信商品使用类目缓存
|
||
if (!dbProd.wx_cat_leaf.IsNullOrZero())
|
||
{
|
||
if (dbProd.wx_cat_3 == 7370)
|
||
dbProd.wx_cat_3 = 547591;
|
||
if (dbProd.wx_cat_leaf == 7370)
|
||
dbProd.wx_cat_leaf = 547591;
|
||
|
||
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
|
||
{
|
||
try
|
||
{
|
||
PDDDBProdListForm.GetProdWxCat(dbProd, null, shop);
|
||
|
||
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();
|
||
if (aiCateIdLst.Count == 0 || aiCateIdLst.Count == 1)
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"获取类目失败 未识别到完整类目\"}";
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"获取类目失败 " + ex.Message + "\"}";
|
||
}
|
||
|
||
////-------------------------------------------------------------------------------------------------------------------------------------
|
||
//// 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张主图
|
||
//{
|
||
// imgId++;
|
||
// string getImgError;
|
||
// var imgUrl = gallery_item.url;
|
||
// {
|
||
// if (!imgUrl.Contains("wxapp") && imgUrl.Contains("mmecimage.cn"))
|
||
// imgUrl = imgUrl.Replace("https://", "http://");
|
||
// }
|
||
// var image = GetHtml.GetUrlImg(imgUrl, 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)
|
||
// {
|
||
// try
|
||
// {
|
||
// image.Save(imgFullPath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
// }
|
||
// catch
|
||
// {
|
||
// // 真实图像失败传假图也能识别
|
||
// 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之间的随机字节
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// 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 = "正在生成类目模板";
|
||
}));
|
||
}
|
||
|
||
if (aiCateIdLst.LastOrDefault() == 7370)
|
||
{
|
||
aiCateIdLst.RemoveAt(aiCateIdLst.Count - 1);
|
||
aiCateIdLst.Add(547591);
|
||
}
|
||
|
||
string getCateRst = WXUpload.getCategoryOnShelf(shop, aiCateIdLst);
|
||
if (!getCateRst.Contains("\"code\":0"))
|
||
{
|
||
Thread.Sleep(500);
|
||
getCateRst = WXUpload.getCategoryOnShelf(shop, aiCateIdLst);
|
||
}
|
||
if (!getCateRst.Contains("\"code\":0"))
|
||
{
|
||
Thread.Sleep(500);
|
||
getCateRst = WXUpload.getCategoryOnShelf(shop, aiCateIdLst);
|
||
}
|
||
if (!getCateRst.Contains("\"code\":0"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
var error = BaseRegex.GetStringJson(ref getCateRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getCateRst.Replace("{", "【").Replace("}", "】");
|
||
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 (leafCatId == 547591)
|
||
bound = GlobalConfig.WxCatBoundList.FirstOrDefault(b => b.leaf_id == 7370);
|
||
if (bound == null)
|
||
{
|
||
if (!isRetryCat)
|
||
{
|
||
PDDDBProdListForm.GetProdWxCat(dbProd, null, shop);
|
||
isRetryCat = true;
|
||
goto retryCat;
|
||
}
|
||
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 + ")\"}";
|
||
|
||
// 定向类目需指定品牌Id
|
||
var spBrandId = "";
|
||
var spBrandName = "";
|
||
if (leafCatId == 547591)
|
||
{
|
||
// 先写死
|
||
//spBrandId = 10914219.ToString();
|
||
|
||
var rst = WXUpload.getMixBrand(shop, leafCatId.ToString());
|
||
Invoke(new Action(() => { spBrandName = cmbSpBrandName.Text.Trim(); }));
|
||
|
||
if (!string.IsNullOrEmpty(spBrandName) && rst.Contains("\"code\":0"))
|
||
{
|
||
var jObj = JsonHelper.JObjectParse(rst);
|
||
if (rst.Contains("mixBrandList"))
|
||
{
|
||
foreach (var jItem in jObj["mixBrandList"]) // bizuinBrandList mixBrandList
|
||
{
|
||
if (jItem["chName"].ParseToString() == spBrandName)
|
||
spBrandId = jItem["brandId"].ParseToString();
|
||
}
|
||
}
|
||
if (rst.Contains("bizuinBrandList"))
|
||
{
|
||
foreach (var jItem in jObj["bizuinBrandList"]) // bizuinBrandList mixBrandList
|
||
{
|
||
if (jItem["chName"].ParseToString() == spBrandName)
|
||
spBrandId = jItem["brandId"].ParseToString();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (spBrandId.IsNullOrEmpty())
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"定向类目绑定品牌失败\"}";
|
||
}
|
||
|
||
// 国表定向类目
|
||
upProdParam.product.info.brandId = spBrandId.ParseToLong();
|
||
}
|
||
else
|
||
{
|
||
|
||
// 检测是否有类目上传权限
|
||
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 || chkAiImage.Checked)
|
||
{
|
||
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 = "正在选取售后属性";
|
||
}));
|
||
}
|
||
|
||
// 非上海仓退货
|
||
if (!chkUseShanghaiReturnOrderAddress.Checked)
|
||
{
|
||
var afterSaleAddress = "";
|
||
var afterSaleDetail = "";
|
||
// 厂商直采获取售后地址用于处理售后单
|
||
if (dbProd.product_get_type_text == "厂商直采")
|
||
{
|
||
|
||
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\":\"售后地址信息获取失败\"}";
|
||
}
|
||
}
|
||
|
||
// 官方库1688厂家数据必须有退货地址才能上传,用户自采数据使用店铺或默认退货地址 26.5.29
|
||
// 官方库暂时也放开限制可以随意传 26.5.31
|
||
else if (dbProd.product_get_type_text == "1688厂家" && dbProd.add_user_name == "admin" && 1 == 2)
|
||
{
|
||
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\":\"售后地址信息获取失败\"}";
|
||
}
|
||
}
|
||
|
||
else if (GlobalConfig.GlobalSettings.IsWxUseSoftwareDefaultAddress == true && !IsWxNotUseSoftwareDefaultAddressOnce)
|
||
{
|
||
if (GlobalConfig.WXShopDefaultAddressList.Any(a => a.shop_id == shop.ShopId))
|
||
WXShopDefaultAddressListForm.GetShopDefaultAddress(new List<ShopLoginInfo>() { shop });
|
||
var address = GlobalConfig.WXShopDefaultAddressList.First(a => a.shop_id == shop.ShopId);
|
||
if (!address.isFullAddress)
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"店铺地址信息获取失败\"}";
|
||
afterSaleAddress = JsonHelper.SerializeObject(address);
|
||
}
|
||
|
||
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");
|
||
}
|
||
// 上海仓退货
|
||
else
|
||
{
|
||
try
|
||
{
|
||
string addressId = "";
|
||
string setAddressRst = WXProdNoCheckEditHelper.SetShanghaiReturnOrderAddress(shop);
|
||
if (setAddressRst.Contains("\"success\":true"))
|
||
{
|
||
addressId = WXProdNoCheckEditHelper.dicShopAddressId[shop.ShopId];
|
||
}
|
||
else
|
||
{
|
||
var errmsg = BaseRegex.GetStringJson(ref setAddressRst, "msg");
|
||
if (string.IsNullOrWhiteSpace(errmsg))
|
||
errmsg = setAddressRst;
|
||
WXProdNoCheckEditHelper.dicShopAddressId.Remove(shop.ShopId);
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"退货地址指定失败:" + errmsg + "\"}";
|
||
}
|
||
|
||
upProdParam.product.info.afterSaleInfo = new afterSaleInfoParam();
|
||
upProdParam.product.info.afterSaleInfo.afterSaleAddressId = addressId;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
WXProdNoCheckEditHelper.dicShopAddressId.Remove(shop.ShopId);
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"退货地址指定失败:" + ex.Message + "\"}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
// 厂商直采获取推单运费模板
|
||
#region 获取推单运费模板,计算运费加价。
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在选取运费模板";
|
||
}));
|
||
}
|
||
|
||
var shippingTemplateJson = "";
|
||
var shipPrice = 0;
|
||
|
||
if (dbProd.product_get_type_text == "厂商直采")
|
||
{
|
||
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 + "\"}";
|
||
}
|
||
try
|
||
{
|
||
var addressArr = JsonHelper.JObjectParse(expressRst)["freightTemplateList"];
|
||
foreach (var addressObj in addressArr)
|
||
{
|
||
var addressStr = JsonHelper.SerializeObject(addressObj);
|
||
if (addressObj["isDefault"].ParseToInt() == 1)
|
||
{
|
||
string templateId = addressObj["templateId"].ParseToString();
|
||
upProdParam.product.info.expressInfo = new expressInfoParam();
|
||
upProdParam.product.info.expressInfo.templateId = templateId; // BaseRegex.GetStringJson(ref expressRst, "templateId");
|
||
break;
|
||
}
|
||
}
|
||
if (upProdParam.product.info.expressInfo == null)
|
||
{
|
||
upProdParam.product.info.expressInfo = new expressInfoParam();
|
||
upProdParam.product.info.expressInfo.templateId = BaseRegex.GetStringJson(ref expressRst, "templateId");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"运费模板获取失败 " + ex.Message + "\"}";
|
||
}
|
||
#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)))
|
||
{
|
||
Debug.WriteLine("详情图:缓存");
|
||
var image = wxImgMapDic[BaseClass.GetMd5(gallery_item.url)];
|
||
upProdParam.product.info.detail.detailImg.Add(image.PlatformUrl);
|
||
continue;
|
||
}
|
||
|
||
if (wxImgMapOldDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||
{
|
||
upProdParam.product.info.detail.detailImg.Add(wxImgMapOldDic[BaseClass.GetMd5(gallery_item.url)]);
|
||
continue;
|
||
}
|
||
|
||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||
{
|
||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||
}
|
||
else
|
||
{
|
||
Debug.WriteLine("详情图:上传");
|
||
// 使用接口链接传详情图
|
||
var urlImg = BaseClass.BuildWXImgObjString("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)] = new ImageCache
|
||
{
|
||
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||
PlatformUrl = upImgUrl,
|
||
};
|
||
|
||
wxImgMapOldDic[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.BuildWXImgObjString("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)] = new ImageCache
|
||
{
|
||
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||
PlatformUrl = upImgUrl,
|
||
};
|
||
|
||
wxImgMapOldDic[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)
|
||
{
|
||
ImageCacheService.SaveImageCaches(Platform, wxImgMapDic.Values);
|
||
|
||
SaveImageCacheOld(dbProd.spu_id, wxImgMapOldDic);
|
||
|
||
isChangeImgDic = false;
|
||
}
|
||
#endregion
|
||
|
||
WXUploadProductInfoRecommendParam recommendParamRst = new WXUploadProductInfoRecommendParam();
|
||
if (chkUseRecommand.Checked)
|
||
{
|
||
WXUploadProductInfoRecommendParam recommendParam = new WXUploadProductInfoRecommendParam();
|
||
//recommendParam.productId = upProdParam.product.productKey.productId;
|
||
recommendParam.predictTypeList = new List<int>() { 5, 4, 2 };
|
||
recommendParam.productInfo = new RecommendProductInfoParam();
|
||
recommendParam.productInfo.title = upProdParam.product.info.title;
|
||
recommendParam.productInfo.headImg = new List<string>();
|
||
recommendParam.productInfo.headImg.AddRange(upProdParam.product.info.headImg);
|
||
recommendParam.productInfo.brandId = upProdParam.product.info.brandId.ParseToString();
|
||
recommendParam.productInfo.category = JsonHelper.DeserializeJsonToList<categoryParam>(JsonHelper.SerializeObject(upProdParam.product.info.category));
|
||
recommendParam.productInfo.detail = new productDetailParam(); //JsonHelper.DeserializeJsonToObject<productDetailParam>(JsonHelper.SerializeObject(upProdParam.product.info.detail));
|
||
var recommendRst = WXUpload.generalProductInfoRecommend(shop, recommendParam);
|
||
if (recommendRst.Contains("\"code\":0"))
|
||
{
|
||
recommendParamRst = JsonHelper.DeserializeJsonToObject<WXUploadProductInfoRecommendParam>(recommendRst);
|
||
}
|
||
}
|
||
if (recommendParamRst.productInfo == null)
|
||
recommendParamRst.productInfo = new RecommendProductInfoParam();
|
||
if (recommendParamRst.productInfo.param == null)
|
||
recommendParamRst.productInfo.param = new List<RecommendProductInfoParamResult>();
|
||
|
||
#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)
|
||
{
|
||
// 修改书名
|
||
if (wxEditPropParam.categorys.FirstOrDefault().name == "书名" && wxEditCategoryParam == wxEditPropParam.categorys.LastOrDefault())
|
||
{
|
||
wxEditCategoryParam.name = prodTitle;
|
||
}
|
||
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.name == "格数")
|
||
{
|
||
|
||
}
|
||
if (propInfo.values.Count == 0)
|
||
continue;
|
||
|
||
|
||
var attr = productAttr.attr.FirstOrDefault(r => r.name == propInfo.name);
|
||
if (attr == null)
|
||
attr = productAttr.attr.FirstOrDefault(r => r.name.Replace("填充材料", "填充材质") == propInfo.name ||
|
||
r.name.Replace("材质", "材质种类") == propInfo.name);
|
||
// 材质 产品名称 适用年龄 面料 生产企业名称 CCC证书编号 尺寸(长) 尺寸(宽) 尺寸(高) 物品(含配件)清单 型号 产品名称
|
||
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编号" || propInfo.name == "书号") && !prodInfo.property.goods_properties.Any(p => p.name == "ISBN版号/CN刊号"))
|
||
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 == "厂名" && !prodInfo.property.goods_properties.Any(p => p.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 (attrValue.IsNullOrEmpty())
|
||
attrValue = attrValueLst.FirstOrDefault(v => v.Replace("高硼硅玻璃", "耐热玻璃(高硼硅)") == 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 (attr.name == "书名" /*&& dbProd.product_get_type_text == "微信小店"*/)
|
||
{
|
||
attrValue = prodTitle;
|
||
}
|
||
if (attr.name == "作者" && attrValue == "无")
|
||
{
|
||
attrValue = new List<string>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||
attrValue = "无";
|
||
}
|
||
|
||
if (attrValue.IsNullOrEmpty() && attr.type == "integer_unit" && (propInfo.values.FirstOrDefault()?.value).IsNumber())
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault()?.value + " " + attr.value.Split(';').FirstOrDefault();
|
||
}
|
||
if (attrValue.IsNullOrEmpty() && attr.name == "包装")
|
||
{
|
||
if (propInfo.values.FirstOrDefault()?.value == "平装-胶订")
|
||
attrValue = "平装";
|
||
}
|
||
}
|
||
// 强制改为国产
|
||
{
|
||
if (attrValueLst.Contains("国产"))
|
||
attrValue = "国产";
|
||
else if (attr.name == "是否进口")
|
||
{
|
||
attrValue = "非进口";
|
||
if (attr.value == "是;否")
|
||
attrValue = "否";
|
||
}
|
||
else if (attr.name == "商品产地")
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
else if (attr.name == "产地")
|
||
{
|
||
if (attr.type == "select_one")
|
||
{
|
||
//北京;天津;上海;重庆;河北石家庄;河北唐山;河北秦皇岛;河北邯郸;河北邢台;河北保定;河北张家口;河北承德;河北沧州;河北廊坊;河北衡水;山西太原;山西大同;山西阳泉;山西长治;山西晋城;山西朔州;山西晋中;山西运城;山西忻州;山西临汾;山西吕梁;内蒙古呼和浩特;内蒙古包头;内蒙古乌海;内蒙古赤峰;内蒙古通辽;内蒙古鄂尔多斯;内蒙古呼伦贝尔;内蒙古巴彦淖尔;内蒙古乌兰察布;内蒙古兴安;内蒙古锡林郭勒;内蒙古阿拉善;辽宁沈阳;辽宁大连;辽宁鞍山;辽宁抚顺;辽宁本溪;辽宁丹东;辽宁锦州;辽宁营口;辽宁阜新;辽宁辽阳;辽宁盘锦;辽宁铁岭;辽宁朝阳;辽宁葫芦岛;吉林长春;吉林吉林;吉林四平;吉林辽源;吉林通化;吉林白山;吉林松原;吉林白城;吉林延边;黑龙江哈尔滨;黑龙江齐齐哈尔;黑龙江鸡西;黑龙江鹤岗;黑龙江双鸭山;黑龙江大庆;黑龙江伊春;黑龙江佳木斯;黑龙江七台河;黑龙江牡丹江;黑龙江黑河;黑龙江绥化;黑龙江大兴安岭;江苏南京;江苏无锡;江苏徐州;江苏常州;江苏苏州;江苏南通;江苏连云港;江苏淮安;江苏盐城;江苏扬州;江苏镇江;江苏泰州;江苏宿迁;浙江杭州;浙江宁波;浙江温州;浙江嘉兴;浙江湖州;浙江绍兴;浙江金华;浙江衢州;浙江舟山;浙江台州;浙江丽水;安徽合肥;安徽芜湖;安徽蚌埠;安徽淮南;安徽马鞍山;安徽淮北;安徽铜陵;安徽安庆;安徽黄山;安徽滁州;安徽阜阳;安徽宿州;安徽六安;安徽亳州;安徽池州;安徽宣城;福建福州;福建厦门;福建莆田;福建三明;福建泉州;福建漳州;福建南平;福建龙岩;福建宁德;江西南昌;江西景德镇;江西萍乡;江西九江;江西新余;江西鹰潭;江西赣州;江西吉安;江西宜春;江西抚州;江西上饶;山东济南;山东青岛;山东淄博;山东枣庄;山东东营;山东烟台;山东潍坊;山东济宁;山东泰安;山东威海;山东日照;山东临沂;山东德州;山东聊城;山东滨州;山东菏泽;河南郑州;河南开封;河南洛阳;河南平顶山;河南安阳;河南鹤壁;河南新乡;河南焦作;河南濮阳;河南许昌;河南漯河;河南三门峡;河南南阳;河南商丘;河南信阳;河南周口;河南驻马店;河南济源;湖北武汉;湖北黄石;湖北十堰;湖北宜昌;湖北襄阳;湖北鄂州;湖北荆门;湖北孝感;湖北荆州;湖北黄冈;湖北咸宁;湖北随州;湖北恩施;湖北仙桃;湖北潜江;湖北天门;湖北神农架;湖南长沙;湖南株洲;湖南湘潭;湖南衡阳;湖南邵阳;湖南岳阳;湖南常德;湖南张家界;湖南益阳;湖南郴州;湖南永州;湖南怀化;湖南娄底;湖南湘西;广东广州;广东韶关;广东深圳;广东珠海;广东汕头;广东佛山;广东江门;广东湛江;广东茂名;广东肇庆;广东惠州;广东梅州;广东汕尾;广东河源;广东阳江;广东清远;广东东莞;广东中山;广东潮州;广东揭阳;广东云浮;广西南宁;广西柳州;广西桂林;广西梧州;广西北海;广西防城港;广西钦州;广西贵港;广西玉林;广西百色;广西贺州;广西河池;广西来宾;广西崇左;海南海口;海南三亚;海南三沙;海南儋州;海南五指山;海南琼海;海南文昌;海南万宁;海南东方;海南定安;海南屯昌;海南澄迈;海南临高;海南白沙;海南昌江;海南乐东;海南陵水;海南保亭;海南琼中;四川成都;四川自贡;四川攀枝花;四川泸州;四川德阳;四川绵阳;四川广元;四川遂宁;四川内江;四川乐山;四川南充;四川眉山;四川宜宾;四川广安;四川达州;四川雅安;四川巴中;四川资阳;四川阿坝;四川甘孜;四川凉山;贵州贵阳;贵州六盘水;贵州遵义;贵州安顺;贵州毕节;贵州铜仁;贵州黔西南;贵州黔东南;贵州黔南;云南昆明;云南曲靖;云南玉溪;云南保山;云南昭通;云南丽江;云南普洱;云南临沧;云南楚雄;云南红河;云南文山;云南西双版纳;云南大理;云南德宏;云南怒江;云南迪庆;西藏拉萨;西藏日喀则;西藏昌都;西藏林芝;西藏山南;西藏那曲;西藏阿里;陕西西安;陕西铜川;陕西宝鸡;陕西咸阳;陕西渭南;陕西延安;陕西汉中;陕西榆林;陕西安康;陕西商洛;甘肃兰州;甘肃嘉峪关;甘肃金昌;甘肃白银;甘肃天水;甘肃武威;甘肃张掖;甘肃平凉;甘肃酒泉;甘肃庆阳;甘肃定西;甘肃陇南;甘肃临夏;甘肃甘南;青海西宁;青海海东;青海海北;青海黄南;青海海南;青海果洛;青海玉树;青海海西;宁夏银川;宁夏石嘴山;宁夏吴忠;宁夏固原;宁夏中卫;新疆乌鲁木齐;新疆克拉玛依;新疆吐鲁番;新疆哈密;新疆昌吉;新疆博尔塔拉;新疆巴音郭楞;新疆阿克苏;新疆克孜勒苏;新疆喀什;新疆和田;新疆伊犁;新疆塔城;新疆阿勒泰;新疆石河子;新疆阿拉尔;新疆图木舒克;新疆五家渠;新疆北屯;新疆铁门关;新疆双河;新疆可克达拉;新疆昆玉;新疆胡杨河;新疆新星;新疆白杨
|
||
//北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆
|
||
var values = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).ToList();
|
||
if (values.Contains("中国大陆"))
|
||
attrValue = "中国大陆";
|
||
else
|
||
{
|
||
var value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(v));
|
||
if (value == null)
|
||
value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(string.Join("", v.Take(2))));
|
||
if (value == null)
|
||
value = values.FirstOrDefault(v => "北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆".Contains(string.Join("", v.Take(2))));
|
||
attrValue = value;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
}
|
||
}
|
||
// 强制非收藏品
|
||
{
|
||
if (attrValueLst.Contains("是否具有拍卖/收藏价值"))
|
||
{
|
||
attrValue = "不具有";
|
||
}
|
||
if (attrValueLst.Contains("是否批量生产(孤品)"))
|
||
{
|
||
attrValue = "批量生产";
|
||
}
|
||
}
|
||
if (attrValue.IsNullOrEmpty() && attr.isRequired == true)
|
||
{
|
||
if (attrValueLst.Contains("其他"))
|
||
attrValue = "其他";
|
||
else if (attrValueLst.Contains("常规"))
|
||
attrValue = "常规";
|
||
else if (attrValueLst.Contains("通用"))
|
||
attrValue = "通用";
|
||
else if (attr.value.Contains("绒丝;羽毛;白鸭绒;白鹅绒;灰鸭绒;灰鹅绒;鸭毛片;鹅毛片"))
|
||
{
|
||
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 = "1 %";
|
||
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")
|
||
{
|
||
var propValue = propInfo.values.FirstOrDefault()?.value;
|
||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,4})cm");
|
||
if (!string.IsNullOrEmpty(match))
|
||
{
|
||
attrValue = match + " cm";
|
||
}
|
||
}
|
||
else if (attr.value == "mm")
|
||
{
|
||
var propValue = propInfo.values.FirstOrDefault()?.value;
|
||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,4})mm");
|
||
if (!string.IsNullOrEmpty(match))
|
||
{
|
||
attrValue = match + " mm";
|
||
}
|
||
}
|
||
else if (attr.value.Contains("岁以上") && attr.value.Contains("个月以上"))
|
||
{
|
||
attrValue = "7 岁以上";
|
||
if (propInfo.values.FirstOrDefault().value.Contains("岁以上") || propInfo.values.FirstOrDefault().value.Contains("个月以上"))
|
||
attrValue = propInfo.values.FirstOrDefault().value;
|
||
if (propInfo.values.FirstOrDefault().value.Contains("岁"))
|
||
{
|
||
var propValue = propInfo.values.FirstOrDefault().value;
|
||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,3})");
|
||
if (!string.IsNullOrEmpty(match))
|
||
{
|
||
attrValue = match + " 岁以上";
|
||
}
|
||
}
|
||
else if (propInfo.values.FirstOrDefault().value.Contains("月"))
|
||
{
|
||
var propValue = propInfo.values.FirstOrDefault().value;
|
||
var match = BaseRegex.GetMatchRegexString(ref propValue, @"([\d]{1,3})");
|
||
if (!string.IsNullOrEmpty(match))
|
||
{
|
||
attrValue = match + " 个月以上";
|
||
}
|
||
}
|
||
}
|
||
else if (attr.value == "个")
|
||
{
|
||
if ((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 == "只;个")
|
||
{
|
||
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.TrimStart('-', ' ');
|
||
else
|
||
attrValue = "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
|
||
attrValue = "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
|
||
attrValue = "100 g";
|
||
}
|
||
else if (attr.value == "日;月;年")
|
||
{
|
||
var propInfoValue = (propInfo.values.FirstOrDefault()?.value).ParseToString();
|
||
if (propInfoValue.EndsWith("日") || propInfoValue.EndsWith("月") || propInfoValue.EndsWith("年"))
|
||
attrValue = propInfo.values.FirstOrDefault()?.value + propInfoValue.LastOrDefault();
|
||
else
|
||
attrValue = "30 日";
|
||
}
|
||
else if (attr.value.ParseToString().Length > 0 && !attr.value.ParseToString().Contains(";"))
|
||
{
|
||
if ((propInfo.values.FirstOrDefault()?.value).ParseToString().EndsWith(attr.value))
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault()?.value;
|
||
if (attrValue.Substring(0, attrValue.Length - attr.value.Length - 1).ParseToInt() == 0)
|
||
attrValue = BaseRegex.GetMatchMaxRegexString(ref attrValue, "(\\d{1,6})") + " " + attr.value;
|
||
if (attrValue.Substring(0, attrValue.Length - attr.value.Length - 1).ParseToInt() == 0)
|
||
attrValue = "1 " + attr.value;
|
||
}
|
||
else
|
||
attrValue = "1 " + attr.value;
|
||
}
|
||
else
|
||
{
|
||
var param = recommendParamRst.productInfo.param.FirstOrDefault(p => p.categorys?.FirstOrDefault()?.name == attr.name);
|
||
if (param != null && param.categorys.Count == 2)
|
||
{
|
||
attrValue = param.categorys[1].name;
|
||
if (attrValue.Contains("磅") && attrValue.Replace("磅", "").ParseToDecimal() > 0)
|
||
{
|
||
if ((";" + attr.value + ";").Contains(";g;"))
|
||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 454).ParseToInt() + "g";
|
||
else if ((";" + attr.value + ";").Contains(";kg;"))
|
||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 0.454m).ParseToDecimal() + "kg";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
attrValue = propInfo.values.FirstOrDefault()?.value.ParseToString();
|
||
var units = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||
foreach (var unit in units)
|
||
{
|
||
var val = attrValue.Replace(unit, "").Trim();
|
||
if (attr.type == "decimal4_unit" && val.ParseToDecimal() != 0m)
|
||
{
|
||
attrValue = val + " " + unit;
|
||
break;
|
||
}
|
||
if (attr.type == "integer_unit" && val.ParseToInt() != 0)
|
||
{
|
||
attrValue = val + " " + unit;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
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 wxPropParam in upProdParam.product.info.param)
|
||
{
|
||
if (wxPropParam.categorys.Count > 0 &&
|
||
wxPropParam.categorys.FirstOrDefault().name == "作者" && (wxPropParam.categorys.LastOrDefault().name == "无" ||
|
||
wxPropParam.categorys.LastOrDefault().name == "-" || wxPropParam.categorys.LastOrDefault().name == "/"))
|
||
{
|
||
wxPropParam.categorys.LastOrDefault().name = upProdParam.product.info.param.FirstOrDefault(p => p.categorys.FirstOrDefault()?.name == "出版社名称").categorys.LastOrDefault()?.name;
|
||
}
|
||
}
|
||
|
||
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 == "产地")
|
||
{
|
||
if (attr.type == "select_one")
|
||
{
|
||
//北京;天津;上海;重庆;河北石家庄;河北唐山;河北秦皇岛;河北邯郸;河北邢台;河北保定;河北张家口;河北承德;河北沧州;河北廊坊;河北衡水;山西太原;山西大同;山西阳泉;山西长治;山西晋城;山西朔州;山西晋中;山西运城;山西忻州;山西临汾;山西吕梁;内蒙古呼和浩特;内蒙古包头;内蒙古乌海;内蒙古赤峰;内蒙古通辽;内蒙古鄂尔多斯;内蒙古呼伦贝尔;内蒙古巴彦淖尔;内蒙古乌兰察布;内蒙古兴安;内蒙古锡林郭勒;内蒙古阿拉善;辽宁沈阳;辽宁大连;辽宁鞍山;辽宁抚顺;辽宁本溪;辽宁丹东;辽宁锦州;辽宁营口;辽宁阜新;辽宁辽阳;辽宁盘锦;辽宁铁岭;辽宁朝阳;辽宁葫芦岛;吉林长春;吉林吉林;吉林四平;吉林辽源;吉林通化;吉林白山;吉林松原;吉林白城;吉林延边;黑龙江哈尔滨;黑龙江齐齐哈尔;黑龙江鸡西;黑龙江鹤岗;黑龙江双鸭山;黑龙江大庆;黑龙江伊春;黑龙江佳木斯;黑龙江七台河;黑龙江牡丹江;黑龙江黑河;黑龙江绥化;黑龙江大兴安岭;江苏南京;江苏无锡;江苏徐州;江苏常州;江苏苏州;江苏南通;江苏连云港;江苏淮安;江苏盐城;江苏扬州;江苏镇江;江苏泰州;江苏宿迁;浙江杭州;浙江宁波;浙江温州;浙江嘉兴;浙江湖州;浙江绍兴;浙江金华;浙江衢州;浙江舟山;浙江台州;浙江丽水;安徽合肥;安徽芜湖;安徽蚌埠;安徽淮南;安徽马鞍山;安徽淮北;安徽铜陵;安徽安庆;安徽黄山;安徽滁州;安徽阜阳;安徽宿州;安徽六安;安徽亳州;安徽池州;安徽宣城;福建福州;福建厦门;福建莆田;福建三明;福建泉州;福建漳州;福建南平;福建龙岩;福建宁德;江西南昌;江西景德镇;江西萍乡;江西九江;江西新余;江西鹰潭;江西赣州;江西吉安;江西宜春;江西抚州;江西上饶;山东济南;山东青岛;山东淄博;山东枣庄;山东东营;山东烟台;山东潍坊;山东济宁;山东泰安;山东威海;山东日照;山东临沂;山东德州;山东聊城;山东滨州;山东菏泽;河南郑州;河南开封;河南洛阳;河南平顶山;河南安阳;河南鹤壁;河南新乡;河南焦作;河南濮阳;河南许昌;河南漯河;河南三门峡;河南南阳;河南商丘;河南信阳;河南周口;河南驻马店;河南济源;湖北武汉;湖北黄石;湖北十堰;湖北宜昌;湖北襄阳;湖北鄂州;湖北荆门;湖北孝感;湖北荆州;湖北黄冈;湖北咸宁;湖北随州;湖北恩施;湖北仙桃;湖北潜江;湖北天门;湖北神农架;湖南长沙;湖南株洲;湖南湘潭;湖南衡阳;湖南邵阳;湖南岳阳;湖南常德;湖南张家界;湖南益阳;湖南郴州;湖南永州;湖南怀化;湖南娄底;湖南湘西;广东广州;广东韶关;广东深圳;广东珠海;广东汕头;广东佛山;广东江门;广东湛江;广东茂名;广东肇庆;广东惠州;广东梅州;广东汕尾;广东河源;广东阳江;广东清远;广东东莞;广东中山;广东潮州;广东揭阳;广东云浮;广西南宁;广西柳州;广西桂林;广西梧州;广西北海;广西防城港;广西钦州;广西贵港;广西玉林;广西百色;广西贺州;广西河池;广西来宾;广西崇左;海南海口;海南三亚;海南三沙;海南儋州;海南五指山;海南琼海;海南文昌;海南万宁;海南东方;海南定安;海南屯昌;海南澄迈;海南临高;海南白沙;海南昌江;海南乐东;海南陵水;海南保亭;海南琼中;四川成都;四川自贡;四川攀枝花;四川泸州;四川德阳;四川绵阳;四川广元;四川遂宁;四川内江;四川乐山;四川南充;四川眉山;四川宜宾;四川广安;四川达州;四川雅安;四川巴中;四川资阳;四川阿坝;四川甘孜;四川凉山;贵州贵阳;贵州六盘水;贵州遵义;贵州安顺;贵州毕节;贵州铜仁;贵州黔西南;贵州黔东南;贵州黔南;云南昆明;云南曲靖;云南玉溪;云南保山;云南昭通;云南丽江;云南普洱;云南临沧;云南楚雄;云南红河;云南文山;云南西双版纳;云南大理;云南德宏;云南怒江;云南迪庆;西藏拉萨;西藏日喀则;西藏昌都;西藏林芝;西藏山南;西藏那曲;西藏阿里;陕西西安;陕西铜川;陕西宝鸡;陕西咸阳;陕西渭南;陕西延安;陕西汉中;陕西榆林;陕西安康;陕西商洛;甘肃兰州;甘肃嘉峪关;甘肃金昌;甘肃白银;甘肃天水;甘肃武威;甘肃张掖;甘肃平凉;甘肃酒泉;甘肃庆阳;甘肃定西;甘肃陇南;甘肃临夏;甘肃甘南;青海西宁;青海海东;青海海北;青海黄南;青海海南;青海果洛;青海玉树;青海海西;宁夏银川;宁夏石嘴山;宁夏吴忠;宁夏固原;宁夏中卫;新疆乌鲁木齐;新疆克拉玛依;新疆吐鲁番;新疆哈密;新疆昌吉;新疆博尔塔拉;新疆巴音郭楞;新疆阿克苏;新疆克孜勒苏;新疆喀什;新疆和田;新疆伊犁;新疆塔城;新疆阿勒泰;新疆石河子;新疆阿拉尔;新疆图木舒克;新疆五家渠;新疆北屯;新疆铁门关;新疆双河;新疆可克达拉;新疆昆玉;新疆胡杨河;新疆新星;新疆白杨
|
||
//北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆
|
||
var values = attr.value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).ToList();
|
||
if (values.Contains("中国大陆"))
|
||
attrValue = "中国大陆";
|
||
else
|
||
{
|
||
var value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(v));
|
||
if (value == null)
|
||
value = values.FirstOrDefault(v => prodTitle.ParseToString().Contains(string.Join("", v.Take(2))));
|
||
if (value == null)
|
||
value = values.FirstOrDefault(v => "北京;天津;上海;重庆;河北;山西;内蒙古;辽宁;吉林;黑龙江;江苏;浙江;安徽;福建;江西;山东;河南;湖北;湖南;广东;广西;海南;四川;贵州;云南;西藏;陕西;甘肃;青海;宁夏;新疆".Contains(string.Join("", v.Take(2))));
|
||
attrValue = value;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
attrValue = "中国大陆";
|
||
}
|
||
}
|
||
else if (attr.name == "是否具有拍卖/收藏价值")
|
||
{
|
||
attrValue = "不具有";
|
||
}
|
||
else if (attr.name == "是否批量生产(孤品)")
|
||
{
|
||
attrValue = "批量生产";
|
||
}
|
||
//else if (attrValueLst.Any(v => v.Contains("%")))
|
||
//{
|
||
// attrValue = attrValueLst.FirstOrDefault();
|
||
//}
|
||
else if (!(attr.type == "decimal4_unit" || attr.type == "integer_unit"))
|
||
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>() { "赵老师", "钱老师", "孙老师", "李老师", "周老师", "吴老师", "郑老师", "王老师", "张老师", "孙老师", "刘老师" }.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||
attrValue = "无";
|
||
}
|
||
if (attr.name == "包装")
|
||
attrValue = "平装";
|
||
if (attr.name == "出版时间")
|
||
attrValue = DateTime.Now.AddMonths(0 - Randomx.GetId(3, 7)).ToString("yyyy-MM");
|
||
}
|
||
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 == "保质期")
|
||
//{
|
||
// if (chkDefaultBestBefore.Checked == false)
|
||
// return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品属性不含保质期,跳过上传\"}";
|
||
// if (txtDefaultBestBefore.Text.ParseToInt() < 15)
|
||
// return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"食品默认保质期设置小于15天,跳过上传\"}";
|
||
// attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||
//}
|
||
}
|
||
|
||
if (attr.name == "保质期")
|
||
{
|
||
if (chkDefaultBestBefore.Checked == false)
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"属性不含保质期,跳过上传\"}";
|
||
if (txtDefaultBestBefore.Text.ParseToInt() < 3)
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"默认保质期设置小于3天,跳过上传\"}";
|
||
attrValue = txtDefaultBestBefore.Text.ParseToInt() + " 天";
|
||
}
|
||
}
|
||
if (attrValue.IsNullOrEmpty() && attr.type == "string")
|
||
{
|
||
attrValue = "其他";
|
||
}
|
||
if ((attrValue.IsNullOrEmpty() || attrValue == "见包装" || attrValue == "%") && (attr.type == "decimal4_unit" || attr.type == "integer_unit"))
|
||
{
|
||
// 走系统推荐
|
||
var param = recommendParamRst.productInfo.param.FirstOrDefault(p => p.categorys?.FirstOrDefault()?.name == attr.name);
|
||
if (param != null && param.categorys.Count == 2)
|
||
{
|
||
attrValue = param.categorys[1].name;
|
||
if (attrValue.Contains("磅") && attrValue.Replace("磅", "").ParseToDecimal() > 0)
|
||
{
|
||
if ((";" + attr.value + ";").Contains(";g;"))
|
||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 454).ParseToInt() + "g";
|
||
else if ((";" + attr.value + ";").Contains(";kg;"))
|
||
attrValue = (attrValue.Replace("磅", "").ParseToDecimal() * 0.454m).ParseToDecimal() + "kg";
|
||
}
|
||
}
|
||
else if (attr.value == "%")
|
||
attrValue = "1 %";
|
||
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 == "mm")
|
||
attrValue = "20 mm";
|
||
else if (attr.value == "毫米(mm);厘米(cm);米(m)")
|
||
attrValue = "20 毫米(mm)";
|
||
else if (attr.value.Contains("岁以上") && attr.value.Contains("个月以上"))
|
||
attrValue = "7 岁以上";
|
||
else if (attr.value == "只;个")
|
||
attrValue = "1 个";
|
||
else if (attr.value == "个")
|
||
attrValue = "1 个";
|
||
else if (attr.value == "ml")
|
||
attrValue = "100 ml";
|
||
else if (attr.value == "L")
|
||
attrValue = "1 L";
|
||
else if (attr.value == "日;月;年")
|
||
attrValue = "30 日";
|
||
}
|
||
|
||
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);
|
||
}
|
||
if (upProdParam.product.info.category.FirstOrDefault()?.name == "图书" || prodInfo.detail.cats.FirstOrDefault() == "书籍/杂志/报纸")
|
||
{
|
||
foreach (var param in upProdParam.product.info.param.ToList())
|
||
{
|
||
if (param.categorys.FirstOrDefault()?.name == "作者" && param.categorys.LastOrDefault()?.name == "无")
|
||
{
|
||
param.categorys.LastOrDefault().name = upProdParam.product.info.param.FirstOrDefault(p => p.categorys.FirstOrDefault()?.name == "出版社名称")?.categorys?.LastOrDefault()?.name;
|
||
if (param.categorys.LastOrDefault().name.IsNullOrEmpty())
|
||
param.categorys.LastOrDefault().name = "无";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
foreach (var param in upProdParam.product.info.param.ToList())
|
||
{
|
||
var nameExistParams = upProdParam.product.info.param.Where(c => c.categorys?.FirstOrDefault()?.name == param.categorys?.FirstOrDefault()?.name).ToList();
|
||
for (int i = 0; i < 10 && nameExistParams.Count > 1; i++)
|
||
{
|
||
upProdParam.product.info.param.Remove(nameExistParams.LastOrDefault());
|
||
nameExistParams = upProdParam.product.info.param.Where(c => c.categorys?.FirstOrDefault()?.name == param.categorys?.FirstOrDefault()?.name).ToList();
|
||
}
|
||
}
|
||
#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;
|
||
|
||
var maxSkuSpecCnt = prodInfo.detail.sku.Max(x => x.spec?.Count).ParseToInt();
|
||
foreach (var skuTmp in prodInfo.detail.sku.ToList())
|
||
{
|
||
if (skuTmp.spec?.Count != maxSkuSpecCnt)
|
||
prodInfo.detail.sku.Remove(skuTmp);
|
||
}
|
||
|
||
// 处理系统指定的规格名称
|
||
//if ((upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料") &&
|
||
// (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 ((upProdParam.product.info.category.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail.cats.FirstOrDefault() == "食品饮料"))
|
||
////{
|
||
//// if (!prodInfo.detail.sku.FirstOrDefault().spec.Any(s => s.parent_name == "规格"))
|
||
//// {
|
||
//// foreach (var sku in prodInfo.detail.sku)
|
||
//// {
|
||
//// sku.spec.FirstOrDefault().parent_name = "规格";
|
||
//// }
|
||
//// }
|
||
////}
|
||
// 坚果炒货类,系统返回的试规格/净含量但是要求填规格
|
||
if ((upProdParam.product.info?.category?.FirstOrDefault()?.name == "食品饮料" || prodInfo.detail?.cats?.FirstOrDefault() == "食品饮料") &&
|
||
(upProdParam.product.info?.category?.LastOrDefault()?.name == "坚果炒货" || upProdParam.product.info?.category?.LastOrDefault()?.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
|
||
{
|
||
var leafCat = upProdParam.product.info.category.LastOrDefault();
|
||
if (leafCat?.catInfo?.saleAttr?.attr != null)
|
||
{
|
||
foreach (var att in leafCat.catInfo.saleAttr.attr)
|
||
{
|
||
//decimal4_unit //g;kg;斤
|
||
if (att.isRequired == true)
|
||
{
|
||
// 规格属性名放在第二个规格上
|
||
if (att.normalRelease.ruleType == 2 && prodInfo.detail.sku.FirstOrDefault()?.spec.Count == 2)
|
||
{
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
// 如果有指定规格属性名称就不再设置
|
||
if (!sku.spec.Any(sp => sp.parent_name == att.name))
|
||
{
|
||
sku.spec[1].parent_name = att.name;
|
||
}
|
||
// 如果不在指定位置上,交换位置
|
||
else if (sku.spec[0].parent_name == att.name)
|
||
{
|
||
var specTmp = sku.spec[0];
|
||
sku.spec[0] = sku.spec[1];
|
||
sku.spec[1] = specTmp;
|
||
}
|
||
if (att.type == "decimal4_unit")
|
||
{
|
||
if (att.value == "g;kg;斤")
|
||
{
|
||
var specName = "";
|
||
foreach (var unit in att.value.Split(';').Reverse().ToList())
|
||
{
|
||
Match specMatch = Regex.Match(sku.spec[1].spec_name.Replace(" ", "").Replace("-", "负号"), @"\d+(.\d+)?" + unit);
|
||
//Match specMatch = Regex.Match(sku.spec[1].spec_name.Replace(" ", ""), @"((0{1}.\d{1,4})|([1-9]\d{1}.\d{1,4})|([1-9]+\d)|0)" + unit);
|
||
if (specMatch.Success)
|
||
{
|
||
specName = specMatch.Value.Replace(unit, "")/*.ParseToDecimal().ParseToInt()*/ + " " + unit;
|
||
break;
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(specName))
|
||
specName = Randomx.GetId(10, 500) + " g";
|
||
sku.spec[1].spec_name = specName;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 规格属性名放在第一个规格上
|
||
else
|
||
{
|
||
foreach (var sku in prodInfo.detail.sku)
|
||
{
|
||
// 如果有指定规格属性名称就不再设置
|
||
if (!sku.spec.Any(sp => sp.parent_name == att.name))
|
||
{
|
||
sku.spec[0].parent_name = att.name;
|
||
}
|
||
// 如果不在指定位置上,交换位置
|
||
else if (sku.spec.Count > 1 && sku.spec[1].parent_name == att.name)
|
||
{
|
||
var specTmp = sku.spec[0];
|
||
sku.spec[0] = sku.spec[1];
|
||
sku.spec[1] = specTmp;
|
||
}
|
||
if (att.type == "decimal4_unit")
|
||
{
|
||
if (att.value == "g;kg;斤")
|
||
{
|
||
var specName = "";
|
||
foreach (var unit in att.value.Split(';').Reverse().ToList())
|
||
{
|
||
Match specMatch = Regex.Match(sku.spec[0].spec_name.Replace(" ", "").Replace("-", "负号"), @"\d+(.\d+)?" + unit);
|
||
//Match specMatch = Regex.Match(sku.spec[0].spec_name.Replace(" ", ""), @"((0{1}.\d{1,4})|([1-9]\d{1}.\d{1,4})|([1-9]+\d)|0)" + unit);
|
||
if (specMatch.Success)
|
||
{
|
||
specName = specMatch.Value.Replace(unit, "")/*.ParseToDecimal().ParseToInt()*/ + " " + unit;
|
||
break;
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(specName))
|
||
specName = Randomx.GetId(10, 500) + " g";
|
||
sku.spec[0].spec_name = specName;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
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)))
|
||
{
|
||
Debug.WriteLine("SKU图:缓存");
|
||
var image = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)];
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = image.PlatformUrl, });
|
||
continue;
|
||
}
|
||
|
||
if (wxImgMapOldDic.ContainsKey(BaseClass.GetMd5(sku.thumb_url)))
|
||
{
|
||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = wxImgMapOldDic[BaseClass.GetMd5(sku.thumb_url)], });
|
||
continue;
|
||
}
|
||
|
||
|
||
// 使用接口链接传sku图
|
||
if (1 == 1 && !sku.thumb_url.Contains("wst.wxapp.tc.qq.com"))
|
||
{
|
||
Debug.WriteLine("SKU图:上传");
|
||
var urlImg = BaseClass.BuildWXImgObjString("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)] = new ImageCache
|
||
{
|
||
Md5 = BaseClass.GetMd5(sku.thumb_url),
|
||
PlatformUrl = upImgUrl,
|
||
};
|
||
|
||
wxImgMapOldDic[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.BuildWXImgObjString("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)] = new ImageCache
|
||
{
|
||
Md5 = BaseClass.GetMd5(sku.thumb_url),
|
||
PlatformUrl = upImgUrl,
|
||
};
|
||
|
||
wxImgMapOldDic[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)
|
||
{
|
||
ImageCacheService.SaveImageCaches(Platform, wxImgMapDic.Values);
|
||
|
||
SaveImageCacheOld(dbProd.spu_id, wxImgMapOldDic);
|
||
|
||
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();
|
||
// 商品裂变随机增加价格
|
||
if (selectProd.is_fission_title && chkFissionRandomPriceChange.Checked)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var fissionRandomPrice = Randomx.GetId((txtFissionRandomPriceChange.Text.ParseToDecimal() * 100).ParseToInt() + 1);
|
||
skuParam.productSkuInfo.salePrice += fissionRandomPrice;
|
||
}));
|
||
}
|
||
// sku图
|
||
skuParam.productSkuInfo.thumbImg = upProdParam.product.info.productSaleAttrs[0].items.FirstOrDefault(a => a.value == skuInfo.spec[0].spec_name)?.imgUrl;
|
||
if (dbProd.special_prod_type == "爆款数据")
|
||
{
|
||
if (!skuInfo.out_sku_sn.StartsWith("BS")) // Best-seller 爆款
|
||
skuInfo.out_sku_sn = "BS" + skuInfo.out_sku_sn;
|
||
}
|
||
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
|
||
|
||
#region 佣金信息,需要权限
|
||
if (BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||
{
|
||
upProdParam.product.info.leagueItemInfo = new leagueItemInfoParam();
|
||
upProdParam.product.info.leagueItemInfo.itemSwitch = 1;
|
||
upProdParam.product.info.leagueItemInfo.itemRatio = commissionRate;
|
||
upProdParam.product.info.leagueItemInfo.headSupplierPublicItemSwitch = 1;
|
||
upProdParam.product.info.leagueItemInfo.headSupplierPublicItemServiceRatio = commissionRate;
|
||
}
|
||
#endregion
|
||
|
||
#region 资质信息
|
||
// 微信回采直接复制
|
||
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.category.FirstOrDefault()?.name != "图书" &&
|
||
// upProdParam.product.info.category.FirstOrDefault()?.name != "食品饮料")
|
||
else if (dbProd.product_get_type_text == "微信店采" &&
|
||
upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
|
||
{
|
||
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 = "正在生成图书专有信息";
|
||
}));
|
||
}
|
||
|
||
if (lstQulificationImage.Count == 0)
|
||
{
|
||
var pageCount = 1;
|
||
var seconds = 0m;
|
||
lstQulificationImage = AdminForms.WXAdminQualificationImageForm.AdminGetServerQualificationImageLst(out pageCount, out seconds, "图书");
|
||
}
|
||
var qulificationImage = lstQulificationImage.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
|
||
if (qulificationImage != null)
|
||
{
|
||
if (qulificationImage.img_base64.IsNullOrEmpty())
|
||
{
|
||
var pageCount = 1;
|
||
var seconds = 0m;
|
||
qulificationImage.img_base64 = AdminForms.WXAdminQualificationImageForm.AdminGetServerQualificationImageLst(out pageCount, out seconds, "图书", qulificationImage.img_md5)
|
||
.FirstOrDefault()?.img_base64;
|
||
}
|
||
}
|
||
|
||
//string publisher = "出版社名称:" + new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||
////string isbn = "ISBN:";
|
||
//string isbn = "ISBN/CN刊号:";
|
||
////string bookName = "书名:";
|
||
//string bookName = "图书名称:";
|
||
//string bookPrice = "定价:" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice) * 0.01;
|
||
//string author = "作者:王老师";
|
||
//string publishTime = "出版时间:" + DateTime.Now.AddMonths(-3).ToString("yyyy年MM月dd日");
|
||
//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;
|
||
// isbn = "ISBN/CN刊号:" + propParam.categorys[1].name;
|
||
// if (propParam.categorys[1].name.Length == 13)
|
||
// {
|
||
// var isbnStr = propParam.categorys[1].name;
|
||
// isbn = "ISBN/CN刊号:" + isbnStr[0] + isbnStr[1] + isbnStr[2] + "-" + isbnStr[3] + "-" + isbnStr[4] + isbnStr[5] + isbnStr[6] + isbnStr[7] + "-" + isbnStr[8] + isbnStr[9] + isbnStr[10] + isbnStr[11] + "-" + isbnStr[12];
|
||
// }
|
||
// }
|
||
// else if (propParam.categorys[0].name.Contains("书名"))
|
||
// {
|
||
// //bookName = "书名:" + propParam.categorys[1].name;
|
||
// bookName = "图书名称:" + propParam.categorys[1].name;
|
||
// }
|
||
// 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;
|
||
|
||
//int imgW = 800; int imgH = 800; int textImgH = 0;
|
||
//string getImgError;
|
||
//var img_url = upProdParam.product.info.headImg[0];
|
||
//if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||
// img_url = img_url.Replace("https://", "http://");
|
||
//var imageMain = GetHtml.GetUrlImg(img_url, out getImgError);
|
||
//if (imageMain == null)
|
||
// imageMain = new Bitmap(800, 800);
|
||
//using (Bitmap bitmap = new Bitmap(1, 1)) // 尺寸不重要,只是为了使用Graphics对象
|
||
//using (Graphics g = Graphics.FromImage(bitmap)) // 获取Graphics对象
|
||
//{
|
||
// // 定义字体
|
||
// Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
// // 定义要测量的字符串
|
||
// string text = bookStr;
|
||
// // 测量字符串大小
|
||
// SizeF size = g.MeasureString(text, font, imgW - 120);
|
||
// // 输出高度信息
|
||
// //Console.WriteLine("Text Height: " + size.Height);
|
||
// textImgH = size.Height.ParseToInt() + 180;
|
||
//}
|
||
|
||
////var bookImg = new Bitmap(imgW, imgH);
|
||
////using (Graphics g = Graphics.FromImage(bookImg))
|
||
////{
|
||
//// g.Clear(Color.White);
|
||
//// //Font font = new Font("宋体", 15, FontStyle.Bold);
|
||
//// //Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||
//// Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||
//// //Font font = new Font("宋体", 17, FontStyle.Bold);
|
||
//// Brush textBrush = Brushes.Black;
|
||
//// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
//// RectangleF rectF = new RectangleF(60, 80, imgW - 120, imgH - 180);
|
||
//// g.DrawString(bookStr, font, textBrush, rectF);
|
||
////}
|
||
|
||
//// 绘制一张带主图的商品详情页
|
||
//var bookImg = new Bitmap(imgW, imgH + textImgH);
|
||
//using (Graphics g = Graphics.FromImage(bookImg))
|
||
//{
|
||
// g.Clear(Color.FromArgb(248, 239, 244));
|
||
|
||
// g.DrawImage(imageMain, new Rectangle(0, 0, imgW, imgH), 0, 0, imageMain.Width, imageMain.Height, GraphicsUnit.Pixel);
|
||
|
||
// //Font font = new Font("宋体", 15, FontStyle.Bold);
|
||
// //Font font = new Font("微软雅黑", 15, FontStyle.Regular);
|
||
// Font font = new Font("微软雅黑", 18, FontStyle.Regular);
|
||
// //Font font = new Font("宋体", 17, FontStyle.Bold);
|
||
// Brush textBrush = Brushes.Black;
|
||
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
// RectangleF rectF = new RectangleF(60, imgH + 80, imgW - 120, textImgH - 180);
|
||
// g.DrawString(bookStr, font, textBrush, rectF);
|
||
//}
|
||
|
||
|
||
string publisher = "出版发行:" + new List<string>() { "技术出版社", "文化出版社", "美术出版社" }[Randomx.GetId(3)];
|
||
//string isbn = "ISBN:";
|
||
string isbn = "ISBN/CN刊号:";
|
||
//string bookName = "书名:";
|
||
string bookName = "图书名称:";
|
||
string bookPrice = "定 价:" + upProdParam.product.productSkus.Max(s => s.productSkuInfo.salePrice) * 0.01;
|
||
string author = "作 者:王老师";
|
||
string publishTime = "出版时间:" + DateTime.Now.AddMonths(-3).ToString("yyyy年MM月dd日");
|
||
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;
|
||
isbn = "ISBN/CN刊号:" + propParam.categorys[1].name;
|
||
if (propParam.categorys[1].name.Length == 13)
|
||
{
|
||
var isbnStr = propParam.categorys[1].name;
|
||
isbn = "ISBN/CN刊号:" + isbnStr[0] + isbnStr[1] + isbnStr[2] + "-" + isbnStr[3] + "-" + isbnStr[4] + isbnStr[5] + isbnStr[6] + isbnStr[7] + "-" + isbnStr[8] + isbnStr[9] + isbnStr[10] + isbnStr[11] + "-" + isbnStr[12];
|
||
}
|
||
}
|
||
else if (propParam.categorys[0].name.Contains("书名"))
|
||
{
|
||
//bookName = "书名:" + propParam.categorys[1].name;
|
||
bookName = "图书名称:" + propParam.categorys[1].name;
|
||
}
|
||
else if (propParam.categorys[0].name.Contains("定价"))
|
||
{
|
||
//bookPrice = "定价:" + propParam.categorys[1].name;
|
||
propParam.categorys[1].name = bookPrice;
|
||
}
|
||
else if (propParam.categorys[0].name.Contains("作者"))
|
||
{
|
||
if (propParam.categorys[1].name != "/")
|
||
author = "作 者:" + propParam.categorys[1].name;
|
||
else
|
||
author = "";
|
||
}
|
||
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;
|
||
}
|
||
if (author.IsNullOrEmpty())
|
||
author = "作 者:" + publisher.Replace("出版发行:", "");
|
||
|
||
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;
|
||
|
||
int imgW = 800; int imgH = 800; int textImgH = 0;
|
||
string getImgError;
|
||
var img_url = upProdParam.product.info.headImg[0];
|
||
if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||
img_url = img_url.Replace("https://", "http://");
|
||
var imageMain = GetHtml.GetUrlImg(img_url, out getImgError);
|
||
if (imageMain == null)
|
||
imageMain = new Bitmap(800, 800);
|
||
using (Bitmap bitmap = new Bitmap(1, 1)) // 尺寸不重要,只是为了使用Graphics对象
|
||
using (Graphics g = Graphics.FromImage(bitmap)) // 获取Graphics对象
|
||
{
|
||
// 定义字体
|
||
Font font = new Font("微软雅黑", 16, FontStyle.Regular);
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
// 定义要测量的字符串
|
||
string text = bookStr;
|
||
// 测量字符串大小
|
||
SizeF size = g.MeasureString(text, font, imgW - 120);
|
||
// 输出高度信息
|
||
//Console.WriteLine("Text Height: " + size.Height);
|
||
textImgH = size.Height.ParseToInt() + 180;
|
||
}
|
||
|
||
|
||
var bookImg = TemuKJD.Properties.Resources.empty_book_900_1200;
|
||
if (!string.IsNullOrEmpty(qulificationImage?.img_base64))
|
||
{
|
||
// 使用服务端随即图
|
||
try
|
||
{
|
||
bookImg = Base64ChangeImgUrl.Base64ToImage(qulificationImage.img_base64);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
}
|
||
imgH = bookImg.Height;
|
||
imgW = bookImg.Width;
|
||
using (Graphics g = Graphics.FromImage(bookImg))
|
||
{
|
||
Brush textBrush = Brushes.Black;
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
|
||
float txtTop = 240, txtBottom = 240, txtLeft = 280, txtRight = 270;
|
||
if (qulificationImage.txt_margin.ParseToString().Split(',').Select(m => m.ParseToInt()).ToList() is List<int> marginValueList && marginValueList.Count == 4)
|
||
{
|
||
txtLeft = marginValueList[0] + 10 - Randomx.GetId(21);
|
||
txtTop = marginValueList[1] + 10 - Randomx.GetId(21);
|
||
txtRight = marginValueList[2] + 10 - Randomx.GetId(21);
|
||
txtBottom = marginValueList[3] + 10 - Randomx.GetId(21);
|
||
}
|
||
int txtWidth = (int)imgW - (int)txtLeft - (int)txtRight; // 370;
|
||
|
||
// 书名
|
||
Font font = new Font("宋体", 22, FontStyle.Bold);
|
||
RectangleF rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(bookName.Replace("图书名称:", ""), font, textBrush, rectF);
|
||
// 测量文本的高度 决定接下来文字绘制位置
|
||
var textSize = g.MeasureString(bookName.Replace("图书名称:", ""), font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
font = new Font("宋体", 15, FontStyle.Bold);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(author.Replace("作 者:", "").TrimEnd('著', ' ') + " 著", font, textBrush, rectF);
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(author.Replace("作 者:", "").TrimEnd('著', ' ') + " 著", font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(publisher.Replace("出版发行:", ""), font, textBrush, rectF);
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(publisher.Replace("出版发行:", ""), font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop - 80);
|
||
g.DrawString(isbn.Replace("ISBN/CN刊号:", "ISBN "), font, textBrush, rectF);
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "ISBN "), font, txtWidth);
|
||
txtTop += 20 + textSize.Height;
|
||
|
||
// 以下从下往上写
|
||
txtTop = imgH - txtBottom;
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(binding, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(binding, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(edition, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(edition, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(publishTime, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(publishTime, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(author, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(author, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(bookPrice + "元", font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(bookPrice + "元", font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(bookName, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(bookName, font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "书 号:ISBN "), font, txtWidth);
|
||
textSize = g.MeasureString(isbn.Replace("ISBN/CN刊号:", "书 号:"), font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(isbn.Replace("ISBN/CN刊号:", "书 号: "), font, textBrush, rectF);
|
||
|
||
// 测量文本的高度
|
||
textSize = g.MeasureString(publisher, font, txtWidth);
|
||
txtTop -= (10 + textSize.Height);
|
||
rectF = new RectangleF(txtLeft, txtTop, txtWidth, imgH - txtTop);
|
||
g.DrawString(publisher, 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 }, });
|
||
|
||
#region 将资质图作为主图的最后一张。
|
||
using (MemoryStream memoryStream = new MemoryStream())
|
||
{
|
||
bookImg.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||
byte[] imageBytes = memoryStream.ToArray();
|
||
var imgBase64 = Convert.ToBase64String(imageBytes);
|
||
|
||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||
var upDate = UserLogin.GetSignaturex();
|
||
upDate += "&token=" + token.accessToken;
|
||
//upDate += "&is_file=true";
|
||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||
// upDate += "&random_code=true";
|
||
upDate += "&img_url=" + location;
|
||
upDate += "&img_base64=" + imgBase64;
|
||
|
||
var sTime = DateTime.Now;
|
||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在上传资质图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||
}));
|
||
}
|
||
|
||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||
{
|
||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||
token = new WxApiBLL().GetRandomWxToken();
|
||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
}
|
||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||
upProdParam.product.info.headImg = upProdParam.product.info.headImg.Take(8).ToList();
|
||
upProdParam.product.info.headImg.Add(upImgUrl);
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
|
||
#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("食品名称") && !propParam.categorys[1].name.Contains("见包装") && !propParam.categorys[1].name.Contains("见外包装") &&
|
||
!propParam.categorys[1].name.Contains("1") && propParam.categorys[1].name.Length > 5)
|
||
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";
|
||
|
||
int width = 800;
|
||
int height = 1000;
|
||
var bookImg = new Bitmap(width, height);
|
||
using (Graphics g = Graphics.FromImage(bookImg))
|
||
{
|
||
g.Clear(Color.Gray);
|
||
|
||
Brush borderBrush = Brushes.Gray;
|
||
Brush contentBrush = Brushes.White;
|
||
g.FillRectangle(contentBrush, new RectangleF(8, 8, width - 16, height - 16));
|
||
g.FillRectangle(borderBrush, new RectangleF(18, 18, width - 36, height - 36));
|
||
g.FillRectangle(contentBrush, new RectangleF(22, 22, width - 44, height - 44));
|
||
g.FillRectangle(borderBrush, new RectangleF(40, 140, width - 80, 4));
|
||
|
||
SizeF textSize;
|
||
{
|
||
Font font = new Font("微软雅黑", 30, FontStyle.Regular);
|
||
Brush textBrush = Brushes.DarkRed;
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||
// 测量文本的宽度
|
||
textSize = g.MeasureString("商 品 标 签", font);
|
||
float x = (width - textSize.Width) / 2;
|
||
|
||
RectangleF rectF = new RectangleF(x, 50, width - x, height - 200);
|
||
g.DrawString("商 品 标 签", font, textBrush, rectF);
|
||
}
|
||
|
||
{
|
||
//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, 120 + textSize.Height, width - 160, height - 80 - 120 - textSize.Height);
|
||
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
|
||
}
|
||
#endregion
|
||
|
||
#region AI生成图片,用于商品裂变
|
||
if (chkAiImage.Checked)
|
||
{
|
||
int imgCount = 1;
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cell != null)
|
||
cell.Value = "正在Ai生图";
|
||
imgCount = txtAiImgCount.Text.Trim().ParseToInt();
|
||
if (imgCount == 0)
|
||
imgCount = 1;
|
||
}));
|
||
|
||
List<Task> tList = new List<Task>();
|
||
List<string> errStrLst = new List<string>();
|
||
for (int n = 0; n < upProdParam.product.info.headImg.Count && n < imgCount; n++)
|
||
{
|
||
while (tList.Count >= 10)
|
||
{
|
||
Thread.Sleep(500);
|
||
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
|
||
}
|
||
var tt = Task.Run(() =>
|
||
{
|
||
var imgUrl = GetAiImg(upProdParam.product.info.headImg[n], upProdParam.product.info.shortTitle);
|
||
if (imgUrl.StartsWith("生成Ai图片错误"))
|
||
{
|
||
errStrLst.Add(imgUrl);
|
||
return;
|
||
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + imgUrl + "\"}";
|
||
}
|
||
|
||
// api上传图片文件 Ai主图
|
||
if (1 == 1)
|
||
{
|
||
try
|
||
{
|
||
string errMsg = "";
|
||
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800);
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
errStrLst.Add(errMsg);
|
||
return;
|
||
//return errMsg;
|
||
}
|
||
|
||
var urlImg = BaseClass.BuildWXImgObjString("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=" + imgUrl;
|
||
upDate += "&img_base64=" + imgBase64;
|
||
|
||
var sTime = DateTime.Now;
|
||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||
if (cell != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
cell.Value = "正在上传Ai主图文件 " + (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.headImg[n] = upImgUrl;
|
||
//if (n == 0)
|
||
// upProdParam.product.info.detail.detailImg.Insert(0, upImgUrl);
|
||
}
|
||
else
|
||
{
|
||
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||
errStrLst.Add("上传Ai图失败 " + upImgErrMsg);
|
||
return;
|
||
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"上传Ai图失败 " + upImgErrMsg + "\"}";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errStrLst.Add("上传Ai图失败 " + ex.Message);
|
||
return;
|
||
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"上传Ai图失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
});
|
||
tList.Add(tt);
|
||
}
|
||
while (tList.Count > 0)
|
||
{
|
||
Thread.Sleep(500);
|
||
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
|
||
}
|
||
// 错误超过一定数量直接报错返回
|
||
if (errStrLst.Count > 0 && errStrLst.Count >= imgCount / 3)
|
||
{
|
||
return string.Join(",", errStrLst);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 添加图片随机外框,用于商品裂变
|
||
if (selectProd.is_fission_title && chkRandomImgBorder.Checked)
|
||
{
|
||
// selectProd.isFission
|
||
int mainCount = 9;
|
||
int detailCount = 1;
|
||
Invoke(new Action(() =>
|
||
{
|
||
mainCount = txtMainBorderImgCount.Text.Trim().ParseToInt();
|
||
detailCount = txtDetailBorderImgCount.Text.Trim().ParseToInt();
|
||
}));
|
||
// api上传图片文件 边框主图
|
||
if (1 == 1)
|
||
{
|
||
if (chkRandomMainImgOrder.Checked)
|
||
upProdParam.product.info.headImg = upProdParam.product.info.headImg.OrderBy(x => Guid.NewGuid()).Take(100).ToList();
|
||
for (int n = 0; n < upProdParam.product.info.headImg.Count && n < mainCount; n++)
|
||
{
|
||
var imgUrl = upProdParam.product.info.headImg[n];
|
||
try
|
||
{
|
||
string errMsg = "";
|
||
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800, true);
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
return errMsg;
|
||
}
|
||
|
||
var urlImg = BaseClass.BuildWXImgObjString("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=" + imgUrl;
|
||
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.headImg[n] = upImgUrl;
|
||
}
|
||
else
|
||
{
|
||
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化主图失败 " + upImgErrMsg + "\"}";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化主图失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
}
|
||
// api上传图片文件 边框详情图
|
||
if (1 == 1)
|
||
{
|
||
if (chkRandomDetailImgOrder.Checked)
|
||
upProdParam.product.info.detail.detailImg = upProdParam.product.info.detail.detailImg.OrderBy(x => Guid.NewGuid()).Take(100).ToList();
|
||
for (int n = 0; n < upProdParam.product.info.detail.detailImg.Count && n < detailCount; n++)
|
||
{
|
||
var imgUrl = upProdParam.product.info.detail.detailImg[n];
|
||
try
|
||
{
|
||
string errMsg = "";
|
||
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
|
||
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800, true);
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
return errMsg;
|
||
}
|
||
|
||
var urlImg = BaseClass.BuildWXImgObjString("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=" + imgUrl;
|
||
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[n] = upImgUrl;
|
||
}
|
||
else
|
||
{
|
||
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化详情图失败 " + upImgErrMsg + "\"}";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化详情图失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#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.category[1].name == "水果")
|
||
if (chkFreightInsurance.Checked)
|
||
{
|
||
upProdParam.product.info.extraService.freightInsurance = 1;
|
||
}
|
||
else
|
||
{
|
||
upProdParam.product.info.extraService.freightInsurance = 0;
|
||
}
|
||
// 假1赔3
|
||
if (upProdParam.product.info.category[0].name == "珠宝首饰" || upProdParam.product.info.category[1].name == "时尚饰品")
|
||
{
|
||
upProdParam.product.info.extraService.fakeOnePayFour = 1;
|
||
}
|
||
// 坏损包退 damageGuarantee
|
||
if (upProdParam.product.info.category[0].name == "生鲜" || upProdParam.product.info.category[0].name == "酒类" ||
|
||
upProdParam.product.info.category[0].name == "食品饮料" || upProdParam.product.info.category[0].name == "保健食品/膳食营养补充食品" ||
|
||
(upProdParam.product.info.category[0].name == "农资园艺" && upProdParam.product.info.category[1].name == "花卉绿植"))
|
||
{
|
||
upProdParam.product.info.extraService.damageGuarantee = 1;
|
||
}
|
||
// 生鲜不支持换货,关闭
|
||
if (upProdParam.product.info.category[0].name == "生鲜")
|
||
{
|
||
upProdParam.product.info.extraService.exchangeSupport = 0;
|
||
}
|
||
// 上传拒绝七天无理由
|
||
if (RejectSevenDayReturn == true)
|
||
{
|
||
upProdParam.product.info.extraService.sevenDayReturn = 0;
|
||
}
|
||
|
||
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))
|
||
{
|
||
if (uploadDraftRst.Contains("\"errcode\":9401043"))
|
||
error = "sku价格异常,请检查加价比例";
|
||
else
|
||
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)
|
||
{
|
||
ImageCacheService.SaveImageCaches(Platform, wxImgMapDic.Values);
|
||
|
||
SaveImageCacheOld(dbProd.spu_id, wxImgMapOldDic);
|
||
|
||
isChangeImgDic = false;
|
||
}
|
||
#endregion
|
||
|
||
upProdParam.product.productKey.productId = BaseRegex.GetLongJson(ref uploadDraftRst, "productId").ParseToString();
|
||
|
||
var commissionRstStr = "";
|
||
if (chkUpDraft.Checked && BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||
{
|
||
var rst = WXUpload.addLeagueItemForUpdatingProduct(shop, 1, commissionRate, 1, commissionRate, upProdParam.product.productKey.productId.ParseToLong());
|
||
if (!rst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||
commissionRstStr = "设置佣金比例失败 " + rst;
|
||
}
|
||
}
|
||
|
||
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\":\"指定上传到草稿箱" + commissionRstStr + "\"}";
|
||
}
|
||
|
||
// 提交商品上架
|
||
if (!chkTestNoAuditUpload.Checked)
|
||
{
|
||
var uploadProdRst = WXUpload.upProductV2(shop, upProdParam);
|
||
//{"success":true,"retcode":209006,"errcode":209006,"productId":10001226244322,"productKey":{"productId":"10001226244322"}} // 提审成功
|
||
//{"success":true,"retcode":0,"errcode":0,"productId":10001226095876,"productKey":{"productId":"10001226095876"}} // 未能提审
|
||
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();
|
||
|
||
if (BaseClass.UserAuthority.Contains("佣金上货") && chkCommission.Checked)
|
||
{
|
||
var rst = WXUpload.addLeagueItemForUpdatingProduct(shop, 1, commissionRate, 1, commissionRate, upProdParam.product.productKey.productId.ParseToLong(), 1);
|
||
if (!rst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
|
||
commissionRstStr = "设置佣金比例失败 " + rst;
|
||
}
|
||
}
|
||
if (chkIsSubmitSuccess.Checked)
|
||
{
|
||
Thread.Sleep(Randomx.GetId(2000, 3001));
|
||
var uploadCheckRst = WXUpload.SearchProductUpload(shop, upProdParam.product.productKey.productId);
|
||
if (uploadCheckRst.Contains("\"productList\":[]") || uploadCheckRst.Contains("\"totalNum\":0"))
|
||
{
|
||
return "{\"success\":false,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"草稿箱\",\"errMsg\":\"上架提审失败 请检查是否在架商品数已达到上限或店铺受到其他限制\"}";
|
||
}
|
||
}
|
||
}
|
||
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);
|
||
}
|
||
if (!string.IsNullOrEmpty(dbProd.secret_spu_id))
|
||
{
|
||
//add_secret_spu_id_shop_id_map //测试id "2017522348787531778" FC4C8B7F3C6E4B029AD2A12D4D323B41 // 老函数已作废
|
||
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 (!GlobalConfig.dicWxShopUploadInfo.ContainsKey(shop.ShopId))
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId] = new WxShopUploadInfo();
|
||
if (!GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.ContainsKey(day))
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] = 0;
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] += 1;
|
||
// 删除45天前的记录
|
||
var removeKeys = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt()).ToList();
|
||
foreach (var key in removeKeys)
|
||
{
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Remove(key);
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", GlobalConfig.dicWxShopUploadInfo);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvShopRow.Cells["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day];
|
||
}));
|
||
}
|
||
|
||
return "{\"success\":true,\"draftId\":" + upProdParam.product.productKey.productId + ",\"status\":\"已上传\",\"msg\":\"上传成功" + commissionRstStr + "\"}";
|
||
}
|
||
|
||
|
||
public static string GetImgBase64ForApi(out string errorMsg, string img_url, bool needAddRandomBlock, bool wantAddRandomBlock, int imgWidth = 0, int imgHeight = 0, bool wantAddRandomBorder = false)
|
||
{
|
||
errorMsg = "";
|
||
string imgBase64 = "";
|
||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||
//生成主图base64字符串
|
||
string getImgError;
|
||
//if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||
//优选靓键店 登录 进店 397652670 重庆川味百年传奇山椒笋尖低脂解馋泡椒脆笋脆嫩爽口开胃解腻追剧办公解馋休闲小零食独立小包装 547009 371857150 0 初始化图片上传失败 值不能为 null。
|
||
//参数名: source https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/6acd9a520004f3272b49791884351f15000000a100004f50 14秒
|
||
if (!img_url.Contains("wxapp") && !img_url.Contains("mmecimage.cn"))
|
||
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 + " " + img_url + "\"}";
|
||
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));
|
||
}
|
||
if (wantAddRandomBorder)
|
||
{
|
||
var borderColor = Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256));
|
||
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, 0, imageBg.Width, 20));
|
||
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, imageBg.Height - 20, imageBg.Width, 20));
|
||
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, 0, 20, imageBg.Height));
|
||
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(imageBg.Width - 20, 0, 20, imageBg.Height));
|
||
}
|
||
}
|
||
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 "";
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 图片宽高均达到指定尺寸时返回 true;尺寸不足或无效输入返回 false。
|
||
/// </summary>
|
||
public bool IsBase64ImageSizeValid(string base64Image, int width, int height)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(base64Image) || width <= 0 || height <= 0)
|
||
return false;
|
||
|
||
try
|
||
{
|
||
using (var stream = new MemoryStream(Convert.FromBase64String(base64Image)))
|
||
using (var image = System.Drawing.Image.FromStream(stream))
|
||
{
|
||
return image.Width >= width && image.Height >= height;
|
||
}
|
||
}
|
||
catch (FormatException)
|
||
{
|
||
return false;
|
||
}
|
||
catch (ArgumentException)
|
||
{
|
||
return false;
|
||
}
|
||
catch (OutOfMemoryException)
|
||
{
|
||
// GDI+ 对不支持或损坏的图片也可能抛出此异常。
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public string UploadImg(ShopLoginInfo shop, string img_url, DataGridViewCell cell = null, bool randomBlock = false)
|
||
{
|
||
string getImgError;
|
||
if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
|
||
img_url = img_url.Replace("https://", "http://");
|
||
var image = GetHtml.GetUrlImg(img_url, 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;
|
||
}));
|
||
});
|
||
|
||
if (BaseClass.UserAuthority.Contains("裂变调试") && chkFissionGoodsName.Checked)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
txtAddCount.Text = "" + titles.Count;
|
||
if (titles.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowError("裂变标题数量不足");
|
||
return;
|
||
}
|
||
|
||
//this.lstTemuDBProductSelect.Clear();
|
||
//NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
|
||
//lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}));
|
||
}
|
||
|
||
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 productNameLst = new List<string>() { prod.product_name };
|
||
if (chkRandomFissionProduct.Checked)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var titleCount = txtRandomFissionProductCount.Text.Trim().ParseToInt();
|
||
if (prod.fission_words.ParseToString().Length > 20 && titleCount > 0)
|
||
{
|
||
productNameLst = prod.fission_words.Replace("fission_goods_names:", "")
|
||
.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).OrderBy(x => Guid.NewGuid()).Distinct().Take(titleCount)
|
||
.ToList();
|
||
}
|
||
}));
|
||
}
|
||
foreach (var productName in productNameLst)
|
||
{
|
||
var selectProd = JsonHelper.DeserializeJsonToObject<TemuDBProductSelect>(JsonHelper.SerializeObject(prod));
|
||
selectProd.product_name = productName;
|
||
if (chkRandomFissionProduct.Checked)
|
||
selectProd.is_fission_title = true;
|
||
selectProd.out_product_Id = prod.id.ToString();
|
||
selectProd.id = 1;
|
||
if (lstTemuDBProductSelect.Count > 0)
|
||
selectProd.id = lstTemuDBProductSelect.Max(p => p.id) + 1;
|
||
lstTemuDBProductSelect.Add(selectProd);
|
||
|
||
addCount--;
|
||
if (addCount <= 0)
|
||
break;
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}));
|
||
//addCount--;
|
||
if (addCount <= 0)
|
||
break;
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", 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 += "&ban_wx=0";
|
||
|
||
//data += "&in_ext_codes=" + txtExtCodeFilter.Text;
|
||
data += "&in_spu_ids=" + txtIdFilter.Text;
|
||
|
||
string serach_group = cmbGroupFilter.Text.Trim();
|
||
if (BaseClass.UserAuthority.Contains("商品采集") || BaseClass.ParentAuthority.Contains("商品采集"))
|
||
{
|
||
if (BaseClass.GroupId == 3)
|
||
serach_group = cmbGroupFilter.Text.Trim().Replace("我的商品", "用户" + BaseClass.UserName);
|
||
else
|
||
serach_group = cmbGroupFilter.Text.Trim().Replace("我的商品", "用户" + BaseClass.ParentUserName);
|
||
}
|
||
data += "&in_groups=" + serach_group;
|
||
|
||
data += "&in_notes=" + cmbNotes.Text.Trim();
|
||
|
||
data += "&product_name=" + txtSearchGoodsName.Text.Trim();
|
||
|
||
// 商品采集权限可以随机管理员或自己采集的商品
|
||
string addUserName = BaseClass.UserAuthority.Contains("商品采集") ? ("admin," + BaseClass.UserName) : "admin";
|
||
if (BaseClass.GroupId != 3)
|
||
addUserName = BaseClass.ParentAuthority.Contains("商品采集") ? ("admin," + BaseClass.ParentUserName) : "admin";
|
||
|
||
// 采集用户如果没有爆款数据或货源选择权限,则只能随机自己采集的商品
|
||
if ((BaseClass.UserAuthority.Contains("商品采集") || BaseClass.UserAuthority.Contains("商品采集")) &&
|
||
cmbHot.Text != "爆款数据" && !BaseClass.UserAuthority.Contains("货源选择"))
|
||
data += "&add_user_name=" + (BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName);
|
||
|
||
// 防止手输查询学员数据
|
||
if (!BaseClass.UserAuthority.Contains("学员数据") && !BaseClass.ParentAuthority.Contains("学员数据") && cmbSourceType.Text.Contains("学员数据"))
|
||
{
|
||
cmbSourceType.Text = cmbSourceType.Text.Replace("学员数据", "");
|
||
}
|
||
// 如果指定只有自己采集的商品,则只会随机自己采集的商品
|
||
else if ((cmbSourceType.Text.Trim().Contains("多多商品") || cmbSourceType.Text.Trim().Contains("1688商品") || cmbSourceType.Text.Trim().Contains("微信商品")) &&
|
||
cmbSourceType.Text.Trim().Replace("多多商品", "").Replace("1688商品", "").Replace("微信商品", "").Trim(',').IsNullOrEmpty())
|
||
data += "&add_user_name=" + (BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName);
|
||
else
|
||
data += "&add_user_name=" + addUserName;
|
||
|
||
if (!string.IsNullOrWhiteSpace(cmbSourceType.Text.Trim()))
|
||
{
|
||
// 采集来源判断
|
||
data += "&product_get_type=" + cmbSourceType.Text.Trim().Replace("已采集数据", "1688外部数据")
|
||
.Replace("多多商品", "机会商品,多多外部数据").Replace("1688商品", "1688厂家,1688外部数据").Replace("微信商品", "微信店采,微信外部数据");
|
||
}
|
||
|
||
|
||
|
||
if (btnSwitchCatType.Text == "P")
|
||
data += "&in_cates=" + (cmbCateFilter1.Text == "全部" ? "" : cmbCateFilter1.Text);
|
||
else
|
||
{
|
||
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());
|
||
}
|
||
|
||
// 爆款数据商品
|
||
// 不为空搜内容
|
||
if (!string.IsNullOrWhiteSpace(cmbHot.Text.Trim()))
|
||
data += "&special_prod_type=" + cmbHot.Text;
|
||
// 为空按照权限搜
|
||
else if (BaseClass.SaLevel > 0 || BaseClass.UserAuthority.Contains("爆款数据"))
|
||
data += "&special_prod_type=爆款数据,普通商品";
|
||
else
|
||
data += "&special_prod_type=普通商品";
|
||
|
||
// 聚水潭商品处理条件校验
|
||
data += "&is_supplier_prod_ok=" + cmbJstInitSet.Text.Trim();
|
||
|
||
// 微信安全商品检测
|
||
data += "&wx_safe_status=" + cmbWxSafe.Text.Trim().Replace("安全+未校验", "安全商品,未校验");
|
||
|
||
// 指定天数爆款数据 // 原7天爆款数据
|
||
//if (chkSevenDays.Checked)
|
||
// data += "&add_days_less=21";
|
||
if (chkUpdateInDays.Checked)
|
||
{
|
||
data += "&add_days_less=" + txtUpdateInDays.Text.Trim();
|
||
data += "&add_days_less_type=" + (cmbUpdateInDays.Text == "更新" ? "mdy" : "add");
|
||
}
|
||
|
||
// 回采数据
|
||
if (chkWXComplateProd.Checked)
|
||
data += "&has_wx_format=1";
|
||
|
||
// 标题裂变
|
||
if (chkRandomFissionProduct.Checked)
|
||
data += "&fission_words=fission_goods_names:";
|
||
|
||
if (chkFilterViewUv.Checked)
|
||
data += "&min_view_uv=" + numFilterViewUv.Value;
|
||
|
||
if (chkFilterSaleCountNum.Checked)
|
||
data += "&sale_count_num_more=" + numFilterSaleCountNum.Value;
|
||
}));
|
||
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>();
|
||
}
|
||
}
|
||
|
||
public string GetAiImg(string imgUrl, string imgWord)
|
||
{
|
||
string image_url = imgUrl;
|
||
string word = imgWord;
|
||
string secret = "sadhjufhe15c4fbvFBvcvds+5sdfds@#%$xsc";
|
||
string time = BaseClass.DateTimeToTimestampSeconds(DateTime.Now).ToString();
|
||
string code = BaseClass.GetMd5(secret + time).ToLower();
|
||
|
||
try
|
||
{
|
||
//string url = "http://ai-bs.jiaotian.vip:" + Randomx.GetId(20010, 20021) + "/index.php?obj=public/image";
|
||
//http://svn.jiaotian.vip:20010-20020/index.php?obj=public/image
|
||
string url = "http://svn.jiaotian.vip:" + Randomx.GetId(20010, 20021) + "/index.php?obj=public/image";
|
||
string data = "time=" + time + "&code=" + code + "&image_url=" + image_url + "&word=" + word;
|
||
string html = GetHtml.PostUtf8(url, data, "", 120);
|
||
if (!string.IsNullOrEmpty(html) && !html.Contains("error"))
|
||
{
|
||
return html;
|
||
}
|
||
else
|
||
{
|
||
return "生成Ai图片错误 " + html;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "生成Ai图片错误 " + ex.Message;
|
||
}
|
||
}
|
||
|
||
private void btnClearUpload_Click(object sender, EventArgs e)
|
||
{
|
||
if (BaseMsgForm.ShowConfirm("确定清空待上传商品吗?清空后不可恢复!").DialogResult == DialogResult.Cancel)
|
||
return;
|
||
|
||
lstTemuDBProductSelect.Clear();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", 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 (IsFormLoad)
|
||
{
|
||
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();
|
||
Task.Run(() =>
|
||
{
|
||
var rows = this.dgvSelectProduct.Rows.Cast<DataGridViewRow>().ToList(); //Cast后Rows做foreach循环时仍会夹花跳过,所以要ToList转一个新的数组。
|
||
foreach (var row in rows)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
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 async void btnClearAll_Click(object sender, EventArgs e)
|
||
{
|
||
dgvSelectProduct.Rows.Clear();
|
||
upload_draft_product_lst.Clear();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
}
|
||
|
||
private void chkAddMorePriceFirst_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (IsFormLoad)
|
||
{
|
||
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)
|
||
{
|
||
PDDDBProdUploadSelectCacheForm selectCacheForm = new PDDDBProdUploadSelectCacheForm(lstTemuDBProductSelect);
|
||
selectCacheForm.ShowDialog();
|
||
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", 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 = "厂商直采";
|
||
cmbHot.Text = "普通商品";
|
||
chkSkipQualification.Checked = false;
|
||
cmbHot_TextChanged(null, null);
|
||
chkFilterViewUv.Checked = false;
|
||
numFilterViewUv.Value = 200;
|
||
if (chkWXComplateProd.Visible == true) chkWXComplateProd.Checked = false;
|
||
if (chkRandomFissionProduct.Visible == true) chkRandomFissionProduct.Checked = false;
|
||
if (txtRandomFissionProductCount.Visible == true) txtRandomFissionProductCount.Text = "";
|
||
|
||
|
||
|
||
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.ValidShopLoginList.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 (!GlobalConfig.dicWxShopUploadInfo.ContainsKey(shop.ShopId))
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId] = new WxShopUploadInfo();
|
||
if (!GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.ContainsKey(day))
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] = 0;
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] += 1;
|
||
// 删除45天前的记录
|
||
var removeKeys = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt());
|
||
foreach (var key in removeKeys)
|
||
{
|
||
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Remove(key);
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", GlobalConfig.dicWxShopUploadInfo);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvShopRow.Cells["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo[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 txtMaxPrice_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.SkuMaxPrice = txtMaxPrice.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;
|
||
if (chkHighestPriceSku.Checked)
|
||
chkLowestPriceSku.Checked = false;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
private void chkLowestPriceSku_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.OnlyLowestPriceSku = chkLowestPriceSku.Checked;
|
||
if (chkLowestPriceSku.Checked)
|
||
chkHighestPriceSku.Checked = false;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void chkSameSpecPriceUp_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.SameSpecSamePriceUp = chkSameSpecPriceUp.Checked;
|
||
if (chkSameSpecPriceUp.Checked)
|
||
chkSameSpecPriceDown.Checked = false;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
private void chkSameSpecPriceDown_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
wxUploadRule.SameSpecSamePriceDown = chkSameSpecPriceDown.Checked;
|
||
if (chkSameSpecPriceDown.Checked)
|
||
chkSameSpecPriceUp.Checked = false;
|
||
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 cmbGroupFilter_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
if (cmbGroupFilter.Text == "我的商品" && cmbSourceType.Text != "多多商品" && cmbSourceType.Text != "1688商品" && cmbSourceType.Text != "微信商品")
|
||
{
|
||
cmbSourceType.Text = "";
|
||
}
|
||
}
|
||
|
||
private void cmbSourceType_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
// fillPddCate();
|
||
//else
|
||
// fillWxCate();
|
||
|
||
if (cmbSourceType.Text != "厂商直采"/* && cmbSourceType.Text != "1688厂家"*/)
|
||
{
|
||
cmbJstInitSet.Text = "";
|
||
}
|
||
else
|
||
{
|
||
cmbJstInitSet.Text = "是";
|
||
}
|
||
}
|
||
|
||
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)
|
||
{
|
||
Debug.WriteLine($"Filter1 修改:{cmbCateFilter1.Text}");
|
||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
if (btnSwitchCatType.Text != "W")
|
||
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)
|
||
{
|
||
Debug.WriteLine($"Filter1 修改:{cmbCateFilter2.Text}");
|
||
//if (cmbSourceType.Text != "厂商直采" && cmbSourceType.Text != "1688厂家" && cmbSourceType.Text != "微信店采" && cmbSourceType.Text != "微信小店")
|
||
if (btnSwitchCatType.Text != "W")
|
||
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", lstTemuDBProductSelect);
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}
|
||
|
||
private void btnFilterShop_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
string group = cmbFilterShopGroup.Text.Trim().Trim(';');
|
||
if (group == "全部")
|
||
group = "";
|
||
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
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;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colGroup"].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 = "全部";
|
||
cmbFilterShopGroup.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();
|
||
|
||
string group = cmbFilterShopGroup.Text.Trim().Trim(';');
|
||
if (group == "全部")
|
||
group = "";
|
||
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == false)
|
||
continue;
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colGroup"].Value.ParseToString()))
|
||
continue;
|
||
|
||
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();
|
||
|
||
string group = cmbFilterShopGroup.Text.Trim().Trim(';');
|
||
if (group == "全部")
|
||
group = "";
|
||
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == false)
|
||
continue;
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colGroup"].Value.ParseToString()))
|
||
continue;
|
||
|
||
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)
|
||
{
|
||
WXSelectDBProdListForm.Instance.lstTemuDBProductSelect = lstTemuDBProductSelect;
|
||
WXSelectDBProdListForm.Instance.cmbSourceType.Items.Clear();
|
||
WXSelectDBProdListForm.Instance.cmbSourceType.Items.AddRange(this.cmbSourceType.Items.Cast<Object>().ToArray());
|
||
WXSelectDBProdListForm.Instance.SaveComplete -= dbProdList_SaveComplete;
|
||
WXSelectDBProdListForm.Instance.SaveComplete += dbProdList_SaveComplete;
|
||
WXSelectDBProdListForm.Instance.Show();
|
||
WXSelectDBProdListForm.Instance.BringToFront();
|
||
}
|
||
|
||
public void dbProdList_SaveComplete(object obj)
|
||
{
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", lstTemuDBProductSelect);
|
||
Invoke(new Action(() =>
|
||
{
|
||
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
|
||
}));
|
||
}
|
||
|
||
private void cmbHot_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (cmbHot.Text == "爆款数据")
|
||
{
|
||
cmbSourceType.Text = "";
|
||
cmbJstInitSet.Text = "";
|
||
}
|
||
else
|
||
{
|
||
cmbSourceType.Text = "厂商直采";
|
||
cmbJstInitSet.Text = "是";
|
||
// 商品采集用户无货源选择权限只能随机自己的商品
|
||
if ((BaseClass.UserAuthority.Contains("商品采集") || BaseClass.ParentAuthority.Contains("商品采集")) &&
|
||
!BaseClass.UserAuthority.Contains("货源选择") && BaseClass.SaLevel == 0)
|
||
{
|
||
cmbSourceType.Text = "多多商品,1688商品,微信商品";
|
||
cmbJstInitSet.Text = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnLoginAssistant_Click(object sender, EventArgs e)
|
||
{
|
||
WXSaleAssistantForm assistantForm = new WXSaleAssistantForm();
|
||
assistantForm.OpenType = "login";
|
||
assistantForm.InitUrl = "https://store.weixin.qq.com/talent/home";
|
||
assistantForm.ShowDialog();
|
||
lstWxSaleAssistantCookie = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<Cookie>>("wx_sale_assistant_cookies");
|
||
if (lstWxSaleAssistantCookie == null)
|
||
lstWxSaleAssistantCookie = new List<Cookie>();
|
||
}
|
||
|
||
private void txtFissionTitle_TextChanged(object sender, EventArgs e)
|
||
{
|
||
if (this.IsFormLoad)
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_prod_fission_title", txtFissionTitle.Text);
|
||
lblFissionTitleCount.Text = "标题数:" + txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList().Count();
|
||
}
|
||
|
||
private void btnSwitchCatType_Click(object sender, EventArgs e)
|
||
{
|
||
if (btnSwitchCatType.Text == "W")
|
||
{
|
||
btnSwitchCatType.Text = "P";
|
||
fillPddCate();
|
||
}
|
||
else
|
||
{
|
||
btnSwitchCatType.Text = "W";
|
||
fillWxCate();
|
||
}
|
||
}
|
||
|
||
private void chkSkipReplaceText_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (this.IsFormLoad)
|
||
{
|
||
wxUploadRule.IsSkipHasFilterWordsProd = chkSkipReplaceText.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
}
|
||
|
||
private void chkRemoveSpecialChar_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void chkIsSubmitSuccess_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void chkUseShanghaiReturnOrderAddress_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!IsFormLoad) return;
|
||
|
||
wxUploadRule.IsUseShanghaiReturnOrderAddress = chkUseShanghaiReturnOrderAddress.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
int globalShopUploadCntLimitRetryTimes = 5;
|
||
private void numJumpCnt_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
globalShopUploadCntLimitRetryTimes = numJumpCnt.Value.ParseToInt();
|
||
}
|
||
|
||
|
||
|
||
void SaveImageCacheOld(string spuId, Dictionary<string, string> wxImgMapOldDic)
|
||
{
|
||
//if (EnvironmentHelper.IsProduction)
|
||
//{
|
||
// return;
|
||
//}
|
||
|
||
//var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
||
//var data = "";
|
||
//Invoke(new Action(() =>
|
||
//{
|
||
// data = UserLogin.GetSignaturex();
|
||
// //data += "&spu_id=" + dbProd.spu_id;
|
||
// data += "&spu_id=" + spuId;
|
||
// data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapOldDic);
|
||
//}));
|
||
//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);
|
||
}
|
||
|
||
private void chkNotUploadShopProdMoreThan_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (IsFormLoad)
|
||
{
|
||
wxUploadRule.IsNotUploadShopProdMoreThan = chkNotUploadShopProdMoreThan.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
|
||
colOnSaleNum.Visible = wxUploadRule.IsNotUploadShopProdMoreThan;
|
||
}
|
||
}
|
||
|
||
private void numNotUploadShopProdMoreThan_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
if (IsFormLoad)
|
||
{
|
||
wxUploadRule.NotUploadShopProdMoreThan = numNotUploadShopProdMoreThan.Value.ParseToInt();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
}
|
||
|
||
private void chkRejectSevenDayReturn_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
RejectSevenDayReturn = chkRejectSevenDayReturn.Checked;
|
||
}
|
||
/// <summary>
|
||
/// 刷新服务端配置
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void btnLoadConfig_Click(object sender, EventArgs e)
|
||
{
|
||
InitUserConfig();
|
||
}
|
||
}
|
||
|
||
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 searchProductWithSpuId(ShopLoginInfo shop, string spuId)
|
||
{
|
||
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&spuId=" + spuId;
|
||
string refere = "https://store.weixin.qq.com/shop/goods/list";
|
||
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 brandId = "2100000000")
|
||
{
|
||
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"":" + brandId + "}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getMixBrand(ShopLoginInfo shop, string catId = "547591")
|
||
{
|
||
//{"code":0,"brandRequire":1,"bizuinBrandList":[{"brandId":"10914219","chName":"名圣","enName":"","classificationNo":"14","tradeMarkSymbol":1,"registerDetails":{"registrant":"广州哇晓商贸有限责任公司","registerNo":"88879184","startTime":"1786254874","endTime":"2098915200","isPermanent":false},"applicationDetails":{},"grantType":2,"grantDetails":{"grantCertifications":["1786181562555-oRVwX2XGcQYT_YI7RbfnMdcXF3Cs-1512"],"grantLevel":"1","startTime":"0","endTime":"1820332800","isPermanent":false,"brandOwnerType":2},"status":3,"createTime":"1786254883","updateTime":"1786359925","auditInfo":{"auditId":"11736892187","auditStatus":3,"auditTimestamp":1786359925,"submitTimestamp":1786254882},"version":1,"outsideShopType":0,"outsideShopNikename":"","isNewApply":1,"specialQualification":["1786181592374-oRVwX2XGcQYT_YI7RbfnMdcXF3Cs-3202"],"innerBrand":{"id":"10914219","name":"名圣","cnName":"名圣","enName":"","group":0,"certificateNumber":"88879184","status":0,"disableScene":0,"brandStoreName":"","brandLevel":1,"remark":"","brandLevelAuditStatus":2,"brandLevelAuditId":"11839403256"}},{"brandId":"10796790","chName":"嘉飞","enName":"","classificationNo":"21","tradeMarkSymbol":1,"registerDetails":{"registrant":"佛山曜叶科技有限公司","registerNo":"32799300","startTime":"1786019090","endTime":"1870732800","isPermanent":false},"applicationDetails":{},"grantType":2,"grantDetails":{"grantCertifications":["1786010853000-oRVwX2XGcQYT_YI7RbfnMdcXF3Cs-6420"],"grantLevel":"10001","startTime":"0","endTime":"1798560000","isPermanent":false,"brandOwnerType":2},"status":3,"createTime":"1786010877","updateTime":"1786019115","auditInfo":{"auditId":"11582110870","auditStatus":3,"auditTimestamp":1786019115,"submitTimestamp":1786019104},"version":3,"outsideShopType":0,"outsideShopNikename":"","isNewApply":0,"specialQualification":["1786010862808-oRVwX2XGcQYT_YI7RbfnMdcXF3Cs-7538"],"innerBrand":{"id":"10796790","name":"嘉飞","cnName":"嘉飞","enName":"","group":0,"certificateNumber":"32799300","status":0,"disableScene":0,"brandStoreName":"","brandLevel":1,"remark":"","brandLevelAuditStatus":2,"brandLevelAuditId":"8194702850"}}],"mixBrandList":[{"brandId":"10914219","chName":"名圣","enName":"","classificationNo":"14","tradeMarkSymbol":1,"registerDetails":{"registrant":"广州哇晓商贸有限责任公司","registerNo":"88879184","startTime":"1786254874","endTime":"2098915200","isPermanent":false},"applicationDetails":{},"grantType":2,"grantDetails":{"grantCertifications":["1786181562555-oRVwX2XGcQYT_YI7RbfnMdcXF3Cs-1512"],"grantLevel":"1","startTime":"0","endTime":"1820332800","isPermanent":false,"brandOwnerType":2},"status":3,"createTime":"1786254883","updateTime":"1786359925","auditInfo":{"auditId":"11736892187","auditStatus":3,"auditTimestamp":1786359925,"submitTimestamp":1786254882},"version":1,"outsideShopType":0,"outsideShopNikename":"","isNewApply":1,"specialQualification":["1786181592374-oRVwX2XGcQYT_YI7RbfnMdcXF3Cs-3202"],"innerBrand":{"id":"10914219","name":"名圣","cnName":"名圣","enName":"","group":0,"certificateNumber":"88879184","status":0,"disableScene":0,"brandStoreName":"","brandLevel":1,"remark":"","brandLevelAuditStatus":2,"brandLevelAuditId":"11839403256"}}],"categoryType":1}
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/getMixBrand?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = @"{""categoryId"":""" + catId + @"""}";
|
||
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 };
|
||
prodParam.type = 1;
|
||
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 checkProductUpload(ShopLoginInfo shop, string productId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/checkUploadProductDraftStatus?token=&lang=zh_CN&productKey=%7B%22productId%22:" +
|
||
productId + "%7D&preview=false";
|
||
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}";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string SearchProductUpload(ShopLoginInfo shop, string productId)
|
||
{
|
||
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&fromProductManager=1&pageNum=1&status[]=2&spuId=" + productId;
|
||
string referer = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_EDIT";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 店铺首页获取参数,包括是否开通优选联盟
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <returns></returns>
|
||
public static string GetAndUpdateWebStatus(ShopLoginInfo shop)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradehome/home/getAndUpdateWebStatus?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/home";
|
||
string body = @"{""timeQuery"":{""startMs"":" + BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-1)) +
|
||
@",""endMs"":" + BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddSeconds(-1)) + @"}}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string addLeagueItemForUpdatingProduct(ShopLoginInfo shop, int itemSwitch, int itemRatio, int headSupplierItemSwitch, int HeadSupplierItemRatio, long prodId, int updType = 2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/common/cgi/goods/addLeagueItemForUpdatingProduct?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/home";
|
||
string body = @"{""itemSwitch"":" + itemSwitch + @",""itemRatio"":" + itemRatio + @",""headSupplierPublicItemSwitch"":" + headSupplierItemSwitch +
|
||
@",""headSupplierPublicItemServiceRatio"":" + HeadSupplierItemRatio + @",""productId"":" + prodId + @",""scene"":2,""updType"":" + updType + @"}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
public static string generalProductInfoRecommend(ShopLoginInfo shop, WXUploadProductInfoRecommendParam recommendParam)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/aiRecommendCompat/cgi/goods/generalProductInfoRecommend?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + recommendParam.productId + "&isUpdateAuditFree=0&source=list_edit&continueEditInfo={%22isEditingContinued%22:false,%22lastEditDraftTime%22:0,%22listingTime%22:0}";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
string body = JsonConvert.SerializeObject(recommendParam, jsonSetting);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, 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 bool IsSkipHasFilterWordsProd { get; set; } = false;
|
||
|
||
public int SkuMinPrice { get; set; } = 10;
|
||
public int SkuMaxPrice { get; set; } = 9999;
|
||
|
||
public int WaitSeconds { get; set; } = 10;
|
||
|
||
public bool OnlyHighestPriceSku { get; set; } = false;
|
||
public bool OnlyLowestPriceSku { get; set; } = false;
|
||
public bool SameSpecSamePriceUp { get; set; } = false;
|
||
public bool SameSpecSamePriceDown { get; set; } = false;
|
||
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; }
|
||
|
||
/// <summary>
|
||
/// 上海仓退货
|
||
/// </summary>
|
||
public bool IsUseShanghaiReturnOrderAddress { get; set; } = false;
|
||
|
||
public bool IsNotUploadShopProdMoreThan { get; set; } = false;
|
||
public int NotUploadShopProdMoreThan { get; set; } = 500;
|
||
/// <summary>
|
||
/// 选中上传的商铺
|
||
/// </summary>
|
||
public List<string> SelectedShopIds { get; set; } = [];
|
||
}
|
||
|
||
|
||
class WaitingProductConfig : BindableBase
|
||
{
|
||
public WaitingProductConfig()
|
||
{
|
||
IdFilter = "";
|
||
SearchGoodsName = "";
|
||
SourceType = "厂商直采";
|
||
GroupFilter = "";
|
||
Hot = "普通商品";
|
||
WxSafe = "安全+未校验";
|
||
CateFilter1 = "全部";
|
||
CateFilter2 = "全部";
|
||
CateFilter3 = "全部";
|
||
Notes = "";
|
||
JstInitSet = "是";
|
||
AddCount = "500";
|
||
SkipQualification = false;
|
||
RandomFissionProduct = false;
|
||
RandomFissionProductCount = "100";
|
||
WXComplateProd = false;
|
||
UpdateInDaysChecked = false;
|
||
UpdateInDays = "30";
|
||
UpdateInDaysType = "新增";
|
||
FilterViewUvChecked = false;
|
||
FilterViewUv = 200m;
|
||
FilterSaleCountNumChecked = false;
|
||
FilterSaleCountNum = 1m;
|
||
}
|
||
|
||
/// <summary>
|
||
/// txtIdFilter
|
||
/// </summary>
|
||
public string IdFilter
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// txtSearchGoodsName
|
||
/// </summary>
|
||
public string SearchGoodsName
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbSourceType
|
||
/// </summary>
|
||
public string SourceType
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbGroupFilter
|
||
/// </summary>
|
||
public string GroupFilter
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbHot
|
||
/// </summary>
|
||
public string Hot
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbWxSafe
|
||
/// </summary>
|
||
public string WxSafe
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbCateFilter1
|
||
/// </summary>
|
||
public string CateFilter1
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbCateFilter2
|
||
/// </summary>
|
||
public string CateFilter2
|
||
{
|
||
get => GetValue<string>();
|
||
set => base.SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbCateFilter3
|
||
/// </summary>
|
||
public string CateFilter3
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbNotes
|
||
/// </summary>
|
||
public string Notes
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbJstInitSet
|
||
/// </summary>
|
||
public string JstInitSet
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// txtAddCount
|
||
/// </summary>
|
||
public string AddCount
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// chkSkipQualification
|
||
/// </summary>
|
||
public bool SkipQualification
|
||
{
|
||
get => GetValue<bool>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// chkRandomFissionProduct
|
||
/// </summary>
|
||
public bool RandomFissionProduct
|
||
{
|
||
get => GetValue<bool>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// txtRandomFissionProductCount
|
||
/// </summary>
|
||
public string RandomFissionProductCount
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// chkWXComplateProd
|
||
/// </summary>
|
||
public bool WXComplateProd
|
||
{
|
||
get => GetValue<bool>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// chkUpdateInDays
|
||
/// </summary>
|
||
public bool UpdateInDaysChecked
|
||
{
|
||
get => GetValue<bool>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// txtUpdateInDays
|
||
/// </summary>
|
||
public string UpdateInDays
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// cmbUpdateInDays
|
||
/// </summary>
|
||
public string UpdateInDaysType
|
||
{
|
||
get => GetValue<string>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// chkFilterViewUv
|
||
/// </summary>
|
||
public bool FilterViewUvChecked
|
||
{
|
||
get => GetValue<bool>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// numFilterViewUv
|
||
/// </summary>
|
||
public decimal FilterViewUv
|
||
{
|
||
get => GetValue<decimal>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// chkFilterSaleCountNum
|
||
/// </summary>
|
||
public bool FilterSaleCountNumChecked
|
||
{
|
||
get => GetValue<bool>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// numFilterSaleCountNum
|
||
/// </summary>
|
||
public decimal FilterSaleCountNum
|
||
{
|
||
get => GetValue<decimal>();
|
||
set => SetValue(value);
|
||
}
|
||
|
||
public void Assign(WaitingProductConfig config)
|
||
{
|
||
if (config == null || ReferenceEquals(config, this)) return;
|
||
|
||
IdFilter = config.IdFilter;
|
||
SearchGoodsName = config.SearchGoodsName;
|
||
SourceType = config.SourceType;
|
||
GroupFilter = config.GroupFilter;
|
||
Hot = config.Hot;
|
||
WxSafe = config.WxSafe;
|
||
CateFilter1 = config.CateFilter1;
|
||
CateFilter2 = config.CateFilter2;
|
||
CateFilter3 = config.CateFilter3;
|
||
Notes = config.Notes;
|
||
JstInitSet = config.JstInitSet;
|
||
AddCount = config.AddCount;
|
||
SkipQualification = config.SkipQualification;
|
||
RandomFissionProduct = config.RandomFissionProduct;
|
||
RandomFissionProductCount = config.RandomFissionProductCount;
|
||
WXComplateProd = config.WXComplateProd;
|
||
UpdateInDaysChecked = config.UpdateInDaysChecked;
|
||
UpdateInDays = config.UpdateInDays;
|
||
UpdateInDaysType = config.UpdateInDaysType;
|
||
FilterViewUvChecked = config.FilterViewUvChecked;
|
||
FilterViewUv = config.FilterViewUv;
|
||
FilterSaleCountNumChecked = config.FilterSaleCountNumChecked;
|
||
FilterSaleCountNum = config.FilterSaleCountNum;
|
||
}
|
||
}
|
||
}
|