Files
KJD/TEMUKJD/WXForms/AdminForms/WXAdminAddressSyncForm.cs
2026-03-26 21:34:59 +08:00

422 lines
18 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using AllBase.Model.Param.TemuProductManage;
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.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TemuKJD.BLL;
using TemuKJD.Extension;
using TemuKJD.BaseForms;
using Work;
using NaiBa.Util;
using TemuKJD.WXForms.ShopForms;
namespace TemuKJD.WXForms.AdminForms
{
public partial class WXAdminAddressSyncForm : BaseForms.BaseGeneralForm
{
static WXAdminAddressSyncForm inst = null;
public static WXAdminAddressSyncForm Instance
{
get { if (inst == null) inst = new WXAdminAddressSyncForm(); return inst; }
set { inst = value; }
}
public static ConcurrentList<ShopLoginInfo> lstAdminShopInfo { get; set; } = new ConcurrentList<ShopLoginInfo>();
public WXAdminAddressSyncForm()
{
InitializeComponent();
Instance = this;
}
private void AdminShopForm_Load(object sender, EventArgs e)
{
this.ucSplitPage1.PageChange += UcSplitPage1_PageChange;
this.dgvShop.AddSelectorColumn("colSelect");
this.dgvShop.AddMergeColumnHeader(new List<string>() { /*"colMinus",*/ "colProductRemaining", "colPlus" }, "选品限额");
this.dgvShop.AddMergeColumn(new List<string>() { /*"colMinus",*/ "colProductRemaining", "colPlus" });
this.dgvShop.Columns["colMinus"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
this.dgvShop.Columns["colPlus"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
this.dgvShop.Columns["colPlus"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
if (BaseClass.SaLevel != 1)
{
dgvShop.Columns["colSubSa"].Visible = false;
}
}
bool firstLoad = true;
private void AdminShopForm_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible == true && firstLoad)
{
firstLoad = false;
this.pbLoading.Visible = true;
SearchShop(this.ucSplitPage1.CurrentPage);
}
}
private void UcSplitPage1_PageChange(object obj)
{
SearchShop(this.ucSplitPage1.CurrentPage);
}
public void SearchShop(int page)
{
List<string> shopIdList = GetCheckedShopIdList();
if (InvokeRequired)
{
Invoke(new Action(() =>
{
this.pbLoading.Visible = true;
this.dgvShop.Rows.Clear();
lstAdminShopInfo.Clear();
}));
}
else
{
this.pbLoading.Visible = true;
this.dgvShop.Rows.Clear();
lstAdminShopInfo.Clear();
}
Task.Run(() =>
{
int pageCount;
decimal seconds = 0;
var list = AdminGetServerShopLst(out pageCount, out seconds, page, ucSplitPage1.PageSize);
lstAdminShopInfo.AddRange(list);
this.ucSplitPage1.TotalPage = pageCount;
foreach (var shop in lstAdminShopInfo)
{
Invoke(new Action(() =>
{
int rowIndex = this.dgvShop.Rows.Add(
shopIdList.Contains(shop.ShopId + shop.UserName),
shop.LoginName,
shop.ShopId,
shop.ShopAccount,
shop.Notes,
shop.GroupName,
"-",
shop.AddProductRemaining,
"+",
//"±",
shop.Cookies,
shop.UserName,
shop.SubUserName,
shop.UploadAccount,
shop.BuyAccount,
shop.ChatAccount,
"",
"进入",
"检测",
string.IsNullOrWhiteSpace(shop.LoginStatus) ? "未登录" : shop.LoginStatus.Trim(),
string.IsNullOrWhiteSpace(shop.LoginStatus2) ? "国际版未登录" : shop.LoginStatus2.Trim(),
"购买",
"多重登录",
shop.ApiAuthStatus,
shop.BuyApiAuth.ApiAuthStatus,
"导入Cookie",
"复制Cookie",
"上传",
shop.OperateSubSaName,
"编辑",
"删除");
}));
}
Invoke(new Action(() =>
{
this.pbLoading.Visible = false;
this.statusBar.lblTaskStatus.Text = "店铺查询完毕";
#if DEBUG
this.statusBar.lblTaskStatus.Text += ",耗时:" + seconds;
#endif
}));
});
}
private void btnSearch_Click(object sender, EventArgs e)
{
if (this.ucSplitPage1.CurrentPage != 1)
this.ucSplitPage1.CurrentPage = 1;
else
SearchShop(1);
}
private void pnlEmpty_Click(object sender, EventArgs e)
{
this.txtUserName.Text = "";
this.txtLoginName.Text = "";
this.txtNotes.Text = "";
this.txtShopId.Text = "";
this.txtShopName.Text = "";
}
bool IsOperate { get; set; } = false;
private void shopLoginForm_SaveComplete(object obj)
{
SearchShop(this.ucSplitPage1.CurrentPage);
}
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
string loginName = dgvShop.Rows[e.RowIndex].Cells["colLoginName"].Value.ParseToString();
string accountId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
var shop = lstAdminShopInfo.FirstOrDefault(v => v.LoginName == loginName && v.ShopId == accountId);
switch (headerText)
{
case "检测":
//CheckShopLoginAsync(new string[] { loginName });
break;
case "进入店铺":
IsOperate = true;
{
WXAdminShopLoginForm adminLoginForm = new WXAdminShopLoginForm(shop);
adminLoginForm.openType = EnumOpenType.manage;
adminLoginForm.WindowState = FormWindowState.Maximized;
adminLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home";
adminLoginForm.Show();
}
IsOperate = false;
break;
case "API购买":
{
WXAdminShopLoginForm shopLoginForm = new WXAdminShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.manage;
shopLoginForm.WindowState = FormWindowState.Maximized;
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139";
shopLoginForm.Show();
}
break;
case "复制Cookie":
List<CefSharp.Cookie> cooks = null;
try { cooks = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies); } catch (Exception ex) { }
if (cooks == null)
cooks = new List<CefSharp.Cookie>();
string cookJs = "";
var keys = new string[] { "_qimei_uuid", "_qpsvr_localtk", "biz_magic", "biz_rand", "biz_ticket", "biz_token", "ptcz", "RK", "yyb_muid" };
foreach (var shopCook in cooks)
{
var cookie = shopCook.Name + "=" + shopCook.Value;
if (!keys.Any(k => cookie.StartsWith(k)))
continue;
cookJs += "\r\ndocument.cookie='" + cookie.Substring(0, Math.Max(0, cookie.IndexOf("="))) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';";
}
foreach (var shopCook in cooks)
{
var cookie = shopCook.Name + "=" + shopCook.Value;
if (!keys.Any(k => cookie.StartsWith(k)))
continue;
if (!cookie.StartsWith("biz_magic") && !cookie.StartsWith("biz_rand") && !cookie.StartsWith("biz_ticket") && !cookie.StartsWith("biz_token"))
cookJs += "\r\ndocument.cookie='" + cookie + "; domain=.qq.com; expires=" +
DateTime.Now.AddMonths(1).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'UTC'", new DateTimeFormatInfo()) + "; path=/';";
else
cookJs += "\r\ndocument.cookie='" + cookie + "; domain=store.weixin.qq.com; expires=" +
DateTime.Now.AddMonths(1).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'UTC'", new DateTimeFormatInfo()) + "; path=/';";
}
cookJs += "\r\nsetTimeout(() => { window.location.href='https://store.weixin.qq.com/shop/goods/list'; }, 200)";
Clipboard.SetDataObject(cookJs);
BaseMsgForm.ShowInfo("复制成功");
break;
case "导入Cookie":
WXShopUpdateCookieForm updateCookieForm = new WXShopUpdateCookieForm(shop);
updateCookieForm.SaveComplete += UpdateCookieForm_SaveComplete;
updateCookieForm.ShowDialog();
break;
case "删除":
if (BaseMsgForm.ShowConfirm("确定删除店铺吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
return;
if (ShopBLL.AdminDelServerShop(shop))
SearchShop(this.ucSplitPage1.CurrentPage);
break;
case "编辑":
WXShopAddEditForm editForm = new WXShopAddEditForm(new List<ShopLoginInfo> { shop });
editForm.SaveCompleteWithDescribe += EditForm_SaveCompleteWithDescribe;
editForm.ShowDialog();
break;
case "登录":
IsOperate = true;
{
WXAdminShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop });
if (shop.LoginStatus != "登录成功")
{
WXAdminShopLoginForm adminLoginForm = new WXAdminShopLoginForm(shop);
adminLoginForm.openType = EnumOpenType.manage;
adminLoginForm.WindowState = FormWindowState.Maximized;
adminLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home";
adminLoginForm.Show();
}
else
{
WXAdminShopLoginForm shopLoginForm = new WXAdminShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
}
}
IsOperate = false;
break;
case "上传商品":
IsOperate = true;
{
//UploadProduct(shop);
}
IsOperate = false;
break;
case "+":
case "±":
break;
case "":
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
break;
default:
break;
}
}
private void UpdateCookieForm_SaveComplete(object obj)
{
Task.Run(() =>
{
//CheckShopListLogin(new string[] { (obj as DouShopLoginInfo).LoginName });
//RefreshDataGridView(false);
SearchShop(this.ucSplitPage1.CurrentPage);
});
}
private void EditForm_SaveCompleteWithDescribe(object obj, object isAdd, object sender)
{
var shopInfoLst = obj as List<ShopLoginInfo>;
if (shopInfoLst != null)
{
this.pbLoading.Visible = true;
Task.Run(() =>
{
int i = 1;
foreach (var shopInfo in shopInfoLst)
{
Invoke(new Action(() =>{
this.statusBar.pgbTaskProgress.Value = i;
this.statusBar.pgbTaskProgress.Text = i + "/" + shopInfoLst.Count;
i++;
}));
if ((isAdd as bool?) == true)
{
var shop = lstAdminShopInfo.FirstOrDefault(v => v.LoginName == shopInfo.LoginName);
if (shop != null)
{
BaseMsgForm.ShowError("店铺" + shopInfo.LoginName + "已存在!");
}
else
{
ShopBLL.AdminAddServerShop(shopInfo);
}
}
else
{
ShopBLL.AdminMdyServerShop(shopInfo);
}
}
Invoke(new Action(() =>
{
this.pbLoading.Visible = false;
this.statusBar.pgbTaskProgress.Text = "准备就绪";
}));
});
SearchShop(this.ucSplitPage1.CurrentPage);
}
}
private List<string> GetCheckedList()
{
List<string> shopLoginNameList = new List<string>();
for (int i = 0; i < dgvShop.Rows.Count; i++)
{
if (dgvShop.Rows[i].Cells["colSelect"].Value.ParseToBool())
{
string shopName = dgvShop.Rows[i].Cells["colLoginName"].Value.ParseToString();
shopLoginNameList.Add(shopName);
}
}
return shopLoginNameList;
}
private List<string> GetCheckedShopIdList()
{
List<string> shopNameList = new List<string>();
for (int i = 0; i < dgvShop.Rows.Count; i++)
{
if (dgvShop.Rows[i].Cells["colSelect"].Value.ParseToBool())
{
string shopName = dgvShop.Rows[i].Cells["colShopId"].Value.ParseToString();
shopName += dgvShop.Rows[i].Cells["colUser"].Value.ParseToString();
shopNameList.Add(shopName);
}
}
return shopNameList;
}
public List<ShopLoginInfo> AdminGetServerShopLst(out int pageCount, out decimal seconds, int page = 1, int pageSize = 50)
{
List<ShopLoginInfo> list = new List<ShopLoginInfo>();
pageCount = 1;
seconds = 0;
var url = BaseClass.BuildObjString("shop/admin_get_shop_list");
var data = UserLogin.GetSignaturex() +
"&page=" + page +
"&page_size=" + pageSize +
"&search_user_name=" + txtUserName.Text.Trim() +
"&search_login_name=" + txtLoginName.Text.Trim() +
"&search_notes=" + txtNotes.Text.Trim() +
"&search_id=" + txtShopId.Text.Trim() +
"&search_name=" + txtShopName.Text.Trim();
if (BaseClass.SaLevel > 1)
data += "&operate_sub_sa_name=" + BaseClass.UserName;
var html = GetHtml.PostUtf8(url, data);
//if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
// html = GetHtml.PostUtf8(url, data);
//if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
// html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html)
|| !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass"))
{
return list;
}
int count = BaseRegex.GetIntJson(ref html, "count");
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
pageCount = Math.Max(pageCount, 1);
seconds = BaseRegex.GetDecimalJson(ref html, "seconds");
return ShopBLL.DeserializationShop(html);
}
private void dgvShop_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
}
}
}