token调用逻辑优化 店铺统计(30%)
This commit is contained in:
1 parent
b42155ae6c
commit
b3f446dee8
7 files changed
+1939
-137
No files matched your search
@@ -133,7 +133,7 @@ namespace TemuKJD.WXForms.TalkForms
|
||||
lstShopAfterSale = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<WxShopAfterSaleInfo>>("wx_shop_after_sale_list");
|
||||
if (lstShopAfterSale == null)
|
||||
lstShopAfterSale = new ConcurrentList<WxShopAfterSaleInfo>();
|
||||
RefreshAfterSale();
|
||||
//RefreshAfterSale();
|
||||
}));
|
||||
|
||||
while (true)
|
||||
@@ -141,9 +141,12 @@ namespace TemuKJD.WXForms.TalkForms
|
||||
Thread.Sleep(1000);
|
||||
if (DateTime.Now > nextRefreshTime)
|
||||
{
|
||||
Invoke(new Action(() => { pbLoading.Visible = true; }));
|
||||
nextRefreshTime = DateTime.Now.AddMinutes(30);
|
||||
Invoke(new Action(() => { RefreshCookie(true); }));
|
||||
Invoke(new Action(() => { RefreshMsgCount(); }));
|
||||
RefreshCookie(true);
|
||||
RefreshMsgCount();
|
||||
RefreshAfterSale(true);
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
}
|
||||
var deltaTime = nextRefreshTime - DateTime.Now;
|
||||
Invoke(new Action(() =>
|
||||
@@ -985,25 +988,25 @@ namespace TemuKJD.WXForms.TalkForms
|
||||
|
||||
private void pnlRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
nextRefreshTime = DateTime.Now.AddMinutes(30);
|
||||
RefreshCookie();
|
||||
//nextRefreshTime = DateTime.Now.AddMinutes(30);
|
||||
pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
RefreshCookie();
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
});
|
||||
}
|
||||
|
||||
DateTime nextRefreshTime = DateTime.Now;
|
||||
void RefreshCookie(bool isAuto = false)
|
||||
{
|
||||
pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
if (!isAuto)
|
||||
WXShopListForm.UpdateShop();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
if (!isAuto)
|
||||
WXShopListForm.UpdateShop();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
}
|
||||
LoadShop();
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
});
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
}
|
||||
LoadShop();
|
||||
}
|
||||
|
||||
private void btnFilterShop_Click(object sender, EventArgs e)
|
||||
@@ -1045,71 +1048,71 @@ namespace TemuKJD.WXForms.TalkForms
|
||||
|
||||
private void btnRefreshAfterSale_Click(object sender, EventArgs e)
|
||||
{
|
||||
RefreshAfterSale(true);
|
||||
this.pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
RefreshAfterSale(true);
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
});
|
||||
}
|
||||
|
||||
void RefreshAfterSale(bool refreshAll = false)
|
||||
{
|
||||
this.pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
List<Task> tList = new List<Task>();
|
||||
if (refreshAll)
|
||||
lstShopAfterSale.Clear();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
List<Task> tList = new List<Task>();
|
||||
if (refreshAll)
|
||||
lstShopAfterSale.Clear();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
var afterInfo = lstShopAfterSale.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||||
if (afterInfo == null)
|
||||
afterInfo = new WxShopAfterSaleInfo() { ShopId = shop.ShopId };
|
||||
Invoke(new Action(() => { LoadShopAfterSale(afterInfo, ""); }));
|
||||
var t = Task.Run(() =>
|
||||
{
|
||||
var afterInfo = lstShopAfterSale.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||||
if (afterInfo == null)
|
||||
afterInfo = new WxShopAfterSaleInfo() { ShopId = shop.ShopId };
|
||||
Invoke(new Action(() => { LoadShopAfterSale(afterInfo, ""); }));
|
||||
var t = Task.Run(() =>
|
||||
try
|
||||
{
|
||||
try
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
{
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
{
|
||||
Invoke(new Action(() => { LoadShopAfterSale(new WxShopAfterSaleInfo() { ShopId = shop.ShopId }, "店铺掉线"); }));
|
||||
return;
|
||||
}
|
||||
Invoke(new Action(() => { LoadShopAfterSale(new WxShopAfterSaleInfo() { ShopId = shop.ShopId }, "店铺掉线"); }));
|
||||
return;
|
||||
}
|
||||
|
||||
var afterSaleInfo = lstShopAfterSale.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||||
if (refreshAll || afterSaleInfo == null || afterSaleInfo.RefreshTime.Date != DateTime.Now.Date)
|
||||
var afterSaleInfo = lstShopAfterSale.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
|
||||
if (refreshAll || afterSaleInfo == null || afterSaleInfo.RefreshTime.Date != DateTime.Now.Date)
|
||||
{
|
||||
lstShopAfterSale.RemoveAll(sa => sa.ShopId == shop.ShopId);
|
||||
var rst = WxShopStatisticsForm.GetShopMainInfoList(shop);
|
||||
if (!rst.Contains("\"code\":0"))
|
||||
{
|
||||
lstShopAfterSale.RemoveAll(sa => sa.ShopId == shop.ShopId);
|
||||
var rst = GetApiServiceList(shop);
|
||||
if (!rst.Contains("\"code\":0"))
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
{
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
{
|
||||
Invoke(new Action(() => { LoadShopAfterSale(new WxShopAfterSaleInfo() { ShopId = shop.ShopId }, "店铺掉线"); }));
|
||||
return;
|
||||
}
|
||||
|
||||
afterInfo = new WxShopAfterSaleInfo() { ShopId = shop.ShopId, RefreshTime = DateTime.Now };
|
||||
lstShopAfterSale.Add(afterInfo);
|
||||
Invoke(new Action(() => { LoadShopAfterSale(afterInfo, "查询失败"); }));
|
||||
Invoke(new Action(() => { LoadShopAfterSale(new WxShopAfterSaleInfo() { ShopId = shop.ShopId }, "店铺掉线"); }));
|
||||
return;
|
||||
}
|
||||
|
||||
var afterCount = JsonHelper.JObjectParse(rst)["aftersaleAllRet"]["totalNum"].ParseToInt();
|
||||
afterInfo = new WxShopAfterSaleInfo() { ShopId = shop.ShopId, RefreshTime = DateTime.Now, AfterSaleCount = afterCount };
|
||||
afterInfo = new WxShopAfterSaleInfo() { ShopId = shop.ShopId, RefreshTime = DateTime.Now };
|
||||
lstShopAfterSale.Add(afterInfo);
|
||||
Invoke(new Action(() => { LoadShopAfterSale(afterInfo, "已查询"); }));
|
||||
Invoke(new Action(() => { LoadShopAfterSale(afterInfo, "查询失败"); }));
|
||||
return;
|
||||
}
|
||||
|
||||
var afterCount = JsonHelper.JObjectParse(rst)["aftersaleAllRet"]["totalNum"].ParseToInt();
|
||||
afterInfo = new WxShopAfterSaleInfo() { ShopId = shop.ShopId, RefreshTime = DateTime.Now, AfterSaleCount = afterCount };
|
||||
lstShopAfterSale.Add(afterInfo);
|
||||
Invoke(new Action(() => { LoadShopAfterSale(afterInfo, "已查询"); }));
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
});
|
||||
tList.Add(t);
|
||||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 20) { Thread.Sleep(100); }
|
||||
}
|
||||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 1) { Thread.Sleep(100); }
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_after_sale_list", lstShopAfterSale);
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
});
|
||||
tList.Add(t);
|
||||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 20) { Thread.Sleep(100); }
|
||||
}
|
||||
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 1) { Thread.Sleep(100); }
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_after_sale_list", lstShopAfterSale);
|
||||
}
|
||||
|
||||
private void btnToKfMainPage_Click(object sender, EventArgs e)
|
||||
@@ -1129,20 +1132,6 @@ namespace TemuKJD.WXForms.TalkForms
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取店铺后台主页售后数量等数据
|
||||
/// </summary>
|
||||
/// <param name="shop"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetApiServiceList(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 GetKfMsgStatistics(ShopLoginInfo shop, long beginDateTick, long endDateTick)
|
||||
{
|
||||
@@ -1154,50 +1143,50 @@ namespace TemuKJD.WXForms.TalkForms
|
||||
|
||||
private void btnRefreshMsgCount_Click(object sender, EventArgs e)
|
||||
{
|
||||
RefreshMsgCount();
|
||||
pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
RefreshMsgCount();
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
});
|
||||
}
|
||||
|
||||
void RefreshMsgCount()
|
||||
{
|
||||
pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
lstShopKfStatistics.Clear();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
lstShopKfStatistics.Clear();
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
var kfMsg = new WxShopKfStatistics() { ShopId = shop.ShopId };
|
||||
var kfMsgRst = GetKfMsgStatistics(shop, BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date), BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now));
|
||||
if (!kfMsgRst.Contains("\"ret\":0"))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
var kfMsg = new WxShopKfStatistics() { ShopId = shop.ShopId };
|
||||
var kfMsgRst = GetKfMsgStatistics(shop, BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date), BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now));
|
||||
if (!kfMsgRst.Contains("\"ret\":0"))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
var jObj = JsonHelper.JObjectParse(kfMsgRst);
|
||||
kfMsg.user_cnt = jObj["cardResp"]["objects"]["tableValueLine"][0]["columnValue"][1].ParseToInt();
|
||||
kfMsg.sesseion_cnt = jObj["cardResp"]["objects"]["tableValueLine"][0]["columnValue"][2].ParseToInt();
|
||||
kfMsg.service_noreply_ratio = jObj["cardResp"]["objects"]["tableValueLine"][0]["columnValue"][5].ParseToDecimal();
|
||||
lstShopKfStatistics.Add(kfMsg);
|
||||
var jObj = JsonHelper.JObjectParse(kfMsgRst);
|
||||
kfMsg.user_cnt = jObj["cardResp"]["objects"]["tableValueLine"][0]["columnValue"][1].ParseToInt();
|
||||
kfMsg.sesseion_cnt = jObj["cardResp"]["objects"]["tableValueLine"][0]["columnValue"][2].ParseToInt();
|
||||
kfMsg.service_noreply_ratio = jObj["cardResp"]["objects"]["tableValueLine"][0]["columnValue"][5].ParseToDecimal();
|
||||
lstShopKfStatistics.Add(kfMsg);
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
int count = Math.Max(1, lstShopKfStatistics.Count());
|
||||
lblUserCount.Text = lstShopKfStatistics.Sum(s => s.user_cnt).ParseToString();
|
||||
lblTalkCount.Text = lstShopKfStatistics.Sum(s => s.sesseion_cnt).ParseToString();
|
||||
lblReplyCount.Text = lstShopKfStatistics.Sum(s => s.service_reply_ratio * 100 / count).ParseToDecimal().ToString("0.0") + "%";
|
||||
}));
|
||||
}
|
||||
catch
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
}
|
||||
int count = Math.Max(1, lstShopKfStatistics.Count());
|
||||
lblUserCount.Text = lstShopKfStatistics.Sum(s => s.user_cnt).ParseToString();
|
||||
lblTalkCount.Text = lstShopKfStatistics.Sum(s => s.sesseion_cnt).ParseToString();
|
||||
lblReplyCount.Text = lstShopKfStatistics.Sum(s => s.service_reply_ratio * 100 / count).ParseToDecimal().ToString("0.0") + "%";
|
||||
}));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
catch
|
||||
{
|
||||
int count = Math.Max(1, lstShopKfStatistics.Count());
|
||||
lblUserCount.Text = lstShopKfStatistics.Sum(s => s.user_cnt).ParseToString();
|
||||
lblTalkCount.Text = lstShopKfStatistics.Sum(s => s.sesseion_cnt).ParseToString();
|
||||
lblReplyCount.Text = lstShopKfStatistics.Sum(s => s.service_reply_ratio * 100 / count).ParseToDecimal().ToString("0.0") + "%";
|
||||
pbLoading.Visible = false;
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
int count = Math.Max(1, lstShopKfStatistics.Count());
|
||||
lblUserCount.Text = lstShopKfStatistics.Sum(s => s.user_cnt).ParseToString();
|
||||
lblTalkCount.Text = lstShopKfStatistics.Sum(s => s.sesseion_cnt).ParseToString();
|
||||
lblReplyCount.Text = lstShopKfStatistics.Sum(s => s.service_reply_ratio * 100 / count).ParseToDecimal().ToString("0.0") + "%";
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user