Files
KJD/TEMUKJD/WXForms/ShopForms/WXShopOptimizeForm.cs
T
2026-04-27 20:38:53 +08:00

1506 lines
74 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using NaiBa.Util.Extension;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TemuKJD.Extension;
using TemuKJD.BaseForms;
using TemuKJD.ToolForms;
using Work;
using TemuKJD.BLL;
using System.Text.RegularExpressions;
using TemuKJD.PDDForms.ProductSelectForms;
using TemuKJD.WXForms.ShopForms;
using AllBase.Model.Result.PDDResult;
using AllBase.Model.Param.WXParam;
using AllBase.Model.Result.WXResult;
using Newtonsoft.Json;
using NaiBa.Util;
using AllBase.Model.Config;
using TemuKJD.WXForms.ProductForms;
using TemuKJD.WXForms.AdminForms;
namespace TemuKJD.WXForms.ShopForms
{
public partial class WXShopOptimizeForm : BaseForm
{
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public bool IsLoadComplate { get; set; } = false;
bool isInit = false;
CheckBox chkSelectAll = null;
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
public string pdd_product_cates = "";
ConcurrentList<WxOptimizeOrderAfterSaleInfo> lstWxOptimizeOrderAfterSaleInfo = new ConcurrentList<WxOptimizeOrderAfterSaleInfo>();
ConcurrentList<WxOptimizeProductEvaluationInfo> lstWxOptimizeProductEvaluationInfo = new ConcurrentList<WxOptimizeProductEvaluationInfo>();
ConcurrentList<WxOptimizeOrderWayBillInfo> lstWxOptimizeOrderWayBillInfo = new ConcurrentList<WxOptimizeOrderWayBillInfo>(); // 揽收
ConcurrentList<WxOptrimizeLinerCgiInfo> lstWxOptrimizeLinerCgiInfo = new ConcurrentList<WxOptrimizeLinerCgiInfo>(); // 物流
public WXShopOptimizeForm()
{
InitializeComponent();
}
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
{
this.ucTabControl1.TabPages.RemoveAt(4);
dicCheckedShopId = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, bool>>("wx_checked_shop_dic");
if (dicCheckedShopId == null)
dicCheckedShopId = new Dictionary<string, bool>();
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
dgvShop.Columns["colSelect"].HeaderText = "";
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
dgvData1.AddSelectorColumn("colDgv1Check");
dgvData1.AddImgColumn("colDgv1Img", "colDgv1ImgUrl");
dgvData2.AddSelectorColumn("colDgv2Check");
dgvData2.AddImgColumn("colDgv2Img", "colDgv2ImgUrl");
dgvData3.AddSelectorColumn("colCheck");
dgvData3.AddImgColumn("colImg", "colImgUrl");
dgvData4.AddSelectorColumn("colDgv4Check");
dgvData4.AddImgColumn("colDgv4Img", "colDgv4ImgUrl");
IsLoadComplate = true;
}
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
if (!chkSelectAll.Checked)
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
row.Cells["colSelect"].Value = false;
}
}
else
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
if(row.Visible == true)
row.Cells["colSelect"].Value = true;
}
}
foreach (var r in dgvShop.Rows.Cast<DataGridViewRow>())
{
dicCheckedShopId[r.Cells["colShopId"].Value.ParseToString()] = r.Cells["colSelect"].Value.ParseToBool();
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
}
private void btnRefreshShop_Click(object sender, EventArgs e)
{
pbLoadingShop.Visible = true;
RefreshShopLogin();
}
private void UserSelectDbProductForm_VisibleChanged(object sender, EventArgs e)
{
if (Visible == true)
{
RefreshShopLogin();
if (!isInit)
{
Task.Run(() =>
{
foreach (var shop in GlobalConfig.ShopLoginList)
{
}
});
}
isInit = true;
}
}
private void RefreshShopLogin()
{
// 店铺Id
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
// 获取被删除的店铺
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> !GlobalConfig.ShopLoginList.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
// 更新被删除的店铺列表
foreach (var row in dgvRowList)
{
dgvShop.Rows.Remove(row);
}
// 绑定其他店铺(含新导入的店铺)
foreach (ShopLoginInfo shopEntity in GlobalConfig.ShopLoginList)
{
if (!string.IsNullOrEmpty(shopEntity.ShopId))
BindShop(shopEntity, selectIds);
}
cmbFilterShopNotes.Items.Clear();
//cmbFilterShopNotes.Items.Add("");
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterShopNotes.Items.Add(note);
}
}
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
{
if (shopEntity == null)
return;
if (shopEntity.is_shop_expire)
return;
if (selectShopId == null)
selectShopId = new List<string>();
bool canUse = shopEntity.LoginStatus == "登录成功";
//canUse = true; // 内部库不需要校验登录状态
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
if (row == null)
{
this.dgvShop.Rows.Add(
//!isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse),
dicCheckedShopId.Keys.Contains(shopEntity.ShopId) && dicCheckedShopId[shopEntity.ShopId] == true,
shopEntity.LoginName,
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.Notes,
"选择商品",
canUse ? "在线" : "掉线",
"", //lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
canUse,
shopEntity.AddProductRemaining,
"",
msg
);
}
else
{
row.Cells["colSelect"].Value = !isInit || (selectShopId.Contains(shopEntity.ShopId) && canUse);
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
row.Cells["colShopNotes"].Value = shopEntity.Notes;
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
row.Cells["colCanUse"].Value = canUse;
row.Cells["colApi"].Value = ""; //lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期";
row.Cells["colRemaining"].Value = shopEntity.AddProductRemaining;
row.Cells["colMessage"].Value = msg;
}
displayAuthStatus(shopEntity);
}
void displayAuthStatus(ShopLoginInfo shop)
{
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ParseToString() == shop?.ShopId);
foreach (var row in rows)
{
bool canUse = row.Cells["colLoginStatus"].Value.ParseToString() == "在线";
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
canUse = row.Cells["colApi"].Value.ParseToString() == "可用";
(row.Cells["colApi"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colApi"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
(row.Cells["colApi"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
(row.Cells["colApi"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
}
}
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvShop.Columns[e.ColumnIndex].HeaderText;
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
string shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToString();
string shopAccount = dgvShop.Rows[e.RowIndex].Cells["colShopName"].Value.ToString();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
var row = dgvShop.Rows[e.RowIndex];
switch (columnName)
{
case "colSelect":
//if (row.Cells["colCanUse"].Value.ParseToBool())
{
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
chkSelectAll.CheckedChanged -= chkSelectAll_CheckedChanged;
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
chkSelectAll.Checked = true;
else
chkSelectAll.Checked = false;
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
}
//else
{
//BaseMsgForm.ShowInfo("店铺未登录!");
}
dicCheckedShopId[row.Cells["colShopId"].Value.ParseToString()] = row.Cells["colSelect"].Value.ParseToBool();
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_checked_shop_dic", dicCheckedShopId);
break;
case "colLoginStatus":
{
if (WXShopListForm.Instance == null)
WXShopListForm.Instance = new WXShopListForm();
WXShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
//shopLoginForm.prodUserSelectForm = this;
if (shop.LoginStatus != "登录成功")
{
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
RefreshShopLogin();
}
else
{
shopLoginForm.openType = EnumOpenType.manage;
shopLoginForm.WindowState = FormWindowState.Maximized;
shopLoginForm.Show();
}
}
break;
case "colApi":
{
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.manage;
shopLoginForm.WindowState = FormWindowState.Maximized;
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/servicemarket/detail?serviceId=3984039898079707139";
shopLoginForm.Show();
}
break;
}
}
private void btnStop_Click(object sender, EventArgs e)
{
if (this.cancellationTokenSource != null)
this.cancellationTokenSource.Cancel();
}
private void btnFilterShop_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dgvShop.Rows)
{
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
if (notes == "全部")
notes = "";
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (!row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()))
{
row.Visible = false;
row.Cells["colSelect"].Value = false;
continue;
}
if (!string.IsNullOrWhiteSpace(notes) && !notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString()))
{
row.Visible = false;
row.Cells["colSelect"].Value = false;
continue;
}
row.Visible = true;
}
}
private void btnEmptyShop_Click(object sender, EventArgs e)
{
txtFilterShopName.Text = "";
cmbFilterShopNotes.Text = "全部";
btnFilterShop_Click(null, null);
}
private void btnReverse_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dgvShop.Rows)
{
if (row.Visible == true)
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
}
}
private void btnAddSelect_Click(object sender, EventArgs e)
{
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
if (notes == "全部")
notes = "";
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
foreach (DataGridViewRow row in dgvShop.Rows)
{
if (row.Visible == true)
{
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
{
row.Cells["colSelect"].Value = true;
}
}
}
}
private void btnAddUnSelect_Click(object sender, EventArgs e)
{
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
if (notes == "全部")
notes = "";
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
foreach (DataGridViewRow row in dgvShop.Rows)
{
if (row.Visible == true)
{
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
{
row.Cells["colSelect"].Value = false;
}
}
}
}
private void btnSelectOnline_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
if (row.Visible == true)
{
if (row.Cells["colLoginStatus"].Value.ParseToString() == "在线")
{
row.Cells["colSelect"].Value = true;
}
else
{
row.Cells["colSelect"].Value = false;
}
}
}
}
private void btnSelectOffline_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dgvShop.Rows)
{
if (row.Visible == true)
{
if (row.Cells["colLoginStatus"].Value.ParseToString() != "在线")
{
row.Cells["colSelect"].Value = true;
}
else
{
row.Cells["colSelect"].Value = false;
}
}
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
var lstShopId = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
if (lstShopId.Count == 0)
{
BaseMsgForm.ShowInfo("请选择店铺!");
return;
}
btnSearch.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
if (ucCheckBox1.Checked)
{
pictureBox1.Visible = true;
dgvData1.Rows.Clear();
lstWxOptimizeOrderAfterSaleInfo.Clear();
}
if (ucCheckBox2.Checked)
{
pictureBox2.Visible = true;
dgvData2.Rows.Clear();
lstWxOptimizeProductEvaluationInfo.Clear();
}
if (ucCheckBox3.Checked)
{
pictureBox3.Visible = true;
dgvData3.Rows.Clear();
lstWxOptimizeOrderWayBillInfo.Clear();
}
if (ucCheckBox4.Checked)
{
pictureBox4.Visible = true;
dgvData4.Rows.Clear();
lstWxOptrimizeLinerCgiInfo.Clear();
}
Task.Run(() =>
{
List<ShopLoginInfo> shopLst = GlobalConfig.ShopLoginList.Where(s => lstShopId.Contains(s.ShopId)).ToList();
foreach (var shop in shopLst)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
if (ucCheckBox1.Checked)
{
SearchData1(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
if (ucCheckBox2.Checked)
{
SearchData2(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
if (ucCheckBox3.Checked)
{
SearchData3WayBill(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
if (ucCheckBox4.Checked)
{
SearchData4(shop);
Thread.Sleep(Randomx.GetId(200, 500));
}
}
Invoke(new Action(() =>
{
if (cancellationTokenSource.IsCancellationRequested)
{
//this.statusBar.lblTaskStatus.Text = "品质退款查询完毕 " + this.statusBar.lblTaskStatus.Text;
//BaseMsgForm.ShowInfo("品质退款查询完毕");
this.statusBar.lblTaskStatus.Text = "优化数据查询中断 " + this.statusBar.lblTaskStatus.Text;
BaseMsgForm.ShowInfo("优化数据查询中断");
}
else
{
//this.statusBar.lblTaskStatus.Text = "品质退款查询完毕";
//BaseMsgForm.ShowInfo("品质退款查询完毕");
this.statusBar.lblTaskStatus.Text = "优化数据查询完毕";
BaseMsgForm.ShowInfo("优化数据查询完毕");
}
pictureBox1.Visible = false;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
pictureBox4.Visible = false;
btnSearch.Enabled = true;
}));
}, cancellationTokenSource.Token).ContinueWith(delegate
{
}, cancellationTokenSource.Token);
}
public void SearchData1(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
int page = 0;
int totalPage = 1;
int pageSize = 20;
int startTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date.AddDays(-30));
int endTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date) - 1;
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData1 = ShopOptimize.GetProductRefundOrder(shop, page, startTime, endTime);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData1.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData1, "msg");
if (string.IsNullOrEmpty(error))
error = getData1;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var prodObjs = JsonHelper.JObjectParse(getData1);
if (page == 1)
{
var totalNum = prodObjs["total"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox1.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询品质退款,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
var orderAfterSaleInfoLst = new List<WxOptimizeOrderAfterSaleInfo>();
foreach (JObject refundOrderObj in prodObjs["data"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var refundOrder = JsonHelper.DeserializeJsonToObject<WxOptimizeOrderAfterSaleInfo>(oStr);
if (lstWxOptimizeOrderAfterSaleInfo.Any(o => o.orderInfo.orderId == refundOrder.orderInfo.orderId))
continue;
refundOrder.shopId = shop.ShopId;
refundOrder.shopName = shop.ShopAccount;
lstWxOptimizeOrderAfterSaleInfo.Add(refundOrder);
orderAfterSaleInfoLst.Add(refundOrder);
}
// 查询是否被优化过
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("yyyy-MM-dd HH:mm");
if (!string.IsNullOrEmpty(orderAfterSale.optimizeWaybillId))
orderAfterSale.optimizeWaybillId = "已优化";
}
}
catch (Exception ex)
{
foreach (var orderAfterSale in orderAfterSaleInfoLst)
{
orderAfterSale.optimizeWaybillId = "查询失败";
orderAfterSale.optimizeTime = "";
}
}
}
foreach (var refundOrder in orderAfterSaleInfoLst)
{
Invoke(new Action(() =>
{
var rowIndex = this.dgvData1.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
refundOrder.orderInfo.imgUrl,
DataGridViewExtension.defaultBitmap,
refundOrder.orderInfo.spuId,
refundOrder.orderInfo.name,
refundOrder.orderInfo.skuName,
refundOrder.orderInfo.skuCode,
refundOrder.orderInfo.orderId,
BaseClass.StampToDateTime(refundOrder.orderInfo.createTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
refundOrder.reason,
refundOrder.optimizeWaybillId + "\r\n" + refundOrder.optimizeTime,
"优化"
);
dgvData1.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
/// <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 refundOrderObj in prodObjs["finderProductEvaluationInfoList"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var prodEvaluationInfo = JsonHelper.DeserializeJsonToObject<WxOptimizeProductEvaluationInfo>(oStr);
if (lstWxOptimizeProductEvaluationInfo.Any(o => o.productEvaluationId == prodEvaluationInfo.productEvaluationId))
continue;
prodEvaluationInfo.shopId = shop.ShopId;
prodEvaluationInfo.shopName = shop.ShopAccount;
lstWxOptimizeProductEvaluationInfo.Add(prodEvaluationInfo);
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
{
prodEvaluationInfo.order_id = "";
while (getOrderRst.Contains("\"orderId\""))
{
prodEvaluationInfo.order_id += (" " + BaseRegex.GetStringJson(ref getOrderRst, "orderId"));
getOrderRst = getOrderRst.Substring(getOrderRst.IndexOf("\"orderId\"") + "\"orderId\"".Length);
}
prodEvaluationInfo.order_id = prodEvaluationInfo.order_id.Trim(' ');
if (prodEvaluationInfo.order_id.IsNullOrEmpty())
prodEvaluationInfo.order_id = "未获取到对应订单号";
if (prodEvaluationInfo.order_id.Contains(" "))
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("yyyy-MM-dd HH:mm");
if (!string.IsNullOrEmpty(evaluationInfo.optimizeWaybillId))
evaluationInfo.optimizeWaybillId = "已优化";
}
}
catch (Exception ex)
{
foreach (var evaluationInfo in productEvaluationInfoLst)
{
evaluationInfo.optimizeWaybillId = "查询失败";
evaluationInfo.optimizeTime = "";
}
}
}
foreach (var prodEvaluationInfo in productEvaluationInfoLst)
{
var lblLst = prodEvaluationInfo.evaluationInfo?.firstEvaluationInfo?.buyerEvaluationInfo?.labelList;
var content = prodEvaluationInfo.evaluationInfo.firstEvaluationInfo.buyerEvaluationInfo.content + " " +
prodEvaluationInfo.evaluationInfo.firstEvaluationInfo.buyerEvaluationInfo.defaultContent;
Invoke(new Action(() =>
{
var rowIndex = this.dgvData2.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
prodEvaluationInfo.productInfo.imgUrl,
DataGridViewExtension.defaultBitmap,
prodEvaluationInfo.productInfo.productId,
prodEvaluationInfo.productInfo.spuName,
prodEvaluationInfo.productInfo.skuName,
"", // spuCode 此处获取不到填空
prodEvaluationInfo.productEvaluationId,
prodEvaluationInfo.order_id, // orderId
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.optimizeWaybillId + "\r\n" + prodEvaluationInfo.optimizeTime,
"优化"
);
dgvData2.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
public void SearchData3WayBill(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
bool is24 = false;
var is24Rst = ShopOptimize.Get24H48HFlag(shop); // if_24hOr_48hFlag
if (!is24Rst.Contains("\"code\":0") || BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag").IsNullOrEmpty())
{
var error = BaseRegex.GetStringJson(ref is24Rst, "msg");
if (string.IsNullOrEmpty(error))
error = is24Rst;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
{
shopRow.Cells["colMessage"].Value = "获取揽收时效失败" + error;
if(error.Contains("\"code\":2") && error.Contains("[194,62,3,176,14,1]"))
shopRow.Cells["colMessage"].Value = "店铺无时效评分";
}
}));
}
return;
}
is24 = BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag") == "1";
int page = 0;
int totalPage = 1;
int pageSize = 20;
int startTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date.AddDays(-30));
int endTime = BaseClass.DateTimeToTimestampSeconds(DateTime.Now.Date) - 1;
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData3WayBill = ShopOptimize.GetProductOrderWayBill(shop, page, startTime, endTime, is24);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData3WayBill.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData3WayBill, "msg");
if (string.IsNullOrEmpty(error))
error = getData3WayBill;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var wayBillObjs = JsonHelper.JObjectParse(getData3WayBill);
if (page == 1)
{
var totalNum = wayBillObjs["total"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox3.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询揽收不达标,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
List<WxOptimizeOrderWayBillInfo> waybillLst = new List<WxOptimizeOrderWayBillInfo>();
foreach (JObject refundOrderObj in wayBillObjs["data"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var orderWayBill = JsonHelper.DeserializeJsonToObject<WxOptimizeOrderWayBillInfo>(oStr);
if (lstWxOptimizeOrderWayBillInfo.Any(o => o.orderInfo.orderId == orderWayBill.orderInfo.orderId))
continue;
orderWayBill.shopId = shop.ShopId;
orderWayBill.shopName = shop.ShopAccount;
if (!orderWayBill.realPickupTime.ParseToInt().IsNullOrZero())
{
// 24小时揽收率截至第二天
if (is24 && BaseClass.StampToDateTime(orderWayBill.realPickupTime.ParseToInt()).Date <= BaseClass.StampToDateTime(orderWayBill.payTime.ParseToInt()).Date.AddDays(1))
continue;
// 48小时揽收率按48小时算
if (!is24 && BaseClass.StampToDateTime(orderWayBill.realPickupTime.ParseToInt()) <= BaseClass.StampToDateTime(orderWayBill.payTime.ParseToInt()).AddDays(2))
continue;
}
else
{
}
waybillLst.Add(orderWayBill);
}
// 查询是否被优化过
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("yyyy-MM-dd HH:mm");
if (!string.IsNullOrEmpty(orderWaybill.optimizeWaybillId))
orderWaybill.optimizeWaybillId = "已优化";
}
}
catch (Exception ex)
{
foreach (var orderWaybill in waybillLst)
{
orderWaybill.optimizeWaybillId = "查询失败";
orderWaybill.optimizeTime = "";
}
}
}
foreach (var orderWaybill in waybillLst)
{
lstWxOptimizeOrderWayBillInfo.Add(orderWaybill);
Invoke(new Action(() =>
{
var rowIndex = this.dgvData3.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
orderWaybill.orderInfo.imgUrl,
DataGridViewExtension.defaultBitmap,
orderWaybill.orderInfo.spuId,
orderWaybill.orderInfo.name,
orderWaybill.orderInfo.skuName + " x" + orderWaybill.orderInfo.productCnt,
orderWaybill.orderInfo.skuCode,
orderWaybill.orderInfo.orderId + "\r\n" + orderWaybill.waybillId,
orderWaybill.delivery.deliveryName,
BaseClass.StampToDateTime(orderWaybill.payTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
orderWaybill.realPickupTime.ParseToInt().IsNullOrZero() ? "" : BaseClass.StampToDateTime(orderWaybill.realPickupTime.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
orderWaybill.pickupDuration.ParseToInt().IsNullOrZero() ? "" : ((orderWaybill.pickupDuration.ParseToInt() / 3600.0m).ToString("f2") + "小时" + "\r\n" + "[" + (is24 ? "次日" : "48小时") + "]"),
orderWaybill.optimizeWaybillId + "\r\n" + orderWaybill.optimizeTime,
"优化"
);
dgvData3.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
public void SearchData4(ShopLoginInfo shop)
{
if (shop.LoginStatus != "登录成功")
{
return;
}
bool is24 = false;
var is24Rst = ShopOptimize.Get24H48HFlag(shop); // if_24hOr_48hFlag
if (!is24Rst.Contains("\"code\":0") || BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag").IsNullOrEmpty())
{
var error = BaseRegex.GetStringJson(ref is24Rst, "msg");
if (string.IsNullOrEmpty(error))
error = is24Rst;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
{
shopRow.Cells["colMessage"].Value = "获取配送时效失败" + error;
if(error.Contains("\"code\":2") && error.Contains("[194,62,3,176,14,1]"))
shopRow.Cells["colMessage"].Value = "店铺无时效评分";
}
}));
}
return;
}
is24 = BaseRegex.GetStringJson(ref is24Rst, "if_24hOr_48hFlag") == "1";
int page = 0;
int totalPage = 1;
int pageSize = 20;
long startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-30));
long endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now);
while (page < totalPage)
{
page++;
if (cancellationTokenSource.IsCancellationRequested)
break;
var getData4 = ShopOptimize.GetOrderLinerCgi(shop, page, startTime, endTime, is24);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getData4.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJson(ref getData4, "msg");
if (string.IsNullOrEmpty(error))
error = getData4;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, shopIdLst, "店铺掉线"); }));
}
else
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = error;
}));
}
break;
}
try
{
var wayBillObjs = JsonHelper.JObjectParse(getData4);
if (page == 1)
{
var totalNum = wayBillObjs["total"].ParseToInt();
totalPage = Math.Ceiling(1m * totalNum / pageSize).ParseToInt();
}
Invoke(new Action(() =>
{
this.pictureBox4.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询配送不达标,店铺:" + shop.ShopAccount + " " + page + "/" + totalPage;
}));
List<WxOptrimizeLinerCgiInfo> optrimizeLinerCgiLst = new List<WxOptrimizeLinerCgiInfo>();
foreach (JObject refundOrderObj in wayBillObjs["list"])
{
var oStr = JsonHelper.SerializeObject(refundOrderObj);
var orderLinerCgiInfo = JsonHelper.DeserializeJsonToObject<WxOptrimizeLinerCgiInfo>(oStr);
if (lstWxOptrimizeLinerCgiInfo.Any(o => o.order_id == orderLinerCgiInfo.order_id))
continue;
orderLinerCgiInfo.shopId = shop.ShopId;
orderLinerCgiInfo.shopName = shop.ShopAccount;
optrimizeLinerCgiLst.Add(orderLinerCgiInfo);
lstWxOptrimizeLinerCgiInfo.Add(orderLinerCgiInfo);
}
// 查询是否被优化过
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("yyyy-MM-dd HH:mm");
if (!string.IsNullOrEmpty(linerCgi.optimizeWaybillId))
linerCgi.optimizeWaybillId = "已优化";
}
}
catch (Exception ex)
{
foreach (var linerCgi in optrimizeLinerCgiLst)
{
linerCgi.optimizeWaybillId = "查询失败";
linerCgi.optimizeTime = "";
}
}
}
foreach (var orderLinerCgiInfo in optrimizeLinerCgiLst)
{
Invoke(new Action(() =>
{
var rowIndex = this.dgvData4.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
orderLinerCgiInfo.product_list.FirstOrDefault().head_img_url,
DataGridViewExtension.defaultBitmap,
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => p.product_id)),
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => p.title)),
string.Join("\r\n", orderLinerCgiInfo.product_list.Select(p => "x" + p.product_count)),
"", //skuCode不展示
orderLinerCgiInfo.order_id + "\r\n" + orderLinerCgiInfo.waybill_id,
orderLinerCgiInfo.delivery_name,
BaseClass.StampToDateTime(orderLinerCgiInfo.collect_time.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + BaseClass.StampToDateTime(orderLinerCgiInfo.receipt_time.ParseToInt()).ToString("yyyy-MM-dd HH:mm:ss"),
"发货地:" + orderLinerCgiInfo.ship_city + "\r\n" + "收货地:" + orderLinerCgiInfo.ship_province + orderLinerCgiInfo.receipt_city,
(orderLinerCgiInfo.transport_duration.ParseToInt() / 3600) + "小时" + (orderLinerCgiInfo.transport_duration.ParseToInt() % 3600) / 60 + "分" +
"\r\n标准时长" + (orderLinerCgiInfo.transport_std_duration.ParseToInt() / 3600) + "小时", /*+ (orderLinerCgiInfo.transport_std_duration.ParseToInt() % 3600)*/
orderLinerCgiInfo.optimizeWaybillId + "\r\n" + orderLinerCgiInfo.optimizeTime,
"优化"
);
dgvData4.Rows[rowIndex].Height = 60;
}));
}
}
catch (Exception ex)
{
Invoke(new Action(() =>
{
var shopRow = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
if (shopRow != null)
shopRow.Cells["colMessage"].Value = ex.Message;
}));
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (this.cancellationTokenSource != null)
cancellationTokenSource.Cancel();
}
public string OptimizeExpress(ShopLoginInfo shop, string orderId, string productEvaluationId = "")
{
var url = BaseClass.BuildObjString("shop/select_waybill");
var data = "";
data = UserLogin.GetSignaturex();
data += "&shop_id=" + shop.ShopId;
data += "&order_id=" + 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"))
{
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");
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);
var optimizeExpressRst = WXHttpResponseBLL.e57PostResponse(url, bodyStr, "");
if (!optimizeExpressRst.Contains("修改物流信息成功") && !optimizeExpressRst.Contains("<code>200</code>"))
optimizeExpressRst = WXHttpResponseBLL.e57PostResponse(url, bodyStr, "");
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(optimizeExpressRst); //<AjaxResult><msg>订单不存在,orderId:3735398415030708224</msg><code>500</code></AjaxResult>
string msg = xmlDoc["AjaxResult"]["msg"].InnerText;
string code = xmlDoc["AjaxResult"]["code"].InnerText;
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.Contains("修改物流信息成功") && !optimizeExpressRst.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.Contains("修改物流信息成功") && !optimizeExpressRst.Contains("<code>200</code>"))
return "优化失败,回滚失败\r\n" + errMsg + " " + msg;
else
return "优化失败\r\n" + errMsg;
}
if (!optimizeExpressRst.Contains("修改物流信息成功") && !optimizeExpressRst.Contains("<code>200</code>"))
return "优化失败,已回滚\r\n" + msg;
return "优化成功";
}
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))
{
var rst = OptimizeExpress(shop, orderId);
row.Cells[$"colDgv{dgvNum}OptimizeStatus"].Value = rst;
}
else
{
BaseMsgForm.ShowError("缺少单编号无法优化!");
}
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 static class ShopOptimize
{
public static string GetProductRefundOrder(ShopLoginInfo shop, int pageId, int beginTick, int endTick)
{
string url = "https://store.weixin.qq.com/shop-faas/statistic/dsr/product/refund/order?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=product&key=productQualityRatio_30d&detail=product";
string body = @"{""page"":" + pageId + @",""pageSize"":20,""beginTs"":" + beginTick + @",""endTs"":" + endTick + @"}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
/// <summary>
/// 商品评价
/// </summary>
/// <param name="shop"></param>
/// <param name="pageId"></param>
/// <param name="beginTick"></param>
/// <param name="endTick"></param>
/// <returns></returns>
public static string GetProductEvaluation(ShopLoginInfo shop, int pageId, int beginTick, int endTick)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeevaluation/cgi/search?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/evaluate/home";
string body = @"{""orderId"":"""",""productId"":"""",""productEvaluationId"":"""",""buyerEvaluationTimeStart"":" + beginTick + @",""buyerEvaluationTimeEnd"":" + endTick +
@",""status"":2,""page"":" + pageId + @",""visibleType"":0}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string Get24H48HFlag(ShopLoginInfo shop)
{
string url = "https://store.weixin.qq.com/shop-faas/statistic/cgi/search?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/rate2";
string body = "{\"days\":14,\"scoreTypeList\":[63,1000]}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string GetProductOrderWayBill(ShopLoginInfo shop, int pageId, int beginTick, int endTick, bool is24 = false)
{
string url = "https://store.weixin.qq.com/shop-faas/statistic/dsr/logistics/pickup/insale?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=collectIn_48hOrdRatio_30d&valid=collectIn_48hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d&detail=insale";
if (is24)
referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=collectIn_24hOrdRatio_30d&valid=collectIn_24hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d&detail=insale";
string body = @"{""page"":" + pageId + @",""pageSize"":20,""beginTs"":" + beginTick + @",""endTs"":" + endTick + @"}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string GetOrderLinerCgi(ShopLoginInfo shop, int pageId, long beginTick, long endTick, bool is24 = false)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodelinercgi/cgi/liner/query?token=&lang=zh_CN";
string referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=waybillArriveOntimeRatio_30d&valid=collectIn_48hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d";
if (is24)
referer = "https://store.weixin.qq.com/shop/setting/ratedetail?type=logistics&key=waybillArriveOntimeRatio_30d&valid=collectIn_24hOrdRatio_30d|waybillArriveOntimeRatio_30d|waybillNegtiveOrdRatio_30d";
string body = @"{""time_query"":{""dateFormat"":2,""dateType"":0,""dateRange"":30,""startMs"":" + endTick + @",""endMs"":" + endTick +
@"},""limit"":10,""offset"":" + (Math.Max(0, pageId - 1) * 10) + @",""id"":""ratedetail-wuliu-route-order-table"",""biz"":""store"",""is_std"":""0"",""sort"":[""std_route_rate"",""desc""]}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
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;
}
}
}