超级店铺管理功能
This commit is contained in:
1 parent
d3e404ac2a
commit
fe2d2883db
91 files changed
+4295
-587
No files matched your search
@@ -0,0 +1,499 @@
|
||||
using AllBase;
|
||||
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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.Extension;
|
||||
using TemuKJD.KJDForms.BaseForms;
|
||||
using TemuKJD.KJDForms.ShopForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.KJDForms.AdminForms
|
||||
{
|
||||
public partial class AdminShopForm : Form
|
||||
{
|
||||
public List<ShopLoginInfo> lstShopInfo = new List<ShopLoginInfo>();
|
||||
|
||||
public AdminShopForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void AdminShopForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.ucSplitPage1.PageChange += UcSplitPage1_PageChange;
|
||||
|
||||
this.dgvShop.AddSelectorColumn("colSelect");
|
||||
}
|
||||
|
||||
private void AdminShopForm_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (this.Visible == true)
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
}
|
||||
|
||||
private void UcSplitPage1_PageChange(object obj)
|
||||
{
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
|
||||
public void SearchShop(int page)
|
||||
{
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
this.dgvShop.Rows.Clear();
|
||||
this.lstShopInfo.Clear();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
this.dgvShop.Rows.Clear();
|
||||
this.lstShopInfo.Clear();
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
int pageCount;
|
||||
var list = AdminGetServerShop(out pageCount, page);
|
||||
lstShopInfo.AddRange(list);
|
||||
this.ucSplitPage1.TotalPage = pageCount;
|
||||
|
||||
foreach (var shop in lstShopInfo)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
int rowIndex = this.dgvShop.Rows.Add(
|
||||
false,
|
||||
shop.LoginName,
|
||||
shop.ShopId,
|
||||
shop.ShopAccount,
|
||||
shop.Notes,
|
||||
shop.Cookies,
|
||||
shop.UserName,
|
||||
shop.SubUserName,
|
||||
shop.GroupName,
|
||||
shop.UploadAccount,
|
||||
shop.BuyAccount,
|
||||
shop.ChatAccount,
|
||||
"",
|
||||
"进入",
|
||||
"检测",
|
||||
string.IsNullOrWhiteSpace(shop.LoginStatus) ? "未登录" : shop.LoginStatus.Trim(),
|
||||
"多重登录",
|
||||
shop.ApiAuthStatus,
|
||||
shop.BuyApiAuth.ApiAuthStatus,
|
||||
"复制Cookies",
|
||||
"编辑",
|
||||
"删除");
|
||||
}));
|
||||
}
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = false;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
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 = false;
|
||||
private void btnLoginSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
IsOperate = true;
|
||||
if (this.btnLoginSelect.Text == "登录选中")
|
||||
{
|
||||
List<string> shopLoginNameList = GetCheckedList();
|
||||
if (!shopLoginNameList.Any())
|
||||
{
|
||||
BaseMsgForm.ShowError("请选择需要登录的店铺");
|
||||
IsOperate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
shopLoginNameList = shopLoginNameList.Distinct().ToList();
|
||||
foreach (var loginName in shopLoginNameList)
|
||||
{
|
||||
if (IsOperate == false)
|
||||
break;
|
||||
|
||||
var shopInfo = this.lstShopInfo.FirstOrDefault(v => v.LoginName == loginName);
|
||||
if (shopInfo != null && !string.IsNullOrEmpty(shopInfo.LoginName) && !string.IsNullOrEmpty(shopInfo.Password))
|
||||
{
|
||||
AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shopInfo);
|
||||
shopLoginForm.openType = EnumOpenType.login;
|
||||
shopLoginForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
if (shopLoginNameList.Count>0)
|
||||
{
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
}
|
||||
IsOperate = 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 = this.lstShopInfo.FirstOrDefault(v => v.LoginName == loginName && v.ShopId == accountId);
|
||||
|
||||
switch (headerText)
|
||||
{
|
||||
case "检测":
|
||||
//CheckShopLoginAsync(new string[] { loginName });
|
||||
break;
|
||||
case "进入店铺":
|
||||
IsOperate = true;
|
||||
{
|
||||
AdminShopLoginForm adminLoginForm = new AdminShopLoginForm(shop);
|
||||
adminLoginForm.openType = EnumOpenType.manage;
|
||||
adminLoginForm.WindowState = FormWindowState.Maximized;
|
||||
adminLoginForm.Show();
|
||||
}
|
||||
IsOperate = false;
|
||||
break;
|
||||
case "复制Cookies":
|
||||
string cook = shop.Cookies;
|
||||
string cookJs = "";
|
||||
foreach (var cookie in shop.Cookies.Split(';'))
|
||||
{
|
||||
cookJs += "\r\ndocument.cookie='" + cookie.Trim() + "';";
|
||||
}
|
||||
cookJs += "\r\nsetTimeout(() => { window.location.href='https://seller.kuajingmaihuo.com'; }, 200)";
|
||||
Clipboard.SetDataObject(cookJs);
|
||||
BaseMsgForm.ShowInfo("复制成功");
|
||||
break;
|
||||
case "删除":
|
||||
if (BaseMsgForm.ShowConfirm("确定删除店铺吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||||
return;
|
||||
AdminDelServerShop(shop);
|
||||
break;
|
||||
case "编辑":
|
||||
ShopAddEditForm editForm = new ShopAddEditForm(shop);
|
||||
editForm.SaveCompleteWithDescribe += EditForm_SaveCompleteWithDescribe;
|
||||
editForm.ShowDialog();
|
||||
break;
|
||||
case "登录":
|
||||
IsOperate = true;
|
||||
{
|
||||
AdminShopLoginForm shopLoginForm = new AdminShopLoginForm(shop);
|
||||
shopLoginForm.openType = EnumOpenType.login;
|
||||
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
|
||||
shopLoginForm.ShowDialog();
|
||||
}
|
||||
IsOperate = false;
|
||||
break;
|
||||
default:
|
||||
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void EditForm_SaveCompleteWithDescribe(object obj, object isAdd)
|
||||
{
|
||||
var shopInfo = obj as ShopLoginInfo;
|
||||
if (shopInfo != null)
|
||||
{
|
||||
if ((isAdd as bool?) == true)
|
||||
{
|
||||
var shop = lstShopInfo.FirstOrDefault(v => v.LoginName == shopInfo.LoginName);
|
||||
if (shop != null)
|
||||
{
|
||||
BaseMsgForm.ShowError("店铺" + shopInfo.LoginName + "已存在!");
|
||||
}
|
||||
else
|
||||
{
|
||||
AdminAddServerShop(shopInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AdminMdyServerShop(shopInfo);
|
||||
}
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetCheckedList()
|
||||
{
|
||||
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["colLoginName"].Value.ParseToString();
|
||||
shopNameList.Add(shopName);
|
||||
}
|
||||
}
|
||||
return shopNameList;
|
||||
}
|
||||
|
||||
public List<ShopLoginInfo> AdminGetServerShop(out int pageCount, int page = 1, int pageSize = 50)
|
||||
{
|
||||
List<ShopLoginInfo> list = new List<ShopLoginInfo>();
|
||||
pageCount = 1;
|
||||
|
||||
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();
|
||||
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);
|
||||
|
||||
var jArr = JObject.Parse(html)["data"];
|
||||
if (jArr.Count() == 0)
|
||||
return list;
|
||||
foreach (JObject jObj in jArr)
|
||||
{
|
||||
string shopStr = jObj.ToString();
|
||||
ShopLoginInfo shop = new ShopLoginInfo();
|
||||
shop.DbId = BaseRegex.GetStringJson(ref shopStr, "id");
|
||||
if (shop.DbId == null)
|
||||
continue;
|
||||
shop.LoginName = BaseRegex.GetStringJson(ref shopStr, "login_name");
|
||||
shop.Password = BaseRegex.GetStringJson(ref shopStr, "login_pass");
|
||||
shop.ShopId = BaseRegex.GetStringJson(ref shopStr, "shop_id");
|
||||
shop.ShopAccount = BaseRegex.GetStringJson(ref shopStr, "shop_account");
|
||||
shop.UserName = BaseRegex.GetStringJson(ref shopStr, "user_name");
|
||||
shop.SubUserName = BaseRegex.GetStringJson(ref shopStr, "sub_user_name");
|
||||
shop.GroupName = BaseRegex.GetStringJson(ref shopStr, "shop_group");
|
||||
shop.Cookies = BaseRegex.GetStringJson(ref shopStr, "cookie");
|
||||
shop.Cookies = shop.Cookies.Replace("&", "&").Replace("%", "%").Replace("+", "+");
|
||||
shop.CompanyName = BaseRegex.GetStringJson(ref shopStr, "company_name");
|
||||
shop.Notes = BaseRegex.GetStringJson(ref shopStr, "notes");
|
||||
shop.LoginStatus = BaseRegex.GetStringJson(ref shopStr, "login_status");
|
||||
|
||||
list.Add(shop);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static string AdminAddServerShop(ShopLoginInfo _shop)
|
||||
{
|
||||
var url = BaseClass.BuildObjString("shop/admin_add_shop");
|
||||
var data = UserLogin.GetSignaturex()
|
||||
+ "&shop_user_name=" + _shop.UserName
|
||||
+ "&login_name=" + _shop.LoginName
|
||||
+ "&login_pass=" + GetHtml.UrlEncodeUtf8(_shop.Password)
|
||||
+ "&shop_id=" + _shop.ShopId
|
||||
+ "&shop_account=" + _shop.ShopAccount
|
||||
+ "&cookie=" + _shop.Cookies
|
||||
+ "&shop_group=" + GetHtml.UrlEncodeUtf8(_shop.GroupName)
|
||||
+ "&sub_user_name=" + GetHtml.UrlEncodeUtf8(_shop.SubUserName)
|
||||
+ "¬es=" + GetHtml.UrlEncodeUtf8(_shop.Notes)
|
||||
+ "&login_status=" + _shop.LoginStatus;
|
||||
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200") && !result.Contains("已达上限") && !result.Contains("已存在"))
|
||||
result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200") && !result.Contains("已达上限") && !result.Contains("已存在"))
|
||||
result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200"))
|
||||
{
|
||||
var msg = BaseRegex.GetStringJson(ref result, "msg");
|
||||
if (string.IsNullOrEmpty(msg))
|
||||
msg = "店铺保存失败!";
|
||||
BaseMsgForm.ShowError(msg);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string AdminMdyServerShop(ShopLoginInfo _shop)
|
||||
{
|
||||
var url = BaseClass.BuildObjString("shop/admin_mdy_shop");
|
||||
var data = UserLogin.GetSignaturex()
|
||||
+ "&shop_user_name=" + _shop.UserName
|
||||
+ "&login_name=" + _shop.LoginName
|
||||
+ "&login_pass=" + GetHtml.UrlEncodeUtf8(_shop.Password)
|
||||
+ "&shop_group=" + GetHtml.UrlEncodeUtf8(_shop.GroupName)
|
||||
+ "&sub_user_name=" + GetHtml.UrlEncodeUtf8(_shop.SubUserName)
|
||||
+ "¬es=" + GetHtml.UrlEncodeUtf8(_shop.Notes);
|
||||
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200") && !result.Contains("已达上限") && !result.Contains("已存在"))
|
||||
result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200") && !result.Contains("已达上限") && !result.Contains("已存在"))
|
||||
result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200"))
|
||||
{
|
||||
var msg = BaseRegex.GetStringJson(ref result, "msg");
|
||||
if (string.IsNullOrEmpty(msg))
|
||||
msg = "店铺保存失败!";
|
||||
BaseMsgForm.ShowError(msg);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void AdminDelServerShop(ShopLoginInfo _shop)
|
||||
{
|
||||
var url = BaseClass.BuildObjString("shop/admin_del_shop");
|
||||
var data = UserLogin.GetSignaturex() + "&login_name=" + _shop.LoginName
|
||||
+ "&shop_user_name=" + _shop.UserName;
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200"))
|
||||
BaseMsgForm.ShowError("删除失败:" + BaseRegex.GetStringJson(ref result, "msg"));
|
||||
else
|
||||
{
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.btnCheck.Text == "检测选中")
|
||||
{
|
||||
List<string> shopNameList = GetCheckedList();
|
||||
if (!shopNameList.Any())
|
||||
{
|
||||
BaseMsgForm.ShowError("请选择需要检测的店铺");
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
CheckShopListLogin(shopNameList.Distinct().ToArray());
|
||||
SearchShop(this.ucSplitPage1.CurrentPage);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测店铺授权状态
|
||||
/// </summary>
|
||||
/// <param name="shopNames"></param>
|
||||
/// <param name="isShowProgress"></param>
|
||||
public void CheckShopListLogin(string[] shopNames, bool isShowProgress = true)
|
||||
{
|
||||
if (isShowProgress)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
this.statusBar.lblTaskStatus.Text = "正在检测...";
|
||||
this.statusBar.pgbTaskProgress.Value = 0;
|
||||
this.statusBar.pgbTaskProgress.Maximum = shopNames.Length;
|
||||
this.statusBar.pgbTaskProgress.Text = "0" + "/" + shopNames.Length;
|
||||
}));
|
||||
}
|
||||
|
||||
CheckShopLogin(shopNames, isShowProgress);
|
||||
|
||||
if (this.Created && isShowProgress)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.pbLoading.Visible = false;
|
||||
this.statusBar.lblTaskStatus.Text = "检测完毕";
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckShopLogin(string[] shopNames, bool isShowProgress = true)
|
||||
{
|
||||
for (int i = 0; i < shopNames.Length; i++)
|
||||
{
|
||||
var shop = this.lstShopInfo.FirstOrDefault(v => v.LoginName == shopNames[i]);
|
||||
var campanys = this.lstShopInfo.Where(v => v.LoginName == shopNames[i]).ToList();
|
||||
if (shop != null)
|
||||
{
|
||||
//var loginResult = "\"code\":0";//GetShopStatus(shop);
|
||||
var loginResult = ShopListForm.GetShopStatus(shop);
|
||||
if (loginResult.Contains("\"success\":true"))
|
||||
{
|
||||
foreach (var sc in campanys)
|
||||
{
|
||||
sc.LoginStatus = "登录成功";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var sc in campanys)
|
||||
{
|
||||
sc.LoginStatus = "未登录";
|
||||
}
|
||||
}
|
||||
ShopListForm.UpdateServerShopCookies(shop, shop.Cookies); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie
|
||||
}
|
||||
if (this.Created && isShowProgress)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "正在检测...";
|
||||
this.statusBar.pgbTaskProgress.Value = (i + 1);
|
||||
this.statusBar.pgbTaskProgress.Text = (i + 1) + "/" + shopNames.Length;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void chkShowDelete_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if(chkShowDelete.Checked)
|
||||
{
|
||||
this.dgvShop.Columns["colEdit"].Visible = true;
|
||||
this.dgvShop.Columns["colDelete"].Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dgvShop.Columns["colEdit"].Visible = false;
|
||||
this.dgvShop.Columns["colDelete"].Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user