Files
KJD/TEMUKJD/WXForms/ShopForms/WxShopStatisticsForm.cs

862 lines
46 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using AllBase.Extension;
using AllBase.Helper;
using AllBase.Model.Config;
using AllBase.Model.Result;
using AllBase.Model.Result.WXResult;
using NaiBa.Util.Extension;
using NaiBa.Util.Winform.Extension;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TemuKJD.BLL;
using TemuKJD.KJDForms.ShopForms;
using TemuKJD.UserComponent;
using TemuKJD.WXForms.ProductForms;
namespace TemuKJD.WXForms.ShopForms
{
public partial class WxShopStatisticsForm : BaseForms.BaseForm
{
bool isInit = false;
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public List<WxShopSaleStatisticsGroup> lstShopStatisticsInfo = new List<WxShopSaleStatisticsGroup>();
public List<string> lstHideColumns = new List<string>();
public WxShopStatisticsForm()
{
InitializeComponent();
}
private void WxShopStatisticsForm_Load(object sender, EventArgs e)
{
this.dgvShop.AddSelectorColumn("colSelect");
lstHideColumns = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<string>>("wx_shop_sale_statistics_hide_columns");
if (lstHideColumns == null)
lstHideColumns = new List<string>();
foreach (DataGridViewColumn column in dgvShop.Columns)
{
if (lstHideColumns.Contains(column.HeaderText))
column.Visible = false;
if (!string.IsNullOrEmpty(column.HeaderText) && column.HeaderText != "店铺登录号码" && column.HeaderText != "详情")
{
var chk = new UcCheckBox() { Name = "chk" + column.Name, Tag = column.Name, Text = column.HeaderText, Checked = column.Visible, };
chk.CheckedChanged += Chk_CheckedChanged;
this.flowLayoutPanel1.Controls.Add(chk);
}
}
lstShopStatisticsInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<List<WxShopSaleStatisticsGroup>>("wx_shop_sale_statistics_info");
if (lstShopStatisticsInfo == null)
lstShopStatisticsInfo = new List<WxShopSaleStatisticsGroup>();
}
private void Chk_CheckedChanged(object sender, EventArgs e)
{
var chk = sender as UcCheckBox;
if (chk != null)
{
dgvShop.Columns[chk.Tag.ParseToString()].Visible = chk.Checked;
if (!chk.Checked)
{
lstHideColumns.Add(chk.Text);
}
else
{
lstHideColumns.Remove(chk.Text);
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig<List<string>>("wx_shop_sale_statistics_hide_columns", lstHideColumns);
}
}
private void WxShopStatisticsForm_VisibleChanged(object sender, EventArgs e)
{
if (Visible == true)
{
//if (!isInit)
{
//isInit = true;
RefreshShop();
}
}
}
public void RefreshShop()
{
this.pbLoading.Visible = true;
// 店铺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.ValidShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
// 更新被删除的店铺列表
foreach (var row in dgvRowList)
{
dgvShop.Rows.Remove(row);
}
// 获取被删除的统计信息并删除
List<WxShopSaleStatisticsGroup> statisticsDeleteLst = lstShopStatisticsInfo.Where(row
=> !GlobalConfig.ValidShopLoginList.Any(s => s.ShopId == row.ShopId.ToString())).ToList();
foreach (var s in statisticsDeleteLst)
{
lstShopStatisticsInfo.Remove(s);
}
// 绑定店铺(含新导入的店铺)
foreach (ShopLoginInfo shopEntity in GlobalConfig.ValidShopLoginList)
{
if (!string.IsNullOrEmpty(shopEntity.ShopId))
BindShop(shopEntity, selectIds);
}
cmbFilterShopNotes.Items.Clear();
foreach (var note in GlobalConfig.ValidShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterShopNotes.Items.Add(note);
}
cmbFilterShopGroup.Items.Clear();
foreach (var group in GlobalConfig.ValidShopLoginList.Select(s => s.GroupName).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterShopGroup.Items.Add(group);
}
GetShopStatistics(GlobalConfig.ValidShopLoginList, selectIds);
}
private void GetShopStatistics(NaiBa.Util.ConcurrentList<ShopLoginInfo> shops, List<string> selectIds)
{
Invoke(new Action(() =>
{
this.statusBar.pgbTaskProgress.Maximum = shops.Count;
this.statusBar.lblTaskStatus.Text = "正在查询";
}));
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var cancellationToken = cancellationTokenSource.Token;
List<Task> tLst = new List<Task>();
foreach (ShopLoginInfo shopEntity in shops)
{
if (cancellationToken.IsCancellationRequested)
break;
Invoke(new Action(() =>
{
this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1);
this.statusBar.lblTaskStatus.Text = "正在查询 " + this.statusBar.pgbTaskProgress.Value + "/" + shops.Count;
if (this.statusBar.pgbTaskProgress.Value % 10 == 0)
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_sale_statistics_info", lstShopStatisticsInfo);
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(
p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
if (row != null)
{
row.Cells["colOnSaleProductNumber"].Value = ""; // 商品数量
row.Cells["colScore"].Value = ""; // 店铺体验分
row.Cells["colScoreChange"].Value = ""; // 较昨日变化
row.Cells["colPayCnt"].Value = ""; // 今日订单
row.Cells["colPayCnt7"].Value = ""; // 7日订单
row.Cells["colPayCnt30"].Value = ""; // 30日订单
row.Cells["colPay"].Value = ""; // 今日成交金额
row.Cells["colPay7"].Value = ""; // 7日成交金额
row.Cells["colPay30"].Value = ""; // 30日成交金额
row.Cells["colRefund"].Value = ""; // 今日退款金额
row.Cells["colRefund7"].Value = ""; // 7日退款金额
row.Cells["colRefund30"].Value = ""; // 30日退款金额
row.Cells["colOrderNum"].Value = ""; // 待发货
row.Cells["colShipErr"].Value = ""; // 物流异常
row.Cells["colAfterSale"].Value = ""; // 售后
row.Cells["colPunish"].Value = ""; // 店铺违规
row.Cells["colTotalAmount"].Value = ""; // 货款金额
row.Cells["colAvailableAmount"].Value = ""; // 可提现余额
row.Cells["colPendingAmount"].Value = ""; // 待结算金额
row.Cells["colDepositBalance"].Value = ""; // 保证金
}
}));
var t = Task.Run(() =>
{
if (cancellationToken.IsCancellationRequested)
return;
if (string.IsNullOrEmpty(shopEntity.ShopId))
return;
bool canUse = shopEntity.LoginStatus == "登录成功";
if (!canUse)
{
BindShop(shopEntity, selectIds);
return;
}
WxShopSaleStatisticsGroup statistics = lstShopStatisticsInfo.FirstOrDefault(s => s.ShopId.ToString() == shopEntity.ShopId);
if (statistics == null)
{
statistics = new WxShopSaleStatisticsGroup()
{
Notes = shopEntity.Notes,
GroupName = shopEntity.GroupName,
ShopId = shopEntity.ShopId.ParseToString(),
ShopAccount = shopEntity.ShopAccount,
};
lstShopStatisticsInfo.Add(statistics);
}
GetShopStatistics(shopEntity, statistics);
Invoke(new Action(() =>
{
this.lblPayCnt.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfoToday.pay_order_cnt.ParseToLong()).ToString();
this.lblPayCnt1.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo1Day.pay_order_cnt.ParseToLong()).ToString();
this.lblPayCnt7.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo7Day.pay_order_cnt.ParseToLong()).ToString();
this.lblPayCnt30.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo30Day.pay_order_cnt.ParseToLong()).ToString();
this.lblPay.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfoToday.pay_gmv.ParseToDecimal() * 0.01m).ToString("f2");
this.lblPay1.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo1Day.pay_gmv.ParseToDecimal() * 0.01m).ToString("f2");
this.lblPay7.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo7Day.pay_gmv.ParseToDecimal() * 0.01m).ToString("f2");
this.lblPay30.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo30Day.pay_gmv.ParseToDecimal() * 0.01m).ToString("f2");
this.lblPayRefund.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfoToday.pay_refund_gmv.ParseToLong() * 0.01m).ToString();
this.lblPayRefund1.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo1Day.pay_refund_gmv.ParseToLong() * 0.01m).ToString();
this.lblPayRefund7.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo7Day.pay_refund_gmv.ParseToLong() * 0.01m).ToString();
this.lblPayRefund30.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopSaleInfo30Day.pay_refund_gmv.ParseToLong() * 0.01m).ToString();
this.lblOrderNum.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopMainInfo.orderNumRet?.num.ParseToInt()).ToString();
this.lblWaybillError.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopMainInfo.waybillErrorRet?.num.ParseToInt()).ToString();
this.lblAfterSaleAll.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopMainInfo.aftersaleAllRet?.num.ParseToInt()).ToString();
this.lblPunish.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopMainInfo.punishRet?.num.ParseToInt()).ToString();
this.lblTotalAmount.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopAmount.totalAmount * 0.01m).ToString();
this.lblAvailableAmount.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopAmount.availableAmount * 0.01m).ToString();
this.lblPendingAmount.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopAmount.pendingAmount * 0.01m).ToString();
this.lblDepositBalance.Text = this.lstShopStatisticsInfo.Sum(s => s.WxShopAmount.DepositBalance * 0.01m).ToString();
BindShop(shopEntity, selectIds);
}));
});
//t.Wait();
while(tLst.Where(ta => !ta.IsCompleted && !ta.IsFaulted && !ta.IsCanceled).Count() >= 3)
{
Thread.Sleep(10);
}
tLst.Add(t);
}
while (tLst.Where(ta => !ta.IsCompleted && !ta.IsFaulted && !ta.IsCanceled).Count() > 0)
{
Thread.Sleep(10);
}
Invoke(new Action(() =>
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_sale_statistics_info", lstShopStatisticsInfo);
this.statusBar.lblTaskStatus.Text = "查询结束";
this.pbLoading.Visible = false;
}));
}, cancellationTokenSource.Token);
}
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null)
{
if (shopEntity == null)
return;
if (shopEntity.is_point_shop_expire)
return;
if (selectShopId == null)
selectShopId = new List<string>();
WxShopSaleStatisticsGroup statistics = lstShopStatisticsInfo.FirstOrDefault(s => s.ShopId.ToString() == shopEntity.ShopId);
if (statistics == null)
{
statistics = new WxShopSaleStatisticsGroup()
{
Notes = shopEntity.Notes,
GroupName = shopEntity.GroupName,
ShopId = shopEntity.ShopId.ParseToString(),
ShopAccount = shopEntity.ShopAccount,
};
lstShopStatisticsInfo.Add(statistics);
}
bool canUse = shopEntity.LoginStatus == "登录成功";
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(
p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
var subUserNames = shopEntity.SubUserName.Split(',').Where(su => !string.IsNullOrEmpty(su));
var subUsers = WXSubAccountShopEditForm.lstAllSubAccount.Where(su => subUserNames.Contains(su.user_name));
decimal? scoreChange = null;
if (statistics.scoreRetInfo?.dsrScore?.valueList?.Count > 1)
scoreChange = statistics.scoreRetInfo?.dsrScore?.valueList[0].value - statistics.scoreRetInfo?.dsrScore?.valueList[1].value; // 较昨日变化
//string scoreChangeStr = scoreChange == null ? "" : scoreChange.Value.ToString("+0.00;−0.00");
string scoreChangeStr = scoreChange == null ? "" : scoreChange.Value.ToString("+0.00;-0.00");
if (row == null)
{
int rowId = this.dgvShop.Rows.Add(
false,
canUse ? "在线" : "掉线",
"详情",
shopEntity.LoginName,
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.Notes,
shopEntity.GroupName,
string.Join(",", subUsers.Select(s => s.nick_name)),
statistics.ProdCount.ParseToNullableInt(), // 在售商品
statistics.curScoreValue.ParseToNullableDecimal(), // 店铺体验分
scoreChange, // 较昨日变化
statistics.WxShopSaleInfoToday.pay_order_cnt, // 今日订单
statistics.WxShopSaleInfo1Day.pay_order_cnt, // 昨日订单
statistics.WxShopSaleInfo7Day.pay_order_cnt, // 7日订单
statistics.WxShopSaleInfo30Day.pay_order_cnt, // 30日订单
statistics.WxShopSaleInfoToday.pay_gmv, // 今日成交金额
statistics.WxShopSaleInfo1Day.pay_gmv, // 昨日成交金额
statistics.WxShopSaleInfo7Day.pay_gmv, // 7日成交金额
statistics.WxShopSaleInfo30Day.pay_gmv, // 30日成交金额
statistics.WxShopSaleInfoToday.pay_refund_gmv, // 今日退款金额
statistics.WxShopSaleInfo1Day.pay_refund_gmv, // 昨日退款金额
statistics.WxShopSaleInfo7Day.pay_refund_gmv, // 7日退款金额
statistics.WxShopSaleInfo30Day.pay_refund_gmv, // 30日退款金额
statistics.WxShopMainInfo.orderNumRet?.num, // 待发货
statistics.WxShopMainInfo.waybillErrorRet?.num, // 物流异常
statistics.WxShopMainInfo.aftersaleAllRet?.num, // 售后
statistics.WxShopMainInfo.punishRet?.num, // 店铺违规
statistics.WxShopAmount.totalAmount * 0.01m, // 货款金额
statistics.WxShopAmount.availableAmount * 0.01m, // 可提现余额
statistics.WxShopAmount.pendingAmount * 0.01m, // 待结算金额
statistics.WxShopAmount.DepositBalance * 0.01m // 保证金
);
row = dgvShop.Rows[rowId];
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightGreen : Color.OrangeRed;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkGreen : Color.DarkRed;
row.Height = 32;
}
else
{
row.Cells["colSelect"].Value = selectShopId.Contains(shopEntity.ShopId) && canUse;
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightGreen : Color.OrangeRed;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkGreen : Color.DarkRed;
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
row.Cells["colShopAccount"].Value = shopEntity.ShopAccount;
row.Cells["colNotes"].Value = shopEntity.Notes;
row.Cells["colGroup"].Value = shopEntity.GroupName;
row.Cells["colSubUser"].Value = string.Join(",", subUsers.Select(s => s.nick_name));
row.Cells["colOnSaleProductNumber"].Value = statistics.ProdCount.ParseToNullableInt(); // 商品数量
row.Cells["colScore"].Value = statistics.curScoreValue.ParseToNullableDecimal(); // 店铺体验分
row.Cells["colScoreChange"].Value = scoreChange; // 较昨日变化
row.Cells["colPayCnt"].Value = statistics.WxShopSaleInfoToday.pay_order_cnt; // 今日订单
row.Cells["colPayCnt1"].Value = statistics.WxShopSaleInfo1Day.pay_order_cnt; // 昨日订单
row.Cells["colPayCnt7"].Value = statistics.WxShopSaleInfo7Day.pay_order_cnt; // 7日订单
row.Cells["colPayCnt30"].Value = statistics.WxShopSaleInfo30Day.pay_order_cnt; // 30日订单
row.Cells["colPay"].Value = statistics.WxShopSaleInfoToday.pay_gmv.ParseToNullableLong() * 0.01m; // 今日成交金额
row.Cells["colPay1"].Value = statistics.WxShopSaleInfo1Day.pay_gmv.ParseToNullableLong() * 0.01m; // 昨日成交金额
row.Cells["colPay7"].Value = statistics.WxShopSaleInfo7Day.pay_gmv.ParseToNullableLong() * 0.01m; // 7日成交金额
row.Cells["colPay30"].Value = statistics.WxShopSaleInfo30Day.pay_gmv.ParseToNullableLong() * 0.01m; // 30日成交金额
row.Cells["colRefund"].Value = statistics.WxShopSaleInfoToday.pay_refund_gmv.ParseToNullableLong() * 0.01m; // 今日退款金额
row.Cells["colRefund1"].Value = statistics.WxShopSaleInfo1Day.pay_refund_gmv.ParseToNullableLong() * 0.01m; // 昨日退款金额
row.Cells["colRefund7"].Value = statistics.WxShopSaleInfo7Day.pay_refund_gmv.ParseToNullableLong() * 0.01m; // 7日退款金额
row.Cells["colRefund30"].Value = statistics.WxShopSaleInfo30Day.pay_refund_gmv.ParseToNullableLong() * 0.01m; // 30日退款金额
row.Cells["colOrderNum"].Value = statistics.WxShopMainInfo.orderNumRet?.num; // 待发货
row.Cells["colShipErr"].Value = statistics.WxShopMainInfo.waybillErrorRet?.num; // 物流异常
row.Cells["colAfterSale"].Value = statistics.WxShopMainInfo.aftersaleAllRet?.num; // 售后
row.Cells["colPunish"].Value = statistics.WxShopMainInfo.punishRet?.num; // 店铺违规
row.Cells["colTotalAmount"].Value = statistics.WxShopAmount.totalAmount * 0.01m; // 货款金额
row.Cells["colAvailableAmount"].Value = statistics.WxShopAmount.availableAmount * 0.01m; ; // 可提现余额
row.Cells["colPendingAmount"].Value = statistics.WxShopAmount.pendingAmount * 0.01m; // 待结算金额
row.Cells["colDepositBalance"].Value = statistics.WxShopAmount.DepositBalance * 0.01m; ; // 保证金
}
row.Cells["colScore"].Style.ForeColor = DefaultForeColor;
if (statistics.scoreRetInfo?.dsrScore?.level == 3)
row.Cells["colScore"].Style.ForeColor = Color.DarkGreen; // Color.Green;
if (statistics.scoreRetInfo?.dsrScore?.level == 2)
row.Cells["colScore"].Style.ForeColor = Color.ForestGreen; // Color.MediumSeaGreen;
if (statistics.scoreRetInfo?.dsrScore?.level == 1)
row.Cells["colScore"].Style.ForeColor = Color.Red;
}
private void GetShopStatistics(ShopLoginInfo shop, WxShopSaleStatisticsGroup statistics)
{
if (statistics == null || statistics.WxShopMainInfo == null ||
statistics.WxShopSaleInfoToday == null || statistics.WxShopSaleInfo1Day == null || statistics.WxShopSaleInfo7Day == null || statistics.WxShopSaleInfo30Day == null)
return;
if (statistics.lastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
var shopScoreRst = GetShopScore(shop);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (shopScoreRst.Contains("\"code\":0"))
{
statistics.curScoreValue = BaseRegex.GetDecimalJson(ref shopScoreRst, "curValue");
statistics.scoreRetInfo = JsonHelper.DeserializeJsonToObject<DSRShopScoreRetInfo>(JsonHelper.JObjectParse(shopScoreRst)["dsrScoreRet"].ParseToString());
}
else
{
string errStr = BaseRegex.GetStringJson(ref shopScoreRst, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref shopScoreRst, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = shopScoreRst;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
var prodLstRst = WXProdNoCheckEditHelper.scanProductPreview(shop, 1, "", 20);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (prodLstRst.Contains("\"success\":true"))
{
var prodObjs = JsonHelper.JObjectParse(prodLstRst);
var totalNum = prodObjs["totalNum"].ParseToInt();
statistics.ProdCount = totalNum;
}
else
{
string errStr = BaseRegex.GetStringJson(ref prodLstRst, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref prodLstRst, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = prodLstRst;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
statistics.lastRefreshDate = DateTime.Now.Date;
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
if (statistics.WxShopMainInfo.LastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
string html = GetShopMainInfoList(shop);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
statistics.WxShopMainInfo = JsonHelper.DeserializeJsonToObject<WxShopMainStatisticsInfo>(html);
statistics.WxShopMainInfo.LastRefreshDate = DateTime.Now.Date;
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
if (statistics.WxShopSaleInfoToday.LastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
string html = GetShopSaleInfoRealTimeList(shop,
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date),
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now));
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
var saleStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["total"]);
statistics.WxShopSaleInfoToday = JsonHelper.DeserializeJsonToObject<WxShopSaleStatisticsInfo>(saleStr);
statistics.WxShopSaleInfoToday.LastRefreshDate = DateTime.Now.Date;
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
if (statistics.WxShopSaleInfo1Day.LastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
string html = GetShopSaleInfoList(shop,
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-1)),
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date) - 1);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
var saleStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["total"]);
statistics.WxShopSaleInfo1Day = JsonHelper.DeserializeJsonToObject<WxShopSaleStatisticsInfo>(saleStr);
statistics.WxShopSaleInfo1Day.LastRefreshDate = DateTime.Now.Date;
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
if (statistics.WxShopSaleInfo7Day.LastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
string html = GetShopSaleInfoList(shop,
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-7)),
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date) - 1);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
var saleStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["total"]);
statistics.WxShopSaleInfo7Day = JsonHelper.DeserializeJsonToObject<WxShopSaleStatisticsInfo>(saleStr);
statistics.WxShopSaleInfo7Day.LastRefreshDate = DateTime.Now.Date;
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
if (statistics.WxShopSaleInfo30Day.LastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
string html = GetShopSaleInfoList(shop,
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-30)),
BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date) - 1);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
var saleStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["total"]);
statistics.WxShopSaleInfo30Day = JsonHelper.DeserializeJsonToObject<WxShopSaleStatisticsInfo>(saleStr);
statistics.WxShopSaleInfo30Day.LastRefreshDate = DateTime.Now.Date;
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
if (statistics.WxShopAmount.LastRefreshDate != DateTime.Now.Date && shop.LoginStatus == "登录成功")
{
try
{
string html = GetShopAmount(shop);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
var amountStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(html)["data"]);
statistics.WxShopAmount = JsonHelper.DeserializeJsonToObject<WxAmount>(amountStr);
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
html = GetShopBalance(shop);
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
if (html.Contains("\"code\":0"))
{
statistics.WxShopAmount.DepositBalance = BaseRegex.GetIntJson(ref html, "depositBalance");
}
else
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
statistics.err_msg = errStr;
return;
}
statistics.WxShopAmount.LastRefreshDate = DateTime.Now.Date;
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(Randomx.GetId(50, 100));
statistics.err_msg = ex.Message;
return;
}
}
}
private void btnSetColumn_Click(object sender, EventArgs e)
{
this.panel1.Visible = true;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.panel1.Visible = false;
}
/// <summary>
/// 获取店铺后台主页售后数量等数据
/// </summary>
/// <param name="shop"></param>
/// <returns></returns>
public static string GetShopMainInfoList(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradehome/home/main?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/home";
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
return result;
//{"code":0,"orderNumRet":{"code":0,"pendingShipNum":"1"},"waybillErrorRet":{"code":0,"totalNum":0},"aftersaleAllRet":{"code":0,"totalNum":3},"guaranteeRet":{"code":0,"totalNum":0},"prewarnRet":{"code":0,"waitStatusCount":0},"punishRet":{"code":0,"pendingNum":1},"mchUndealRet":{"code":0,"totalNum":0}}
//pendingShipNum待发货 waybillErrorRet物流异常 aftersaleAllRet售后 guaranteeRet服务保障 prewarnRet店铺预警 punishRet店铺违规 mchUndealRet工单
}
public static string GetShopSaleInfoList(ShopLoginInfo shop, long startTime, long endTime)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodelinercgi/cgi/liner_query/3/home-overview-shop-offline?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/home";
//string data = @"{""time_query"":{""dateFormat"":2,""dateType"":0,""dateRange"":7,""startMs"":1767974400000,""endMs"":1770566399999}}";
string data = @"{""time_query"":{""dateFormat"":2,""dateType"":0,""dateRange"":7,""startMs"":" + startTime + @",""endMs"":" + endTime + "}}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, referer);
return result;
}
public static string GetShopSaleInfoRealTimeList(ShopLoginInfo shop, long startTime, long endTime)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodelinercgi/cgi/liner_query/3/home-overview-shop-realtime?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/home";
//string data = @"{""time_query"":{""dateFormat"":1,""dateType"":0,""dateRange"":7,""startMs"":1767974400000,""endMs"":1770566399999}}";
string data = @"{""time_query"":{""dateFormat"":1,""dateType"":0,""dateRange"":1,""startMs"":" + startTime + @",""endMs"":" + endTime + "}}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, referer);
return result;
}
public static string GetShopScore(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradehome/home/minor?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/home";
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
return result;
}
public static string GetShopAmount(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradefunds/cgi/generalAccount/getGeneralAccountBalance?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/funds/home";
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
return result;
}
public static string GetShopBalance(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradedeposit/home/cgi/getDepositMPayState?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/funds/home";
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, referer);
return result;
}
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["colShopAccount"].Value.ToString();
var shop = GlobalConfig.ValidShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
var row = dgvShop.Rows[e.RowIndex];
switch (columnName)
{
case "colSelect":
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
break;
case "colLoginStatus":
{
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
if (shop.LoginStatus != "登录成功")
{
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
}
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 btnGetSelect_Click(object sender, EventArgs e)
{
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
ReGetStatistics(selectIds);
}
void ReGetStatistics(List<string> reGetShopIds)
{
var shopList = new NaiBa.Util.ConcurrentList<ShopLoginInfo>();
shopList.AddRange(GlobalConfig.ValidShopLoginList.Where(s => reGetShopIds.Contains(s.ShopId)));
foreach (var shop in shopList)
{
WxShopSaleStatisticsGroup statistics = lstShopStatisticsInfo.FirstOrDefault(s => s.ShopId.ToString() == shop.ShopId);
if (statistics != null)
{
statistics.WxShopMainInfo.LastRefreshDate = DateTime.MinValue;
statistics.WxShopSaleInfoToday.LastRefreshDate = DateTime.MinValue;
statistics.WxShopSaleInfo1Day.LastRefreshDate = DateTime.MinValue;
statistics.WxShopSaleInfo7Day.LastRefreshDate = DateTime.MinValue;
statistics.WxShopSaleInfo30Day.LastRefreshDate = DateTime.MinValue;
statistics.WxShopAmount.LastRefreshDate = DateTime.MinValue;
statistics.lastRefreshDate = DateTime.MinValue;
}
//this.lstSubOrderInfo.RemoveAll(o => o.supplierId.ParseToString() == shop.ShopId);
}
this.pbLoading.Visible = true;
GetShopStatistics(shopList, reGetShopIds);
}
private void btnGetNotGet_Click(object sender, EventArgs e)
{
RefreshShop();
}
private void pnlFliter_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();
string group = cmbFilterShopGroup.Text.Trim().Trim(';');
if (group == "全部")
group = "";
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (!row.Cells["colShopAccount"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
{
row.Visible = false;
row.Cells["colSelect"].Value = false;
continue;
}
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colNotes"].Value.ParseToString()))
{
row.Visible = false;
row.Cells["colSelect"].Value = false;
continue;
}
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colGroup"].Value.ParseToString()))
{
row.Visible = false;
row.Cells["colSelect"].Value = false;
continue;
}
row.Visible = true;
}
}
private void pnlClear_Click(object sender, EventArgs e)
{
txtFilterShopName.Text = "";
cmbFilterShopNotes.Text = "全部";
cmbFilterShopGroup.Text = "全部";
pnlFliter_Click(null, null);
}
private void btnRefresh_Click(object sender, EventArgs e)
{
RefreshShop();
}
}
}