3068 lines
163 KiB
C#
3068 lines
163 KiB
C#
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;
|
||
using TemuKJD.WXForms.AdminForms;
|
||
using CefSharp.WinForms;
|
||
using NaiBa.CefHelper;
|
||
using CefSharp;
|
||
using TemuKJD.Helper;
|
||
using NaiBa.CefHelper.Handler;
|
||
|
||
namespace TemuKJD.WXForms.ShopForms
|
||
{
|
||
public partial class WXShopOptimizeForm : BaseForm
|
||
{
|
||
public string kdnAuth = "";
|
||
public string kdnAuthKey = "Auth";
|
||
public string expressToolUrl = "https://56.kdniao.com/main.html";
|
||
public Dictionary<string, object> dicKdnRequest = new Dictionary<string, object>();
|
||
public ChromiumWebBrowser cefWebBrowser = null;
|
||
|
||
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<WxOptimizeLinerCgiInfo> lstWxOptrimizeLinerCgiInfo = new ConcurrentList<WxOptimizeLinerCgiInfo>(); // 物流
|
||
ConcurrentList<WxOptimizeFeedbackOrderInfo> lstWxOptimizeFeedbackOrderInfo = new ConcurrentList<WxOptimizeFeedbackOrderInfo>(); // 反向物流
|
||
|
||
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("colDgv3Check");
|
||
dgvData3.AddImgColumn("colDgv3Img", "colDgv3ImgUrl");
|
||
dgvData4.AddSelectorColumn("colDgv4Check");
|
||
dgvData4.AddImgColumn("colDgv4Img", "colDgv4ImgUrl");
|
||
dgvData5.AddSelectorColumn("colDgv5Check");
|
||
dgvData5.AddImgColumn("colDgv5Img", "colDgv5ImgUrl");
|
||
|
||
this.tabPage6.Select();
|
||
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(expressToolUrl);
|
||
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
|
||
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
||
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
|
||
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
||
splitContainer4.Panel2.Controls.Add(cefWebBrowser);
|
||
Task.Run(() => {
|
||
Thread.Sleep(500);
|
||
Invoke(new Action(() => { this.tabPage1.Select(); }));
|
||
});
|
||
//this.ucTabControl1.TabPages.Remove(tabPage6);
|
||
|
||
IsLoadComplate = true;
|
||
}
|
||
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
||
{
|
||
//if (url.StartsWith("https://lmsapinew.kdniao.com/WayBillMonitor/GetWayBillPageResult"))
|
||
//{
|
||
// var reqStr = JsonHelper.SerializeObject(request.Headers);
|
||
// var keys = request.Headers.AllKeys;
|
||
// foreach (var key in keys)
|
||
// {
|
||
// this.dicKdnRequest[key] = request.Headers.GetValues(key);
|
||
// }
|
||
//}
|
||
if (url .StartsWith("https://lmsapinew.kdniao.com/"))
|
||
{
|
||
try
|
||
{
|
||
kdnAuth = request.Headers["Auth"].ParseToString();
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
}
|
||
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
||
{
|
||
if (url.StartsWith("https://lmsapinew.kdniao.com/WayBillMonitor/GetWayBillPageResult"))
|
||
{
|
||
var reqStr = JsonHelper.SerializeObject(request.Headers);
|
||
var keys = request.Headers.AllKeys;
|
||
foreach (var key in keys)
|
||
{
|
||
this.dicKdnRequest[key] = request.Headers[key];
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
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();
|
||
pbLoadingShop.Visible = false;
|
||
}
|
||
|
||
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();
|
||
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopNotes.Items.Add(note);
|
||
}
|
||
cmbFilterShopGroup.Items.Clear();
|
||
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.GroupName).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopGroup.Items.Add(note);
|
||
}
|
||
}
|
||
|
||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
|
||
{
|
||
if (shopEntity == null)
|
||
return;
|
||
if (shopEntity.is_point_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,
|
||
shopEntity.GroupName,
|
||
"选择商品",
|
||
canUse ? "在线" : "掉线",
|
||
GlobalConfig.lstWxShopAuthInfo.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["colGroup"].Value = shopEntity.GroupName;
|
||
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
|
||
row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
|
||
row.Cells["colCanUse"].Value = canUse;
|
||
row.Cells["colApi"].Value = GlobalConfig.lstWxShopAuthInfo.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 btnStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.cancellationTokenSource != null)
|
||
this.cancellationTokenSource.Cancel();
|
||
}
|
||
|
||
private void btnFilterShop_Click(object sender, EventArgs e)
|
||
{
|
||
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();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
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;
|
||
}
|
||
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 btnEmptyShop_Click(object sender, EventArgs e)
|
||
{
|
||
txtFilterShopName.Text = "";
|
||
cmbFilterShopNotes.Text = "全部";
|
||
cmbFilterShopGroup.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();
|
||
|
||
string group = cmbFilterShopGroup.Text.Trim().Trim(';');
|
||
if (group == "全部")
|
||
group = "";
|
||
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == false)
|
||
continue;
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colGroup"].Value.ParseToString()))
|
||
continue;
|
||
|
||
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();
|
||
|
||
string group = cmbFilterShopGroup.Text.Trim().Trim(';');
|
||
if (group == "全部")
|
||
group = "";
|
||
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (row.Visible == false)
|
||
continue;
|
||
|
||
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
|
||
continue;
|
||
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colGroup"].Value.ParseToString()))
|
||
continue;
|
||
|
||
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();
|
||
}
|
||
if (ucCheckBox5.Checked)
|
||
{
|
||
pictureBox5.Visible = true;
|
||
dgvData5.Rows.Clear();
|
||
lstWxOptimizeFeedbackOrderInfo.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));
|
||
}
|
||
if (ucCheckBox5.Checked)
|
||
{
|
||
SearchData5(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;
|
||
pictureBox5.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;
|
||
}));
|
||
var orderAfterSaleInfoLst = new List<WxOptimizeOrderAfterSaleInfo>();
|
||
foreach (JObject badOrderObj in prodObjs["data"])
|
||
{
|
||
var oStr = JsonHelper.SerializeObject(badOrderObj);
|
||
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;
|
||
|
||
orderAfterSaleInfoLst.Add(refundOrder);
|
||
}
|
||
|
||
// 获取收货地址
|
||
if (1==1)
|
||
{
|
||
var orderIds = string.Join(",", orderAfterSaleInfoLst.Select(a => a.orderInfo.orderId));
|
||
var getOrderRst = ShopOptimize.orderSearchByOrderId(shop, orderIds);
|
||
Thread.Sleep(Randomx.GetId(200, 350));
|
||
if (!getOrderRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getOrderRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getOrderRst;
|
||
|
||
foreach (var refundOrder in orderAfterSaleInfoLst)
|
||
{
|
||
refundOrder.province = "地址获取失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var orderObj = JsonHelper.JObjectParse(getOrderRst)["orderList"];
|
||
var wxOrderLst = JsonHelper.DeserializeJsonToList<WxOrderInfoLite>(JsonHelper.SerializeObject(orderObj));
|
||
|
||
foreach (var refundOrder in orderAfterSaleInfoLst)
|
||
{
|
||
var wxOrder = wxOrderLst.FirstOrDefault(o => o.commonInfo.orderId == refundOrder.orderInfo.orderId);
|
||
if (wxOrder != null)
|
||
{
|
||
refundOrder.orderTime = wxOrder.commonInfo.createTime;
|
||
refundOrder.province = wxOrder.acceptInfo.addressInfo.provinceName;
|
||
refundOrder.city = wxOrder.acceptInfo.addressInfo.cityName;
|
||
refundOrder.district = wxOrder.acceptInfo.addressInfo.countyName;
|
||
|
||
var prod = wxOrder.orderProductInfo.FirstOrDefault(p => p.productId == refundOrder.spuId && p.skuCode == refundOrder.skuCode);
|
||
if (prod != null)
|
||
refundOrder.skuId = prod.skuId;
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
foreach (var refundOrder in orderAfterSaleInfoLst)
|
||
{
|
||
refundOrder.province = "地址解析失败";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否被优化过
|
||
var url = BaseClass.BuildObjString("shop/get_waybill_no_user_name");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&status=2";
|
||
data += "&order_ids=" + string.Join(",", orderAfterSaleInfoLst.Select(w => w.orderInfo.orderId));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
orderAfterSale.optimizeWaybillId = "查询失败";
|
||
orderAfterSale.optimizeTime = "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeExpressInfo>(sProd);
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == orderAfterSale.orderInfo.orderId);
|
||
orderAfterSale.optimizeWaybillId = ov == null ? "" : ov.waybill_id;
|
||
orderAfterSale.optimizeTime = ov == null ? "" : ov?.use_time?.ToString("MM-dd HH:mm");
|
||
if (!string.IsNullOrEmpty(orderAfterSale.optimizeWaybillId))
|
||
orderAfterSale.optimizeWaybillId = "已补发" + "\r\n" + ov?.delivery_id + ":" + ov?.waybill_id;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
orderAfterSale.optimizeWaybillId = "查询失败";
|
||
orderAfterSale.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否有失败记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_rst");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", orderAfterSaleInfoLst.Select(w => w.orderInfo.orderId));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
if (orderAfterSale.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
orderAfterSale.optimizeWaybillId = "查询失败";
|
||
orderAfterSale.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRstInfo>(sProd);
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
if (orderAfterSale.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == orderAfterSale.orderInfo.orderId);
|
||
if (ov != null)
|
||
{
|
||
orderAfterSale.optimizeWaybillId = ov == null ? "" : ov.optimize_rst;
|
||
orderAfterSale.optimizeTime = ov == null ? "" : ov?.mdy_time.ToString("MM-dd HH:mm");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
if (orderAfterSale.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
orderAfterSale.optimizeWaybillId = "查询失败";
|
||
orderAfterSale.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询备注记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_remark");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", orderAfterSaleInfoLst.Select(w => w.orderInfo.orderId));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
orderAfterSale.remark = "备注查询失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRemarkInfo>(sProd);
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == orderAfterSale.orderInfo.orderId);
|
||
orderAfterSale.remark = ov == null ? "" : ov.remark;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var orderAfterSale in orderAfterSaleInfoLst)
|
||
{
|
||
orderAfterSale.remark = "备注查询失败 " + ex.Message;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 显示列表
|
||
foreach (var refundOrder in orderAfterSaleInfoLst)
|
||
{
|
||
if (CheckOrderExist(refundOrder.orderInfo.orderId))
|
||
continue;
|
||
|
||
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.skuId,
|
||
refundOrder.cnt,
|
||
refundOrder.orderInfo.skuName,
|
||
refundOrder.orderInfo.skuCode,
|
||
refundOrder.orderInfo.orderId,
|
||
refundOrder.province + refundOrder.city + refundOrder.district,
|
||
BaseClass.StampToDateTime(refundOrder.orderInfo.createTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
|
||
refundOrder.reason,
|
||
refundOrder.optimizeTime + "\r\n" + refundOrder.optimizeWaybillId.Replace("修改物流信息失败", "补发失败"),
|
||
"补发",
|
||
refundOrder.remark.Trim().IsNullOrEmpty() ? "添加备注" : refundOrder.remark.Trim()
|
||
);
|
||
|
||
var row = dgvData1.Rows[rowIndex];
|
||
row.Height = 60;
|
||
if (refundOrder.optimizeWaybillId.Contains("失败"))
|
||
row.Cells["colDgv1OptimizeStatus"].Style.ForeColor = Color.Red;
|
||
else if (!refundOrder.optimizeTime.IsNullOrEmpty() && !refundOrder.optimizeTime.ParseToString().StartsWith(DateTime.Now.ToString("MM-dd")))
|
||
row.Cells["colDgv1OptimizeStatus"].Style.ForeColor = Color.Orange;
|
||
}));
|
||
}
|
||
}
|
||
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;
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询差评订单
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
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;
|
||
|
||
var productEvaluationInfoLst = new List<WxOptimizeProductEvaluationInfo>();
|
||
foreach (JObject badOrderObj in prodObjs["finderProductEvaluationInfoList"])
|
||
{
|
||
var oStr = JsonHelper.SerializeObject(badOrderObj);
|
||
var prodEvaluationInfo = JsonHelper.DeserializeJsonToObject<WxOptimizeProductEvaluationInfo>(oStr);
|
||
if (lstWxOptimizeProductEvaluationInfo.Any(o => o.productEvaluationId == prodEvaluationInfo.productEvaluationId))
|
||
continue;
|
||
prodEvaluationInfo.shopId = shop.ShopId;
|
||
prodEvaluationInfo.shopName = shop.ShopAccount;
|
||
|
||
productEvaluationInfoLst.Add(prodEvaluationInfo);
|
||
}
|
||
|
||
// 查询收货地址
|
||
foreach (var prodEvaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
var getOrderRst = ShopOptimize.orderSearch(shop, prodEvaluationInfo.productInfo.spuName, prodEvaluationInfo.evaluationInfo.buyer.identity.nickname);
|
||
Thread.Sleep(Randomx.GetId(200, 350));
|
||
if (!getOrderRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getData2, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getData2;
|
||
|
||
prodEvaluationInfo.order_id = error;
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
prodEvaluationInfo.order_id = "";
|
||
var orderObj = JsonHelper.JObjectParse(getOrderRst)["orderList"];
|
||
var wxOrderLst = JsonHelper.DeserializeJsonToList<WxOrderInfoLite>(JsonHelper.SerializeObject(orderObj));
|
||
if (wxOrderLst.Count == 0)
|
||
prodEvaluationInfo.order_id = "未获取到对应订单号";
|
||
else if (wxOrderLst.Count > 1)
|
||
prodEvaluationInfo.order_id = string.Join(" ", wxOrderLst.Select(o => o.commonInfo.orderId)) + " 获取到多条订单号";
|
||
else
|
||
{
|
||
var wxOrder = wxOrderLst.FirstOrDefault();
|
||
if (wxOrder != null)
|
||
{
|
||
prodEvaluationInfo.order_id = wxOrder.commonInfo.orderId;
|
||
prodEvaluationInfo.orderTime = wxOrder.commonInfo.createTime;
|
||
prodEvaluationInfo.province = wxOrder.acceptInfo.addressInfo.provinceName;
|
||
prodEvaluationInfo.city = wxOrder.acceptInfo.addressInfo.cityName;
|
||
prodEvaluationInfo.district = wxOrder.acceptInfo.addressInfo.countyName;
|
||
|
||
var prod = wxOrder.orderProductInfo.FirstOrDefault(p => p.productId == prodEvaluationInfo.spuId && p.skuId == prodEvaluationInfo.skuId);
|
||
if (prod != null)
|
||
{
|
||
prodEvaluationInfo.skuCode = prod.skuCode;
|
||
prodEvaluationInfo.cnt = prod.productCnt;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
prodEvaluationInfo.order_id = "订单号转换失败";
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否被优化过
|
||
var url = BaseClass.BuildObjString("shop/get_waybill_no_user_name");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&status=2";
|
||
data += "&order_ids=" + string.Join(",", productEvaluationInfoLst.Select(w => w.order_id).Where(r => !r.IsNullOrEmpty()));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
evaluationInfo.optimizeWaybillId = "查询失败";
|
||
evaluationInfo.optimizeTime = "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeExpressInfo>(sProd);
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == evaluationInfo.order_id);
|
||
evaluationInfo.optimizeWaybillId = ov == null ? "" : ov.waybill_id;
|
||
evaluationInfo.optimizeTime = ov == null ? "" : ov?.use_time?.ToString("MM-dd HH:mm");
|
||
if (!string.IsNullOrEmpty(evaluationInfo.optimizeWaybillId))
|
||
evaluationInfo.optimizeWaybillId = "已补发" + "\r\n" + ov?.delivery_id + ":" + ov?.waybill_id;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
evaluationInfo.optimizeWaybillId = "查询失败";
|
||
evaluationInfo.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否有失败记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_rst");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", productEvaluationInfoLst.Select(w => w.order_id));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
if (evaluationInfo.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
evaluationInfo.optimizeWaybillId = "查询失败";
|
||
evaluationInfo.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRstInfo>(sProd);
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
if (evaluationInfo.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == evaluationInfo.order_id);
|
||
if (ov != null)
|
||
{
|
||
evaluationInfo.optimizeWaybillId = ov == null ? "" : ov.optimize_rst;
|
||
evaluationInfo.optimizeTime = ov == null ? "" : ov?.mdy_time.ToString("MM-dd HH:mm");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
if (evaluationInfo.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
evaluationInfo.optimizeWaybillId = "查询失败";
|
||
evaluationInfo.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询备注记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_remark");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", productEvaluationInfoLst.Select(w => w.order_id));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
evaluationInfo.remark = "备注查询失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRemarkInfo>(sProd);
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == evaluationInfo.order_id);
|
||
evaluationInfo.remark = ov == null ? "" : ov.remark;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var evaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
evaluationInfo.remark = "备注查询失败 " + ex.Message;
|
||
}
|
||
}
|
||
}
|
||
|
||
//显示列表
|
||
foreach (var prodEvaluationInfo in productEvaluationInfoLst)
|
||
{
|
||
if (CheckOrderExist(prodEvaluationInfo.order_id))
|
||
continue;
|
||
|
||
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.skuId,
|
||
prodEvaluationInfo.cnt,
|
||
prodEvaluationInfo.productInfo.skuName,
|
||
"", // spuCode 此处获取不到填空
|
||
prodEvaluationInfo.productEvaluationId,
|
||
prodEvaluationInfo.order_id,
|
||
prodEvaluationInfo.province + prodEvaluationInfo.city + prodEvaluationInfo.district,
|
||
prodEvaluationInfo.orderTime.IsNullOrZero() ? "" : BaseClass.StampToDateTime(prodEvaluationInfo.orderTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
|
||
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(),
|
||
prodEvaluationInfo.optimizeTime + "\r\n" + prodEvaluationInfo.optimizeWaybillId.Replace("修改物流信息失败", "补发失败"),
|
||
"补发",
|
||
prodEvaluationInfo.remark.Trim().IsNullOrEmpty() ? "添加备注" : prodEvaluationInfo.remark.Trim()
|
||
);
|
||
|
||
var row = dgvData2.Rows[rowIndex];
|
||
row.Height = 60;
|
||
if (prodEvaluationInfo.optimizeWaybillId.Contains("失败"))
|
||
row.Cells["colDgv2OptimizeStatus"].Style.ForeColor = Color.Red;
|
||
else if (!prodEvaluationInfo.optimizeTime.IsNullOrEmpty() && !prodEvaluationInfo.optimizeTime.ParseToString().StartsWith(DateTime.Now.ToString("MM-dd")))
|
||
row.Cells["colDgv2OptimizeStatus"].Style.ForeColor = Color.Orange;
|
||
}));
|
||
}
|
||
}
|
||
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;
|
||
}));
|
||
|
||
List<WxOptimizeOrderWayBillInfo> waybillLst = new List<WxOptimizeOrderWayBillInfo>();
|
||
foreach (JObject badOrderObj in wayBillObjs["data"])
|
||
{
|
||
var oStr = JsonHelper.SerializeObject(badOrderObj);
|
||
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
|
||
{
|
||
|
||
}
|
||
waybillLst.Add(orderWayBill);
|
||
}
|
||
|
||
// 获取收货地址
|
||
if (1 == 1)
|
||
{
|
||
var orderIds = string.Join(",", waybillLst.Select(a => a.orderInfo.orderId));
|
||
var getOrderRst = ShopOptimize.orderSearchByOrderId(shop, orderIds);
|
||
Thread.Sleep(Randomx.GetId(200, 350));
|
||
if (!getOrderRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getOrderRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getOrderRst;
|
||
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
orderWaybill.province = "地址获取失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var orderObj = JsonHelper.JObjectParse(getOrderRst)["orderList"];
|
||
var wxOrderLst = JsonHelper.DeserializeJsonToList<WxOrderInfoLite>(JsonHelper.SerializeObject(orderObj));
|
||
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
var wxOrder = wxOrderLst.FirstOrDefault(o => o.commonInfo.orderId == orderWaybill.orderInfo.orderId);
|
||
if (wxOrder != null)
|
||
{
|
||
orderWaybill.orderTime = wxOrder.commonInfo.createTime;
|
||
orderWaybill.province = wxOrder.acceptInfo.addressInfo.provinceName;
|
||
orderWaybill.city = wxOrder.acceptInfo.addressInfo.cityName;
|
||
orderWaybill.district = wxOrder.acceptInfo.addressInfo.countyName;
|
||
|
||
var prod = wxOrder.orderProductInfo.FirstOrDefault(p => p.productId == orderWaybill.spuId && p.skuCode == orderWaybill.skuCode);
|
||
if (prod != null)
|
||
orderWaybill.skuId = prod.skuId;
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
orderWaybill.province = "地址解析失败";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否被优化过
|
||
var url = BaseClass.BuildObjString("shop/get_waybill_no_user_name");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&status=2";
|
||
data += "&order_ids=" + string.Join(",", waybillLst.Select(w => w.orderInfo.orderId));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
orderWaybill.optimizeWaybillId = "查询失败";
|
||
orderWaybill.optimizeTime = "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeExpressInfo>(sProd);
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == orderWaybill.orderInfo.orderId);
|
||
orderWaybill.optimizeWaybillId = ov == null ? "" : ov.waybill_id;
|
||
orderWaybill.optimizeTime = ov == null ? "" : ov?.use_time?.ToString("MM-dd HH:mm");
|
||
if (!string.IsNullOrEmpty(orderWaybill.optimizeWaybillId))
|
||
orderWaybill.optimizeWaybillId = "已补发" + "\r\n" + ov?.delivery_id + ":" + ov?.waybill_id;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
orderWaybill.optimizeWaybillId = "查询失败";
|
||
orderWaybill.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否有失败记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_rst");
|
||
if (waybillLst.Select(w => w.orderInfo.orderId).Contains("3735310410457956864"))
|
||
{
|
||
|
||
}
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", waybillLst.Select(w => w.orderInfo.orderId));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
if (orderWaybill.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
orderWaybill.optimizeWaybillId = "查询失败";
|
||
orderWaybill.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRstInfo>(sProd);
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
if (orderWaybill.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == orderWaybill.orderInfo.orderId);
|
||
if (ov != null)
|
||
{
|
||
orderWaybill.optimizeWaybillId = ov == null ? "" : ov.optimize_rst;
|
||
orderWaybill.optimizeTime = ov == null ? "" : ov?.mdy_time.ToString("MM-dd HH:mm");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
if (orderWaybill.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
orderWaybill.optimizeWaybillId = "查询失败";
|
||
orderWaybill.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询备注记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_remark");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", waybillLst.Select(w => w.orderInfo.orderId));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
orderWaybill.remark = "备注查询失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRemarkInfo>(sProd);
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == orderWaybill.orderInfo.orderId);
|
||
orderWaybill.remark = ov == null ? "" : ov.remark;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
orderWaybill.remark = "备注查询失败 " + ex.Message;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 显示列表
|
||
foreach (var orderWaybill in waybillLst)
|
||
{
|
||
if (CheckOrderExist(orderWaybill.orderInfo.orderId))
|
||
continue;
|
||
|
||
lstWxOptimizeOrderWayBillInfo.Add(orderWaybill);
|
||
|
||
if (orderWaybill.orderInfo.orderId == "3736739387308396544")
|
||
{
|
||
//3736739387308396544
|
||
}
|
||
|
||
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.skuId,
|
||
orderWaybill.cnt,
|
||
orderWaybill.orderInfo.skuName + " x" + orderWaybill.orderInfo.productCnt,
|
||
orderWaybill.orderInfo.skuCode,
|
||
orderWaybill.orderInfo.orderId, // + "\r\n" + orderWaybill.waybillId,
|
||
orderWaybill.province + orderWaybill.city + orderWaybill.district,
|
||
orderWaybill.orderTime.IsNullOrZero() ? "" : BaseClass.StampToDateTime(orderWaybill.orderTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
|
||
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() ? "" : ((orderWaybill.pickupDuration.ParseToInt() / 3600.0m).ToString("f2") + "小时" + "\r\n" + "[" + (is24 ? "次日" : "48小时") + "]"),
|
||
orderWaybill.delivery.deliveryName,
|
||
orderWaybill.waybillId,
|
||
orderWaybill.optimizeTime + "\r\n" + orderWaybill.optimizeWaybillId.Replace("修改物流信息失败", "补发失败"),
|
||
"补发",
|
||
orderWaybill.remark.Trim().IsNullOrEmpty() ? "添加备注" : orderWaybill.remark.Trim()
|
||
);
|
||
|
||
var row = dgvData3.Rows[rowIndex];
|
||
row.Height = 60;
|
||
if (orderWaybill.optimizeWaybillId.Contains("失败"))
|
||
row.Cells["colDgv3OptimizeStatus"].Style.ForeColor = Color.Red;
|
||
else if (!orderWaybill.optimizeTime.IsNullOrEmpty() && !orderWaybill.optimizeTime.ParseToString().StartsWith(DateTime.Now.ToString("MM-dd")))
|
||
row.Cells["colDgv3OptimizeStatus"].Style.ForeColor = Color.Orange;
|
||
}));
|
||
}
|
||
}
|
||
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;
|
||
}));
|
||
List<WxOptimizeLinerCgiInfo> optrimizeLinerCgiLst = new List<WxOptimizeLinerCgiInfo>();
|
||
foreach (JObject badOrderObj in wayBillObjs["list"])
|
||
{
|
||
var oStr = JsonHelper.SerializeObject(badOrderObj);
|
||
var orderLinerCgiInfo = JsonHelper.DeserializeJsonToObject<WxOptimizeLinerCgiInfo>(oStr);
|
||
if (lstWxOptrimizeLinerCgiInfo.Any(o => o.order_id == orderLinerCgiInfo.order_id))
|
||
continue;
|
||
orderLinerCgiInfo.shopId = shop.ShopId;
|
||
orderLinerCgiInfo.shopName = shop.ShopAccount;
|
||
|
||
optrimizeLinerCgiLst.Add(orderLinerCgiInfo);
|
||
}
|
||
|
||
// 获取收货地址
|
||
if (1 == 1)
|
||
{
|
||
var orderIds = string.Join(",", optrimizeLinerCgiLst.Select(a => a.order_id));
|
||
var getOrderRst = ShopOptimize.orderSearchByOrderId(shop, orderIds);
|
||
Thread.Sleep(Randomx.GetId(200, 350));
|
||
if (!getOrderRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getOrderRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getOrderRst;
|
||
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
linerCgi.province = "地址获取失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var orderObj = JsonHelper.JObjectParse(getOrderRst)["orderList"];
|
||
var wxOrderLst = JsonHelper.DeserializeJsonToList<WxOrderInfoLite>(JsonHelper.SerializeObject(orderObj));
|
||
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
var wxOrder = wxOrderLst.FirstOrDefault(o => o.commonInfo.orderId == linerCgi.order_id);
|
||
if (wxOrder != null)
|
||
{
|
||
linerCgi.orderTime = wxOrder.commonInfo.createTime;
|
||
linerCgi.province = wxOrder.acceptInfo.addressInfo.provinceName;
|
||
linerCgi.city = wxOrder.acceptInfo.addressInfo.cityName;
|
||
linerCgi.district = wxOrder.acceptInfo.addressInfo.countyName;
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
linerCgi.province = "地址解析失败";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否被优化过
|
||
var url = BaseClass.BuildObjString("shop/get_waybill_no_user_name");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&status=2";
|
||
data += "&order_ids=" + string.Join(",", optrimizeLinerCgiLst.Select(w => w.order_id));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
linerCgi.optimizeWaybillId = "查询失败";
|
||
linerCgi.optimizeTime = "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeExpressInfo>(sProd);
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == linerCgi.order_id);
|
||
linerCgi.optimizeWaybillId = ov == null ? "" : ov.waybill_id;
|
||
linerCgi.optimizeTime = ov == null ? "" : ov?.use_time?.ToString("MM-dd HH:mm");
|
||
if (!string.IsNullOrEmpty(linerCgi.optimizeWaybillId))
|
||
linerCgi.optimizeWaybillId = "已补发" + "\r\n" + ov?.delivery_id + ":" + ov?.waybill_id;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
linerCgi.optimizeWaybillId = "查询失败";
|
||
linerCgi.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否有失败记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_rst");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", optrimizeLinerCgiLst.Select(w => w.order_id));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
if (linerCgi.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
linerCgi.optimizeWaybillId = "查询失败";
|
||
linerCgi.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRstInfo>(sProd);
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
if (linerCgi.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == linerCgi.order_id);
|
||
linerCgi.optimizeWaybillId = ov == null ? "" : ov.optimize_rst;
|
||
linerCgi.optimizeTime = ov == null ? "" : ov?.mdy_time.ToString("MM-dd HH:mm");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
if (linerCgi.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
linerCgi.optimizeWaybillId = "查询失败";
|
||
linerCgi.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询备注记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_remark");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", optrimizeLinerCgiLst.Select(w => w.order_id));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
linerCgi.remark = "备注查询失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRemarkInfo>(sProd);
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == linerCgi.order_id);
|
||
linerCgi.remark = ov == null ? "" : ov.remark;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var linerCgi in optrimizeLinerCgiLst)
|
||
{
|
||
linerCgi.remark = "备注查询失败 " + ex.Message;
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach (var orderLinerCgiInfo in optrimizeLinerCgiLst)
|
||
{
|
||
if (CheckOrderExist(orderLinerCgiInfo.order_id))
|
||
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)),
|
||
"", // skuId不展示
|
||
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => "x" + p.product_count)),
|
||
"", //skuCode不展示
|
||
orderLinerCgiInfo.order_id, // + "\r\n" + orderLinerCgiInfo.waybill_id,
|
||
orderLinerCgiInfo.province + orderLinerCgiInfo.city + orderLinerCgiInfo.district,
|
||
orderLinerCgiInfo.orderTime.IsNullOrZero() ? "" : BaseClass.StampToDateTime(orderLinerCgiInfo.orderTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
|
||
|
||
orderLinerCgiInfo.delivery_name,
|
||
orderLinerCgiInfo.waybill_id,
|
||
BaseClass.StampToDateTime(orderLinerCgiInfo.collect_time.ParseToInt()).ToString("yy-MM-dd HH:mm:ss") + "\r\n" + BaseClass.StampToDateTime(orderLinerCgiInfo.receipt_time.ParseToInt()).ToString("yy-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.optimizeTime + "\r\n" + orderLinerCgiInfo.optimizeWaybillId.Replace("修改物流信息失败", "补发失败"),
|
||
"补发",
|
||
orderLinerCgiInfo.remark.Trim().IsNullOrEmpty() ? "添加备注" : orderLinerCgiInfo.remark.Trim()
|
||
);
|
||
|
||
var row = dgvData4.Rows[rowIndex];
|
||
row.Height = 60;
|
||
if (orderLinerCgiInfo.optimizeWaybillId.Contains("失败"))
|
||
row.Cells["colDgv4OptimizeStatus"].Style.ForeColor = Color.Red;
|
||
else if (!orderLinerCgiInfo.optimizeTime.IsNullOrEmpty() && !orderLinerCgiInfo.optimizeTime.ParseToString().StartsWith(DateTime.Now.ToString("MM-dd")))
|
||
row.Cells["colDgv4OptimizeStatus"].Style.ForeColor = Color.Orange;
|
||
}));
|
||
}
|
||
}
|
||
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 SearchData5(ShopLoginInfo shop)
|
||
{
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 查询店铺是24小时时效还是48小时时效
|
||
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) - 1;
|
||
while (page < totalPage)
|
||
{
|
||
page++;
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var getData5 = ShopOptimize.GetFeedbackOrder(shop, page, startTime, endTime, is24);
|
||
Thread.Sleep(Randomx.GetId(300, 600));
|
||
if (!getData5.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getData5, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getData5;
|
||
|
||
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 feedbackObjs = JsonHelper.JObjectParse(getData5);
|
||
if (page == 1)
|
||
{
|
||
var totalNum = feedbackObjs["total"].ParseToInt();
|
||
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pictureBox5.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在查询反向物流,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
|
||
}));
|
||
List<WxOptimizeFeedbackOrderInfo> optrimizeFeedbackOrderLst = new List<WxOptimizeFeedbackOrderInfo>();
|
||
foreach (JObject badOrderObj in feedbackObjs["data"])
|
||
{
|
||
var oStr = JsonHelper.SerializeObject(badOrderObj);
|
||
var feedbackOrderInfo = JsonHelper.DeserializeJsonToObject<WxOptimizeFeedbackOrderInfo>(oStr);
|
||
if (lstWxOptimizeFeedbackOrderInfo.Any(o => o.orderInfo.orderId == feedbackOrderInfo.orderInfo.orderId))
|
||
continue;
|
||
feedbackOrderInfo.shopId = shop.ShopId;
|
||
feedbackOrderInfo.shopName = shop.ShopAccount;
|
||
|
||
optrimizeFeedbackOrderLst.Add(feedbackOrderInfo);
|
||
}
|
||
|
||
// 获取收货地址
|
||
if (1 == 1)
|
||
{
|
||
var orderIds = string.Join(",", optrimizeFeedbackOrderLst.Select(f => f.orderInfo.orderId));
|
||
var getOrderRst = ShopOptimize.orderSearchByOrderId(shop, orderIds);
|
||
Thread.Sleep(Randomx.GetId(200, 350));
|
||
if (!getOrderRst.Contains("\"code\":0"))
|
||
{
|
||
var error = BaseRegex.GetStringJson(ref getOrderRst, "msg");
|
||
if (string.IsNullOrEmpty(error))
|
||
error = getOrderRst;
|
||
|
||
foreach (var linerCgi in optrimizeFeedbackOrderLst)
|
||
{
|
||
linerCgi.province = "地址获取失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var orderObj = JsonHelper.JObjectParse(getOrderRst)["orderList"];
|
||
var wxOrderLst = JsonHelper.DeserializeJsonToList<WxOrderInfoLite>(JsonHelper.SerializeObject(orderObj));
|
||
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
var wxOrder = wxOrderLst.FirstOrDefault(o => o.commonInfo.orderId == feedbackOrder.orderInfo.orderId);
|
||
if (wxOrder != null)
|
||
{
|
||
feedbackOrder.orderTime = wxOrder.commonInfo.createTime;
|
||
feedbackOrder.province = wxOrder.acceptInfo.addressInfo.provinceName;
|
||
feedbackOrder.city = wxOrder.acceptInfo.addressInfo.cityName;
|
||
feedbackOrder.district = wxOrder.acceptInfo.addressInfo.countyName;
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
foreach (var linerCgi in optrimizeFeedbackOrderLst)
|
||
{
|
||
linerCgi.province = "地址解析失败";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否被优化过
|
||
var url = BaseClass.BuildObjString("shop/get_waybill_no_user_name");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&status=2";
|
||
data += "&order_ids=" + string.Join(",", optrimizeFeedbackOrderLst.Select(f => f.orderInfo.orderId));
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var linerCgi in optrimizeFeedbackOrderLst)
|
||
{
|
||
linerCgi.optimizeWaybillId = "查询失败";
|
||
linerCgi.optimizeTime = "";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeExpressInfo>(sProd);
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == feedbackOrder.orderInfo.orderId);
|
||
feedbackOrder.optimizeWaybillId = ov == null ? "" : ov.waybill_id;
|
||
feedbackOrder.optimizeTime = ov == null ? "" : ov?.use_time?.ToString("MM-dd HH:mm");
|
||
if (!string.IsNullOrEmpty(feedbackOrder.optimizeWaybillId))
|
||
feedbackOrder.optimizeWaybillId = "已补发" + "\r\n" + ov?.delivery_id + ":" + ov?.waybill_id;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var linerCgi in optrimizeFeedbackOrderLst)
|
||
{
|
||
linerCgi.optimizeWaybillId = "查询失败";
|
||
linerCgi.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询是否有失败记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_rst");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", optrimizeFeedbackOrderLst.Select(f => f.orderInfo.orderId));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
if (feedbackOrder.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
feedbackOrder.optimizeWaybillId = "查询失败";
|
||
feedbackOrder.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRstInfo>(sProd);
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
if (feedbackOrder.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == feedbackOrder.orderInfo.orderId);
|
||
feedbackOrder.optimizeWaybillId = ov == null ? "" : ov.optimize_rst;
|
||
feedbackOrder.optimizeTime = ov == null ? "" : ov?.mdy_time.ToString("MM-dd HH:mm");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
if (feedbackOrder.optimizeWaybillId.IsNullOrEmpty())
|
||
{
|
||
feedbackOrder.optimizeWaybillId = "查询失败";
|
||
feedbackOrder.optimizeTime = "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 查询备注记录
|
||
url = BaseClass.BuildObjString("shop/get_express_optimize_remark");
|
||
data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&order_ids=" + string.Join(",", optrimizeFeedbackOrderLst.Select(f => f.orderInfo.orderId));
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
foreach (var linerCgi in optrimizeFeedbackOrderLst)
|
||
{
|
||
linerCgi.remark = "备注查询失败";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
try
|
||
{
|
||
var jArr = JObject.Parse(html)["data"];
|
||
var sProd = JsonHelper.SerializeObject(jArr);
|
||
var optimizeLst = JsonHelper.DeserializeJsonToList<WxOptimizeRemarkInfo>(sProd);
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
var ov = optimizeLst.FirstOrDefault(o => o.order_id == feedbackOrder.orderInfo.orderId);
|
||
feedbackOrder.remark = ov == null ? "" : ov.remark;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
foreach (var linerCgi in optrimizeFeedbackOrderLst)
|
||
{
|
||
linerCgi.remark = "备注查询失败 " + ex.Message;
|
||
}
|
||
}
|
||
}
|
||
|
||
foreach (var feedbackOrder in optrimizeFeedbackOrderLst)
|
||
{
|
||
if (CheckOrderExist(feedbackOrder.orderInfo.orderId))
|
||
continue;
|
||
|
||
lstWxOptimizeFeedbackOrderInfo.Add(feedbackOrder);
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rowIndex = this.dgvData5.Rows.Add(
|
||
false,
|
||
shop.ShopId,
|
||
shop.ShopAccount,
|
||
"登录",
|
||
"进店",
|
||
feedbackOrder.orderInfo.imgUrl,
|
||
DataGridViewExtension.defaultBitmap,
|
||
feedbackOrder.orderInfo.spuId,
|
||
feedbackOrder.orderInfo.name,
|
||
"", // skuId不展示
|
||
feedbackOrder.orderInfo.productCnt,
|
||
feedbackOrder.orderInfo.skuCode,
|
||
feedbackOrder.orderInfo.orderId,
|
||
feedbackOrder.province + feedbackOrder.city + feedbackOrder.district,
|
||
feedbackOrder.orderTime.IsNullOrZero() ? "" : BaseClass.StampToDateTime(feedbackOrder.orderTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
|
||
feedbackOrder.delivery.deliveryName,
|
||
feedbackOrder.waybillId,
|
||
feedbackOrder.complainReason,
|
||
feedbackOrder.negativeReviewReason,
|
||
feedbackOrder.optimizeTime + "\r\n" + feedbackOrder.optimizeWaybillId.Replace("修改物流信息失败", "补发失败"),
|
||
"补发",
|
||
feedbackOrder.remark.Trim().IsNullOrEmpty() ? "添加备注" : feedbackOrder.remark.Trim()
|
||
);
|
||
|
||
var row = dgvData5.Rows[rowIndex];
|
||
row.Height = 60;
|
||
if (feedbackOrder.optimizeWaybillId.Contains("失败"))
|
||
row.Cells["colDgv5OptimizeStatus"].Style.ForeColor = Color.Red;
|
||
else if (!feedbackOrder.optimizeTime.IsNullOrEmpty() && !feedbackOrder.optimizeTime.ParseToString().StartsWith(DateTime.Now.ToString("MM-dd")))
|
||
row.Cells["colDgv5OptimizeStatus"].Style.ForeColor = Color.Orange;
|
||
}));
|
||
}
|
||
}
|
||
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 btnCancel_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
}
|
||
|
||
public string OptimizeExpress(ShopLoginInfo shop, string orderId, string orderCreateTime = "", string spuId = "", string skuId = "", int cnt = 1)
|
||
{
|
||
var url = BaseClass.BuildObjString("shop/select_waybill");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&shop_id=" + shop.ShopId;
|
||
data += "&order_id=" + orderId;
|
||
if (!orderCreateTime.IsNullOrEmpty())
|
||
data += "&order_time=" + orderCreateTime;
|
||
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
var errMsg = BaseRegex.GetStringJson(ref html, "msg");
|
||
return "补发失败 " + errMsg;
|
||
}
|
||
var waybill_id = BaseRegex.GetStringJson(ref html, "waybill_id");
|
||
var delivery_id = BaseRegex.GetStringJson(ref html, "delivery_id");
|
||
var delivery_name = BaseRegex.GetStringJson(ref html, "delivery_name");
|
||
|
||
string optimizeExpressRst = "";
|
||
string msg = "";
|
||
string code = "";
|
||
string mode = "";
|
||
if (!chkUseReshipmentApi.Checked)
|
||
{
|
||
JObject body = new JObject();
|
||
body["platform"] = "WEISHOP";
|
||
//body["shopId"] = shop.ShopId;
|
||
body["orderId"] = orderId;
|
||
body["expressNo"] = waybill_id;
|
||
body["expressName"] = delivery_id;
|
||
url = "https://po.e57.cn/prod-api/api/oms-api/order/optimize/optimizeExpressInfo";
|
||
var bodyStr = JsonHelper.SerializeObject(body);
|
||
optimizeExpressRst = WXHttpResponseBLL.e57PostResponse(url, bodyStr, "");
|
||
//<AjaxResult><msg>修改物流信息失败</msg><code>500</code></AjaxResult>
|
||
//if (!optimizeExpressRst.Contains("修改物流信息成功") && !optimizeExpressRst.Contains("<code>200</code>"))
|
||
// optimizeExpressRst = WXHttpResponseBLL.e57PostResponse(url, bodyStr, "");
|
||
}
|
||
else
|
||
{
|
||
mode = "2";
|
||
var rst = ShopOptimize.orderCompensationDelivery(shop, orderId, delivery_id, waybill_id, spuId, skuId, cnt);
|
||
if (rst.Contains("\"code\":0"))
|
||
{
|
||
optimizeExpressRst = "<AjaxResult><msg>补发货修改物流信息成功</msg><code>200</code></AjaxResult>";
|
||
}
|
||
else
|
||
{
|
||
var errMsg = BaseRegex.GetStringJsonByRegs(ref rst, rst, "errmsg", "errMsg");
|
||
optimizeExpressRst = "<AjaxResult><msg>" + errMsg + "</msg><code>500</code></AjaxResult>";
|
||
}
|
||
}
|
||
|
||
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
|
||
try
|
||
{
|
||
xmlDoc.LoadXml(optimizeExpressRst); //<AjaxResult><msg>订单不存在,orderId:3735398415030708224</msg><code>500</code></AjaxResult>
|
||
msg = xmlDoc["AjaxResult"]["msg"].InnerText;
|
||
code = xmlDoc["AjaxResult"]["code"].InnerText;
|
||
|
||
// 记录一下优化结果
|
||
url = BaseClass.BuildObjString("shop/add_mdy_express_optimize_rst");
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&shop_id=" + shop.ShopId;
|
||
data += "&order_id=" + orderId;
|
||
if (msg.ParseToString().Contains("修改物流信息成功") || code == "200")
|
||
{
|
||
data += "&waybill_id=" + waybill_id;
|
||
data += "&delivery_name=" + delivery_name;
|
||
data += "&optimize_rst=补发成功" + mode + " " + delivery_id + ":" + waybill_id;
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(msg) && !msg.Contains("修改物流信息失败"))
|
||
msg = "修改物流信息失败," + msg;
|
||
data += "&optimize_rst=" + (msg.IsNullOrEmpty() ? "补发失败" : msg) + " " + delivery_id + ":" + waybill_id;
|
||
}
|
||
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
url = BaseClass.BuildObjString("shop/update_used_waybill");
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&shop_id=" + shop.ShopId;
|
||
data += "&order_id=" + orderId;
|
||
data += "&waybill_id=" + waybill_id;
|
||
if (!optimizeExpressRst.ParseToString().Contains("修改物流信息成功") && !optimizeExpressRst.ParseToString().Contains("<code>200</code>"))
|
||
data += "&is_rollback=true";
|
||
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
var errMsg = BaseRegex.GetStringJson(ref html, "msg");
|
||
if (!optimizeExpressRst.ParseToString().Contains("修改物流信息成功") && !optimizeExpressRst.ParseToString().Contains("<code>200</code>"))
|
||
return "补发失败,还原失败\r\n" + errMsg + " " + msg + " " + delivery_id + ":" + waybill_id;
|
||
else
|
||
return "补发状态记录失败\r\n" + errMsg + " " + delivery_id + ":" + waybill_id;
|
||
}
|
||
if (!optimizeExpressRst.ParseToString().Contains("修改物流信息成功") && !optimizeExpressRst.ParseToString().Contains("<code>200</code>"))
|
||
return "补发失败,已还原\r\n" + msg + " " + delivery_id + ":" + waybill_id;
|
||
return "补发成功" + mode + " " + delivery_id + ":" + waybill_id;
|
||
}
|
||
|
||
private void dgvData_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
var dgvData = sender as DataGridView;
|
||
if (dgvData == null)
|
||
return;
|
||
|
||
var dgvNum = dgvData.Name.Replace("dgvData", "");
|
||
|
||
var row = dgvData.Rows[e.RowIndex];
|
||
string headerText = dgvData.Columns[e.ColumnIndex].HeaderText;
|
||
var shopId = row.Cells["colDgv" + dgvNum + "ShopId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
|
||
switch (headerText)
|
||
{
|
||
case "删除":
|
||
break;
|
||
case "登录":
|
||
{
|
||
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
|
||
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(row.Cells["colDgv" + dgvNum + "ImgUrl"].Value.ParseToString());
|
||
imgFrom.ShowDialog();
|
||
break;
|
||
}
|
||
case "补发":
|
||
{
|
||
var orderId = row.Cells[$"colDgv{dgvNum}OrderId"].Value.ParseToString();
|
||
if (orderId.Contains("未获取到对应订单号"))
|
||
{
|
||
BaseMsgForm.ShowError("缺少单编号无法补发!");
|
||
return;
|
||
}
|
||
if (orderId.Contains("获取到多条订单号"))
|
||
{
|
||
BaseMsgForm.ShowError("订单编号不符合补发条件!");
|
||
return;
|
||
}
|
||
orderId = orderId.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
|
||
if (string.IsNullOrEmpty(orderId))
|
||
{
|
||
BaseMsgForm.ShowError("缺少订单编号无法补发!");
|
||
return;
|
||
}
|
||
if (chkUseReshipmentApi.Checked && dgvNum != "2")
|
||
{
|
||
BaseMsgForm.ShowError("补发货模式仅支持订单评价补发!");
|
||
return;
|
||
}
|
||
|
||
var orderCreateTime = row.Cells[$"colDgv{dgvNum}OrderTime"].Value.ParseToString();
|
||
var spuId = row.Cells[$"colDgv{dgvNum}SpuId"].Value.ParseToString();
|
||
var skuId = row.Cells[$"colDgv{dgvNum}SkuId"].Value.ParseToString();
|
||
var cnt = row.Cells[$"colDgv{dgvNum}Cnt"].Value.ParseToInt();
|
||
Task.Run(() =>
|
||
{
|
||
var rst = OptimizeExpress(shop, orderId, orderCreateTime, spuId, skuId, cnt);
|
||
Invoke(new Action(() =>
|
||
{
|
||
pictureBox1.Visible = pictureBox2.Visible = pictureBox3.Visible = pictureBox4.Visible = pictureBox5.Visible = false;
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = rst.Replace("修改物流信息失败,", "").Replace("修改物流信息失败,", "");
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.ForeColor = rst.Contains("成功") ? Control.DefaultForeColor : Color.Red;
|
||
}));
|
||
});
|
||
break;
|
||
}
|
||
case "备注":
|
||
{
|
||
var orderId = row.Cells[$"colDgv{dgvNum}OrderId"].Value.ParseToString();
|
||
if (orderId.Contains("未获取到对应订单号"))
|
||
{
|
||
BaseMsgForm.ShowError("缺少单编号无法备注!");
|
||
return;
|
||
}
|
||
if (orderId.Contains("获取到多条订单号"))
|
||
{
|
||
BaseMsgForm.ShowError("订单编号不符合备注条件!");
|
||
return;
|
||
}
|
||
orderId = orderId.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
|
||
if (string.IsNullOrEmpty(orderId))
|
||
{
|
||
BaseMsgForm.ShowError("缺少订单编号无法备注!");
|
||
return;
|
||
}
|
||
pnlUpdateRemark.Tag = row.Cells[$"colDgv{dgvNum}Remark"];
|
||
lblShopName.Text = shop.ShopAccount;
|
||
lblShopId.Text = shop.ShopId;
|
||
lblOrderId.Text = orderId;
|
||
txtRemark.Text = row.Cells[$"colDgv{dgvNum}Remark"].Value.ParseToString();
|
||
if (txtRemark.Text == "添加备注")
|
||
txtRemark.Text = "";
|
||
pnlUpdateRemark.Parent = dgvData.Parent;
|
||
pnlUpdateRemark.BringToFront();
|
||
pnlUpdateRemark.Visible = true;
|
||
}
|
||
break;
|
||
case "":
|
||
row.Cells[$"colDgv{dgvNum}check"].Value = !(bool)row.Cells[$"colDgv{dgvNum}check"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void btnWaybillManage_Click(object sender, EventArgs e)
|
||
{
|
||
WXWaybillManageForm waybillForm = new WXWaybillManageForm();
|
||
waybillForm.ShowDialog();
|
||
}
|
||
|
||
public bool CheckOrderExist(string orderId)
|
||
{
|
||
if (lstWxOptimizeOrderAfterSaleInfo.Any(o => o.orderInfo.orderId == orderId))
|
||
return true;
|
||
if (lstWxOptimizeProductEvaluationInfo.Any(o => o.order_id == orderId))
|
||
return true;
|
||
if (lstWxOptimizeOrderWayBillInfo.Any(o => o.orderInfo.orderId == orderId))
|
||
return true;
|
||
if (lstWxOptrimizeLinerCgiInfo.Any(o => o.order_id == orderId))
|
||
return true;
|
||
if (lstWxOptimizeFeedbackOrderInfo.Any(o => o.orderInfo.orderId == orderId))
|
||
return true;
|
||
return false;
|
||
}
|
||
|
||
private void btnRemarkCancel_Click(object sender, EventArgs e)
|
||
{
|
||
txtRemark.Text = "";
|
||
lblOrderId.Text = "";
|
||
lblShopId.Text = "";
|
||
lblShopName.Text = "";
|
||
pnlUpdateRemark.Visible = false;
|
||
}
|
||
|
||
private void btnRemarkOK_Click(object sender, EventArgs e)
|
||
{
|
||
var cell = this.pnlUpdateRemark.Tag as DataGridViewCell;
|
||
if (cell == null)
|
||
return;
|
||
|
||
var url = BaseClass.BuildObjString("shop/add_mdy_express_optimize_remark");
|
||
var data = "";
|
||
data = UserLogin.GetSignaturex();
|
||
data += "&shop_id=" + lblShopId.Text;
|
||
data += "&order_id=" + lblOrderId.Text;
|
||
data += "&remark=" + txtRemark.Text.Trim();
|
||
|
||
var html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
html = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||
{
|
||
BaseMsgForm.ShowError("修改备注失败,请重试!");
|
||
return;
|
||
}
|
||
cell.Value = txtRemark.Text.Trim().IsNullOrEmpty() ? "添加备注" : txtRemark.Text.Trim();
|
||
|
||
txtRemark.Text = "";
|
||
lblOrderId.Text = "";
|
||
lblShopId.Text = "";
|
||
lblShopName.Text = "";
|
||
pnlUpdateRemark.Visible = false;
|
||
}
|
||
|
||
private void btnFilter_Click(object sender, EventArgs e)
|
||
{
|
||
var orderId = txtFilterOrderId.Text.Trim();
|
||
List<DataGridView> dgvList = new List<DataGridView>() { dgvData1, dgvData2, dgvData3, dgvData4, dgvData5 };
|
||
for (int i = 0; i < dgvList.Count; i++)
|
||
{
|
||
var dgvNum = i + 1;
|
||
foreach (DataGridViewRow row in dgvList[i].Rows)
|
||
{
|
||
if (row.Cells[$"colDgv{dgvNum}OrderId"].Value.ParseToString().Contains(orderId))
|
||
row.Visible = true;
|
||
else
|
||
row.Visible = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnRestoreFilter_Click(object sender, EventArgs e)
|
||
{
|
||
txtFilterOrderId.Text = "";
|
||
List<DataGridView> dgvList = new List<DataGridView>() { dgvData1, dgvData2, dgvData3, dgvData4, dgvData5 };
|
||
for (int i = 0; i< dgvList.Count; i++)
|
||
{
|
||
foreach(DataGridViewRow row in dgvList[i].Rows)
|
||
{
|
||
row.Visible = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnUpdateKdn_Click(object sender, EventArgs e)
|
||
{
|
||
this.ucTabControl1.SelectedTab = tabPage6;
|
||
//kdnAuth
|
||
Task.Run(() =>
|
||
{
|
||
while (!cefWebBrowser.IsBrowserInitialized)
|
||
{
|
||
Thread.Sleep(1000);
|
||
}
|
||
cefWebBrowser.Load(expressToolUrl);
|
||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||
|
||
List<string> waybillIds = new List<string>();
|
||
//var dgvRows1 = dgvData1.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv1OptimizeStatus"].Value.ParseToString().Trim(' ', '\r', '\n').IsNullOrEmpty()).ToList();
|
||
//waybillIds.AddRange(dgvRows1.Select(r => r.Cells["colDgv1WaybillId"].Value.ParseToString()));
|
||
//var dgvRows2 = dgvData2.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv2OptimizeStatus"].Value.ParseToString().Trim(' ', '\r', '\n').IsNullOrEmpty()).ToList();
|
||
//waybillIds.AddRange(dgvRows2.Select(r => r.Cells["colDgv2WaybillId"].Value.ParseToString()));
|
||
var dgvRows3 = dgvData3.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv3OptimizeStatus"].Value.ParseToString().Trim(' ', '\r', '\n').IsNullOrEmpty()).ToList();
|
||
waybillIds.AddRange(dgvRows3.Select(r => r.Cells["colDgv3WaybillId"].Value.ParseToString()));
|
||
var dgvRows4 = dgvData4.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv4OptimizeStatus"].Value.ParseToString().Trim(' ', '\r', '\n').IsNullOrEmpty()).ToList();
|
||
waybillIds.AddRange(dgvRows4.Select(r => r.Cells["colDgv4WaybillId"].Value.ParseToString()));
|
||
var dgvRows5 = dgvData5.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv5OptimizeStatus"].Value.ParseToString().Trim(' ', '\r', '\n').IsNullOrEmpty()).ToList();
|
||
waybillIds.AddRange(dgvRows5.Select(r => r.Cells["colDgv5WaybillId"].Value.ParseToString()));
|
||
waybillIds = waybillIds.Distinct().ToList();
|
||
|
||
while (waybillIds.Count > 0)
|
||
{
|
||
Thread.Sleep(Randomx.GetId(100, 500));
|
||
var waybillIdsTmp = waybillIds.Take(200).ToList();
|
||
waybillIds.RemoveAll(w => waybillIdsTmp.Contains(w));
|
||
|
||
var rst = ShopOptimize.kdniaoGetWayBillPage(string.Join(",", waybillIdsTmp), dicKdnRequest);
|
||
if (!rst.Contains("\"Code\":200"))
|
||
{
|
||
var errMsg = BaseRegex.GetStringJsonByRegs(ref rst, rst, "Message", "Message");
|
||
BaseMsgForm.ShowError("物流信息更新失败 " + errMsg);
|
||
return;
|
||
}
|
||
|
||
var jObj = JsonHelper.JObjectParse(rst)["Data"]["ResultList"];
|
||
var data = JsonHelper.SerializeObject(jObj);
|
||
List<kdnWaybillResultInfo> kdnWaybillList = JsonHelper.DeserializeJsonToList<kdnWaybillResultInfo>(data);
|
||
foreach (var kdnWaybill in kdnWaybillList)
|
||
{
|
||
var rows = dgvData3.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv3WaybillId"].Value.ParseToString() == kdnWaybill.LogisticsCode).ToList();
|
||
if (rows.Count > 0)
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var latelyTraceTime = kdnWaybill.LastUpdateTime.ParseToDateTime();
|
||
var duration = DateTime.Now - latelyTraceTime;
|
||
var durationStr = duration.TotalMinutes < 60 ? duration.TotalMinutes.ParseToInt() + "分钟前" :
|
||
(duration.TotalHours < 24 ? duration.TotalHours.ParseToInt() + "小时前" : duration.TotalDays.ParseToInt() + "天前");
|
||
row.Cells["colDgv3WaybillLatelyTrace"].Value = durationStr + " " + kdnWaybill.LatelyTrace?.AcceptStation;
|
||
row.Cells["colDgv3WaybillStatus"].Value = kdnWaybill.LogisticsStatusStr;
|
||
row.Cells["colDgv3WaybillStatus"].Style.ForeColor = DefaultForeColor;
|
||
if (kdnWaybill.LogisticsStatusStr == "待揽件")
|
||
row.Cells["colDgv3WaybillStatus"].Style.ForeColor = Color.Orange;
|
||
if (kdnWaybill.LogisticsStatusStr == "在途中")
|
||
row.Cells["colDgv3WaybillStatus"].Style.ForeColor = Color.DarkGreen;
|
||
if (kdnWaybill.LogisticsStatusStr == "派件中")
|
||
row.Cells["colDgv3WaybillStatus"].Style.ForeColor = Color.Green;
|
||
if (kdnWaybill.LogisticsStatusStr == "已签收")
|
||
row.Cells["colDgv3WaybillStatus"].Style.ForeColor = Color.LightGreen;
|
||
}));
|
||
}
|
||
continue;
|
||
}
|
||
|
||
rows = dgvData4.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv4WaybillId"].Value.ParseToString() == kdnWaybill.LogisticsCode).ToList();
|
||
if (rows.Count > 0)
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var latelyTraceTime = kdnWaybill.LatelyTrace.AcceptTime.ParseToDateTime();
|
||
var duration = DateTime.Now - latelyTraceTime;
|
||
var durationStr = duration.TotalMinutes < 60 ? duration.TotalMinutes + "分钟" : (duration.TotalHours < 24 ? duration.TotalHours + "小时前" : duration.TotalDays + "天前");
|
||
row.Cells["colDgv4WaybillLatelyTrace"].Value = durationStr + " " + kdnWaybill.LatelyTrace.AcceptStation;
|
||
row.Cells["colDgv4WaybillStatus"].Value = kdnWaybill.LogisticsStatusStr;
|
||
row.Cells["colDgv4WaybillStatus"].Style.ForeColor = DefaultForeColor;
|
||
if (kdnWaybill.LogisticsStatusStr == "待揽件")
|
||
row.Cells["colDgv4WaybillStatus"].Style.ForeColor = Color.Orange;
|
||
if (kdnWaybill.LogisticsStatusStr == "在途中")
|
||
row.Cells["colDgv4WaybillStatus"].Style.ForeColor = Color.DarkGreen;
|
||
if (kdnWaybill.LogisticsStatusStr == "派件中")
|
||
row.Cells["colDgv4WaybillStatus"].Style.ForeColor = Color.Green;
|
||
if (kdnWaybill.LogisticsStatusStr == "已签收")
|
||
row.Cells["colDgv4WaybillStatus"].Style.ForeColor = Color.LightGreen;
|
||
}));
|
||
}
|
||
continue;
|
||
}
|
||
|
||
rows = dgvData5.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv5WaybillId"].Value.ParseToString() == kdnWaybill.LogisticsCode).ToList();
|
||
if (rows.Count > 0)
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var latelyTraceTime = kdnWaybill.LatelyTrace.AcceptTime.ParseToDateTime();
|
||
var duration = DateTime.Now - latelyTraceTime;
|
||
var durationStr = duration.TotalMinutes < 60 ? duration.TotalMinutes + "分钟" : (duration.TotalHours < 24 ? duration.TotalHours + "小时前" : duration.TotalDays + "天前");
|
||
row.Cells["colDgv5WaybillLatelyTrace"].Value = durationStr + " " + kdnWaybill.LatelyTrace.AcceptStation;
|
||
row.Cells["colDgv5WaybillStatus"].Value = kdnWaybill.LogisticsStatusStr;
|
||
row.Cells["colDgv5WaybillStatus"].Style.ForeColor = DefaultForeColor;
|
||
if (kdnWaybill.LogisticsStatusStr == "待揽件")
|
||
row.Cells["colDgv5WaybillStatus"].Style.ForeColor = Color.Orange;
|
||
if (kdnWaybill.LogisticsStatusStr == "在途中")
|
||
row.Cells["colDgv5WaybillStatus"].Style.ForeColor = Color.DarkGreen;
|
||
if (kdnWaybill.LogisticsStatusStr == "派件中")
|
||
row.Cells["colDgv5WaybillStatus"].Style.ForeColor = Color.Green;
|
||
if (kdnWaybill.LogisticsStatusStr == "已签收")
|
||
row.Cells["colDgv5WaybillStatus"].Style.ForeColor = Color.LightGreen;
|
||
}));
|
||
}
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
Invoke(new Action(() => {
|
||
BaseMsgForm.ShowInfo("物流更新完毕");
|
||
}));
|
||
});
|
||
|
||
//var waybillIds = string.Join(",", dgvRows1Tmp.Select(r => r.Cells["colDgv1OrderId"].Value.ParseToString()).Distinct());
|
||
}
|
||
|
||
private void btnBatchOptimize_Click(object sender, EventArgs e)
|
||
{
|
||
List<string> OrderIds = new List<string>();
|
||
List<DataGridViewRow> dgvRows = new List<DataGridViewRow>();
|
||
var dgvRows1 = dgvData1.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv1Check"].Value.ParseToBool() == true).ToList();
|
||
dgvRows.AddRange(dgvRows1.Where(r => !OrderIds.Any(oId => oId == r.Cells["colDgv1OrderId"].Value.ParseToString())));
|
||
OrderIds.AddRange(dgvRows1.Select(r => r.Cells["colDgv1OrderId"].Value.ParseToString()));
|
||
var dgvRows2 = dgvData2.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv2Check"].Value.ParseToBool() == true).ToList();
|
||
dgvRows.AddRange(dgvRows2.Where(r => !OrderIds.Any(oId => oId == r.Cells["colDgv2OrderId"].Value.ParseToString())));
|
||
OrderIds.AddRange(dgvRows2.Select(r => r.Cells["colDgv2OrderId"].Value.ParseToString()));
|
||
var dgvRows3 = dgvData3.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv3Check"].Value.ParseToBool() == true).ToList();
|
||
dgvRows.AddRange(dgvRows3.Where(r => !OrderIds.Any(oId => oId == r.Cells["colDgv3OrderId"].Value.ParseToString())));
|
||
OrderIds.AddRange(dgvRows3.Select(r => r.Cells["colDgv3OrderId"].Value.ParseToString()));
|
||
var dgvRows4 = dgvData4.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv4Check"].Value.ParseToBool() == true).ToList();
|
||
dgvRows.AddRange(dgvRows4.Where(r => !OrderIds.Any(oId => oId == r.Cells["colDgv4OrderId"].Value.ParseToString())));
|
||
OrderIds.AddRange(dgvRows4.Select(r => r.Cells["colDgv4OrderId"].Value.ParseToString()));
|
||
var dgvRows5 = dgvData5.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colDgv5Check"].Value.ParseToBool() == true).ToList();
|
||
dgvRows.AddRange(dgvRows5.Where(r => !OrderIds.Any(oId => oId == r.Cells["colDgv5OrderId"].Value.ParseToString())));
|
||
OrderIds.AddRange(dgvRows5.Select(r => r.Cells["colDgv5OrderId"].Value.ParseToString()));
|
||
OrderIds = OrderIds.Distinct().ToList();
|
||
if (dgvRows.Count <= 0)
|
||
{
|
||
BaseMsgForm.ShowError("请选择订单");
|
||
return;
|
||
}
|
||
|
||
pictureBox1.Visible = pictureBox2.Visible = pictureBox3.Visible = pictureBox4.Visible = pictureBox5.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
int index = 0;
|
||
foreach (var row in dgvRows)
|
||
{
|
||
index++;
|
||
var dgvNum = row.DataGridView.Name.Replace("dgvData", "");
|
||
Invoke(new Action(() =>
|
||
{
|
||
statusBar.lblTaskStatus.Text = "正在批量补发 " + index + "/" + dgvRows.Count;
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.BackColor = row.Cells[$"colDgv{dgvNum}SpuId"].Style.BackColor;
|
||
}));
|
||
|
||
var orderId = row.Cells[$"colDgv{dgvNum}OrderId"].Value.ParseToString();
|
||
if (orderId.Contains("未获取到对应订单号"))
|
||
{
|
||
Invoke(new Action(() => { row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = "缺少单编号无法补发!";
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.BackColor = Color.Yellow;
|
||
}));
|
||
continue;
|
||
}
|
||
if (orderId.Contains("获取到多条订单号"))
|
||
{
|
||
Invoke(new Action(() => { row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = "获取到多条订单号!订单编号不符合补发条件!";
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.BackColor = Color.Yellow;
|
||
}));
|
||
continue;
|
||
}
|
||
orderId = orderId.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
|
||
if (string.IsNullOrEmpty(orderId))
|
||
{
|
||
Invoke(new Action(() => { row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = "缺少订单编号无法补发!";
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.BackColor = Color.Yellow;
|
||
}));
|
||
continue;
|
||
}
|
||
if (chkUseReshipmentApi.Checked && dgvNum != "2")
|
||
{
|
||
Invoke(new Action(() => { row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = "补发货模式仅支持订单评价补发!";
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.BackColor = Color.Yellow;
|
||
}));
|
||
continue;
|
||
}
|
||
var shopId = row.Cells[$"colDgv{dgvNum}ShopId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
{
|
||
Invoke(new Action(() => { row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = "店铺不存在!";
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.BackColor = Color.Yellow;
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
string orderCreateTime = "", spuId = "", skuId = "";
|
||
int cnt = 0;
|
||
Invoke(new Action(() =>
|
||
{
|
||
orderCreateTime = row.Cells[$"colDgv{dgvNum}OrderTime"].Value.ParseToString();
|
||
spuId = row.Cells[$"colDgv{dgvNum}SpuId"].Value.ParseToString();
|
||
skuId = row.Cells[$"colDgv{dgvNum}SkuId"].Value.ParseToString();
|
||
cnt = row.Cells[$"colDgv{dgvNum}Cnt"].Value.ParseToInt();
|
||
}));
|
||
var rst = OptimizeExpress(shop, orderId, orderCreateTime, spuId, skuId, cnt);
|
||
Invoke(new Action(() =>
|
||
{
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = rst.Replace("修改物流信息失败,", "").Replace("修改物流信息失败,", "");
|
||
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Style.ForeColor = rst.Contains("成功") ? Control.DefaultForeColor : Color.Red;
|
||
}));
|
||
}
|
||
Invoke(new Action(() =>
|
||
{
|
||
pictureBox1.Visible = pictureBox2.Visible = pictureBox3.Visible = pictureBox4.Visible = pictureBox5.Visible = false;
|
||
statusBar.lblTaskStatus.Text = "补发结束 " + dgvRows.Count + "/" + dgvRows.Count ;
|
||
}));
|
||
});
|
||
}
|
||
}
|
||
|
||
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";
|
||
|
||
// 该接口开始结束传同一个值,可能是wx页面bug
|
||
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;
|
||
}
|
||
|
||
public static string GetFeedbackOrder(ShopLoginInfo shop, int page, int beginTs, int endTs, bool is24 = false)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/statistic/dsr/logistics/feedback/order?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=waybillNegtiveOrdRatio_30d&valid=collectIn_48hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d&detail=company";
|
||
if (is24)
|
||
referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=waybillNegtiveOrdRatio_30d&valid=collectIn_24hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d&detail=company";
|
||
|
||
string body = @"{""page"":" + page + @",""pageSize"":20,""beginTs"":" + beginTs + @",""endTs"":" + endTs + @"}";
|
||
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
|
||
public static string orderSearch(ShopLoginInfo shop, string prodTitle, string receiverName)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/order/list";
|
||
string body = @"{""isSearch"":true,""pageSize"":30,""orderId"":"""",""orderTime"":{""type"":0,""time"":[null,null]},
|
||
""telNumber"":"""",""title"":""复古刺绣盘扣麻棉衬衫女2022夏新款中式禅意茶服宽松短款v领上衣"",""receiverName"":""浅菊夏離、"",""finderNickName"":"""",
|
||
""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,
|
||
""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":1,""startCreateTime"":null,
|
||
""endCreateTime"":null}";
|
||
|
||
body = @"{""isSearch"":true,""pageSize"":30,""orderId"":"""",""orderTime"":{""type"":0,""time"":[null,null]},
|
||
""telNumber"":"""",""title"":""" + prodTitle + @""",""receiverName"":""" + receiverName + @""",""finderNickName"":"""",""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":1,""startCreateTime"":null,""endCreateTime"":null}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string orderSearchByOrderId(ShopLoginInfo shop, string orderIds)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/order/list";
|
||
string body = @"{""isSearch"":true,""pageSize"":30,""orderId"":""" + orderIds + @""",""orderTime"":{""type"":0,""time"":[null,null]},""telNumber"":"""",""title"":"""",""receiverName"":"""",""finderNickName"":"""",""merchantNotes"":"""",""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0,""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":"""",""page"":1,""startCreateTime"":null,""endCreateTime"":null}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 补发货接口
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="orderIds"></param>
|
||
/// <returns></returns>
|
||
public static string orderCompensationDelivery(ShopLoginInfo shop, string orderId, string deliveryId, string waybillId, string productId, string skuId, int productCnt)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/compensationDelivery?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/order/list";
|
||
//string body = @"{""orderId"":""3736582240830642176"",""reason"":1,""deliveryProductInfo"":[{""deliveryId"":""EMS"",""waybillId"":""9822445565261"",""productInfos"":[{""productId"":""10000697373414"",""skuId"":""11709320615"",""productCnt"":1}]}]}";
|
||
string body = @"{""orderId"":""" + orderId + @""",""reason"":1,""deliveryProductInfo"":[{""deliveryId"":""" + deliveryId +
|
||
@""",""waybillId"":""" + waybillId + @""",""productInfos"":[{""productId"":""" + productId + @""",""skuId"":""" + skuId +
|
||
@""",""productCnt"":" + productCnt + @"}]}]}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
|
||
public static string kdniaoGetWayBillPage(string wayBillIds, Dictionary<string,object> reqDic, int page=1)
|
||
{
|
||
//string body = @"LogisticsCode=321166519053000%0A773423272400495&PlatformOrderCode=&ShipperCode=&StartTime=2026-05-27+00%3A00%3A00&EndTime=2026-06-03+23%3A59%3A59&StartCollectTime=&EndCollectTime=&StartSignTime=&EndSignTime=&StartPayTime=&EndPayTime=&Remark=&ShopName=&Warehouse=&CustomerName=&PlatformName=&CurrentMonitorStatus=&PageIndex=1&PageSize=500&IsFollow=";
|
||
|
||
string url = "https://lmsapinew.kdniao.com/WayBillMonitor/GetWayBillPageResult";
|
||
string referer = "https://56.kdniao.com/";
|
||
string body = @"LogisticsCode=" + wayBillIds.ParseToString().Replace("\r\n", "%0A").Replace("\n", "%0A").Replace(",", "%0A").Replace(",", "%0A") +
|
||
@"&PlatformOrderCode=&ShipperCode=&StartTime=" + DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd") +
|
||
"+00%3A00%3A00&EndTime=" + DateTime.Now.Date.AddDays(1).ToString("yyyy-MM-dd") +
|
||
"+23%3A59%3A59&StartCollectTime=&EndCollectTime=&StartSignTime=&EndSignTime=&StartPayTime=" +
|
||
"&EndPayTime=&Remark=&ShopName=&Warehouse=&CustomerName=&PlatformName=&CurrentMonitorStatus=&PageIndex=1&PageSize=500&IsFollow=";
|
||
var result = WXHttpResponseBLL.kdniaoPostResponse(url, body, referer, reqDic);
|
||
return result;
|
||
}
|
||
}
|
||
|
||
public class kdnWaybillResultInfo
|
||
{
|
||
public long? ID { get; set; } // 881822643,
|
||
public string OrderCode { get; set; } // "26060301782049",
|
||
public string ShipperCode { get; set; } // "ZTO",
|
||
public string ShipperCompanyName { get; set; } // "中通快递",
|
||
public string LogisticsCode { get; set; } // "76939494896052",
|
||
public string OrderPrintTime { get; set; } // "2026-06-03 15:48:17",
|
||
public string OrderPaymentTime { get; set; } // "2026-06-03 15:48:17",
|
||
public int? LogisticsStatus { get; set; } // 3,
|
||
public string LogisticsStatusStr { get; set; } // "在途中",
|
||
public int? LogisticsExceptionType { get; set; } // 4,
|
||
public string LogisticsExceptionTypeStr { get; set; } // "派件异常",
|
||
public string LogisticsExceptionReason { get; set; } // "派件异常",
|
||
public int? MonitorStatus { get; set; } // 1,
|
||
public string MonitorStatusStr { get; set; } // "正常",
|
||
public int? CurrentMonitorStatus { get; set; } // 4,
|
||
public int? Source { get; set; } // 2,
|
||
public string SourceStr { get; set; } // "线下导入-粘贴",
|
||
public int? IgnoreMonitor { get; set; } // 1,
|
||
public string OvertimeStr { get; set; } // "",
|
||
public string OverTimeSpan { get; set; } // "00:00:00",
|
||
public int? SubStatus { get; set; } // 1,
|
||
public kdnWaybillLatelyTrace LatelyTrace { get; set; }
|
||
public int? IsFollow { get; set; } // 0,
|
||
public string LastUpdateTime { get; set; } // "2026-06-03 15:48:20",
|
||
public string CollectTime { get; set; } // "2026-06-01 12:05:08",
|
||
public long? LogisticsStatusEx { get; set; } // 405,
|
||
public string SenderCity { get; set; } // "",
|
||
public string ReceiverCity { get; set; } // "",
|
||
public int? SignTimeoutStatus { get; set; } // 1,
|
||
public int? SignTimeoutType { get; set; } // 2,
|
||
public string LatelyTrackInfo { get; set; } // "2026-06-03 09:18:37 收件人地址/姓名信息不详,且无法联系上收件人,投递失败,等待发件人处理!如有疑问请联系【枣庄市】【枣庄台儿庄区】(0632-4034989)",
|
||
public string ArrivalTimeStr { get; set; } // "需完善收寄城市信息"
|
||
|
||
}
|
||
|
||
public class kdnWaybillLatelyTrace
|
||
{
|
||
public string AcceptTime { get; set; } // "2026-06-03 09:18:37",
|
||
public string AcceptStation { get; set; } // "收件人地址/姓名信息不详,且无法联系上收件人,投递失败,等待发件人处理!如有疑问请联系【枣庄市】【枣庄台儿庄区】(0632-4034989)",
|
||
public string Location { get; set; } // "枣庄市",
|
||
public string Action { get; set; } // "405"
|
||
}
|
||
}
|