Files
KJD/TEMUKJD/WXForms/ShopForms/WXShopOptimizeForm.cs
T
2026-04-26 19:46:54 +08:00

1150 lines
55 KiB
C#
Raw 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.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 TemuKJD.WXForms.ProductForms;
namespace TemuKJD.WXForms.ShopForms
{
public partial class WXShopOptimizeForm : BaseForm
{
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public bool IsLoadComplate { get; set; } = false;
bool isInit = false;
CheckBox chkSelectAll = null;
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
public string pdd_product_cates = "";
ConcurrentList<WxOptimizeOrderAfterSaleInfo> lstWxOptimizeOrderAfterSaleInfo = new ConcurrentList<WxOptimizeOrderAfterSaleInfo>();
ConcurrentList<WxOptimizeProductEvaluationInfo> lstWxOptimizeProductEvaluationInfo = new ConcurrentList<WxOptimizeProductEvaluationInfo>();
ConcurrentList<WxOptimizeOrderWayBillInfo> lstWxOptimizeOrderWayBillInfo = new ConcurrentList<WxOptimizeOrderWayBillInfo>(); // 揽收
ConcurrentList<WxOptrimizeLinerCgiInfo> lstWxOptrimizeLinerCgiInfo = new ConcurrentList<WxOptrimizeLinerCgiInfo>(); // 物流
public WXShopOptimizeForm()
{
InitializeComponent();
}
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
{
this.ucTabControl1.TabPages.RemoveAt(4);
dicCheckedShopId = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, bool>>("wx_checked_shop_dic");
if (dicCheckedShopId == null)
dicCheckedShopId = new Dictionary<string, bool>();
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
dgvShop.Columns["colSelect"].HeaderText = "";
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
dgvData1.AddSelectorColumn("colDgv1Check");
dgvData1.AddImgColumn("colDgv1Img", "colDgv1ImgUrl");
dgvData2.AddSelectorColumn("colDgv2Check");
dgvData2.AddImgColumn("colDgv2Img", "colDgv2ImgUrl");
dgvData3.AddSelectorColumn("colCheck");
dgvData3.AddImgColumn("colImg", "colImgUrl");
dgvData4.AddSelectorColumn("colDgv4Check");
dgvData4.AddImgColumn("colDgv4Img", "colDgv4ImgUrl");
IsLoadComplate = true;
}
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
if (!chkSelectAll.Checked)
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
row.Cells["colSelect"].Value = false;
}
}
else
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
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();
if (!isInit)
{
Task.Run(() =>
{
foreach (var shop in GlobalConfig.ShopLoginList)
{
}
});
}
isInit = true;
}
}
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();
//cmbFilterShopNotes.Items.Add("");
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterShopNotes.Items.Add(note);
}
}
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
{
if (shopEntity == null)
return;
if (shopEntity.is_shop_expire)
return;
if (selectShopId == null)
selectShopId = new List<string>();
bool canUse = shopEntity.LoginStatus == "登录成功";
//canUse = true; // 内部库不需要校验登录状态
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
if (row == null)
{
this.dgvShop.Rows.Add(
//!isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse),
dicCheckedShopId.Keys.Contains(shopEntity.ShopId) && dicCheckedShopId[shopEntity.ShopId] == true,
shopEntity.LoginName,
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.Notes,
"选择商品",
canUse ? "在线" : "掉线",
"", //lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
canUse,
shopEntity.AddProductRemaining,
"",
msg
);
}
else
{
row.Cells["colSelect"].Value = !isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse);
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
row.Cells["colShopNotes"].Value = shopEntity.Notes;
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
row.Cells["colCanUse"].Value = canUse;
row.Cells["colApi"].Value = ""; //lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期";
row.Cells["colRemaining"].Value = shopEntity.AddProductRemaining;
row.Cells["colMessage"].Value = msg;
}
displayAuthStatus(shopEntity);
}
void displayAuthStatus(ShopLoginInfo shop)
{
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ParseToString() == shop?.ShopId);
foreach (var row in rows)
{
bool canUse = row.Cells["colLoginStatus"].Value.ParseToString() == "在线";
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
canUse = row.Cells["colApi"].Value.ParseToString() == "可用";
(row.Cells["colApi"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colApi"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colApi"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
(row.Cells["colApi"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
}
}
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
string shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
string shopAccount = dgvShop.Rows[e.RowIndex].Cells["colShopName"].Value.ToString();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
var row = dgvShop.Rows[e.RowIndex];
switch (columnName)
{
case "colSelect":
//if (row.Cells["colCanUse"].Value.ParseToBool())
{
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
chkSelectAll.Checked = true;
else
chkSelectAll.Checked = false;
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
}
//else
{
//BaseMsgForm.ShowInfo("店铺未登录!");
}
dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool();
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
break;
case "colLoginStatus":
{
if (WXShopListForm.Instance == null)
WXShopListForm.Instance = new WXShopListForm();
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
//shopLoginForm.prodUserSelectForm = this;
if (shop.LoginStatus != "登录成功")
{
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
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 dgvData3_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvData3.Columns[e.ColumnIndex].HeaderText;
var shopId = dgvData3.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
switch (headerText)
{
case "删除":
break;
case "登录":
{
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
//shopLoginForm.prodUserSelectForm = this;
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
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(dgvData3.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString());
imgFrom.ShowDialog();
break;
}
case "":
dgvData3.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvData3.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 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 btnSearch_Click(object sender, EventArgs e)
{
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
if (lstShopId.Count == 0)
{
BaseMsgForm.ShowInfo("请选择店铺!");
return;
}
btnSearch.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
if (ucCheckBox1.Checked)
{
pictureBox1.Visible = true;
dgvData1.Rows.Clear();
lstWxOptimizeOrderAfterSaleInfo.Clear();
}
if (ucCheckBox2.Checked)
{
pictureBox2.Visible = true;
dgvData2.Rows.Clear();
lstWxOptimizeProductEvaluationInfo.Clear();
}
if (ucCheckBox3.Checked)
{
pictureBox3.Visible = true;
dgvData3.Rows.Clear();
lstWxOptimizeOrderWayBillInfo.Clear();
}
if (ucCheckBox4.Checked)
{
pictureBox4.Visible = true;
dgvData4.Rows.Clear();
lstWxOptrimizeLinerCgiInfo.Clear();
}
Task.Run(() =>
{
List<ShopLoginInfo> shopLst = GlobalConfig.ShopLoginList.Where(s => lstShopId.Contains(s.ShopId)).ToList();
foreach (var shop in shopLst)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
if (ucCheckBox1.Checked)
{
SearchData1(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
if (ucCheckBox2.Checked)
{
SearchData2(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
if (ucCheckBox3.Checked)
{
SearchData3WayBill(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
if (ucCheckBox4.Checked)
{
SearchData4(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
}
Invoke(new Action(() =>
{
if (cancellationTokenSource.IsCancellationRequested)
{
//this.statusBar.lblTaskStatus.Text = "品质退款查询完毕 " + this.statusBar.lblTaskStatus.Text;
//BaseMsgForm.ShowInfo("品质退款查询完毕");
this.statusBar.lblTaskStatus.Text = "优化数据查询中断 " + this.statusBar.lblTaskStatus.Text;
BaseMsgForm.ShowInfo("优化数据查询中断");
}
else
{
//this.statusBar.lblTaskStatus.Text = "品质退款查询完毕";
//BaseMsgForm.ShowInfo("品质退款查询完毕");
this.statusBar.lblTaskStatus.Text = "优化数据查询完毕";
BaseMsgForm.ShowInfo("优化数据查询完毕");
}
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
btnSearch.Enabled = true;
}));
}, cancellationTokenSource.Token).ContinueWith(delegate
{
}, cancellationTokenSource.Token);
}
public void SearchData1(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
int page = 0;
int totalPage = 1;
int pageSize = 20;
int startTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date.AddDays(-30));
int endTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date) - 1;
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData1 = ShopOptimize.GetProductRefundOrder(shop, page, startTime, endTime);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData1.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData1, "msg");
if (string.IsNullOrEmpty(error))
error = getData1;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = 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, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var prodObjs = JsonHelper.JObjectParse(getData1);
if (page == 1)
{
var totalNum = prodObjs["total"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox1.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询品质退款,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
foreach (JObject refundOrderObj in prodObjs["data"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var refundOrder = JsonHelper.DeserializeJsonToObject<WxOptimizeOrderAfterSaleInfo>(oStr);
if (lstWxOptimizeOrderAfterSaleInfo.Any(o => o.orderInfo.orderId == refundOrder.orderInfo.orderId))
continue;
refundOrder.shopId = shop.ShopId;
refundOrder.shopName = shop.ShopAccount;
lstWxOptimizeOrderAfterSaleInfo.Add(refundOrder);
Invoke(new Action(() =>
{
var rowIndex = this.dgvData1.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
refundOrder.orderInfo.imgUrl,
DataGridViewExtension.defaultBitmap,
refundOrder.orderInfo.spuId,
refundOrder.orderInfo.name,
refundOrder.orderInfo.skuName,
refundOrder.orderInfo.skuCode,
refundOrder.orderInfo.orderId,
BaseClass.StampToDateTime(refundOrder.orderInfo.createTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
refundOrder.reason);
dgvData1.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
public void SearchData2(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
int page = 0;
int totalPage = 1;
int pageSize = 50;
int startTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date.AddDays(-30));
int endTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date) - 1;
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData2 = ShopOptimize.GetProductEvaluation(shop, page, startTime, endTime);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData2.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData2, "msg");
if (string.IsNullOrEmpty(error))
error = getData2;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = 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, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var prodObjs = JsonHelper.JObjectParse(getData2);
if (page == 1)
{
var totalNum = prodObjs["totalCnt"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox2.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询商品差评,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
if (totalPage == 0)
break;
foreach (JObject refundOrderObj in prodObjs["finderProductEvaluationInfoList"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var prodEvaluationInfo = JsonHelper.DeserializeJsonToObject<WxOptimizeProductEvaluationInfo>(oStr);
if (lstWxOptimizeProductEvaluationInfo.Any(o => o.productEvaluationId == prodEvaluationInfo.productEvaluationId))
continue;
prodEvaluationInfo.shopId = shop.ShopId;
prodEvaluationInfo.shopName = shop.ShopAccount;
lstWxOptimizeProductEvaluationInfo.Add(prodEvaluationInfo);
var lblLst = prodEvaluationInfo.evaluationInfo?.firstEvaluationInfo?.buyerEvaluationInfo?.labelList;
var content = prodEvaluationInfo.evaluationInfo.firstEvaluationInfo.buyerEvaluationInfo.content + " " +
prodEvaluationInfo.evaluationInfo.firstEvaluationInfo.buyerEvaluationInfo.defaultContent;
Invoke(new Action(() =>
{
var rowIndex = this.dgvData2.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
prodEvaluationInfo.productInfo.imgUrl,
DataGridViewExtension.defaultBitmap,
prodEvaluationInfo.productInfo.productId,
prodEvaluationInfo.productInfo.spuName,
prodEvaluationInfo.productInfo.skuName,
"", //spuCode 此处获取不到填空
prodEvaluationInfo.productEvaluationId,
prodEvaluationInfo.evaluationInfo.buyer.identity.nickname,
BaseClass.StampToDateTime(prodEvaluationInfo.evaluationInfo.firstEvaluationInfo.buyerEvaluationInfo.createTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
(content + " " + (lblLst == null ? "" : string.Join(" ", lblLst.Select(e => e.labelName)))).Trim()
);
dgvData2.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
public void SearchData3WayBill(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
bool is24 = false;
var is24Rst = ShopOptimize.Get24H48HFlag(shop); // if_24hOr_48hFlag
if (!is24Rst.Contains("\"code\":0") || BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag").IsNullOrEmpty())
{
var error = BaseRegex.GetStringJson(ref is24Rst, "msg");
if (string.IsNullOrEmpty(error))
error = is24Rst;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = 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, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
{
shopRow.Cells["colMessage"].Value = "获取揽收时效失败" + error;
//if(error.Contains("\"code\":2") && error.Contains("[194,62,3,176,14,1]"))
// shopRow.Cells["colMessage"].Value = "店铺无评分";
}
}));
}
return;
}
is24 = BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag") == "1";
int page = 0;
int totalPage = 1;
int pageSize = 20;
int startTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date.AddDays(-30));
int endTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date) - 1;
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData3WayBill = ShopOptimize.GetProductOrderWayBill(shop, page, startTime, endTime, is24);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData3WayBill.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData3WayBill, "msg");
if (string.IsNullOrEmpty(error))
error = getData3WayBill;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = 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, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var wayBillObjs = JsonHelper.JObjectParse(getData3WayBill);
if (page == 1)
{
var totalNum = wayBillObjs["total"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox3.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询揽收不达标,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
foreach (JObject refundOrderObj in wayBillObjs["data"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var orderWayBill = JsonHelper.DeserializeJsonToObject<WxOptimizeOrderWayBillInfo>(oStr);
if (lstWxOptimizeOrderWayBillInfo.Any(o => o.orderInfo.orderId == orderWayBill.orderInfo.orderId))
continue;
orderWayBill.shopId = shop.ShopId;
orderWayBill.shopName = shop.ShopAccount;
if (!orderWayBill.realPickupTime.ParseToInt().IsNullOrZero())
{
// 24小时揽收率截至第二天
if (is24 && BaseClass.StampToDateTime(orderWayBill.realPickupTime.ParseToInt()).Date <= BaseClass.StampToDateTime(orderWayBill.payTime.ParseToInt()).Date.AddDays(1))
continue;
// 48小时揽收率按48小时算
if (!is24 && BaseClass.StampToDateTime(orderWayBill.realPickupTime.ParseToInt()) <= BaseClass.StampToDateTime(orderWayBill.payTime.ParseToInt()).AddDays(2))
continue;
}
else
{
}
lstWxOptimizeOrderWayBillInfo.Add(orderWayBill);
Invoke(new Action(() =>
{
var rowIndex = this.dgvData3.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
orderWayBill.orderInfo.imgUrl,
DataGridViewExtension.defaultBitmap,
orderWayBill.orderInfo.spuId,
orderWayBill.orderInfo.name,
orderWayBill.orderInfo.skuName + " x" + orderWayBill.orderInfo.productCnt,
orderWayBill.orderInfo.skuCode,
orderWayBill.orderInfo.orderId + "\r\n" + orderWayBill.waybillId,
orderWayBill.delivery.deliveryName,
BaseClass.StampToDateTime(orderWayBill.payTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
orderWayBill.realPickupTime.ParseToInt().IsNullOrZero() ? "" : BaseClass.StampToDateTime(orderWayBill.realPickupTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
(orderWayBill.pickupDuration.ParseToInt().IsNullOrZero() ? "" : (new TimeSpan(orderWayBill.pickupDuration.ParseToLong()).TotalHours.ToString("f2") + "小时" + "\r\n")) + "[" + (is24 ? "次日" : "48小时") + "]"
);
dgvData3.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
public void SearchData4(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
bool is24 = false;
var is24Rst = ShopOptimize.Get24H48HFlag(shop); // if_24hOr_48hFlag
if (!is24Rst.Contains("\"code\":0") || BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag").IsNullOrEmpty())
{
var error = BaseRegex.GetStringJson(ref is24Rst, "msg");
if (string.IsNullOrEmpty(error))
error = is24Rst;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = 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, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
{
shopRow.Cells["colMessage"].Value = "获取配送时效失败" + error;
//if(error.Contains("\"code\":2") && error.Contains("[194,62,3,176,14,1]"))
// shopRow.Cells["colMessage"].Value = "店铺无评分";
}
}));
}
return;
}
is24 = BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag") == "1";
int page = 0;
int totalPage = 1;
int pageSize = 20;
long startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-30));
long endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now);
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData4 = ShopOptimize.GetOrderLinerCgi(shop, page, startTime, endTime, is24);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData4.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData4, "msg");
if (string.IsNullOrEmpty(error))
error = getData4;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = 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, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var wayBillObjs = JsonHelper.JObjectParse(getData4);
if (page == 1)
{
var totalNum = wayBillObjs["total"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox4.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询配送不达标,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
foreach (JObject refundOrderObj in wayBillObjs["list"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var orderLinerCgiInfo = JsonHelper.DeserializeJsonToObject<WxOptrimizeLinerCgiInfo>(oStr);
if (lstWxOptrimizeLinerCgiInfo.Any(o => o.order_id == orderLinerCgiInfo.order_id))
continue;
orderLinerCgiInfo.shopId = shop.ShopId;
orderLinerCgiInfo.shopName = shop.ShopAccount;
//// 24小时揽收率截至第二天
//if (is24 && BaseClass.StampToDateTime(orderLinerCgiInfo.realPickupTime.ParseToInt()).Date <= BaseClass.StampToDateTime(orderLinerCgiInfo.payTime.ParseToInt()).Date.AddDays(1))
// continue;
//// 48小时揽收率按48小时算
//if (!is24 && BaseClass.StampToDateTime(orderLinerCgiInfo.realPickupTime.ParseToInt()) <= BaseClass.StampToDateTime(orderLinerCgiInfo.payTime.ParseToInt()).AddDays(2))
// continue;
lstWxOptrimizeLinerCgiInfo.Add(orderLinerCgiInfo);
Invoke(new Action(() =>
{
var rowIndex = this.dgvData4.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
orderLinerCgiInfo.product_list.FirstOrDefault().head_img_url,
DataGridViewExtension.defaultBitmap,
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => p.product_id)),
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => p.title)),
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => "x" + p.product_count)),
"", //skuCode不展示
orderLinerCgiInfo.order_id + "\r\n" + orderLinerCgiInfo.waybill_id,
orderLinerCgiInfo.delivery_name,
BaseClass.StampToDateTime(orderLinerCgiInfo.collect_time.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + BaseClass.StampToDateTime(orderLinerCgiInfo.receipt_time.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
"发货地:" + orderLinerCgiInfo.ship_city + "\r\n" + "收货地:" + orderLinerCgiInfo.ship_province + orderLinerCgiInfo.receipt_city,
(orderLinerCgiInfo.transport_duration.ParseToInt() / 3600) + "小时" + (orderLinerCgiInfo.transport_duration.ParseToInt() % 3600) / 60 + "分" +
"\r\n标准时长" + (orderLinerCgiInfo.transport_std_duration.ParseToInt() / 3600) + "小时" /*+ (orderLinerCgiInfo.transport_std_duration.ParseToInt() % 3600)*/
);
dgvData4.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
private void dgvData1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (this.cancellationTokenSource != null)
cancellationTokenSource.Cancel();
}
}
public static class ShopOptimize
{
public static string GetProductRefundOrder(ShopLoginInfo shop, int pageId, int beginTick, int endTick)
{
string url = "https://store.weixin.qq.com/shop-faas/statistic/dsr/product/refund/order?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=product&key=productQualityRatio_30d&detail=product";
string body = @"{""page"":" + pageId + @",""pageSize"":20,""beginTs"":" + beginTick + @",""endTs"":" + endTick + @"}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
/// <summary>
/// 商品评价
/// </summary>
/// <param name="shop"></param>
/// <param name="pageId"></param>
/// <param name="beginTick"></param>
/// <param name="endTick"></param>
/// <returns></returns>
public static string GetProductEvaluation(ShopLoginInfo shop, int pageId, int beginTick, int endTick)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeevaluation/cgi/search?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/evaluate/home";
string body = @"{""orderId"":"""",""productId"":"""",""productEvaluationId"":"""",""buyerEvaluationTimeStart"":" + beginTick + @",""buyerEvaluationTimeEnd"":" + endTick +
@",""status"":2,""page"":" + pageId + @",""visibleType"":0}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string Get24H48HFlag(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/statistic/cgi/search?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/rate2";
string body = "{\"days\":14,\"scoreTypeList\":[63,1000]}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string GetProductOrderWayBill(ShopLoginInfo shop, int pageId, int beginTick, int endTick, bool is24 = false)
{
string url = "https://store.weixin.qq.com/shop-faas/statistic/dsr/logistics/pickup/insale?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=collectIn_48hOrdRatio_30d&valid=collectIn_48hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d&detail=insale";
if (is24)
referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=collectIn_24hOrdRatio_30d&valid=collectIn_24hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d&detail=insale";
string body = @"{""page"":" + pageId + @",""pageSize"":20,""beginTs"":" + beginTick + @",""endTs"":" + endTick + @"}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string GetOrderLinerCgi(ShopLoginInfo shop, int pageId, long beginTick, long endTick, bool is24 = false)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodelinercgi/cgi/liner/query?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=waybillArriveOntimeRatio_30d&valid=collectIn_48hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d";
if (is24)
referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=waybillArriveOntimeRatio_30d&valid=collectIn_24hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d";
string body = @"{""time_query"":{""dateFormat"":2,""dateType"":0,""dateRange"":30,""startMs"":" + endTick + @",""endMs"":" + endTick +
@"},""limit"":10,""offset"":" + (Math.Max(0, pageId - 1) * 10) + @",""id"":""ratedetail-wuliu-route-order-table"",""biz"":""store"",""is_std"":""0"",""sort"":[""std_route_rate"",""desc""]}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
}
}