using AllBase; using AllBase.Extension; using AllBase.Helper; using AllBase.Model.Config; using AllBase.Model.Result; 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 List lstShopStatisticsInfo = new List(); public WxShopStatisticsForm() { InitializeComponent(); } private void WxShopStatisticsForm_Load(object sender, EventArgs e) { this.dgvShop.AddSelectorColumn("colSelect"); foreach(DataGridViewColumn column in dgvShop.Columns) { 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>("wx_shop_sale_statistics_info"); if (lstShopStatisticsInfo == null) lstShopStatisticsInfo = new List(); } private void Chk_CheckedChanged(object sender, EventArgs e) { var chk = sender as UcCheckBox; if (chk != null) { dgvShop.Columns[chk.Tag.ParseToString()].Visible = chk.Checked; } } 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().Where(row => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList(); // 获取被删除的店铺 List dgvRowList = dgvShop.Rows.Cast().Where(row => !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList(); // 更新被删除的店铺列表 foreach (var row in dgvRowList) { dgvShop.Rows.Remove(row); } // 获取被删除的统计信息并删除 List statisticsDeleteLst = lstShopStatisticsInfo.Where(row => !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.ShopId.ToString())).ToList(); foreach (var s in statisticsDeleteLst) { lstShopStatisticsInfo.Remove(s); } // 绑定店铺(含新导入的店铺) 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); } GetShopStatistics(GlobalConfig.ShopLoginList.ToList(), selectIds); } private void GetShopStatistics(List shops, List selectIds) { Invoke(new Action(() => { this.statusBar.pgbTaskProgress.Maximum = shops.Count; this.statusBar.lblTaskStatus.Text = "正在查询"; })); Task.Run(() => { List tLst = new List(); foreach (ShopLoginInfo shopEntity in shops) { 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().FirstOrDefault( p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId); if (row != null) { row.Cells["colOnSaleProductNumber"].Value = ""; // 商品数量 row.Cells["colScore"].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 (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.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.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.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() >= 2) { 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; })); }); } private void BindShop(ShopLoginInfo shopEntity, List selectShopId = null) { if (shopEntity == null) return; if (selectShopId == null) selectShopId = new List(); 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().FirstOrDefault( p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId); if (row == null) { int rowId = this.dgvShop.Rows.Add( false, canUse ? "在线" : "掉线", "详情", shopEntity.LoginName, shopEntity.ShopId, shopEntity.ShopAccount, shopEntity.Notes, shopEntity.GroupName, statistics.ProdCount.ParseToNullableInt(), // 在售商品 statistics.curScoreValue.ParseToNullableDecimal(), // 店铺体验分 statistics.WxShopSaleInfoToday.pay_order_cnt, // 今日订单 statistics.WxShopSaleInfo7Day.pay_order_cnt, // 7日订单 statistics.WxShopSaleInfo30Day.pay_order_cnt, // 30日订单 statistics.WxShopSaleInfoToday.pay_gmv, // 今日成交金额 statistics.WxShopSaleInfo7Day.pay_gmv, // 7日成交金额 statistics.WxShopSaleInfo30Day.pay_gmv, // 30日成交金额 statistics.WxShopSaleInfoToday.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["colOnSaleProductNumber"].Value = statistics.ProdCount.ParseToNullableInt(); // 商品数量 row.Cells["colScore"].Value = statistics.curScoreValue.ParseToNullableDecimal(); // 店铺体验分 row.Cells["colPayCnt"].Value = statistics.WxShopSaleInfoToday.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["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["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; ; // 保证金 } } private void GetShopStatistics(ShopLoginInfo shop, WxShopSaleStatisticsGroup statistics) { if (statistics == null || statistics.WxShopMainInfo == null || statistics.WxShopSaleInfoToday == 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"); } 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 = WXPreSale.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(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(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.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(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(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(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; } /// /// 获取店铺后台主页售后数量等数据 /// /// /// 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.ShopLoginList.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().Where(row => row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList(); ReGetStatistics(selectIds); } void ReGetStatistics(List reGetShopIds) { var shopList = GlobalConfig.ShopLoginList.Where(s => reGetShopIds.Contains(s.ShopId)).ToList(); 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.WxShopSaleInfo7Day.LastRefreshDate = DateTime.MinValue; statistics.WxShopSaleInfo30Day.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 notesLst = notes.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; } row.Visible = true; } } private void pnlClear_Click(object sender, EventArgs e) { txtFilterShopName.Text = ""; cmbFilterShopNotes.Text = "全部"; pnlFliter_Click(null, null); } } }