1277 lines
61 KiB
C#
1277 lines
61 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;
|
||
using CefSharp.WinForms;
|
||
using CefSharp;
|
||
using TemuKJD.Helper;
|
||
using NaiBa.CefHelper;
|
||
using NaiBa.CefHelper.Handler;
|
||
|
||
namespace TemuKJD.WXForms.ProductForms
|
||
{
|
||
public partial class WXFinderSquareForm : BaseForm
|
||
{
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
public bool IsLoadComplate { get; set; } = false;
|
||
|
||
public ConcurrentList<AuthInfo> lstShopAuthInfo = new ConcurrentList<AuthInfo>();
|
||
public ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
//public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
|
||
public Dictionary<string, WxShopUploadInfo> dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
|
||
|
||
WXAddFinderParam wxAddFinderParam = new WXAddFinderParam();
|
||
|
||
ChromiumWebBrowser mainWebBrowser = null;
|
||
CheckBox chkSelectAll = null;
|
||
ShopLoginInfo currentShop;
|
||
|
||
int PageBegin = 1;
|
||
int PageEnd = 20;
|
||
string currentGetTalentParam = "";
|
||
List<WXFinderTalentInfo> lstWXFinderTalentInfo = new List<WXFinderTalentInfo>();
|
||
|
||
public WXFinderSquareForm()
|
||
{
|
||
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>();
|
||
|
||
// 授权Token
|
||
lstWXShopTokenInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<WXShopTokenInfo>>("wx_shop_token_list");
|
||
if (lstWXShopTokenInfo == null)
|
||
lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
|
||
|
||
// 选中信息
|
||
//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>();
|
||
|
||
// 邀约参数
|
||
wxAddFinderParam = NaiBa.Util.Helper.ConfigHelper.LoadConfig<WXAddFinderParam>("wx_add_finder_param");
|
||
if (wxAddFinderParam == null)
|
||
wxAddFinderParam = new WXAddFinderParam();
|
||
|
||
txtContactPerson.TextAlignChanged -= txtContactPerson_TextChanged;
|
||
txtExplain.TextAlignChanged -= txtExplain_TextChanged;
|
||
txtMobile.TextAlignChanged -= txtMobile_TextChanged;
|
||
txtWxNumber.TextAlignChanged -= txtWxNumber_TextChanged;
|
||
|
||
this.txtContactPerson.Text = wxAddFinderParam.ContactPerson;
|
||
this.txtExplain.Text = wxAddFinderParam.Explain;
|
||
this.txtMobile.Text = wxAddFinderParam.Mobile;
|
||
this.txtWxNumber.Text = wxAddFinderParam.WxNumber;
|
||
|
||
txtContactPerson.TextAlignChanged += txtContactPerson_TextChanged;
|
||
txtExplain.TextAlignChanged += txtExplain_TextChanged;
|
||
txtMobile.TextAlignChanged += txtMobile_TextChanged;
|
||
txtWxNumber.TextAlignChanged += txtWxNumber_TextChanged;
|
||
|
||
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
|
||
dgvShop.Columns["colSelect"].HeaderText = "";
|
||
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
|
||
this.dgvTalent.AddSelectorColumn("colCheck");
|
||
dgvTalent.AddImgColumn("colImg", "colImgUrl");
|
||
|
||
InitCef();
|
||
Task.Run(() =>
|
||
{
|
||
// 直到店铺加载完后再加载客服内容
|
||
while (!StartUp.IsShopInit)
|
||
Thread.Sleep(100);
|
||
currentShop = GlobalConfig.ShopLoginList.FirstOrDefault();
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.textBox1.Text = currentShop.ShopAccount;
|
||
this.textBox1.Tag = currentShop.ShopId;
|
||
}));
|
||
SetMainBrowserUrl(currentShop);
|
||
});
|
||
|
||
IsLoadComplate = true;
|
||
}
|
||
|
||
void InitCef()
|
||
{
|
||
if (mainWebBrowser == null)
|
||
{
|
||
mainWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
|
||
mainWebBrowser.KeyboardHandler = new KeyboardHandler();
|
||
mainWebBrowser.Dock = DockStyle.Fill;
|
||
|
||
var lifeSpanHandler = new LifeSpanHandlerLocal(PopWindowType.NewTitleWindow);
|
||
lifeSpanHandler.parent = mainWebBrowser;
|
||
lifeSpanHandler.OnPop += MainLifeHandler_OnPop;
|
||
mainWebBrowser.LifeSpanHandler = lifeSpanHandler;
|
||
|
||
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
|
||
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
||
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
|
||
mainWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
||
|
||
mainWebBrowser.AddressChanged += MainWebBrowser_AddressChanged;
|
||
mainWebBrowser.FrameLoadEnd += MainWebBrowser_FrameLoadEnd;
|
||
mainPanel.Controls.Add(mainWebBrowser);
|
||
}
|
||
}
|
||
|
||
private void MainWebBrowser_AddressChanged(object sender, AddressChangedEventArgs e)
|
||
{
|
||
//this.txtAddress.Text = e.Address;
|
||
}
|
||
private void MainWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
||
{
|
||
}
|
||
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
||
{
|
||
return false;
|
||
}
|
||
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
||
{
|
||
if (url.StartsWith("https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/finderSquare/cgi/getSquareTalentList"))
|
||
{
|
||
currentGetTalentParam = postData;
|
||
}
|
||
}
|
||
private void MainLifeHandler_OnPop(object sender, PopData e)
|
||
{
|
||
var targetUrl = e.Url;
|
||
var lifeHandler = sender as LifeSpanHandlerLocal;
|
||
|
||
Task.Run(() =>
|
||
{
|
||
if (lifeHandler.parent != null)
|
||
{
|
||
var cookies = CEFBrowser.GetCookieList("", lifeHandler.parent.RequestContext.GetCookieManager(null));
|
||
Invoke(new Action(() =>
|
||
{
|
||
CefForm cefForm = new CefForm(targetUrl, cookies);
|
||
cefForm.Show();
|
||
}));
|
||
}
|
||
});
|
||
}
|
||
|
||
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;
|
||
RefreshShopLogin();
|
||
}
|
||
|
||
private void UserSelectDbProductForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (Visible == true)
|
||
{
|
||
RefreshShopLogin();
|
||
updateAuthor();
|
||
}
|
||
}
|
||
|
||
private void RefreshShopLogin()
|
||
{
|
||
// 店铺Id
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
// 获取被删除的店铺
|
||
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||
// 更新被删除的店铺列表
|
||
foreach (var row in dgvRowList)
|
||
{
|
||
dgvShop.Rows.Remove(row);
|
||
}
|
||
// 绑定其他店铺(含新导入的店铺)
|
||
foreach (ShopLoginInfo shopEntity in GlobalConfig.ShopLoginList)
|
||
{
|
||
if (!string.IsNullOrEmpty(shopEntity.ShopId))
|
||
BindShop(shopEntity, selectIds);
|
||
}
|
||
cmbFilterShopNotes.Items.Clear();
|
||
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopNotes.Items.Add(note);
|
||
}
|
||
pbLoadingShop.Visible = false;
|
||
}
|
||
|
||
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(
|
||
dgvShop.Rows.Count == 0 ? true : (selectShopId.Contains(shopEntity.ShopId) && canUse),
|
||
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 = 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_CellClick(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];
|
||
foreach(DataGridViewRow r in dgvShop.Rows)
|
||
{
|
||
if (r == row)
|
||
continue;
|
||
if (r.Cells["colSelect"].Value.ParseToBool() == true)
|
||
r.Cells["colSelect"].Value = false;
|
||
}
|
||
row.Cells["colSelect"].Value = true;
|
||
|
||
if (currentShop != shop)
|
||
{
|
||
this.textBox1.Text = shopAccount;
|
||
this.textBox1.Tag = shopId;
|
||
currentShop = shop;
|
||
|
||
Task.Run(() =>
|
||
{
|
||
SetMainBrowserUrl(shop);
|
||
});
|
||
}
|
||
}
|
||
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];
|
||
|
||
this.textBox1.Text = shopAccount;
|
||
this.textBox1.Tag = shopId;
|
||
currentShop = shop;
|
||
|
||
switch (columnName)
|
||
{
|
||
case "colSelect":
|
||
////if (row.Cells["colCanUse"].Value.ParseToBool())
|
||
//{
|
||
// row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
|
||
// chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
|
||
// if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
|
||
// chkSelectAll.Checked = true;
|
||
// else
|
||
// chkSelectAll.Checked = false;
|
||
// chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
|
||
//}
|
||
////else
|
||
////{
|
||
//// //BaseMsgForm.ShowInfo("店铺未登录!");
|
||
////}
|
||
|
||
//dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool();
|
||
//NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
|
||
break;
|
||
case "colLoginStatus":
|
||
{
|
||
if (WXShopListForm.Instance == null)
|
||
WXShopListForm.Instance = new WXShopListForm();
|
||
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
//shopLoginForm.prodUserSelectForm = this;
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopLogin();
|
||
}
|
||
else
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.Show();
|
||
}
|
||
}
|
||
break;
|
||
case "colApi":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139";
|
||
shopLoginForm.Show();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void dgvTalent_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvTalent.Columns[e.ColumnIndex].HeaderText;
|
||
var shopId = dgvTalent.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
var talentAppid = dgvTalent.Rows[e.RowIndex].Cells["colTalentAppid"].Value.ParseToString();
|
||
var talent = this.lstWXFinderTalentInfo.FirstOrDefault(t => t.talentAppid == talentAppid);
|
||
|
||
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);
|
||
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();
|
||
RefreshShopLogin();
|
||
}
|
||
}
|
||
break;
|
||
case "图片":
|
||
{
|
||
ShowImgForm imgFrom = new ShowImgForm(dgvTalent.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString());
|
||
imgFrom.ShowDialog();
|
||
break;
|
||
}
|
||
case "":
|
||
dgvTalent.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvTalent.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void btnStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.cancellationTokenSource != null)
|
||
this.cancellationTokenSource.Cancel();
|
||
}
|
||
|
||
private void btnSearchTalent_Click(object sender, EventArgs e)
|
||
{
|
||
//var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
// => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
//if (shopIdLst.Count <= 0)
|
||
//{
|
||
// BaseMsgForm.ShowError("未勾选店铺!");
|
||
// return;
|
||
//}
|
||
|
||
if (currentShop == null)
|
||
{
|
||
BaseMsgForm.ShowError("当前店铺为空!");
|
||
return;
|
||
}
|
||
|
||
btnSearchTalent.Enabled = false;
|
||
|
||
|
||
pbLoading.Visible = true;
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
dgvTalent.Rows.Clear();
|
||
Task.Run(() =>
|
||
{
|
||
GetTalent(currentShop, currentGetTalentParam);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "达人查询完毕";
|
||
BaseMsgForm.ShowInfo("达人查询完毕");
|
||
pbLoading.Visible = false;
|
||
btnSearchTalent.Enabled = true;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
void GetTalent(ShopLoginInfo shop, string searchParam)
|
||
{
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
return;
|
||
}
|
||
|
||
lstWXFinderTalentInfo = new List<WXFinderTalentInfo>();
|
||
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||
|
||
int page = PageBegin - 1;
|
||
int totalPage = 1;
|
||
int pageSize = 20;
|
||
while (page < totalPage && page < PageEnd)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
page++;
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在查询店铺:" + shop.ShopAccount + " 达人 " + page + "/" + Math.Min(PageEnd, totalPage);
|
||
}));
|
||
Thread.Sleep(Randomx.GetId(2500, 5000));
|
||
|
||
string getFinderTalentRst = "";
|
||
|
||
try
|
||
{
|
||
JObject getTalentParamObj = JsonHelper.JObjectParse(currentGetTalentParam);
|
||
getTalentParamObj["filter"]["offset"] = (page - 1) * getTalentParamObj["filter"]["limit"].ParseToInt();
|
||
getFinderTalentRst = WXFinderSquareBLL.getSquareTalentList(shop, JsonHelper.SerializeObject(getTalentParamObj));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (shopRow != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
shopRow.Cells["colMessage"].Value = "达人查询格式错误";
|
||
}));
|
||
}
|
||
}
|
||
|
||
Thread.Sleep(Randomx.GetId(50, 100));
|
||
if (!getFinderTalentRst.Contains("\"code\":0") && !getFinderTalentRst.Contains("\"success\":true"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getFinderTalentRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getFinderTalentRst;
|
||
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
}
|
||
|
||
if (shopRow != null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
shopRow.Cells["colMessage"].Value = error;
|
||
}));
|
||
}
|
||
break;
|
||
}
|
||
|
||
try
|
||
{
|
||
var talentObj = JsonHelper.JObjectParse(getFinderTalentRst)["list"];
|
||
var wxFinderTalentInfo = JsonHelper.DeserializeJsonToList<WXFinderTalentInfo>(JsonHelper.SerializeObject(talentObj));
|
||
if (page == 1 || 1 == 1)
|
||
{
|
||
var totalNum = BaseRegex.GetIntJson(ref getFinderTalentRst, "totalNum");
|
||
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
|
||
}
|
||
lstWXFinderTalentInfo.AddRange(wxFinderTalentInfo);
|
||
foreach (var finderTalent in wxFinderTalentInfo)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
string tag = "";
|
||
if (finderTalent.finderInfo.topDaren == 1)
|
||
tag += "优质带货者 ";
|
||
if (finderTalent.finderInfo.highResponse == 1)
|
||
tag += "回复率高 ";
|
||
var rowIndex = this.dgvTalent.Rows.Add
|
||
(
|
||
false,
|
||
shop.ShopId,
|
||
shop.ShopAccount,
|
||
"登录",
|
||
"进店",
|
||
finderTalent.finderInfo.headImg,
|
||
DataGridViewExtension.defaultBitmap,
|
||
finderTalent.talentAppid,
|
||
finderTalent.finderInfo.nickname,
|
||
tag,
|
||
string.Join(" ", finderTalent.finderInfo.topCatList.Select(c => c.topCatName)) + "\r\n" + finderTalent.promotionInfo.windowsScore,
|
||
finderTalent.finderInfo.fansNumber,
|
||
finderTalent.promotionInfo.gmv,
|
||
finderTalent.promotionInfo.liveGmv,
|
||
finderTalent.promotionInfo.videoGmv,
|
||
finderTalent.promotionInfo.bizPayGmv,
|
||
"删除",
|
||
""
|
||
);
|
||
dgvTalent.Rows[rowIndex].Height = 60;
|
||
}));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnClearDgv_Click(object sender, EventArgs e)
|
||
{
|
||
var rows = this.dgvTalent.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.dgvTalent.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)
|
||
{
|
||
}
|
||
|
||
private void btnFilterShop_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
{
|
||
row.Visible = false;
|
||
row.Cells["colSelect"].Value = false;
|
||
continue;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
{
|
||
row.Visible = false;
|
||
row.Cells["colSelect"].Value = false;
|
||
continue;
|
||
}
|
||
row.Visible = true;
|
||
}
|
||
}
|
||
|
||
private void btnEmptyShop_Click(object sender, EventArgs e)
|
||
{
|
||
txtFilterShopName.Text = "";
|
||
cmbFilterShopNotes.Text = "全部";
|
||
btnFilterShop_Click(null, null);
|
||
}
|
||
|
||
private void btnReverse_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||
}
|
||
}
|
||
|
||
private void btnAddSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
|
||
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnAddUnSelect_Click(object sender, EventArgs e)
|
||
{
|
||
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
|
||
if (notes == "全部")
|
||
notes = "";
|
||
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
|
||
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectOnline_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colLoginStatus"].Value.ParseToString() == "在线")
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnSelectOffline_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == true)
|
||
{
|
||
if (row.Cells["colLoginStatus"].Value.ParseToString() != "在线")
|
||
{
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
private void SetMainBrowserUrl(ShopLoginInfo shop)
|
||
{
|
||
if (shop == null)
|
||
return;
|
||
|
||
var cookieLst = new List<Cookie>();
|
||
try
|
||
{
|
||
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies.ParseToString().Replace("empty=true;", "[]"));
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
if (mainWebBrowser == null)
|
||
{
|
||
Invoke(new Action(() => { InitCef(); }));
|
||
}
|
||
|
||
var cookieManager = mainWebBrowser.RequestContext.GetCookieManager(null);
|
||
cookieManager.DeleteCookiesAsync("qq.com", null).Wait();
|
||
foreach (var cook in cookieLst)
|
||
{
|
||
var t = CEFBrowser.SetCookieAsync(cook.Domain, cook.Name + "=" + cook.Value + ";", cookieManager);
|
||
t.Wait(5000);
|
||
}
|
||
|
||
mainWebBrowser.Load("https://store.weixin.qq.com/shop/findersquare/find");
|
||
}
|
||
|
||
private void txtPageEnd_TextChanged(object sender, EventArgs e)
|
||
{
|
||
PageEnd = txtPageEnd.Text.ParseToInt();
|
||
}
|
||
|
||
private void txtContactPerson_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxAddFinderParam.ContactPerson = txtContactPerson.Text.Trim();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_add_finder_param", wxAddFinderParam);
|
||
}
|
||
|
||
private void txtWxNumber_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxAddFinderParam.WxNumber = txtWxNumber.Text.Trim();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_add_finder_param", wxAddFinderParam);
|
||
}
|
||
|
||
private void txtMobile_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxAddFinderParam.Mobile = txtMobile.Text.Trim();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_add_finder_param", wxAddFinderParam);
|
||
}
|
||
|
||
private void txtExplain_TextChanged(object sender, EventArgs e)
|
||
{
|
||
wxAddFinderParam.Explain = txtExplain.Text.Trim();
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_add_finder_param", wxAddFinderParam);
|
||
}
|
||
|
||
private void btnAddFinder_Click(object sender, EventArgs e)
|
||
{
|
||
if (wxAddFinderParam.ContactPerson.IsNullOrEmpty())
|
||
{
|
||
BaseMsgForm.ShowError("联系人不能为空");
|
||
return;
|
||
}
|
||
if (wxAddFinderParam.WxNumber.IsNullOrEmpty() || wxAddFinderParam.WxNumber.Length < 6)
|
||
{
|
||
BaseMsgForm.ShowError("请确定微信号不为空,最少六个字符");
|
||
return;
|
||
}
|
||
if (wxAddFinderParam.Mobile.IsNullOrEmpty() || wxAddFinderParam.Mobile.ParseToLong().ToString().Length != 11)
|
||
{
|
||
BaseMsgForm.ShowError("手机号码格式不正确");
|
||
return;
|
||
}
|
||
if (wxAddFinderParam.Explain.IsNullOrEmpty())
|
||
{
|
||
BaseMsgForm.ShowError("合作说明不能为空");
|
||
return;
|
||
}
|
||
var selectRows = dgvTalent.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
|
||
if (selectRows.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowError("请选择要邀约的达人");
|
||
return;
|
||
}
|
||
pbLoading.Visible = true;
|
||
string prodIds = txtProductIds.Text.Trim();
|
||
|
||
this.btnAddFinder.Enabled = false;
|
||
Task.Run(() => {
|
||
Thread.Sleep(5000);
|
||
Invoke(new Action(() => { this.btnAddFinder.Enabled = true; }));
|
||
});
|
||
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
if (string.IsNullOrEmpty(prodIds))
|
||
{
|
||
var shopId = selectRows.FirstOrDefault().Cells["colSupplierId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if(chkReUse.Visible && chkReUse.Checked)
|
||
shop = currentShop;
|
||
var talentAppid = selectRows.FirstOrDefault().Cells["colTalentAppid"].Value.ParseToString();
|
||
var talent = this.lstWXFinderTalentInfo.FirstOrDefault(t => t.talentAppid == talentAppid);
|
||
prodIds = GetFinderProdList(shop, talent);
|
||
if (prodIds.Contains("\"success\":false"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var errMsg = BaseRegex.GetStringJson(ref prodIds, "msg");
|
||
if (!string.IsNullOrEmpty(errMsg))
|
||
{
|
||
errMsg = GetHtml.UrlDecode(errMsg);
|
||
selectRows.FirstOrDefault().Cells["colOpResult"].Value = errMsg;
|
||
}
|
||
else
|
||
selectRows.FirstOrDefault().Cells["colOpResult"].Value = "达人邀约失败,请稍后再试";
|
||
}));
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbLoading.Visible = false;
|
||
this.statusBar.lblTaskStatus.Text = "达人邀约操作中断";
|
||
BaseMsgForm.ShowError("达人邀约操作中断");
|
||
}));
|
||
return;
|
||
}
|
||
}
|
||
|
||
{
|
||
int num = 0;
|
||
foreach (var row in selectRows)
|
||
{
|
||
num++;
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "达人邀约 第 " + num + " 条,共 " + selectRows.Count + " 条";
|
||
row.Cells["colOpResult"].Value = "";
|
||
}));
|
||
if (this.cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var shopId = row.Cells["colSupplierId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (chkReUse.Visible && chkReUse.Checked)
|
||
shop = currentShop;
|
||
var talentAppid = row.Cells["colTalentAppid"].Value.ParseToString();
|
||
var talent = this.lstWXFinderTalentInfo.FirstOrDefault(t => t.talentAppid == talentAppid);
|
||
|
||
if (shop!=null && talent != null)
|
||
{
|
||
List<string> prodIdLst = prodIds.Split(new string[] { ",", ",", ";", ";", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
var finderUsername = talent.accountList.FirstOrDefault(a => !a.finderUsername.IsNullOrEmpty())?.finderUsername;
|
||
var promotionInvitationRst = WXFinderSquareBLL.createPromotionInvitation(shop, prodIdLst, finderUsername, talent.talentAppid,
|
||
wxAddFinderParam.ContactPerson, wxAddFinderParam.WxNumber, wxAddFinderParam.Mobile,
|
||
wxAddFinderParam.Explain.Replace("\r", "").Replace("\n", ""));
|
||
Thread.Sleep(Randomx.GetId(3000, 5000));
|
||
|
||
if (!promotionInvitationRst.ParseToString().Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref promotionInvitationRst, "errmsg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = promotionInvitationRst;
|
||
if (promotionInvitationRst.ParseToString().Contains("biz magic invalid"))
|
||
{
|
||
shop.LoginStatus = "未登录";
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(r
|
||
=> r.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
error = "店铺掉线";
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "达人邀约失败 " + error;
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells["colOpResult"].Value = "已发送邀约";
|
||
}));
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbLoading.Visible = false;
|
||
this.statusBar.lblTaskStatus.Text += "达人邀约操作结束";
|
||
BaseMsgForm.ShowInfo("达人邀约操作结束");
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
public string GetFinderProdList(ShopLoginInfo shop, WXFinderTalentInfo finderTalent)
|
||
{
|
||
int page = 0;
|
||
int pageSize = 10;
|
||
int totalPage = 1;
|
||
List<string> wxProdIds = new List<string>();
|
||
List<WXProdIdWithListingTime> wxProdIdWithListingTimeLst = new List<WXProdIdWithListingTime>();
|
||
while (page < totalPage )
|
||
{
|
||
page++;
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在查询达人邀约商品 第 " + page + " 页";
|
||
if (totalPage > 1)
|
||
this.statusBar.lblTaskStatus.Text = "正在查询达人邀约商品 第 " + page + " 页,共 " + totalPage + " 页";
|
||
}));
|
||
|
||
var finderUsername = finderTalent.accountList.FirstOrDefault(a => !a.finderUsername.IsNullOrEmpty())?.finderUsername;
|
||
var getFinderProdRst = WXFinderSquareBLL.WxFinderSquareGetProdList(shop, page, finderUsername, finderTalent.talentAppid);
|
||
Thread.Sleep(Randomx.GetId(1500, 2500));
|
||
if (!getFinderProdRst.Contains("\"code\":0"))
|
||
{
|
||
if (getFinderProdRst.Contains("\"code\":100002"))
|
||
{
|
||
return "{\"success\":false,\"code\":100002,\"msg\":\"店铺未设置达人推广商品,请先设置后再邀约达人\"}";
|
||
}
|
||
if (getFinderProdRst.Contains("biz magic invalid"))
|
||
{
|
||
shop.LoginStatus = "未登录";
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(r
|
||
=> r.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表失败,店铺掉线\"}";
|
||
}
|
||
var error = BaseRegex.GetStringJson(ref getFinderProdRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getFinderProdRst;
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表失败 " + GetHtml.UrlEncodeUtf8(error) + "\"}";
|
||
}
|
||
if (page == 1)
|
||
{
|
||
var totalNum = BaseRegex.GetIntJson(ref getFinderProdRst, "totalNum");
|
||
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
|
||
}
|
||
try
|
||
{
|
||
var jArr = JsonHelper.JObjectParse(getFinderProdRst)["itemList"] as JArray;
|
||
foreach (var jItem in jArr)
|
||
{
|
||
WXProdIdWithListingTime p = new WXProdIdWithListingTime()
|
||
{
|
||
listingTime = jItem["listingTime"].ParseToInt(),
|
||
productName = jItem["productName"].ParseToString(),
|
||
spuId = jItem["spuId"].ParseToString(),
|
||
};
|
||
wxProdIdWithListingTimeLst.Add(p);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
// 商品总数不到30,直接返回
|
||
if (wxProdIdWithListingTimeLst.Count <= 30)
|
||
return string.Join(",", wxProdIdWithListingTimeLst.Select(p => p.spuId));
|
||
|
||
// 商品数量超过30,按出单量和上架时间倒序取前30
|
||
var wxProdIdWithListingTimeLstTmp = new List<WXProdIdWithListingTime>();//wxProdIdWithListingTimeLst
|
||
wxProdIdWithListingTimeLstTmp.AddRange(wxProdIdWithListingTimeLst);
|
||
while (wxProdIdWithListingTimeLstTmp.Count() > 0)
|
||
{
|
||
var getProdRst = WXFinderSquareBLL.getSaleSortProduct(shop, wxProdIdWithListingTimeLstTmp.Take(200).Select(p => p.spuId).ToList());
|
||
// 每次最多传200个id,取最高的50,每组销量最高的50在一起一定能获取全部商品最高的50(带货最多30个商品,可以确保一定是销量最高的前30)
|
||
wxProdIdWithListingTimeLstTmp.RemoveRange(0, Math.Min(wxProdIdWithListingTimeLstTmp.Count, 200));
|
||
|
||
Thread.Sleep(Randomx.GetId(1500, 2500));
|
||
if (!getProdRst.Contains("\"success\":true"))
|
||
{
|
||
if (getProdRst.Contains("biz magic invalid"))
|
||
{
|
||
shop.LoginStatus = "未登录";
|
||
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(r
|
||
=> r.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
|
||
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表2失败,店铺掉线\"}";
|
||
}
|
||
var error = BaseRegex.GetStringJson(ref getProdRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getProdRst;
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表2失败 " + GetHtml.UrlEncodeUtf8(error) + "\"}";
|
||
}
|
||
try
|
||
{
|
||
var jArr = JsonHelper.JObjectParse(getProdRst)["productList"] as JArray;
|
||
foreach (var jItem in jArr)
|
||
{
|
||
var soldNum = jItem["soldNum"]?.ParseToInt();
|
||
var pExist = wxProdIdWithListingTimeLst.FirstOrDefault(p => p.spuId == jItem["productId"].ParseToString());
|
||
if (pExist != null)
|
||
{
|
||
pExist.soldNum = soldNum;
|
||
}
|
||
else
|
||
{
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表2失败 商品未找到\"}";
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return "{\"success\":false,\"msg\":\"查询达人商品列表2失败 " + ex.Message + "\"}";
|
||
}
|
||
}
|
||
wxProdIdWithListingTimeLst = wxProdIdWithListingTimeLst.OrderByDescending(p => p.soldNum).ThenByDescending(p => p.listingTime).ToList().Take(30).ToList();
|
||
return string.Join(",", wxProdIdWithListingTimeLst.Select(p => p.spuId));
|
||
}
|
||
}
|
||
|
||
public class WXFinderSquareBLL
|
||
{
|
||
public static string getSquareTalentList(ShopLoginInfo shop, string bodyJson)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/finderSquare/cgi/getSquareTalentList?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/findersquare/find";
|
||
//@"{""filter"":{""isLiveFinder"":0,""isVideoFinder"":0,""isMpPromoter"":0,""limit"":20,""offset"":20,""topCatId"":[1495,6870],""otherCheckers"":[""hasContact""],""hasContact"":1,""randomSeed"":8275,""sortKey"":0,""sortDirection"":1,""topCatIdList"":[1495,6870]}}";
|
||
string body = bodyJson;
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string WxFinderSquareGetProdList(ShopLoginInfo shop, int page, string finderUsername, string talentAppid)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/finderSquare/cgi/getItemList?token=&lang=zh_CN&offset=" + (page - 1) * 10 +
|
||
"&pageSize=10&productTitle=";
|
||
string referer = "https://store.weixin.qq.com/shop/findersquare/initiate-invite?finderUsername=" + finderUsername + "&talentAppid=" + talentAppid + "&from=5";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getSaleSortProduct(ShopLoginInfo shop, List<string> spuIdLst, int page = 1)
|
||
{
|
||
var spuIdStr = "+" + string.Join("+", spuIdLst);
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/searchProduct" +
|
||
"?token=&lang=zh_CN&pageSize=50&productStatus[]=-1&productSource=[1,16,32]&searchSource=1&useNew=true&pageNum=" + page +
|
||
"&status[]=5&spuId=" + spuIdStr + "&sortType=6";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_ON";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string getListingTimeSortProduct(ShopLoginInfo shop, List<string> spuIdLst, int page = 1)
|
||
{
|
||
var spuIdStr = "+" + string.Join("+", spuIdLst);
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeproductcore/cgi/goods/searchProduct" +
|
||
"?token=&lang=zh_CN&pageSize=50&productStatus[]=-1&productSource=[1,16,32]&searchSource=1&useNew=true&pageNum=" + page +
|
||
"&status[]=5&spuId=" + spuIdStr + "&sortType=18";
|
||
string referer = "https://store.weixin.qq.com/shop/goods/list?currentTab=PRODUCT_STATUS_ON";
|
||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string createPromotionInvitation(ShopLoginInfo shop, List<string> productIdLst, string finderUsername, string talentAppid,
|
||
string contactName, string contactWxId, string contactPhoneNumber, string invitationIntroduction)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/finderSquare/cgi/createPromotionInvitation?token=&lang=zh_CN";
|
||
//string referer = "https://store.weixin.qq.com/shop/findersquare/initiate-invite?finderUsername=v2_060000231003b20faec8c6e08811c4d1cc01ee36b077a7e7c19b328d3bad1d0f59b8cd9a6d26@finder&talentAppid=wx6ea8fdc1005228f1&from=5";
|
||
string referer = "https://store.weixin.qq.com/shop/findersquare/initiate-invite?finderUsername=" + "&talentAppid=" + "&from=5";
|
||
//string body = @"{""finderUsername"":""v2_060000231003b20faec8c6e08811c4d1cc01ee36b077a7e7c19b328d3bad1d0f59b8cd9a6d26@finder"",""talentAppid"":""wx6ea8fdc1005228f1"",""itemList"":{""itemInfo"":[{""spuId"":""10000539273216""},{""spuId"":""10000539258278""}]},""contactInfo"":{""contactName"":""孙xiansheng"",""contactWxId"":""wx2311"",""contactPhoneNumber"":""11111111111"",""invitationIntroduction"":""你好你好"",""inviteScene"":""5""}}";
|
||
string body = @"{""finderUsername"":""" + finderUsername + @""",""talentAppid"":""" + talentAppid + @""",""itemList"":{""itemInfo"":[";
|
||
foreach (var spuId in productIdLst)
|
||
{
|
||
body += @"{""spuId"":""" + spuId + @"""},";
|
||
}
|
||
body = body.TrimEnd(',');
|
||
body += @"]},""contactInfo"":{""contactName"":""" + contactName + @""",""contactWxId"":""" + contactWxId +
|
||
@""",""contactPhoneNumber"":""" + contactPhoneNumber + @""",""invitationIntroduction"":""" + invitationIntroduction + @""",""inviteScene"":""5""}}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public class WXAddFinderParam
|
||
{
|
||
public string ContactPerson { get; set; }
|
||
public string WxNumber { get; set; }
|
||
public string Mobile { get; set; }
|
||
public string Explain { get; set; }
|
||
}
|
||
|
||
public class WXProdIdWithListingTime
|
||
{
|
||
public string spuId { get; set; } // "10000538960743"
|
||
public string productName { get; set; } // "点教英语 《高中英语听力精听训练》强化版"
|
||
public int? listingTime { get; set; } // 1773912220
|
||
public int? soldNum { get; set; }
|
||
}
|
||
}
|