1615 lines
79 KiB
C#
1615 lines
79 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Result;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net.Http;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.ToolForms;
|
||
using Work;
|
||
using TemuKJD.BLL;
|
||
using System.Text.RegularExpressions;
|
||
using TemuKJD.PDDForms.ProductSelectForms;
|
||
using TemuKJD.WXForms.ShopForms;
|
||
using AllBase.Model.Result.PDDResult;
|
||
using AllBase.Model.Param.WXParam;
|
||
using AllBase.Model.Result.WXResult;
|
||
using Newtonsoft.Json;
|
||
using NaiBa.Util;
|
||
using AllBase.Model.Config;
|
||
|
||
namespace TemuKJD.WXForms.ProductForms
|
||
{
|
||
public partial class WXProdPreSaleForm : BaseForm
|
||
{
|
||
int PageBegin = 1;
|
||
int PageEnd = 999;
|
||
string PreType = "";
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
public bool IsLoadComplate { get; set; } = false;
|
||
|
||
bool isInit = false;
|
||
CheckBox chkSelectAll = null;
|
||
ConcurrentList<AuthInfo> lstShopAuthInfo = new ConcurrentList<AuthInfo>();
|
||
ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
public NaiBa.Util.ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
|
||
NaiBa.Util.ConcurrentList<AddPriceRule> lstAddPriceRule = new NaiBa.Util.ConcurrentList<AddPriceRule>();
|
||
AddPriceRule defaultAddPriceRule = null;
|
||
WXUploadRule wxUploadRule = null;
|
||
//public Dictionary<string, List<string>> dicCheckedShopIdList = new Dictionary<string, List<string>>();
|
||
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
|
||
public Dictionary<string, WxShopUploadInfo> dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
|
||
public string pdd_product_cates = "";
|
||
public List<string> forceFilteKeyWords = new List<string>()
|
||
{
|
||
"亏本", "冲量", "白菜价", "跳楼价", "xxx", "xx", "最大", "最小", "低价", "降价", "成本", "赔钱", "甩卖",
|
||
"真丝", "蚕丝", "香云纱", "羊绒", "羊毛", "羊羔绒", "羊羔毛", "羽绒", "皮草"
|
||
};
|
||
public WXProdPreSaleForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
|
||
{
|
||
this.splitContainer1.Dock = DockStyle.Fill;
|
||
|
||
lstShopAuthInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<AuthInfo>>("wx_shop_auth_list");
|
||
if (lstShopAuthInfo == null)
|
||
lstShopAuthInfo = new ConcurrentList<AuthInfo>();
|
||
|
||
lstWXShopTokenInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<WXShopTokenInfo>>("wx_shop_token_list");
|
||
if (lstWXShopTokenInfo == null)
|
||
lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
|
||
lstTemuDBProductSelect = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<TemuDBProductSelect>>("wx_db_prod_upload_list");
|
||
if (lstTemuDBProductSelect == null)
|
||
lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
|
||
|
||
lstAddPriceRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.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 });
|
||
}
|
||
|
||
dicCheckedShopId = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, bool>>("wx_checked_shop_dic");
|
||
if (dicCheckedShopId == null)
|
||
dicCheckedShopId = new Dictionary<string, bool>();
|
||
dicShopUpload = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, WxShopUploadInfo>>("wx_shop_upload_info");
|
||
if (dicShopUpload == null)
|
||
dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
|
||
|
||
defaultAddPriceRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<AddPriceRule>("wx_default_add_price_rule");
|
||
if (defaultAddPriceRule == null)
|
||
{
|
||
defaultAddPriceRule = new AddPriceRule() { AddPriceTimes = 1.3m, AddMorePrice = 1, SinglePriceAdd = 1 };
|
||
}
|
||
|
||
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.chkPreSale.CheckedChanged -= chkPreSale_CheckedChanged;
|
||
this.chkNoPreSale.CheckedChanged -= chkNoPreSale_CheckedChanged;
|
||
|
||
this.txtPreDays.Text = wxUploadRule.PreSaleDays.ParseToString();
|
||
this.chkPreSale.Checked = wxUploadRule.IsPreSale.ParseToBool();
|
||
this.chkNoPreSale.Checked = !wxUploadRule.IsPreSale.ParseToBool();
|
||
|
||
this.txtPreDays.TextChanged += txtPreDays_TextChanged;
|
||
this.chkPreSale.CheckedChanged += chkPreSale_CheckedChanged;
|
||
this.chkNoPreSale.CheckedChanged += chkNoPreSale_CheckedChanged;
|
||
|
||
int prodCount = 0;
|
||
|
||
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;
|
||
|
||
//foreach (var selectProd in upload_draft_product_lst)
|
||
//{
|
||
// int rowIndex = 0;
|
||
// this.dgvSelectProduct.Rows.Insert(rowIndex,
|
||
// true,
|
||
// selectProd.id,
|
||
// selectProd.shop_id,
|
||
// selectProd.shop_account,
|
||
// "登录",
|
||
// "进店",
|
||
// BaseClass.SaLevel > 0 ? selectProd.spu_id : selectProd.spu_id.ParseToString().GetHashCode().ParseToString().Trim('-'),
|
||
// selectProd.skc_id,
|
||
// selectProd.main_img,
|
||
// DataGridViewExtension.defaultBitmap,
|
||
// "",
|
||
// null,
|
||
// selectProd.product_name, // 用户端显示商品原名
|
||
// selectProd.cat_name,
|
||
// BaseClass.SaLevel > 0 ? selectProd.ext_code : selectProd.ext_code.ParseToString().GetHashCode().ParseToString().Trim('-'),
|
||
// selectProd.status,
|
||
// selectProd.draft_id,
|
||
// selectProd.notes,
|
||
// (selectProd.user_notes + " 编辑").Trim(),
|
||
// "删除",
|
||
// selectProd.add_time.ToString("yy-MM-dd HH:mm:ss"),
|
||
// "");
|
||
|
||
// dgvSelectProduct.Rows[rowIndex].Height = 60;
|
||
|
||
// int maxRowCount = 10000;
|
||
// while (dgvSelectProduct.Rows.Count > maxRowCount)
|
||
// {
|
||
// dgvSelectProduct.Rows.RemoveAt(maxRowCount);
|
||
// }
|
||
//}
|
||
|
||
//#if DEBUG
|
||
if (BaseClass.SaLevel == 1)
|
||
{
|
||
//txtIdFilter.Visible = true;
|
||
//txtExtCodeFilter.Visible = true;
|
||
//lblIdFilter.Visible = true;
|
||
//lblExtCodeFilter.Visible = true;
|
||
}
|
||
//#endif
|
||
IsLoadComplate = true;
|
||
}
|
||
|
||
private void btnRefreshAuthor_Click(object sender, EventArgs e)
|
||
{
|
||
updateAuthor(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 升级授权
|
||
/// </summary>
|
||
/// <param name="idRefreshTodayHasGet">今日取过的也取</param>
|
||
private void updateAuthor(bool idRefreshTodayHasGet = false)
|
||
{
|
||
this.pbLoadingShop.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
// 店铺Id
|
||
var updateIds = dgvShop.Rows.Cast<DataGridViewRow>().Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (idRefreshTodayHasGet == true)
|
||
updateIds = selectIds;
|
||
|
||
List<Task> tList = new List<Task>();
|
||
if (idRefreshTodayHasGet)
|
||
lstShopAuthInfo.RemoveAll(s => updateIds.Contains(s.ShopId));
|
||
foreach (var shop in GlobalConfig.ShopLoginList.Where(s => updateIds.Contains(s.ShopId)))
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, ""); }));
|
||
var t = Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
return;
|
||
}
|
||
|
||
var authInfo = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||
if (idRefreshTodayHasGet || authInfo == null || authInfo?.AddTime.Date != DateTime.Now.Date)
|
||
{
|
||
lstShopAuthInfo.RemoveAll(sa => sa.ShopId == shop.ShopId);
|
||
var rst = WXUpload.GetApiServiceList(shop);
|
||
if (!rst.Contains("\"code\":0"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
return;
|
||
}
|
||
|
||
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = DateTime.Now });
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "授权查询失败"); }));
|
||
return;
|
||
}
|
||
|
||
foreach (var itemObj in JsonHelper.JObjectParse(rst)["itemList"])
|
||
{
|
||
// 找到了指定服务
|
||
if (itemObj["serviceName"].ParseToString() == "店统领供应链-商品管理")
|
||
{
|
||
var expiresTick = itemObj["expireTime"].ParseToLong();
|
||
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = BaseClass.StampToDateTime(expiresTick.ParseToInt()) });
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
|
||
return;
|
||
}
|
||
}
|
||
// 没找到指定服务
|
||
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, AddTime = DateTime.Now, ExpiresTime = DateTime.Now });
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
});
|
||
tList.Add(t);
|
||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 20) { Thread.Sleep(100); }
|
||
}
|
||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 1) { Thread.Sleep(100); }
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig( "wx_shop_auth_list", lstShopAuthInfo);
|
||
Invoke(new Action(() => { pbLoadingShop.Visible = false; }));
|
||
});
|
||
}
|
||
|
||
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!chkSelectAll.Checked)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//var list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus == "登录成功").Select(ss => ss.ShopId);
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
//if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
|
||
if(row.Visible == true)
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
|
||
foreach (var r in dgvShop.Rows.Cast<DataGridViewRow>())
|
||
{
|
||
dicCheckedShopId[r.Cells["colShopId"].Value.ParseToString()] = r.Cells["colSelect"].Value.ParseToBool();
|
||
}
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
|
||
}
|
||
|
||
private void btnRefreshShop_Click(object sender, EventArgs e)
|
||
{
|
||
pbLoadingShop.Visible = true;
|
||
RefreshDbProd();
|
||
RefreshShopAuth();
|
||
}
|
||
|
||
private void UserSelectDbProductForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (Visible == true)
|
||
{
|
||
RefreshShopAuth();
|
||
updateAuthor();
|
||
RefreshDbProd();
|
||
|
||
if (!isInit)
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||
{
|
||
//if (shop.LoginStatus == "登录成功")
|
||
//{
|
||
// var rst = WXUpload.scanProductPreview(shop);
|
||
// if (!rst.Contains("\"code\":0") && !rst.Contains("\"success\":true"))
|
||
// {
|
||
// WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
// }
|
||
//}
|
||
}
|
||
|
||
});
|
||
}
|
||
|
||
isInit = true;
|
||
}
|
||
}
|
||
|
||
private void RefreshDbProd()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbLoadingShop.Visible = false;
|
||
}));
|
||
});
|
||
}
|
||
|
||
private void RefreshShopAuth()
|
||
{
|
||
// 店铺Id
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
// 获取被删除的店铺
|
||
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||
// 更新被删除的店铺列表
|
||
foreach (var row in dgvRowList)
|
||
{
|
||
dgvShop.Rows.Remove(row);
|
||
}
|
||
// 绑定其他店铺(含新导入的店铺)
|
||
foreach (ShopLoginInfo shopEntity in GlobalConfig.ShopLoginList)
|
||
{
|
||
if (!string.IsNullOrEmpty(shopEntity.ShopId))
|
||
BindShop(shopEntity, selectIds);
|
||
}
|
||
cmbFilterShopNotes.Items.Clear();
|
||
//cmbFilterShopNotes.Items.Add("");
|
||
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopNotes.Items.Add(note);
|
||
}
|
||
}
|
||
|
||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
|
||
{
|
||
if (shopEntity == null)
|
||
return;
|
||
if (selectShopId == null)
|
||
selectShopId = new List<string>();
|
||
|
||
bool canUse = shopEntity.LoginStatus == "登录成功";
|
||
//canUse = true; // 内部库不需要校验登录状态
|
||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
|
||
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
|
||
if (row == null)
|
||
{
|
||
this.dgvShop.Rows.Add(
|
||
//!isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse),
|
||
dicCheckedShopId.Keys.Contains(shopEntity.ShopId) && dicCheckedShopId[shopEntity.ShopId] == true,
|
||
shopEntity.LoginName,
|
||
shopEntity.ShopId,
|
||
shopEntity.ShopAccount,
|
||
shopEntity.Notes,
|
||
"选择商品",
|
||
canUse ? "在线" : "掉线",
|
||
lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
|
||
canUse,
|
||
dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
|
||
dicShopUpload[shopEntity.ShopId].DicDayUploadCount[day] : 0,
|
||
dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
|
||
dicShopUpload[shopEntity.ShopId].OnSaleCount : 0,
|
||
shopEntity.AddProductRemaining,
|
||
msg
|
||
);
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = !isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse);
|
||
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
|
||
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
|
||
row.Cells["colShopNotes"].Value = shopEntity.Notes;
|
||
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
|
||
row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
|
||
row.Cells["colCanUse"].Value = canUse;
|
||
row.Cells["colApi"].Value = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期";
|
||
row.Cells["colRemaining"].Value = shopEntity.AddProductRemaining;
|
||
row.Cells["colUploadCount"].Value = dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
|
||
dicShopUpload[shopEntity.ShopId].DicDayUploadCount[day] : 0;
|
||
row.Cells["colOnSaleNum"].Value = dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
|
||
dicShopUpload[shopEntity.ShopId].OnSaleCount : 0;
|
||
row.Cells["colMessage"].Value = msg;
|
||
}
|
||
|
||
displayAuthStatus(shopEntity);
|
||
}
|
||
|
||
void displayAuthStatus(ShopLoginInfo shop)
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ParseToString() == shop?.ShopId);
|
||
foreach (var row in rows)
|
||
{
|
||
bool canUse = row.Cells["colLoginStatus"].Value.ParseToString() == "在线";
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
|
||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
|
||
canUse = row.Cells["colApi"].Value.ParseToString() == "可用";
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
|
||
(row.Cells["colApi"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
|
||
}
|
||
}
|
||
|
||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
|
||
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
|
||
string shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
|
||
string shopAccount = dgvShop.Rows[e.RowIndex].Cells["colShopName"].Value.ToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
|
||
var row = dgvShop.Rows[e.RowIndex];
|
||
switch (columnName)
|
||
{
|
||
case "colSelect":
|
||
//if (row.Cells["colCanUse"].Value.ParseToBool())
|
||
{
|
||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
|
||
chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
|
||
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
|
||
chkSelectAll.Checked = true;
|
||
else
|
||
chkSelectAll.Checked = false;
|
||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
}
|
||
//else
|
||
{
|
||
//BaseMsgForm.ShowInfo("店铺未登录!");
|
||
}
|
||
|
||
dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
|
||
break;
|
||
case "colLoginStatus":
|
||
{
|
||
if (WXShopListForm.Instance == null)
|
||
WXShopListForm.Instance = new WXShopListForm();
|
||
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
//shopLoginForm.prodUserSelectForm = this;
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopAuth();
|
||
}
|
||
else
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.Show();
|
||
}
|
||
}
|
||
break;
|
||
case "colApi":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139";
|
||
shopLoginForm.Show();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (lstShopId.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择店铺!");
|
||
return;
|
||
}
|
||
}
|
||
|
||
private void dgvSelectProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvSelectProduct.Columns[e.ColumnIndex].HeaderText;
|
||
var dbId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSelectId"].Value.ParseToString();
|
||
var dbProduct = lstTemuDBProductSelect.FirstOrDefault(p => p.id.ToString() == dbId);
|
||
var shopId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
||
var draftId = dgvSelectProduct.Rows[e.RowIndex].Cells["colDraftId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
|
||
switch (headerText)
|
||
{
|
||
case "删除":
|
||
break;
|
||
case "登录":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
//shopLoginForm.prodUserSelectForm = this;
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopAuth();
|
||
}
|
||
break;
|
||
case "进店":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus == "登录成功")
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home";
|
||
shopLoginForm.Show();
|
||
}
|
||
else
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopAuth();
|
||
}
|
||
}
|
||
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 btnSetPreSale_Click(object sender, EventArgs e)
|
||
{
|
||
var rowLst = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
|
||
if (rowLst.Count <= 0)
|
||
{
|
||
BaseMsgForm.ShowError("请勾选需要操作的商品!");
|
||
return;
|
||
}
|
||
|
||
this.pbLoading.Visible = true;
|
||
this.btnSetPreSale.Enabled = false;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
SetProdPre(rowLst);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "商品设置完毕";
|
||
BaseMsgForm.ShowInfo("商品设置完毕");
|
||
this.pbLoading.Visible = false;
|
||
this.btnSetPreSale.Enabled = true;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
|
||
}
|
||
|
||
void SetProdPre(List<DataGridViewRow> rowLst)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在设置" + "...".Substring(0, DateTime.Now.Second % 4);
|
||
this.statusBar.pgbTaskProgress.Maximum = dgvSelectProduct.Rows.Count;
|
||
this.statusBar.UpdateProgressBar(0);
|
||
}));
|
||
|
||
foreach (var row in rowLst)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "";
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var prodId = row.Cells["colDraftId"].Value.ParseToString();
|
||
var shopId = row.Cells["colSupplierId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺不存在";
|
||
}));
|
||
continue;
|
||
}
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺掉线";
|
||
}));
|
||
continue;
|
||
}
|
||
//shop = new ShopLoginInfo();
|
||
var getEditProdRst = WXUpload.getEditProductV2(shop, prodId);
|
||
Thread.Sleep(Randomx.GetId(50, 100));
|
||
if(getEditProdRst.Contains("biz magic invalid"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
}
|
||
if (!getEditProdRst.Contains("\"success\":true"))
|
||
{
|
||
var errmsg = BaseRegex.GetStringJson(ref getEditProdRst, "msg");
|
||
if (string.IsNullOrWhiteSpace(errmsg))
|
||
errmsg = getEditProdRst;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = errmsg;
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
string productJson = "";
|
||
try
|
||
{
|
||
// 获取免审编辑回传数据
|
||
JObject jObjTmp = JsonHelper.JObjectParse(getEditProdRst);
|
||
jObjTmp["product"]["deliverInfo"]["skuDeliverInfo"]["fullPaymentPresaleDeliveryTime"] = chkPreSale.Checked ? txtPreDays.Text.Trim().ParseToInt() : 0;
|
||
jObjTmp["product"]["deliverInfo"]["deliverType"] = chkPreSale.Checked ? 1 : 0;
|
||
jObjTmp["product"]["info"]["presaleTag"] = chkPreSale.Checked ? 1 : 0;
|
||
jObjTmp["product"]["info"]["presaleTagType"] = chkPreSale.Checked ? 1 : 0;
|
||
productJson = JsonHelper.SerializeObject(jObjTmp);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = ex.Message;
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
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 listingAuditFreeRst = WXUpload.listingAuditFree(shop, productJson, prodId, time1, time2);
|
||
if (!listingAuditFreeRst.Contains("\"code\":0"))
|
||
{
|
||
var errmsg = BaseRegex.GetStringJson(ref listingAuditFreeRst, "msg");
|
||
if (string.IsNullOrWhiteSpace(errmsg))
|
||
errmsg = listingAuditFreeRst;
|
||
if (errmsg.Contains("107232"))
|
||
errmsg = "图片不清晰禁止预售操作";
|
||
if (errmsg.Contains("9401083"))
|
||
errmsg = "店铺处罚中禁止操作";
|
||
|
||
if (getEditProdRst.Contains("biz magic invalid"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺掉线";
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
if (/*chkPreSale.Checked &&*/ chkFailDownProd.Checked)
|
||
{
|
||
var downProd = WXPreSale.DownProd(shop, prodId.ParseToLong());
|
||
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
|
||
if (downProd.Contains("\"code\":0"))
|
||
{
|
||
errmsg += " 预售设置失败 已下架";
|
||
}
|
||
else
|
||
errmsg += " 预售设置失败 下架失败";
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = errmsg;
|
||
}));
|
||
continue;
|
||
}
|
||
if (listingAuditFreeRst.Contains("\"code\":0"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "设置成功";
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.cancellationTokenSource != null)
|
||
this.cancellationTokenSource.Cancel();
|
||
}
|
||
|
||
private void btnSearchProd_Click(object sender, EventArgs e)
|
||
{
|
||
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
if (shopIdLst.Count <= 0)
|
||
{
|
||
BaseMsgForm.ShowError("未勾选上传店铺!");
|
||
return;
|
||
}
|
||
btnSearchProd.Enabled = false;
|
||
pbLoading.Visible = true;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
dgvSelectProduct.Rows.Clear();
|
||
Task.Run(() =>
|
||
{
|
||
GetProduct(shopIdLst);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "商品查询完毕";
|
||
BaseMsgForm.ShowInfo("商品查询完毕");
|
||
pbLoading.Visible = false;
|
||
btnSearchProd.Enabled = true;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
void GetProduct(List<string> shopIdLst)
|
||
{
|
||
List<ShopLoginInfo> shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
|
||
foreach(var shop in shopLst)
|
||
{
|
||
if(cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
continue;
|
||
}
|
||
|
||
int page = PageBegin - 1;
|
||
int totalPage = 1;
|
||
int pageSize = 50;
|
||
string nextKey = "";
|
||
while (page < totalPage && page < PageEnd)
|
||
{
|
||
page++;
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
string getProdOnSaleRst = "";
|
||
|
||
if (string.IsNullOrEmpty(PreType))
|
||
getProdOnSaleRst = WXPreSale.scanProductPreview(shop, page, nextKey, pageSize);
|
||
else
|
||
getProdOnSaleRst = WXPreSale.searchPreProduct(shop, page, PreType == "预售" ? 1 : 0, pageSize);
|
||
Thread.Sleep(Randomx.GetId(50, 100));
|
||
if (!getProdOnSaleRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getProdOnSaleRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getProdOnSaleRst;
|
||
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, shopIdLst, "店铺掉线"); }));
|
||
}
|
||
|
||
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||
Invoke(new Action(() => {
|
||
if (shopRow != null)
|
||
{
|
||
shopRow.Cells["colMsg"].Value = error;
|
||
}
|
||
}));
|
||
break;
|
||
}
|
||
|
||
try
|
||
{
|
||
var prodObjs = JsonHelper.JObjectParse(getProdOnSaleRst);
|
||
if (page == 1)
|
||
{
|
||
var totalNum = prodObjs["totalNum"].ParseToInt();
|
||
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
|
||
nextKey = prodObjs["nextKey"].ParseToString();
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在查询店铺:" + shop.ShopAccount + " " + page + "/" + Math.Min(PageEnd, totalPage);
|
||
//this.statusBar.pgbTaskProgress.Maximum = lstTemuDBProductSelect.Count;
|
||
//this.statusBar.UpdateProgressBar(0);
|
||
}));
|
||
foreach (JObject prod in prodObjs["productList"])
|
||
{
|
||
var pStr = JsonHelper.SerializeObject(prod);
|
||
Invoke(new Action(() =>
|
||
{
|
||
decimal? price = null;
|
||
try { price = prod["skuList"][0]["price"].ParseToDecimal() / 100; } catch { }
|
||
var prodId = prod["productId"].ParseToString();
|
||
if (dgvSelectProduct.Rows.Cast<DataGridViewRow>().Any(r => r.Cells["colDraftId"].ParseToString() == prodId))
|
||
{
|
||
|
||
}
|
||
|
||
var rowIndex = this.dgvSelectProduct.Rows.Add(
|
||
false,
|
||
"",
|
||
shop.ShopId,
|
||
shop.ShopAccount,
|
||
"登录",
|
||
"进店",
|
||
"",
|
||
"",
|
||
prod["productId"].ParseToString(),
|
||
prod["headImg"].ParseToString(),
|
||
DataGridViewExtension.defaultBitmap,
|
||
"", // 替换图地址
|
||
null, // 替换图
|
||
prod["title"].ParseToString(), // 用户端显示商品原名
|
||
(prod["recommendCategory"].IsJTokenNullOrEmpty() || prod["recommendCategory"]["categoryNames"].IsJTokenNullOrEmpty()) ?
|
||
"" : string.Join(" >> ", prod["recommendCategory"]["categoryNames"].Select(s => s.ParseToString())), // 类目名称
|
||
prod["spuCode"].ParseToString(),
|
||
//price,
|
||
prod["price"].ParseToDecimal() * 0.01m,
|
||
prod["soldNum"].ParseToInt(),
|
||
"在售" + (prod["presaleTag"].ParseToInt() == 1 ? "[预售]" : ""),
|
||
"", // 备注
|
||
"",
|
||
"删除",
|
||
BaseClass.StampToDateTime(prod["lastEditDraftTime"].ParseToInt()).ToString("yy-MM-dd HH:mm"),
|
||
"");
|
||
|
||
dgvSelectProduct.Rows[rowIndex].Height = 60;
|
||
dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Style.ForeColor = dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Value.ParseToString().Contains("预售") ? Color.Orange : Color.Blue;
|
||
}));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnClearDgv_Click(object sender, EventArgs e)
|
||
{
|
||
var rows = this.dgvSelectProduct.Rows.Cast<DataGridViewRow>().ToList(); //Cast后Rows做foreach循环时仍会夹花跳过,所以要ToList转一个新的数组。
|
||
foreach (var row in rows)
|
||
{
|
||
if (row.Cells["colCheck"].Value.ParseToBool() == true)
|
||
{
|
||
//var draft_id = row.Cells["colDraftId"].Value.ParseToString();
|
||
//upload_draft_product_lst.RemoveAll(p => p.draft_id == draft_id);
|
||
|
||
this.dgvSelectProduct.Rows.Remove(row);
|
||
}
|
||
}
|
||
//NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
}
|
||
|
||
private void btnClearFilter_Click(object sender, EventArgs e)
|
||
{
|
||
txtIdFilter.Text = "";
|
||
txtExtCodeFilter.Text = "";
|
||
txtProductName.Text = "";
|
||
}
|
||
|
||
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 chkPreSale_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
chkNoPreSale.Checked = !chkPreSale.Checked;
|
||
|
||
wxUploadRule.IsPreSale = chkPreSale.Checked;
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_upload_rule", wxUploadRule);
|
||
}
|
||
|
||
private void btnFilterShop_Click(object sender, EventArgs e)
|
||
{
|
||
foreach(DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
{
|
||
row.Visible = false;
|
||
row.Cells["colSelect"].Value = false;
|
||
continue;
|
||
}
|
||
if (!row.Cells["colShopNotes"].Value.ParseToString().Contains(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
{
|
||
row.Visible = false;
|
||
row.Cells["colSelect"].Value = false;
|
||
continue;
|
||
}
|
||
row.Visible = true;
|
||
}
|
||
}
|
||
|
||
private void btnEmptyShop_Click(object sender, EventArgs e)
|
||
{
|
||
txtFilterShopName.Text = "";
|
||
cmbFilterShopNotes.Text = "全部";
|
||
btnFilterShop_Click(null, null);
|
||
}
|
||
|
||
private void btnReverse_Click(object sender, EventArgs e)
|
||
{
|
||
foreach(DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
}
|
||
}
|
||
|
||
private void btnAddSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
|
||
(row.Cells["colShopNotes"].Value.ParseToString().Contains(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnAddUnSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
|
||
(row.Cells["colShopNotes"].Value.ParseToString().Contains(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectOnline_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colLoginStatus"].Value.ParseToString() == "在线")
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectOffline_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colLoginStatus"].Value.ParseToString() != "在线")
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void txtPageBegin_TextChanged(object sender, EventArgs e)
|
||
{
|
||
PageEnd = txtPageBegin.Text.ParseToInt();
|
||
}
|
||
|
||
private void txtPageEnd_TextChanged(object sender, EventArgs e)
|
||
{
|
||
PageEnd = txtPageEnd.Text.ParseToInt();
|
||
}
|
||
|
||
private void chkNoPreSale_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (chkNoPreSale.Checked)
|
||
chkPreSale.Checked = false;
|
||
else
|
||
chkPreSale.Checked = true;
|
||
}
|
||
|
||
private void btnSelectPre_Click(object sender, EventArgs e)
|
||
{
|
||
foreach(DataGridViewRow row in dgvSelectProduct.Rows)
|
||
{
|
||
Invoke(new Action(() => { }));
|
||
}
|
||
}
|
||
|
||
private void cmbPreType_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
PreType = cmbPreType.Text.Trim();
|
||
}
|
||
|
||
private void btnDown_Click(object sender, EventArgs e)
|
||
{
|
||
var rowLst = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
|
||
if (rowLst.Count <= 0)
|
||
{
|
||
BaseMsgForm.ShowError("请勾选需要操作的商品!");
|
||
return;
|
||
}
|
||
|
||
this.pbLoading.Visible = true;
|
||
this.btnSetPreSale.Enabled = false;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
SetProdDown(rowLst);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "商品下架完毕";
|
||
BaseMsgForm.ShowInfo("商品下架完毕");
|
||
this.pbLoading.Visible = false;
|
||
this.btnSetPreSale.Enabled = true;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
|
||
}
|
||
|
||
void SetProdDown(List<DataGridViewRow> rowLst)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在下架" + "...".Substring(0, DateTime.Now.Second % 4);
|
||
this.statusBar.pgbTaskProgress.Maximum = dgvSelectProduct.Rows.Count;
|
||
this.statusBar.UpdateProgressBar(0);
|
||
}));
|
||
|
||
foreach (var row in rowLst)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "";
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var prodId = row.Cells["colDraftId"].Value.ParseToString();
|
||
var shopId = row.Cells["colSupplierId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺不存在";
|
||
}));
|
||
continue;
|
||
}
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺掉线";
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
var downProdRst = WXPreSale.DownProd(shop, prodId.ParseToLong());
|
||
System.Threading.Thread.Sleep(Randomx.GetId(200, 500));
|
||
if (!downProdRst.Contains("\"code\":0"))
|
||
{
|
||
if (downProdRst.Contains("biz magic invalid"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺掉线";
|
||
}));
|
||
continue;
|
||
}
|
||
}
|
||
|
||
var errmsg = BaseRegex.GetStringJson(ref downProdRst, "msg");
|
||
if (string.IsNullOrWhiteSpace(errmsg))
|
||
errmsg = downProdRst;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = errmsg;
|
||
}));
|
||
}
|
||
|
||
if (downProdRst.Contains("\"code\":0"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "下架成功";
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnFiltSelect_Click(object sender, EventArgs e)
|
||
{
|
||
foreach(DataGridViewRow row in dgvSelectProduct.Rows)
|
||
{
|
||
if (row.Cells["colSoldNum"].Value.ParseToInt() >= txtFiltSaleNum.Text.Trim().ParseToInt())
|
||
row.Cells["colCheck"].Value = false;
|
||
else
|
||
row.Cells["colCheck"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
public class WXPreSale
|
||
{
|
||
public static string searchPreProduct(ShopLoginInfo shop, int pageNum, int presaleType = 1, int pageSize = 50)
|
||
{
|
||
//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=44&status[]=5&presaleType[]=1
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/searchProduct?token=&lang=zh_CN&" +
|
||
"pageSize=" + pageSize + "&productStatus[]=-1&productSource=[1,16,32]&searchSource=1&useNew=true&pageNum=" + pageNum + "&status[]=5&presaleType[]=" + presaleType;
|
||
|
||
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 scanProductPreview(ShopLoginInfo shop, int page, string nextKey = "", int pageSize = 50)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/scanProductPreview?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_ON";
|
||
if (page > 1)
|
||
referer = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_ON¤tPage=" + page;
|
||
//string body = @"{""pageSize"":20,""productStatus"":[-1],""productSource"":""[1,16,32]"",""searchSource"":1,""useNew"":true,""pageNum"":1,""status"":[5]}";
|
||
//string body = @"{""pageSize"":20,""productStatus"":[-1],""productSource"":""[1,16,32]"",""searchSource"":1,""useNew"":true,""pageNum"":2,""status"":[5],""nextKey"":""ChwItc+24YajAhCD14bMBhjqLiDoDCgAMITXhswGEhwIy8im34ajAhCa74XMBhiaXyDeBygAMJrvhcwGGAEgeiiIEw==""}";
|
||
string body = @"{""pageSize"":" + pageSize + @",""productStatus"":[-1],""productSource"":""[1,16,32]"",""searchSource"":1,""useNew"":true,""pageNum"":" + page +
|
||
@",""status"":[5],""nextKey"":""" + nextKey + @"""}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string DownProd(ShopLoginInfo shop, long prodId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductlist/cgi/goods/BatchUnListing?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/list";
|
||
string body = @"{""ids"":[" + prodId + @"],""uploadSource"":6}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getUploadTempImgAuth(ShopLoginInfo shop, int uploadScene = 3)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecchannelspicture/cgi/getUploadTempImgAuth?token=&lang=zh_CN&uploadScene=" + uploadScene;
|
||
string refere = "https://store.weixin.qq.com/shop/goods/entry";
|
||
//{"code":0,"disK":"538c14e950da7b678ce9f5a12658c8acddd09e4b","disT":1767870926,"ext":"23aa0ecfb792a","url":"https://westore.video.qq.com/adtimageupload"}
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, refere);
|
||
return result;
|
||
}
|
||
|
||
public static string adtimageupload(ShopLoginInfo shop, string imgBase64, string dis_k, long dis_t, string ext)
|
||
{
|
||
string url = "https://westorealpha.video.qq.com/adtimageupload";
|
||
string referer = "https://store.weixin.qq.com/";
|
||
string body = imgBase64;
|
||
var result = WXHttpResponseBLL.WeiXinImgPostResponse(shop, url, body, dis_k, dis_t, ext, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getProductClassify(ShopLoginInfo shop, string goodsName, List<string> goodImgUrlsLst)
|
||
{
|
||
string boundaryLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||
string boundaryStr = "----WebKitFormBoundary";
|
||
for (int i = 0; i < 16; i++)
|
||
{
|
||
boundaryStr += boundaryLetters[Randomx.GetId(boundaryLetters.Length)];
|
||
}
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/cgi/common/productClassify?from=B&title=" + GetHtml.UrlEncodeUtf8(goodsName) + "&token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
|
||
string body = @"--" + boundaryStr + @"
|
||
";
|
||
foreach (var imgFullPath in goodImgUrlsLst)
|
||
{
|
||
string fileName = imgFullPath.Split('\\').LastOrDefault();
|
||
body += @"Content-Disposition: form-data; name=""file""; filename=""" + fileName + @"""
|
||
Content-Type: image/jpeg
|
||
|
||
<!>" + imgFullPath + @"<!>
|
||
--" + boundaryStr;
|
||
}
|
||
body += @"--
|
||
";
|
||
var result = WXHttpResponseBLL.WeiXinUploadResponse(shop, url, body, boundaryStr, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getCategoryOnShelf(ShopLoginInfo shop, List<long> catIdLst)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/product/getCategoryOnShelfV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = @"{""catIdList"":[" + string.Join(",", catIdLst) + @"],""brandId"":2100000000}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string batchCheckCategoryRelation(ShopLoginInfo shop, long catId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/product/batchCheckCategoryRelation?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = @"{""categoryIdList"":[" + catId + "]}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string addFinderCategoryV2(ShopLoginInfo shop, long catId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradecategory/cgi/addFinderCategoryV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
string body = @"{""categoryInfo"":{""categories"":[{""id"":""" + catId + @"""}]},""brandIdList"":[],""leafCategoryId"":""" + catId + @""",""reuse"":0,""applyType"":1}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
//{"categoryInfo":{"categories":[{"id":10000257},{"id":10000245},{"id":112888}],"categoryDeposit":"10000.00","isNewApplyCat":true,"licenseGroupList":[{"licenseGroupId":"17","license":{"licenseId":"5","cosIdList":["1768635607165-orc0V2WjFHdNvjNnk967_g14awFw-7487"],"licenseFieldList":[{"key":"audit_license_no","value":"新出发皖字第1027号"},{"key":"audit_license_validty_period","value":"2029-04-30"}],"isReuse":true}}],"ruleVersion":5234,"certificate":[]},"brandIdList":[],"leafCategoryId":112888,"reuse":0,"applyType":"normalApply"}
|
||
//{"code":0,"baseResp":{"errcode":0,"errmsg":"ok"},"auditId":"8362856529"}
|
||
//string body = @"{""categoryInfo"":{""categories"":[{""id"":10000257},{""id"":10000245},{""id"":112888}],""categoryDeposit"":""10000.00"",""isNewApplyCat"":true,""licenseGroupList"":[{""licenseGroupId"":""17"",""license"":{""licenseId"":""5"",""cosIdList"":[""1768635607165-orc0V2WjFHdNvjNnk967_g14awFw-7487""],""licenseFieldList"":[{""key"":""audit_license_no"",""value"":""新出发皖字第1027号""},{""key"":""audit_license_validty_period"",""value"":""2029-04-30""}],""isReuse"":true}}],""ruleVersion"":5234,""certificate"":[]},""brandIdList"":[],""leafCategoryId"":112888,""reuse"":0,""applyType"":""normalApply""}";
|
||
// request.Referer = "https://store.weixin.qq.com/shop/brandAndCat/category/apply?defaultCategoryIds=%5B%2210000257%22%2C%2210000245%22%2C%22112888%22%5D&source=goods&type=apply";
|
||
|
||
return result;
|
||
}
|
||
|
||
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 uploadProductDraft(ShopLoginInfo shop, WXUploadProductParam prodParam)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductupload/common/cgi/goods/uploadProductDraft?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string upProductV2(ShopLoginInfo shop, WXUploadProductParam prodParam)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/upProductV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
public static string upProductJObjectV2(ShopLoginInfo shop, string prodStr)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/upProductV2?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry";
|
||
//JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
//var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 尝试免审 失败
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="productId"></param>
|
||
/// <returns></returns>
|
||
public static string getEditProductV2(ShopLoginInfo shop, string productId)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/getEditProductV2?token=&lang=zh_CN&productKey=%7B%22productId%22:" +
|
||
productId + "%7D&needRealStock=true&preview=false&release=false";
|
||
//url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/getEditProductV2?token=&lang=zh_CN&productKey=%7B%22productId%22:" +
|
||
// productId + "%7D&needRealStock=true&preview=false&release=true";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + productId + "&isUpdateAuditFree=0&source=list_edit&continueEditInfo={%22isEditingContinued%22:false,%22lastEditDraftTime%22:0,%22listingTime%22:0}";
|
||
//referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + productId + "&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo={%22isEditingContinued%22:true,%22lastEditDraftTime%22:0,%22listingTime%22:0}";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string initUploadPart(ShopLoginInfo shop, string submitJson, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodefiletransfer/filecos/initUploadPart?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
string body = submitJson; //@"{""name"":""goods/10000456038253/2026-01-20/1768887306422/submit.json""}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string listingAuditFree(ShopLoginInfo shop, WXUploadProductParam prodParam, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/listingAuditFree?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
var prodStr = JsonConvert.SerializeObject(prodParam, jsonSetting);
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string listingAuditFree(ShopLoginInfo shop, string prodStr, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/listingAuditFree?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
JsonSerializerSettings jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||
JObject jObj = new JObject();
|
||
jObj.Add("data", prodStr);
|
||
string body = JsonHelper.SerializeObject(jObj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string uploadPartBinary(ShopLoginInfo shop, string initFileName, string blobPath, string uploadId, string prodId, int time1, int time2)
|
||
{
|
||
string boundaryLetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||
string boundaryStr = "----WebKitFormBoundary";
|
||
for (int i = 0; i < 16; i++)
|
||
{
|
||
boundaryStr += boundaryLetters[Randomx.GetId(boundaryLetters.Length)];
|
||
}
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodefiletransfer/filecos/uploadPartBinary?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
string body = @"--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""name""
|
||
|
||
" + initFileName + @"
|
||
--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""uploadId""
|
||
|
||
" + uploadId + @"
|
||
--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""partSeq""
|
||
|
||
1
|
||
--" + boundaryStr + @"
|
||
Content-Disposition: form-data; name=""file""; filename=""blob""
|
||
Content-Type: application/octet-stream
|
||
|
||
<!>" + blobPath + @"<!>
|
||
--" + boundaryStr + @"--
|
||
";
|
||
var result = WXHttpResponseBLL.WeiXinUploadResponse(shop, url, body, boundaryStr, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
public static string completeUploadPart(ShopLoginInfo shop, string completeJson, string prodId, int time1, int time2)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodefiletransfer/filecos/completeUploadPart?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/entry?productId=" + prodId +
|
||
"&isUpdateAuditFree=1&source=list_audit_free&continueEditInfo=" +
|
||
"{%22isEditingContinued%22:true,%22lastEditDraftTime%22:" + time1 + "," +
|
||
"%22listingTime%22:" + time2 + "}";
|
||
string body = completeJson; //{"name":"goods/10000466857488/2026-01-20/1768907711117/submit.json","uploadId":"176890774759894589c6096cab2210e0793688fb68b482b766a0387c8667d3280a36385109","etagList":["ade9671ce546efb4cb209f5aa7e5d597"],"partSeqList":[1]}
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 商品列表
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="status"></param>
|
||
/// <param name="pageNum"></param>
|
||
/// <param name="pageSize"></param>
|
||
/// <returns></returns>
|
||
public static string scanProductPreview(ShopLoginInfo shop, string status = "5", int pageNum = 1, int pageSize = 20)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/scanProductPreview?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_ALL";
|
||
string body = @"{""pageSize"":" + pageSize + @",""productStatus"":[-1],""productSource"":""[1,16,32]"",""searchSource"":1,""useNew"":true,""pageNum"":" + pageNum +
|
||
@",""status"":[" + status + @"]}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加售后地址
|
||
/// </summary>
|
||
public static string addAddress(ShopLoginInfo shop, string provinceName, string cityName, string countyName,
|
||
string detailInfo, string userName, string telNumber)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeexpress/address/addAddress?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/address/expressAddressMgmt";
|
||
string address = "{\"addressInfo\":{\"provinceName\":\"" + provinceName +
|
||
"\",\"cityName\":\"" + cityName + "\",\"countyName\":\"" + countyName +
|
||
"\",\"detailInfo\":\"" + detailInfo + "\",\"userName\":\"" + userName +
|
||
"\",\"telNumber\":\"" + telNumber + "\",\"location\":{}},\"defaultSend\":0,\"defaultRecv\":0}";
|
||
|
||
JObject obj = new JObject();
|
||
obj["data"] = address;
|
||
string body = JsonHelper.SerializeObject(obj);
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取服务接口到期时间
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <returns></returns>
|
||
public static string GetApiServiceList(ShopLoginInfo shop)
|
||
{
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeservicemarket/service/GetMyServiceList?offset=0&limit=20&status=2&token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/servicemarket/myServices?status=2";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public class AddPriceRule2
|
||
{
|
||
/// <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 WXUploadRule2
|
||
{
|
||
public int PreSaleDays { get; set; } = 5;
|
||
|
||
public string FilterWords { get; set; } = "二手,亏本,冲量,白菜价,跳楼价,xx,xxx,最大,最小,低价,降价,成本,赔钱,甩卖,真丝,蚕丝,香云纱,羊绒,羊毛,羊羔绒,羊羔毛,羽绒,皮草";
|
||
|
||
public int SkuMinPrice { get; set; } = 10;
|
||
|
||
public int WaitSeconds { get; set; } = 10;
|
||
|
||
public bool OnlyHighestPriceSku { get; set; } = true;
|
||
public bool SameSpecSamePrice { get; set; } = true;
|
||
public bool SkipUploaded { get; set; } = true;
|
||
public bool UpDraft { get; set; } = false;
|
||
public bool IsPreSale { get; set; } = false;
|
||
}
|
||
}
|