1523 lines
68 KiB
C#
1523 lines
68 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Param.FissionManage;
|
||
using AllBase.Model.Param.ProductManage;
|
||
using AllBase.Model.Result;
|
||
using LittleRabbit.Extension;
|
||
using LittleRabbit.LittleRabbitForms.BaseForms;
|
||
using NaiBa.Util;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using Work;
|
||
using Work.BLL.Product;
|
||
using Work.BLL.Upload;
|
||
using Work.DouyinApiClass;
|
||
|
||
namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||
{
|
||
public partial class ViolateManageForm : Form
|
||
{
|
||
private CheckBox chkSelectAllShop = null;
|
||
private CheckBox chkSelectAllViolateParam = null;
|
||
CancellationTokenSource cancellationTokenSource = null;
|
||
|
||
/// <summary>
|
||
/// 排查出的违规信息列表
|
||
/// </summary>
|
||
public List<ViolateParam> LstViolateParam = new List<ViolateParam>();
|
||
|
||
/// <summary>
|
||
/// 导入的违规信息列表
|
||
/// </summary>
|
||
public List<ViolateInfo> LstViolateInfo = new List<ViolateInfo>();
|
||
/// <summary>
|
||
/// 动态查找上家并将违规入库的临时列表
|
||
/// </summary>
|
||
public List<ViolateInfo> LstVioLateInfoTemp = new List<ViolateInfo>();
|
||
|
||
|
||
|
||
public ViolateManageForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void ViolateManageForm_Load(object sender, EventArgs e)
|
||
{
|
||
LoadShops();
|
||
chkSelectAllShop = this.dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false, null, true);
|
||
chkSelectAllShop.CheckedChanged += ChkSelectAll_CheckedChanged;
|
||
chkSelectAllViolateParam = this.dgvCheck.AddSelectorColumn("col_result_select");
|
||
|
||
// 读取违规信息规则名称列表
|
||
GetAllViolateRuleName();
|
||
// 显示违规信息规则名称列表
|
||
//SetViolateSelectList(flpViolate);
|
||
|
||
// 获取暂存的导入违规罚单列表
|
||
LstViolateInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<ViolateInfo>>("violate_Info_list");
|
||
if (LstViolateInfo == null)
|
||
LstViolateInfo = new List<ViolateInfo>();
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var violateInfo in LstViolateInfo)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
ShowViolateInfo(violateInfo);
|
||
}));
|
||
}
|
||
LstVioLateInfoTemp.AddRange(LstViolateInfo);
|
||
});
|
||
|
||
// 获取暂存的还未处理的各种违规
|
||
LstViolateParam = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<ViolateParam>>("violate_param_wait_handle_list");
|
||
if (LstViolateParam == null)
|
||
LstViolateParam = new List<ViolateParam>();
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var violateParam in LstViolateParam)
|
||
{
|
||
string dataFromDescribe = GetDataFromDescribe(violateParam.DataFrom);
|
||
|
||
var shop = GlobalConfig.DouShopLoginList.FirstOrDefault(s => s.ShopAccountId == violateParam.DouShopId);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.dgvCheck.Rows.Add(true, dataFromDescribe, violateParam.DouShopId, shop?.ShopAccount, violateParam.DouProductId,
|
||
violateParam.UpIdNumber, violateParam.From, "货源网", violateParam.RuleNames, violateParam.CheckTime.ToString("yyyy-MM-dd HH:mm"));
|
||
}));
|
||
}
|
||
});
|
||
|
||
// 循环处理获取到的新违规
|
||
OperateViolateListTemp();
|
||
}
|
||
|
||
private void ChkSelectAll_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (!chkSelectAllShop.Checked)
|
||
{
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
row.Cells["colSelect"].Value = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var list = GlobalConfig.DouShopLoginList.Where(s => s.ApiAuthStatus == "授权成功").Select(ss => ss.ShopAccountId).ToList();
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
public static void SetViolateSelectList(Control control)
|
||
{
|
||
if (control == null || ViolateRuleParam.LstViolateRuleName == null)
|
||
return;
|
||
|
||
control.Invoke(new Action(() =>
|
||
{
|
||
control.Controls.Clear();
|
||
}));
|
||
|
||
var seriousViolateRuleNameList = ViolateRuleParam.LstViolateRuleName.Where(rn => ViolateRuleParam.LstSeriousViolateRuleName.Any(r => rn.Contains(r))).ToList();
|
||
var normalViolateRuleNameList = ViolateRuleParam.LstViolateRuleName.Where(rn => !seriousViolateRuleNameList.Contains(rn)).ToList();
|
||
|
||
List<Control> cList = new List<Control>();
|
||
foreach (var item in seriousViolateRuleNameList)
|
||
{
|
||
CheckBox cb = new CheckBox();
|
||
cb.Text = item;
|
||
cb.Name = "cb" + item;
|
||
cb.AutoSize = true;
|
||
cb.Checked = ViolateRuleParam.LstViolateRuleNameSelect.Contains(item);
|
||
cb.ForeColor = Color.FromArgb(240, 10, 0);
|
||
cb.Click += Cb_Click;
|
||
cList.Add(cb);
|
||
}
|
||
foreach (var item in normalViolateRuleNameList)
|
||
{
|
||
CheckBox cb = new CheckBox();
|
||
cb.Text = item;
|
||
cb.Name = "cb" + item;
|
||
cb.AutoSize = true;
|
||
cb.Checked = ViolateRuleParam.LstViolateRuleNameSelect.Contains(item);
|
||
cb.Click += Cb_Click;
|
||
cList.Add(cb);
|
||
}
|
||
|
||
control.Invoke(new Action(() =>
|
||
{
|
||
control.Controls.AddRange(cList.ToArray());
|
||
}));
|
||
}
|
||
|
||
public static void Cb_Click(object sender, EventArgs e)
|
||
{
|
||
var check = sender as CheckBox;
|
||
if (check != null)
|
||
{
|
||
var t = "";
|
||
foreach (var tt in ViolateRuleParam.LstViolateRuleNameSelect)
|
||
{
|
||
t += "\"" + tt + "\"" + ",\r\n";
|
||
}
|
||
if (check.Checked)
|
||
{
|
||
if (!ViolateRuleParam.LstViolateRuleNameSelect.Contains(check.Text))
|
||
ViolateRuleParam.LstViolateRuleNameSelect.Add(check.Text);
|
||
}
|
||
else
|
||
{
|
||
while (ViolateRuleParam.LstViolateRuleNameSelect.Contains(check.Text))
|
||
ViolateRuleParam.LstViolateRuleNameSelect.Remove(check.Text);
|
||
}
|
||
StartUp.SaveViolateRuleNameSelectList();
|
||
}
|
||
}
|
||
|
||
public void ResetStatusBar()
|
||
{
|
||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||
this.statusBar.lblTaskStatus.Text = "准备就绪";
|
||
this.statusBar.pgbTaskProgress.Value = 0;
|
||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||
}
|
||
|
||
public void LoadShops()
|
||
{
|
||
// 获取被删除的店铺
|
||
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> !GlobalConfig.DouShopLoginList.Any(s => s.ShopAccountId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
|
||
// 更新被删除的店铺列表
|
||
foreach (var row in dgvRowList)
|
||
{
|
||
dgvShop.Rows.Remove(row);
|
||
}
|
||
|
||
for (int i = 0; i < GlobalConfig.DouShopLoginList.Count; i++)
|
||
{
|
||
var shop = GlobalConfig.DouShopLoginList[i];
|
||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value?.ToString() == shop.ShopAccountId);
|
||
if (row == null)
|
||
dgvShop.Rows.Add(false, shop.ShopAccountId, shop.ShopAccount, shop.LoginStatus);
|
||
else
|
||
{
|
||
row.Cells["colAuthStatus"].Value = shop.ApiAuthStatus;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnRefreshShop_Click(object sender, EventArgs e)
|
||
{
|
||
LoadShops();
|
||
}
|
||
|
||
private void ViolateManageForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (Visible)
|
||
{
|
||
LoadShops();
|
||
Task.Run(() =>
|
||
{
|
||
SetViolateSelectList(flpViolate);
|
||
});
|
||
}
|
||
}
|
||
|
||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string colId = dgvShop.Columns[e.ColumnIndex].Name;
|
||
if (colId == "colSelect")
|
||
{
|
||
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value.ParseToBool();
|
||
}
|
||
}
|
||
|
||
private void dgvCheck_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
|
||
var columnName = dgvCheck.Columns[e.ColumnIndex].Name;
|
||
if (MouseButtons == MouseButtons.Left)
|
||
{
|
||
if (columnName == "col_result_select")
|
||
{
|
||
dgvCheck.Rows[e.RowIndex].Cells["col_result_select"].Value = !dgvCheck.Rows[e.RowIndex].Cells["col_result_select"].Value.ParseToBool();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void dgvCheck_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
|
||
var columnName = dgvCheck.Columns[e.ColumnIndex].Name;
|
||
if (MouseButtons == MouseButtons.Left)
|
||
{
|
||
if (columnName == "col_result_select")
|
||
{
|
||
dgvCheck.Rows[e.RowIndex].Cells["col_result_select"].Value = !dgvCheck.Rows[e.RowIndex].Cells["col_result_select"].Value.ParseToBool();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void dgvCheck_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
|
||
var douGoodsId = dgvCheck.Rows[e.RowIndex].Cells["col_result_product_id"].Value?.ToString();
|
||
var upId = dgvCheck.Rows[e.RowIndex].Cells["col_result_up_id"].Value?.ToString();
|
||
var from = dgvCheck.Rows[e.RowIndex].Cells["col_result_from"].Value?.ToString();
|
||
var columnName = dgvCheck.Columns[e.ColumnIndex].Name;
|
||
if (columnName == "col_result_product_id")
|
||
{
|
||
var url = "https://haohuo.jinritemai.com/views/product/detail?id=" + douGoodsId;
|
||
GetHtml.OpenUrl(url);
|
||
}
|
||
else if (columnName == "col_result_up_id")
|
||
{
|
||
var url = "";
|
||
if (from == "淘宝")
|
||
url = "https://item.taobao.com/item.htm?id=" + upId;
|
||
else if (from == "阿里巴巴")
|
||
url = "https://detail.1688.com/offer/" + upId + ".html";
|
||
else if (from == "微店")
|
||
url = "https://weidian.com/item.html?itemID=" + upId;
|
||
else if (from == "京喜")
|
||
url = "https://item.m.jd.com/product/" + upId + ".html";
|
||
else if (from == "拼多多")
|
||
url = "http://mobile.yangkeduo.com/goods.html?goods_id=" + upId;
|
||
else if (from == "抖音" || from == "")
|
||
url = "https://haohuo.jinritemai.com/views/product/detail?id=" + upId;
|
||
GetHtml.OpenUrl(url);
|
||
}
|
||
}
|
||
|
||
private void dgvViolateFileData_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
|
||
var douGoodsId = dgvViolateFileData.Rows[e.RowIndex].Cells["col_business_id"].Value.ToString();
|
||
var upId = dgvViolateFileData.Rows[e.RowIndex].Cells["col_up_id"].Value.ToString();
|
||
var from = dgvViolateFileData.Rows[e.RowIndex].Cells["col_from"].Value.ToString();
|
||
var columnName = dgvViolateFileData.Columns[e.ColumnIndex].Name;
|
||
if (columnName == "col_business_id")
|
||
{
|
||
var url = "https://haohuo.jinritemai.com/views/product/detail?id=" + douGoodsId;
|
||
GetHtml.OpenUrl(url);
|
||
}
|
||
else if (columnName == "col_up_id")
|
||
{
|
||
var url = "";
|
||
if (from == "淘宝")
|
||
url = "https://item.taobao.com/item.htm?id=" + upId;
|
||
else if (from == "阿里巴巴")
|
||
url = "https://detail.1688.com/offer/" + upId + ".html";
|
||
else if (from == "微店")
|
||
url = "https://weidian.com/item.html?itemID=" + upId;
|
||
else if (from == "京喜")
|
||
url = "https://item.m.jd.com/product/" + upId + ".html";
|
||
else if (from == "拼多多")
|
||
url = "http://mobile.yangkeduo.com/goods.html?goods_id=" + upId;
|
||
else if (from == "抖音" || from == "")
|
||
url = "https://haohuo.jinritemai.com/views/product/detail?id=" + upId;
|
||
GetHtml.OpenUrl(url);
|
||
}
|
||
}
|
||
|
||
private void btnImport_Click(object sender, EventArgs e)
|
||
{
|
||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||
openFileDialog.Filter = "商家罚单.csv文件(*.csv)|*.csv";
|
||
openFileDialog.RestoreDirectory = true;
|
||
openFileDialog.FilterIndex = 1;
|
||
openFileDialog.Multiselect = true;
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
this.ucTabControl1.SelectedTab = this.tabPageViolateFileList;
|
||
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var fileName in openFileDialog.FileNames)
|
||
{
|
||
string lineStr = string.Empty;
|
||
string productUrl = string.Empty;
|
||
try
|
||
{
|
||
using (StreamReader sr = new StreamReader(fileName, Encoding.Default))
|
||
{
|
||
int row = 0;
|
||
List<string> tableHeader = new List<string>();
|
||
while ((lineStr = sr.ReadLine()) != null)
|
||
{
|
||
if (lineStr.StartsWith("罚单编号"))
|
||
tableHeader = lineStr.Split(',').ToList();
|
||
if (tableHeader.Count == 0 || lineStr.StartsWith("罚单编号"))
|
||
continue;
|
||
List<string> tableBody = FileBase.CsvStrToList(lineStr);
|
||
if (tableHeader.Count != tableBody.Count)
|
||
continue;
|
||
|
||
Dictionary<string, string> tableDic = new Dictionary<string, string>();
|
||
for (int i = 0; i < tableHeader.Count; i++)
|
||
{
|
||
tableDic[tableHeader[i]] = tableBody[i];
|
||
}
|
||
ViolateInfo violateInfo = new ViolateInfo()
|
||
{
|
||
against_detail = tableDic["违规详情"]?.Trim(),
|
||
business_id = tableDic["订单/商品/店铺 编号"]?.Trim(),
|
||
penalize_id = tableDic["罚单编号"]?.Trim(),
|
||
rule_name = tableDic["违规类型"]?.Trim(),
|
||
fileName = fileName,
|
||
};
|
||
if (LstViolateInfo.Any(v => v.penalize_id == violateInfo.penalize_id))
|
||
continue;
|
||
|
||
ShowViolateInfo(violateInfo);
|
||
LstViolateInfo.Add(violateInfo);
|
||
LstVioLateInfoTemp.Add(violateInfo);
|
||
|
||
row++;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex.Message.Contains("无法访问"))
|
||
{
|
||
BaseMsgForm.ShowInfo("文件" + fileName + "打开失败,请查看是否有其他应用正在使用。");
|
||
}
|
||
}
|
||
}
|
||
SaveViolateInfoList();
|
||
});
|
||
}
|
||
}
|
||
|
||
private void ShowViolateInfo(ViolateInfo violateInfo)
|
||
{
|
||
string fileShotName = violateInfo.fileName.Split(new string[] { "\\", ".csv" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
||
string dir = violateInfo.fileName.Split(new string[] { fileShotName }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvViolateFileData.Rows.Add(false, dir, fileShotName, violateInfo.penalize_id, violateInfo.business_id, "", "", violateInfo.rule_name, violateInfo.against_detail, "删除");
|
||
}));
|
||
}
|
||
|
||
private void ucTabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
if (ucTabControl1.SelectedTab == tabPageCheckResult)
|
||
{
|
||
btnClear.Text = "清空排查结果";
|
||
}
|
||
else if (ucTabControl1.SelectedTab == tabPageViolateFileList)
|
||
{
|
||
btnClear.Text = "清空罚单";
|
||
}
|
||
}
|
||
|
||
private void btnClear_Click(object sender, EventArgs e)
|
||
{
|
||
if (btnClear.Text == "清空排查结果")
|
||
{
|
||
if (BaseMsgForm.ShowConfirm("确定要清空排查结果?清空后需要重新排查!").DialogResult == DialogResult.OK)
|
||
{
|
||
dgvCheck.Rows.Clear();
|
||
LstViolateParam.Clear();
|
||
SaveViolateParamWaitHandleList();
|
||
}
|
||
}
|
||
else if (btnClear.Text == "清空罚单")
|
||
{
|
||
if (BaseMsgForm.ShowConfirm("确定要清空罚单列表?清空后再次导入需要重新分析罚单数据!").DialogResult == DialogResult.OK)
|
||
{
|
||
dgvViolateFileData.Rows.Clear();
|
||
LstViolateInfo.Clear();
|
||
LstVioLateInfoTemp.Clear();
|
||
Task.Run(() =>
|
||
{
|
||
SaveViolateInfoList();
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnStartTroubleShooting_Click(object sender, EventArgs e)
|
||
{
|
||
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>()
|
||
.Where(r => r.Cells["colSelect"].Value.ParseToBool())
|
||
.Select(r => r.Cells["colShopId"].Value?.ToString()).ToList();
|
||
var shopList = GlobalConfig.DouShopLoginList.Where(s => lstShopId.Contains(s.ShopAccountId) && s.ApiAuthStatus == "授权成功").ToList();
|
||
if (shopList.Count == 0 && (chkOperateOffSale.Checked || chkOperateOnSale.Checked))
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择要清理素材的店铺");
|
||
return;
|
||
}
|
||
shopList = shopList.Where(s => s.ApiAuthStatus == "授权成功").ToList();
|
||
if (shopList.Count == 0 && (chkOperateOffSale.Checked || chkOperateOnSale.Checked))
|
||
{
|
||
BaseMsgForm.ShowInfo("请检查店铺是否授权");
|
||
return;
|
||
}
|
||
|
||
if (LstVioLateInfoTemp.Count > 0)
|
||
{
|
||
var result = BaseMsgForm.ShowConfirm("正在分析罚单数据,请问是否要继续?").DialogResult;
|
||
if (result != DialogResult.OK)
|
||
return;
|
||
}
|
||
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
if (chkOperateDataBase.Checked && cancellationTokenSource?.IsCancellationRequested != true)
|
||
{
|
||
TroubleShootingDataBase();
|
||
}
|
||
|
||
if (chkOperateOnSale.Checked && cancellationTokenSource?.IsCancellationRequested != true)
|
||
{
|
||
TroubleShootingShopProduct(shopList, true);
|
||
}
|
||
|
||
if (chkOperateOffSale.Checked && cancellationTokenSource?.IsCancellationRequested != true)
|
||
{
|
||
TroubleShootingShopProduct(shopList, false);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
|
||
// 排查完毕后防止数据丢失保存到本地磁盘
|
||
SaveViolateParamWaitHandleList();
|
||
|
||
// 显示排查完毕
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cancellationTokenSource?.IsCancellationRequested != true)
|
||
BaseMsgForm.ShowInfo("排查完毕");
|
||
else
|
||
BaseMsgForm.ShowInfo("排查中断");
|
||
}));
|
||
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
private void TroubleShootingShopProduct(List<DouShopLoginInfo> shopList, bool isOperateOnline = true)
|
||
{
|
||
|
||
|
||
foreach (var shop in shopList)
|
||
{
|
||
int num = 0;
|
||
var total = shopList.Count();
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
num++;
|
||
|
||
this.statusBar.lblTaskStatus.Text = "排查店铺 " + shop.ShopAccount + " " + (isOperateOnline ? "在售" : "仓库") + "商品,当前第" + num + "个店铺/共" + total + "个店铺,获取店铺商品中";
|
||
this.statusBar.pgbTaskProgress.Value = 0;
|
||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||
}));
|
||
|
||
if (shop == null)
|
||
continue;
|
||
|
||
DataGridViewRow row = null;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null)
|
||
{
|
||
if (shop.PayStatus != 1)
|
||
{
|
||
row.Cells["colMessage"].Value = "当前为试用版,请购买专业版";
|
||
return;
|
||
}
|
||
|
||
if (isOperateOnline)
|
||
row.Cells["colMessage"].Value = "正在排查在售商品";
|
||
else
|
||
row.Cells["colMessage"].Value = "正在排查仓库商品";
|
||
}
|
||
}));
|
||
|
||
|
||
// 获取、显示商品数
|
||
GetShopProduct(shop, false);
|
||
|
||
int operateCount = 99999999; // 不限制操作数量
|
||
int totalNumBase = shop.OnlineProductCount; // 删除开始时的在售商品数
|
||
int totalNum = shop.OnlineProductCount; // 在售商品数
|
||
if (!isOperateOnline)
|
||
{
|
||
totalNumBase = shop.OfflineProductCount;
|
||
totalNum = shop.OfflineProductCount;
|
||
}
|
||
int setNum = 0; // 设置商品数量
|
||
int currentNum = 0; // 商品循环计数
|
||
int page = 0;
|
||
int pageSize = 50;
|
||
string deleteProductMessage = "";
|
||
List<DouProductListInfo> productList = new List<DouProductListInfo>();
|
||
|
||
var waitDeleteHtml = "";
|
||
|
||
while ((productList.Count < operateCount && currentNum < totalNumBase) || page == 0)
|
||
{
|
||
page += 1;
|
||
currentNum += pageSize;
|
||
if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { Invoke(new Action(() => { row.Cells["colMessage"].Value = "排查中断"; })); }
|
||
break;
|
||
}
|
||
|
||
// 根据上下架信息,获取商品列表
|
||
var productIsOnlineFlag = isOperateOnline ? 0 : 1;
|
||
waitDeleteHtml = GetShopProductListData(shop, productIsOnlineFlag, page, 50);
|
||
Thread.Sleep(Randomx.GetId(500, 1000));
|
||
|
||
if (waitDeleteHtml.Contains("\"code\":10000"))
|
||
{
|
||
totalNum = BaseRegex.GetIntJson(ref waitDeleteHtml, "total");
|
||
if (isOperateOnline)
|
||
shop.OnlineProductCount = totalNum;
|
||
else
|
||
shop.OfflineProductCount = totalNum;
|
||
|
||
if (operateCount > totalNumBase)
|
||
operateCount = totalNumBase;
|
||
if (currentNum > totalNumBase)
|
||
currentNum = totalNumBase;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.pgbTaskProgress.Value = currentNum;
|
||
this.statusBar.pgbTaskProgress.Text = currentNum + "/" + operateCount;
|
||
this.statusBar.pgbTaskProgress.Maximum = operateCount;
|
||
}));
|
||
if (totalNum == 0)
|
||
{
|
||
deleteProductMessage = "排查结束,店铺没有在售商品";
|
||
if (!isOperateOnline)
|
||
deleteProductMessage = "排查结束,店铺没有仓库商品";
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { row.Cells["colMessage"].Value = deleteProductMessage; }
|
||
}));
|
||
break;
|
||
}
|
||
|
||
try
|
||
{
|
||
JObject jObj = JObject.Parse(waitDeleteHtml);
|
||
var jObjDataStr = jObj["data"]?["data"]?.ToString();
|
||
if (!string.IsNullOrEmpty(jObjDataStr))
|
||
{
|
||
var addList = JsonHelper.DeserializeJsonToList<DouProductListInfo>(jObjDataStr);
|
||
if (addList != null)
|
||
{
|
||
productList.AddRange(addList);
|
||
}
|
||
}
|
||
deleteProductMessage = "已获取:" + currentNum + ",在售商品获取中...";
|
||
if (!isOperateOnline)
|
||
deleteProductMessage = "已获取:" + currentNum + ",仓库商品获取中...";
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { row.Cells["colMessage"].Value = deleteProductMessage; }
|
||
}));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseMsgForm.ShowError("获取商品发生错误:" + ex.Message);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var failMessage = BaseRegex.GetStringJson(ref waitDeleteHtml, "sub_msg");
|
||
if (string.IsNullOrEmpty(failMessage))
|
||
failMessage = waitDeleteHtml;
|
||
deleteProductMessage = ("排查遇到错误," + failMessage).TrimEnd(',');
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { row.Cells["colMessage"].Value = deleteProductMessage; }
|
||
}));
|
||
}
|
||
}
|
||
|
||
// 操作数大于满足筛选条件商品数时,操作数改为商品数
|
||
if (operateCount > productList.Count)
|
||
operateCount = productList.Count;
|
||
|
||
if (operateCount == 0)
|
||
{
|
||
deleteProductMessage = "店铺商品排查完成";
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { row.Cells["colMessage"].Value = deleteProductMessage; }
|
||
}));
|
||
}
|
||
|
||
if (productList.Count == 0)
|
||
{
|
||
deleteProductMessage = "店铺商品排查完成";
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { row.Cells["colMessage"].Value = deleteProductMessage; }
|
||
}));
|
||
}
|
||
|
||
List<ViolateParam> violateParamList = new List<ViolateParam>();
|
||
|
||
for (int i = 0; i < productList.Count && i < operateCount; i++)
|
||
{
|
||
if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { Invoke(new Action(() => { row.Cells["colMessage"].Value = "排查中断"; })); }
|
||
break;
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "排查店铺 " + shop.ShopAccount + " " + (isOperateOnline ? "在售" : "仓库") + "商品,当前第" + num + "个店铺/共" + total + "个店铺,商品排查中";
|
||
this.statusBar.pgbTaskProgress.Value = i + 1;
|
||
this.statusBar.pgbTaskProgress.Text = i + 1 + "/" + operateCount;
|
||
this.statusBar.pgbTaskProgress.Maximum = operateCount;
|
||
|
||
deleteProductMessage = "正在排查在售商品,第 " + (i + 1) + " 件商品,共 " + operateCount + " 件商品";
|
||
if (!isOperateOnline)
|
||
deleteProductMessage = "正在排查仓库商品,第 " + (i + 1) + " 件商品,共 " + operateCount + " 件商品";
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null) { row.Cells["colMessage"].Value = deleteProductMessage; }
|
||
}));
|
||
Thread.Sleep(Randomx.GetId(50, 150));
|
||
|
||
var product = productList[i];
|
||
setNum++;
|
||
|
||
ViolateParam violateParam = new ViolateParam()
|
||
{
|
||
DataFrom = isOperateOnline ? 2 : 3,
|
||
DouProductId = product.product_id.ToString(),
|
||
DouShopId = shop.ShopAccountId,
|
||
};
|
||
violateParamList.Add(violateParam);
|
||
|
||
if (violateParamList.Count >= 50 || i >= productList.Count || i >= operateCount)
|
||
{
|
||
GetViolateUpIdList(violateParamList);
|
||
violateParamList = violateParamList.Where(v => !string.IsNullOrEmpty(v.UpId)).ToList();
|
||
var upIds = violateParamList.Select(v => v.UpId).ToList();
|
||
|
||
var violateResultHtml = ViolateBLL.GetViolateList(upIds);
|
||
// 失败重试
|
||
if (violateResultHtml?.Contains(",") != true)
|
||
violateResultHtml = ViolateBLL.GetViolateList(upIds);
|
||
if (violateResultHtml?.Contains(",") != true)
|
||
continue;
|
||
|
||
var resultViolateList = violateResultHtml.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
|
||
foreach (var resultViolate in resultViolateList)
|
||
{
|
||
var vParam = violateParamList.FirstOrDefault(v => resultViolate.StartsWith(v.UpId));
|
||
if (vParam == null)
|
||
continue;
|
||
|
||
if (resultViolate == null || resultViolate.EndsWith("none") == true) // 没有违规信息
|
||
continue;
|
||
else // 有违规信息
|
||
{
|
||
var violateHtml = resultViolate.Replace(vParam.UpId + ",", "");
|
||
if (ViolateRuleParam.LstViolateRuleNameSelect.Any(v => ("^" + violateHtml + "^").Contains("^" + v + "^")))
|
||
{
|
||
vParam.CheckTime = DateTime.Now;
|
||
vParam.RuleNames = violateHtml;
|
||
if (!LstViolateParam.Any(vp => vp.UpId == vParam.UpId && vp.DouProductId == vParam.DouProductId))
|
||
{
|
||
LstViolateParam.Add(vParam);
|
||
|
||
if (LstViolateParam.Count % 50 == 0)
|
||
SaveViolateParamWaitHandleList();
|
||
|
||
string dataFromDescribe = GetDataFromDescribe(vParam.DataFrom);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.dgvCheck.Rows.Add(true, dataFromDescribe, vParam.DouShopId, shop.ShopAccount, vParam.DouProductId,
|
||
vParam.UpIdNumber, vParam.From, "货源网", vParam.RuleNames, vParam.CheckTime.ToString("yyyy-MM-dd HH:mm"));
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
violateParamList.Clear();
|
||
}
|
||
}
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
var text = "排查店铺商品中断!";
|
||
this.statusBar.lblTaskStatus.Text = text;
|
||
}
|
||
else
|
||
{
|
||
var text = "排查店铺商品完成!";
|
||
this.statusBar.lblTaskStatus.Text = text;
|
||
}
|
||
}));
|
||
// 排查在售/仓库后防止数据丢失保存到本地磁盘
|
||
SaveViolateParamWaitHandleList();
|
||
Thread.Sleep(5000);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 批量排查产品数据库违规
|
||
/// </summary>
|
||
public void TroubleShootingDataBase()
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||
this.statusBar.lblTaskStatus.Text = "排查产品数据库";
|
||
this.statusBar.pgbTaskProgress.Value = 0;
|
||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||
}));
|
||
|
||
int currentNum = 0;
|
||
int current_page = 1;
|
||
int totalCount = 99999999;
|
||
//string begainTime = "2000-01-01";
|
||
//string endTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
|
||
List<ViolateParam> violateParamList = new List<ViolateParam>();
|
||
while (true)
|
||
{
|
||
if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
break;
|
||
}
|
||
|
||
string url = BaseClass.BuildFissionObjString("fession_api");
|
||
string paraStr = "¤t_page=" + current_page
|
||
//+ "&begin_time=" + begainTime
|
||
//+ "&end_time=" + endTime
|
||
+ "&pagesize=500";
|
||
|
||
string requestData = UserLogin.GetSignaturex() + "&act=get" + paraStr;
|
||
|
||
try
|
||
{
|
||
string htmlData = GetHtml.PostUtf8(url, requestData);
|
||
if (htmlData.Contains("\"list\":[]"))
|
||
break;
|
||
|
||
var FessionObj = JsonConvert.DeserializeObject<FissionRoot>(htmlData); // 反序列化
|
||
if (FessionObj != null)
|
||
{
|
||
totalCount = FessionObj.count;
|
||
var fessionDataList = FessionObj.list;
|
||
foreach (var fessionData in fessionDataList)
|
||
{
|
||
if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
break;
|
||
}
|
||
|
||
Thread.Sleep(Randomx.GetId(20, 50));
|
||
|
||
currentNum += 1;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.pgbTaskProgress.Maximum = totalCount;
|
||
this.statusBar.lblTaskStatus.Text = "排查产品数据库";
|
||
this.statusBar.pgbTaskProgress.Value = currentNum;
|
||
this.statusBar.pgbTaskProgress.Text = currentNum + "/" + totalCount;
|
||
}));
|
||
|
||
string prev = "";
|
||
if (fessionData.source == "拼多多")
|
||
prev = "pdd-";
|
||
else if (fessionData.source == "淘宝")
|
||
prev = "tb-";
|
||
else if (fessionData.source == "阿里")
|
||
prev = "al-";
|
||
else if (fessionData.source == "抖音")
|
||
prev = "dy-";
|
||
else if (fessionData.source == "京喜")
|
||
prev = "jx-";
|
||
|
||
ViolateParam violateParam = new ViolateParam()
|
||
{
|
||
DataFrom = 1,
|
||
UpId = prev + fessionData.fession_id
|
||
};
|
||
violateParamList.Add(violateParam);
|
||
|
||
if (violateParamList.Count >= 50 || currentNum >= totalCount)
|
||
{
|
||
var upIds = violateParamList.Select(v => v.UpId).ToList();
|
||
var violateResultHtml = ViolateBLL.GetViolateList(upIds);
|
||
// 失败重试
|
||
if (violateResultHtml?.Contains(",") != true)
|
||
violateResultHtml = ViolateBLL.GetViolateList(upIds);
|
||
if (violateResultHtml?.Contains(",") != true)
|
||
continue;
|
||
|
||
var resultViolateList = violateResultHtml.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
|
||
foreach (var resultViolate in resultViolateList)
|
||
{
|
||
|
||
var vParam = violateParamList.FirstOrDefault(v => resultViolate.StartsWith(v.UpId));
|
||
if (vParam == null)
|
||
continue;
|
||
|
||
if (resultViolate == null || resultViolate.EndsWith("none")) // 没有违规信息
|
||
continue;
|
||
else // 有违规信息
|
||
{
|
||
var violateHtml = resultViolate.Replace(vParam.UpId + ",", "");
|
||
if (ViolateRuleParam.LstViolateRuleNameSelect.Any(v => ("^" + violateHtml + "^").Contains("^" + v + "^")))
|
||
{
|
||
vParam.CheckTime = DateTime.Now;
|
||
vParam.RuleNames = violateHtml;
|
||
if (!LstViolateParam.Any(vp => vp.UpId == vParam.UpId && vp.DouProductId == vParam.DouProductId))
|
||
{
|
||
LstViolateParam.Add(vParam);
|
||
|
||
if (LstViolateParam.Count % 50 == 0)
|
||
SaveViolateParamWaitHandleList();
|
||
|
||
string dataFromDescribe = GetDataFromDescribe(vParam.DataFrom);
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.dgvCheck.Rows.Add(true, dataFromDescribe, "", "", "",
|
||
vParam.UpIdNumber, vParam.From, "货源网", vParam.RuleNames, vParam.CheckTime.ToString("yyyy-MM-dd HH:mm"));
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
violateParamList.Clear();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (currentNum >= totalCount)
|
||
break;
|
||
current_page++;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogSave.Add(Name, "访问产品数据库异常");
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||
this.statusBar.lblTaskStatus.Text = "访问产品数据库异常";
|
||
this.statusBar.pgbTaskProgress.Value = 0;
|
||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||
}));
|
||
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
Thread.Sleep(30000);
|
||
break;
|
||
}
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||
this.statusBar.lblTaskStatus.Text = "产品数据库排查完毕";
|
||
this.statusBar.pgbTaskProgress.Value = 0;
|
||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||
|
||
if (cancellationTokenSource != null && cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
var text = "产品数据库排查中断!";
|
||
this.statusBar.lblTaskStatus.Text = text;
|
||
}
|
||
}));
|
||
// 排查数据库后防止数据丢失保存到本地磁盘
|
||
SaveViolateParamWaitHandleList();
|
||
Thread.Sleep(5000);
|
||
}
|
||
|
||
|
||
private void btnStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 处理违规暂存列表获取上家Id并保存违规信息到服务端
|
||
/// </summary>
|
||
private void OperateViolateListTemp()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
while (true)
|
||
{
|
||
try
|
||
{
|
||
var violateInfo = LstVioLateInfoTemp.FirstOrDefault();
|
||
if (violateInfo != null)
|
||
{
|
||
LstVioLateInfoTemp.Remove(violateInfo);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
int totalCount = LstViolateInfo.Count;
|
||
int currentCount = LstViolateInfo.Count - LstVioLateInfoTemp.Count + 1;
|
||
if (currentCount < 0)
|
||
currentCount = 0;
|
||
this.statusBar.pgbTaskProgress.Maximum = LstViolateInfo.Count;
|
||
this.statusBar.lblTaskStatus.Text = "正在分析罚单数据";
|
||
this.statusBar.pgbTaskProgress.Value = currentCount;
|
||
this.statusBar.pgbTaskProgress.Text = currentCount + "/" + totalCount;
|
||
}));
|
||
|
||
if (violateInfo.up_product_id_number == 0)
|
||
{
|
||
Thread.Sleep(Randomx.GetId(50, 150));
|
||
GetViolateUpId(violateInfo);
|
||
AddViolateToServer(violateInfo);
|
||
|
||
if (LstVioLateInfoTemp.Count % 50 == 0)
|
||
{
|
||
SaveViolateInfoList();
|
||
}
|
||
}
|
||
|
||
if (violateInfo.up_product_id_number > 0)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
string from = "";
|
||
if (string.IsNullOrEmpty(violateInfo.up_product_id))
|
||
from = "";
|
||
else if (violateInfo.up_product_id.StartsWith("pd"))
|
||
from = "拼多多";
|
||
else if (violateInfo.up_product_id.StartsWith("tb"))
|
||
from = "淘宝";
|
||
else if (violateInfo.up_product_id.StartsWith("al"))
|
||
from = "阿里巴巴";
|
||
else if (violateInfo.up_product_id.StartsWith("jx"))
|
||
from = "京喜";
|
||
var row = dgvViolateFileData.Rows.Cast<DataGridViewRow>()
|
||
.FirstOrDefault(r => r.Cells["col_penalize_id"].Value?.ToString() == violateInfo.penalize_id);
|
||
if (row != null)
|
||
{
|
||
row.Cells["col_from"].Value = from;
|
||
row.Cells["col_from_fake"].Value = "货源网";
|
||
row.Cells["col_up_id"].Value = violateInfo.up_product_id_number;
|
||
}
|
||
}));
|
||
}
|
||
|
||
if (!ViolateRuleParam.LstViolateRuleName.Contains(violateInfo?.rule_name?.Trim()))
|
||
{
|
||
UpdateViolateRuleNameList(violateInfo);
|
||
SetViolateSelectList(flpViolate);
|
||
}
|
||
|
||
if (LstVioLateInfoTemp.Count == 0)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (this.statusBar.lblTaskStatus.Text == "正在分析罚单数据")
|
||
{
|
||
ResetStatusBar();
|
||
}
|
||
}));
|
||
}
|
||
|
||
if (LstVioLateInfoTemp.Count == 0)
|
||
{
|
||
SaveViolateInfoList();
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有违规信息规则名称列表
|
||
/// </summary>
|
||
public static void GetAllViolateRuleName()
|
||
{
|
||
if (ViolateRuleParam.LstViolateRuleName != null)
|
||
return;
|
||
|
||
string data = ViolateBLL.GetViolate("1", 1);
|
||
if (data == "none")
|
||
data = "";
|
||
ViolateRuleParam.LstViolateRuleName = data.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
}
|
||
|
||
public static void GetViolateUpIdList(List<ViolateParam> violateParamList)
|
||
{
|
||
string upIdUrl = BaseClass.LoginApiUrl + "?obj=upshopid/upid_dd&act=get_list";
|
||
string upIdData = "&pids=";
|
||
foreach (var violateParam in violateParamList)
|
||
{
|
||
upIdData += violateParam.DouProductId + "," + violateParam.DouProductId.ParseToLong() % 1024 + ";";
|
||
}
|
||
var Data = UserLogin.GetSignaturex() + upIdData; //.TrimEnd(';');
|
||
string upIdsResult = GetHtml.PostUtf8(upIdUrl, Data);
|
||
if (upIdsResult.Contains("参数错误"))
|
||
return;
|
||
if (upIdsResult.Contains(",") != true)
|
||
upIdsResult = GetHtml.PostUtf8(upIdUrl, UserLogin.GetSignaturex() + upIdData);
|
||
if (upIdsResult?.Contains(",") != true)
|
||
upIdsResult = GetHtml.PostUtf8(upIdUrl, UserLogin.GetSignaturex() + upIdData);
|
||
if (upIdsResult?.Contains(",") != true)
|
||
return;
|
||
|
||
var upIdsListResult = upIdsResult.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||
foreach (var upIdStr in upIdsListResult)
|
||
{
|
||
if (!upIdStr.Contains(','))
|
||
continue;
|
||
|
||
var violateParam = violateParamList.Find(v => v.DouProductId == upIdStr.Split(',').FirstOrDefault());
|
||
if (violateParam != null)
|
||
violateParam.UpId = upIdStr.Split(',').LastOrDefault();
|
||
}
|
||
}
|
||
|
||
public static void GetViolateUpId(ViolateParam violateParam)
|
||
{
|
||
var violateInfo = new ViolateInfo() { business_id = violateParam.DouProductId };
|
||
GetViolateUpId(violateInfo);
|
||
if (!string.IsNullOrEmpty(violateInfo.up_product_id))
|
||
{
|
||
violateParam.UpId = violateInfo.up_product_id;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取违规商品上家Id
|
||
/// </summary>
|
||
/// <param name="violateInfo"></param>
|
||
public static void GetViolateUpId(ViolateInfo violateInfo)
|
||
{
|
||
string upIdUrl = BaseClass.LoginApiUrl + "?obj=upshopid/upid_dd&act=get";
|
||
string upIdData = "&pid=" + violateInfo.business_id + "&table=" + (violateInfo.business_id.ParseToLong() % 1024);
|
||
string upId = GetHtml.PostUtf8(upIdUrl, UserLogin.GetSignaturex() + upIdData);
|
||
if (!string.IsNullOrEmpty(upId) && upId != "none")
|
||
{
|
||
string upIdNumber = BaseRegex.GetMatchRegex(ref upId, "\\d{5,20}")[0]?.Groups[0]?.Value;
|
||
if (!string.IsNullOrEmpty(upIdNumber))
|
||
{
|
||
violateInfo.up_product_id = upId;
|
||
violateInfo.up_product_id_number = upIdNumber.ParseToLong();
|
||
}
|
||
}
|
||
if (violateInfo.up_product_id_number <= 0)
|
||
violateInfo.up_product_id_number = -1;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将违规信息保存到云服务端
|
||
/// </summary>
|
||
public static string AddViolateToServer(ViolateInfo violateInfo)
|
||
{
|
||
if (string.IsNullOrEmpty(violateInfo.up_product_id) || violateInfo.up_product_id_number <= 0)
|
||
return "无上家商品";
|
||
|
||
string address = BaseClass.BuildObjString("violate&act=add");
|
||
string param = UserLogin.GetSignaturex()
|
||
+ "&pid=" + violateInfo.up_product_id
|
||
+ "&content=" + violateInfo.rule_name
|
||
+ "&suffix=" + violateInfo.up_product_id_number % 1024;
|
||
string html = GetHtml.PostUtf8(address, param);
|
||
// 服务端无此违规记录,保存违规成功
|
||
if (html.Contains("\"msg\":\"success\"") && html.Contains("\"data\":null"))
|
||
{
|
||
return "上家商品违规信息添加成功";
|
||
}
|
||
// 服务端已记录此商品违规情况,根据是否有追加新违规信息,决定是否要更新违规信息
|
||
else if (html.Contains("\"msg\":\"success\""))
|
||
{
|
||
var dataStrOld = BaseRegex.GetStringJson(ref html, "data");
|
||
if (!string.IsNullOrEmpty(dataStrOld))
|
||
{
|
||
if (!("^" + dataStrOld + "^").Contains("^" + violateInfo.rule_name + "^"))
|
||
{
|
||
var dataStrNew = dataStrOld.Trim('^') + "^" + violateInfo.rule_name;
|
||
address = BaseClass.BuildObjString("violate&act=update");
|
||
param = UserLogin.GetSignaturex()
|
||
+ "&pid=" + violateInfo.up_product_id
|
||
+ "&content=" + dataStrNew
|
||
+ "&suffix=" + violateInfo.up_product_id_number % 1024;
|
||
html = GetHtml.PostUtf8(address, param);
|
||
if (html.Contains("\"msg\":\"success\""))
|
||
return "上家商品违规信息修改成功";
|
||
}
|
||
else
|
||
{
|
||
return "上家商品违规信息已存在";
|
||
}
|
||
}
|
||
}
|
||
return "未知错误:" + html;
|
||
}
|
||
|
||
public static void UpdateViolateRuleNameList(ViolateInfo violate)
|
||
{
|
||
var violateRuleName = new ViolateInfo { rule_name = violate.rule_name, up_product_id = "1", up_product_id_number = 1 };
|
||
ViolateRuleParam.LstViolateRuleName.Add(violateRuleName.rule_name);
|
||
AddViolateToServer(violateRuleName);
|
||
}
|
||
|
||
void GetShopProduct(DouShopLoginInfo shop, bool isShowResult = true)
|
||
{
|
||
DataGridViewRow row = null;
|
||
Invoke(new Action(() =>
|
||
{
|
||
row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopAccountId);
|
||
if (row != null)
|
||
{
|
||
if (isShowResult)
|
||
row.Cells["colMessage"].Value = "正在获取店铺商品数量";
|
||
}
|
||
}));
|
||
|
||
// 读取在售商品数量
|
||
var resultOnline = GetShopProductListData(shop, 0, 1, 10);
|
||
if (resultOnline.Contains("\"code\":10000"))
|
||
{
|
||
if (row != null)
|
||
{
|
||
var text = BaseRegex.GetStringJson(ref resultOnline, "total");
|
||
shop.OnlineProductCount = text.ParseToInt();
|
||
}
|
||
}
|
||
// 读取下架商品数量
|
||
var resultOffline = GetShopProductListData(shop, 1, 1, 10);
|
||
if (resultOffline.Contains("\"code\":10000"))
|
||
{
|
||
if (row != null)
|
||
{
|
||
var text = BaseRegex.GetStringJson(ref resultOffline, "total");
|
||
shop.OfflineProductCount = text.ParseToInt();
|
||
}
|
||
}
|
||
|
||
string resultShowText = "";
|
||
if (resultOnline.Contains("\"code\":10000") && resultOffline.Contains("\"code\":10000"))
|
||
{
|
||
resultShowText = "商品数量获取成功";
|
||
}
|
||
else
|
||
{
|
||
resultShowText = "商品数量获取失败";
|
||
if (!resultOnline.Contains("\"code\":10000"))
|
||
{
|
||
var html = BaseRegex.GetStringJson(ref resultOnline, "sub_msg");
|
||
if (string.IsNullOrEmpty(html))
|
||
html = resultOnline;
|
||
resultShowText += ",获取在售商品错误:" + html;
|
||
}
|
||
if (!resultOffline.Contains("\"code\":10000"))
|
||
{
|
||
var html = BaseRegex.GetStringJson(ref resultOffline, "sub_msg");
|
||
if (string.IsNullOrEmpty(html))
|
||
html = resultOffline;
|
||
resultShowText += ",获取仓库商品错误:" + html;
|
||
}
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (row != null)
|
||
{
|
||
if (isShowResult)
|
||
row.Cells["colMessage"].Value = resultShowText;
|
||
}
|
||
}));
|
||
}
|
||
|
||
public string GetShopProductListData(DouShopLoginInfo shop, int productStatus = 0, int page = 1, int pageSize = 50, long update_end_time = 0)
|
||
{
|
||
// 读取在售商品数量
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("page", page.ToString());
|
||
dictionary.Add("size", pageSize.ToString());
|
||
if (update_end_time > 0)
|
||
dictionary.Add("update_end_time", update_end_time.ToString());
|
||
dictionary["status"] = productStatus.ToString();
|
||
if (productStatus == 0)
|
||
dictionary["check_status"] = "3";
|
||
DouyinApi douApi = new DouyinApi(shop);
|
||
douApi.JsonData = dictionary;
|
||
var resultOnline = douApi.GetProductList();
|
||
return resultOnline;
|
||
}
|
||
|
||
private void BtnDelViolate_Click(object sender, EventArgs e)
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
int num = 0;
|
||
var selectRows = dgvCheck.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["col_result_select"].Value?.ParseToBool() == true).ToList();
|
||
try
|
||
{
|
||
foreach (DataGridViewRow row in selectRows)
|
||
{
|
||
num++;
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.pgbTaskProgress.Maximum = selectRows.Count;
|
||
this.statusBar.lblTaskStatus.Text = "正在删除选中违规商品";
|
||
this.statusBar.pgbTaskProgress.Value = num;
|
||
this.statusBar.pgbTaskProgress.Text = num + "/" + selectRows.Count;
|
||
}));
|
||
|
||
|
||
Thread.Sleep(Randomx.GetId(50, 100));
|
||
|
||
// 数据来源 1.产品数据库 2.店铺在售商品 3.店铺仓库商品
|
||
var dataFrom = GetDataFrom(row.Cells["col_result_data_from"].Value?.ToString());
|
||
var upId = row.Cells["col_result_up_id"].Value?.ToString();
|
||
var shopId = row.Cells["col_result_shop_id"].Value?.ToString();
|
||
var productId = row.Cells["col_result_product_id"].Value?.ToString();
|
||
var violateParam = LstViolateParam.FirstOrDefault(vp => vp.UpIdNumber.ToString() == upId && vp.DouProductId == productId);
|
||
|
||
if (dataFrom == 1)
|
||
{
|
||
string url = BaseClass.BuildFissionObjString("fession_api");
|
||
string paraStr = "&fessiontitle=" + HttpUtility.UrlEncode(upId, Encoding.UTF8)
|
||
+ "¤t_page=1"
|
||
+ "&pagesize=500";
|
||
string requestData = UserLogin.GetSignaturex("", "") + "&act=get" + paraStr;
|
||
try
|
||
{
|
||
string htmlData = GetHtml.PostUtf8(url, requestData);
|
||
var FessionObj = JsonConvert.DeserializeObject<FissionRoot>(htmlData); // 反序列化
|
||
if (FessionObj != null && FessionObj.list != null && FessionObj.list.Count > 0)
|
||
{
|
||
var fessData = FessionObj.list.FirstOrDefault(f => f.fession_id == upId);
|
||
if (fessData != null)
|
||
{
|
||
//{\"code\":1,\"msg\":\"delete success!\"}
|
||
var result = new FissionDataBaseBLL().DelFessionData(fessData.id.ToString());
|
||
if (result.Contains("\"msg\":\"delete success!\""))
|
||
{
|
||
row.Cells["col_result_status"].Value = "删除成功";
|
||
if (violateParam != null)
|
||
violateParam.HandleResult = "删除成功";
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogSave.Add(Name, "访问服务器返回裂变数据异常");
|
||
}
|
||
|
||
row.Cells["col_result_status"].Value = "删除失败,请重试";
|
||
if (violateParam != null)
|
||
violateParam.HandleResult = "删除失败,请重试";
|
||
}
|
||
else
|
||
{
|
||
var shop = GlobalConfig.DouShopLoginList.FirstOrDefault(s => s.ShopAccountId == shopId);
|
||
if (shop != null)
|
||
{
|
||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||
dictionary.Add("product_id", productId);
|
||
DouyinApi douApi = new DouyinApi(shop);
|
||
douApi.JsonData = dictionary;
|
||
var result = douApi.DeleteProduct();
|
||
if (result.Contains("\"code\":10000"))
|
||
{
|
||
row.Cells["col_result_status"].Value = "删除成功";
|
||
if (violateParam != null)
|
||
violateParam.HandleResult = "删除成功";
|
||
continue;
|
||
}
|
||
}
|
||
|
||
row.Cells["col_result_status"].Value = "删除失败,请重试";
|
||
if (violateParam != null)
|
||
violateParam.HandleResult = "删除失败,请重试";
|
||
}
|
||
|
||
if (num % 50 == 0)
|
||
{
|
||
SaveViolateParamWaitHandleList();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
|
||
// 保存处理结果
|
||
SaveViolateParamWaitHandleList();
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
var showText = "删除违规完成";
|
||
if (cancellationTokenSource?.IsCancellationRequested == true)
|
||
showText = "删除违规中断";
|
||
|
||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||
this.statusBar.lblTaskStatus.Text = showText;
|
||
this.statusBar.pgbTaskProgress.Value = 0;
|
||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||
|
||
BaseMsgForm.ShowInfo(showText);
|
||
}));
|
||
});
|
||
}
|
||
|
||
public void SaveViolateParamWaitHandleList()
|
||
{
|
||
var task = Task.Run(() =>
|
||
{
|
||
LstViolateParam = LstViolateParam.Where(v => v.HandleResult != "删除成功").ToList();
|
||
try
|
||
{
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<ViolateParam>>("violate_param_wait_handle_list", LstViolateParam);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
});
|
||
task.Wait();
|
||
}
|
||
|
||
public void SaveViolateInfoList()
|
||
{
|
||
var task = Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<ViolateInfo>>("violate_Info_list", LstViolateInfo);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
});
|
||
task.Wait();
|
||
}
|
||
|
||
private string GetDataFromDescribe(int dataFrom)
|
||
{
|
||
string dataFromDescribe = null;
|
||
if (dataFrom == 1)
|
||
dataFromDescribe = "产品数据库";
|
||
else if (dataFrom == 2)
|
||
dataFromDescribe = "店铺在售商品";
|
||
else if (dataFrom == 3)
|
||
dataFromDescribe = "店铺仓库商品";
|
||
return dataFromDescribe;
|
||
}
|
||
|
||
private int GetDataFrom(string dataFromDescribe)
|
||
{
|
||
int dataFrom = 0;
|
||
if (dataFromDescribe == "产品数据库")
|
||
dataFrom = 1;
|
||
else if (dataFromDescribe == "店铺在售商品")
|
||
dataFrom = 2;
|
||
else if (dataFromDescribe == "店铺仓库商品")
|
||
dataFrom = 3;
|
||
return dataFrom;
|
||
}
|
||
|
||
private void llSelectAllRule_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||
{
|
||
foreach (Control c in flpViolate.Controls)
|
||
{
|
||
var chk = c as CheckBox;
|
||
if (chk != null)
|
||
{
|
||
chk.Checked = true;
|
||
Cb_Click(chk, null);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void llSelectSerious_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||
{
|
||
foreach (Control c in flpViolate.Controls)
|
||
{
|
||
var chk = c as CheckBox;
|
||
if (chk != null)
|
||
{
|
||
if (chk.ForeColor == Color.FromArgb(240, 10, 0))
|
||
{
|
||
chk.Checked = true;
|
||
}
|
||
else
|
||
{
|
||
chk.Checked = false;
|
||
}
|
||
Cb_Click(chk, null);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void llClear_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||
{
|
||
foreach (Control c in flpViolate.Controls)
|
||
{
|
||
var chk = c as CheckBox;
|
||
if (chk != null)
|
||
{
|
||
chk.Checked = false;
|
||
Cb_Click(chk, null);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|