Files
KJD/TEMUKJD/WXForms/OrderForms/WXOrderListForm.cs
T

2330 lines
125 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.BLL.Wx;
using AllBase.Model.Data;
using NaiBa.CefHelper;
using TemuKJD.Helper;
using NaiBa.CefHelper.Handler;
using CefSharp;
using TemuKJD.WXForms.ProductForms;
namespace TemuKJD.WXForms.OrderForms
{
public partial class WXOrderListForm : BaseForm
{
int PageBegin = 1;
int PageEnd = 9999;
List<string> lstPrintLog = new List<string>();
bool isOnlineWayBill = false;
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public bool IsLoadComplate { get; set; } = false;
bool isInit = false;
CheckBox chkSelectAll = null;
ConcurrentList<WxConsignmentOrderInfo> lstWXConsignmentOrderInfo = new ConcurrentList<WxConsignmentOrderInfo>();
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
public WXOrderListForm()
{
InitializeComponent();
}
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
{
dgvOrder.AddMergeColumn(new List<string>() { "colOrderStatus" , "colUpdateStatus" });
dgvOrder.AddMergeColumnHeader(new List<string>() { "colOrderStatus" , "colUpdateStatus" }, "订单状态");
this.splitContainer1.Dock = DockStyle.Fill;
pnlEditReceiveInfo.Location = new Point(pnlUpdateNotes.Location.X, pnlUpdateNotes.Location.Y);
pnlBuyUrl.Location = new Point(pnlUpdateNotes.Location.X, pnlUpdateNotes.Location.Y);
dtpFilterBeginTime.Value = DateTime.Now.AddDays(-1);
dtpFilterEndTime.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
pbLoading.Visible = true;
Task.Run(() =>
{
GetRefreshPrintId();
Invoke(new Action(() => {
pbLoading.Visible = false;
}));
});
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;
this.dgvOrder.AddSelectorColumn("colCheck");
dgvOrder.AddImgColumn("colProductSkcPic", "colImgUrl");
if (BaseClass.UserAuthority.Contains("在线寄件") || BaseClass.ParentAuthority.Contains("在线寄件"))
{
this.dgvOrder.Columns["colPrintId"].Visible = true;
this.dgvOrder.Columns["colOnlineWaybillOrderId"].Visible = true;
this.dgvOrder.Columns["colOnlineWaybill"].Visible = true;
this.btnRefreshPrintId.Visible = true;
//this.btnBatchOnlieWaybill.Visible = true;
//this.btnStopBatchOnlieWaybill.Visible = true;
}
else
{
this.dgvOrder.Columns["colPrintId"].Visible = false;
this.dgvOrder.Columns["colOnlineWaybillOrderId"].Visible = false;
this.dgvOrder.Columns["colOnlineWaybill"].Visible = false;
this.btnRefreshPrintId.Visible = false;
this.btnBatchOnlieWaybill.Visible = false;
this.btnStopBatchOnlieWaybill.Visible = false;
}
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
{
//var list = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus == "登录成功").Select(ss => ss.ShopId);
foreach (DataGridViewRow row in dgvShop.Rows)
{
//if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
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();
//updateAuthor();
if (!isInit)
{
}
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 group in GlobalConfig.ShopLoginList.Select(s => s.GroupName).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterShopGroup.Items.Add(group);
}
cmbFilterOrderShopGroup.Items.Clear();
foreach (var group in GlobalConfig.ShopLoginList.Select(s => s.GroupName).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterOrderShopGroup.Items.Add(group);
}
}
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 == "登录成功";
var rows = dgvShop.Rows.Cast<DataGridViewRow>().Where(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId).ToList();
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
if (rows.Count == 0)
{
this.dgvShop.Rows.Add(
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,
GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].DicDayUploadCount[day] : 0,
GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].OnSaleCount : 0,
shopEntity.AddProductRemaining,
msg
);
}
else
{
foreach (var row in rows)
{
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["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].DicDayUploadCount[day] : 0;
row.Cells["colOnSaleNum"].Value = GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) ? GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].OnSaleCount : 0;
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 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;
}
}
private void dgvSelectProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvOrder.Columns[e.ColumnIndex].HeaderText;
var shopId = dgvOrder.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
var spuId = dgvOrder.Rows[e.RowIndex].Cells["colSpuId"].Value.ParseToString();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
var row = dgvOrder.Rows[e.RowIndex];
var cell = row.Cells[e.ColumnIndex];
var orderId = row.Cells["colOrderId"].Value.ParseToString();
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.InitUrl = "https://store.weixin.qq.com/shop/order/list";
shopLoginForm.Show();
}
else
{
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
RefreshShopLogin();
}
}
break;
case "图片":
{
ShowImgForm imgFrom = new ShowImgForm(dgvOrder.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString());
imgFrom.ShowDialog();
break;
}
case "礼":
case "优化":
{
WXOrderListOptimizeForm form = new WXOrderListOptimizeForm(shop);
form.lblOrderId.Text = orderId;
form.lblSpuId.Text = row.Cells["colSpuId"].Value.ParseToString(); // goodsId
form.lblSkuId.Text = row.Cells["colSkuId"].Value.ParseToString(); // skuId
form.txtGoodsName.Text = row.Cells["colProductName"].Value.ParseToString(); // 商品名称
form.txtSkuName.Text = row.Cells["colSkuSpec"].Value.ParseToString(); // sku规格名称
form.txtCurrentPrice.Text = row.Cells["colCurrentPrice"].Value.ParseToString(); // 当前商品价格
form.txtOrderPrice.Text = row.Cells["colSalePrice"].Value.ParseToString(); // 订单价格
form.txtCurrentStock.Text = row.Cells["colCurrentStock"].Value.ParseToString(); // 当前库存;
form.numAddPrice.Value = 0;
form.ShowDialog();
if (form.EditPriceSuccess == true)
{
if (form.prodObj != null)
{
foreach (var rw in this.dgvOrder.Rows.Cast<DataGridViewRow>())
{
if (rw.Cells["colSpuId"].Value.ParseToString() != spuId)
continue;
foreach (var sku in form.prodObj["skuList"])
{
if (rw.Cells["colSkuId"].Value.ParseToString() == sku["skuId"].ParseToString())
{
rw.Cells["colCurrentPrice"].Value = sku["price"].ParseToInt() * 0.01m + form.numAddPrice.Value;
break;
}
}
}
}
}
if (form.SendGiftSuccess == true)
{
foreach (var rw in this.dgvOrder.Rows.Cast<DataGridViewRow>())
{
if (rw.Cells["colOrderId"].Value.ParseToString() != orderId)
continue;
rw.Cells["colOpResult"].Value = "礼物单已发送";
}
}
if (form.ClearStock == true)
{
foreach (var rw in this.dgvOrder.Rows.Cast<DataGridViewRow>())
{
if (rw.Cells["colSpuId"].Value.ParseToString() != spuId)
continue;
if (rw.Cells["colSkuId"].Value.ParseToString() != row.Cells["colSkuId"].Value.ParseToString())
continue;
rw.Cells["colOpResult"].Value = "清除库存成功";
rw.Cells["colCurrentStock"].Value = 0;
}
}
if (form.IsDownProd == true)
{
foreach (var rw in this.dgvOrder.Rows.Cast<DataGridViewRow>())
{
if (rw.Cells["colSpuId"].Value.ParseToString() != spuId)
continue;
rw.Cells["colOpResult"].Value = "商品下架成功";
//rw.Cells["colCurrentStock"].Value = 0;
}
}
}
break;
case "取消优惠":
{
int onSaleStatusCode = -1;
int pageSize = 50;
var getProdOnSaleRst = WXClearNoVisit.searchProduct(shop, 1, pageSize, spuId, onSaleStatusCode);
Thread.Sleep(Randomx.GetId(50, 100));
if (!getProdOnSaleRst.Contains("\"success\":true"))
{
ShowShopError(shop, getProdOnSaleRst, true);
break;
}
var prodObjs = JsonHelper.JObjectParse(getProdOnSaleRst)["productList"].FirstOrDefault();
if (prodObjs != null)
{
var str = JsonHelper.SerializeObject(prodObjs);
}
var skuId = row.Cells["colSkuId"].Value.ParseToString();
var price = (row.Cells["colCurrentPrice"].Value.ParseToDecimal() * 100).ParseToInt();
var deltaPrice = 0;
while (!price.ToString().EndsWith("66"))
{
deltaPrice++;
price++;
}
JObject changePriceObj = new JObject();
JArray skuArr = new JArray();
foreach (var sku in prodObjs["skuList"])
{
JObject obj = new JObject();
obj["spuId"] = spuId;
obj["skuId"] = sku["skuId"];
obj["salePrice"] = sku["price"].ParseToInt() + deltaPrice;
skuArr.Add(obj);
}
changePriceObj["skuList"] = skuArr;
changePriceObj["uploadSource"] = 6;
// string body = @"{""skuList"":[{""spuId"":" + spuId + @",""skuId"":""" + skuId + @""",""salePrice"":" + newPrice + @"}],""uploadSource"":6}";
var rst = WXOrderList.EditPrice(shop, changePriceObj);
if (!rst.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "err_msg", "error_msg", "errMsg", "errorMsg");
BaseMsgForm.ShowError("修改优惠商品价格失败 " + error);
return;
}
JObject endActivityObj = new JObject();
endActivityObj["platformActivityId"] = "1016";
JArray arr = new JArray();
foreach (var sku in prodObjs["skuList"])
{
JObject obj = new JObject();
obj["productId"] = spuId;
obj["skuId"] = sku["skuId"];
arr.Add(obj);
}
endActivityObj["productList"] = arr;
endActivityObj["actionType"] = 1;
//{ "platformActivityId":"1016","productList":[{ "productId":"10000879673464","skuId":"15601266074"},{ "productId":"10000879673464","skuId":"15601240593"}],"actionType":1}
rst = WXOrderList.cancelActivity(shop, endActivityObj);
if (!rst.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "err_msg", "error_msg", "errMsg", "errorMsg");
BaseMsgForm.ShowError("取消优惠失败 " + error);
return;
}
else
{
foreach (var rw in this.dgvOrder.Rows.Cast<DataGridViewRow>())
{
if (rw.Cells["colSpuId"].Value.ParseToString() != spuId)
continue;
rw.Cells["colOpResult"].Value = "取消优惠成功";
foreach (var sku in prodObjs["skuList"])
{
if (rw.Cells["colSkuId"].Value.ParseToString() == sku["skuId"].ParseToString())
{
rw.Cells["colCurrentPrice"].Value = sku["price"].ParseToInt() * 0.01m + deltaPrice * 0.01m;
break;
}
}
}
BaseMsgForm.ShowInfo("取消优惠成功");
}
}
break;
case "修改":
{
pnlUpdateNotes.Visible = true;
pnlEditReceiveInfo.Visible = false;
pnlBuyUrl.Visible = false;
lblShopName.Text = shop.ShopAccount;
lblOrderId.Text = orderId;
txtNotes.Text = row.Cells["colNotes"].Value.ParseToString();
lblColorTag.Text = row.Cells["colNotesColor"].Value.ParseToString();
ucCheckBox1.CheckBoxCheckColor = Color.Gray;
ucCheckBox1.CheckBoxBorderColor = Color.Gray;
ucCheckBox2.CheckBoxCheckColor = Color.Red;
ucCheckBox2.CheckBoxBorderColor = Color.Red;
ucCheckBox3.CheckBoxCheckColor = Color.Orange;
ucCheckBox3.CheckBoxBorderColor = Color.Orange;
ucCheckBox4.CheckBoxCheckColor = Color.Green;
ucCheckBox4.CheckBoxBorderColor = Color.Green;
ucCheckBox5.CheckBoxCheckColor = Color.Blue;
ucCheckBox5.CheckBoxBorderColor = Color.Blue;
ucCheckBox1.Checked = lblColorTag.Text == "0";
ucCheckBox2.Checked = lblColorTag.Text == "1";
ucCheckBox3.Checked = lblColorTag.Text == "2";
ucCheckBox4.Checked = lblColorTag.Text == "3";
ucCheckBox5.Checked = lblColorTag.Text == "4";
}
break;
case "👁":
{
//cell.Value = "查询中…";
pbLoading.Visible = true;
Task.Run(() =>
{
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colOrderId"].Value.ParseToString() == orderId);
var currentStatus = UpdateOrderStatus(shop, orderId);
Invoke(new Action(() =>
{
foreach (var rw in rows)
{
rw.Cells["colOrderStatus"].Value = currentStatus;
}
}));
if (currentStatus != "待发货" && currentStatus != "已发货")
{
Invoke(new Action(() => { pbLoading.Visible = false; }));
BaseMsgForm.ShowError("订单状态已变化,请勿拍单");
return;
}
var deRst = "测试地址写入{\"code\"0}";
deRst = WXOrderList.decryptOrder(shop, orderId);
if (deRst.Contains("\"code\":0"))
{
var url = BaseClass.BuildObjString("shop/wx_add_mdy_order_address");
var data = UserLogin.GetSignaturex();
data += "&shop_id=" + shop.ShopId;
data += "&order_id=" + orderId;
data += "&order_address=" + GetHtml.UrlEncodeUtf8(deRst);
var html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
{
var errMsg = BaseRegex.GetStringJsonByRegs(ref html, html, "msg");
Invoke(new Action(() =>
{
foreach (var rw in rows)
{
rw.Cells["colOpResult"].Value = errMsg;
rw.Cells["colReceiveInfo"].Value = GetDecryptOrder(deRst);
rw.Cells["colReceiveInfo"].Style.ForeColor = DefaultForeColor;
}
BaseMsgForm.ShowError("查看地址成功但保存到服务端失败:" + errMsg);
}));
}
else
{
Invoke(new Action(() =>
{
foreach(var rw in rows)
{
rw.Cells["colReceiveInfo"].Value = GetDecryptOrder(deRst);
rw.Cells["colReceiveInfo"].Style.ForeColor = DefaultForeColor;
rw.Cells["colOpResult"].Value = "查看地址成功";
}
}));
}
}
else
{
var error = BaseRegex.GetStringJsonByRegs(ref deRst, deRst, "err_msg", "error_msg", "errMsg", "errorMsg", "msg");
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "查看地址失败:" + error;
BaseMsgForm.ShowError("查看地址失败:" + error);
}));
}
//Invoke(new Action(() => { cell.Value = "👁"; }));
Invoke(new Action(() => { pbLoading.Visible = false; }));
});
}
break;
case "填":
{
pnlUpdateNotes.Visible = false;
pnlEditReceiveInfo.Visible = true;
pnlBuyUrl.Visible = false;
lblEditReceiveInfoShopName.Text = shop.ShopAccount;
lblEditReceiveInfoShopId.Text = shop.ShopId;
lblEditReceiveInfoOrderId.Text = orderId;
txtEditReceiveInfoAddress.TextChanged -= txtEditReceiveInfoAddress_TextChanged;
txtEditReceiveInfoAddress.Text = ""; // row.Cells["colReceiveInfo"].Value.ParseToString();
txtEditReceiveInfoAddress.TextChanged += txtEditReceiveInfoAddress_TextChanged;
txtEditReceiveInfoOldAddress.Text = row.Cells["colReceiveInfo"].Value.ParseToString();
}
break;
case "编辑":
{
pnlUpdateNotes.Visible = false;
pnlEditReceiveInfo.Visible = false;
pnlBuyUrl.Visible = true;
lblBuyUrlShopName.Text = shop.ShopAccount;
lblBuyUrlShopId.Text = shop.ShopId;
lblBuyUrlOrderId.Text = orderId;
lblBuyUrlSpuCode.Text = row.Cells["colSpuCode"].Value.ParseToString();
txtBuyUrl.Text = row.Cells["colBuyUrl"].Value.ParseToString();
}
break;
case "打印":
{
Task.Run(() =>
{
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colOrderId"].Value.ParseToString() == orderId);
var currentStatus = UpdateOrderStatus(shop, orderId);
Invoke(new Action(() =>
{
foreach (var rw in rows)
{
rw.Cells["colOrderStatus"].Value = currentStatus;
}
}));
if (currentStatus != "待发货" && currentStatus != "已发货")
{
BaseMsgForm.ShowError("订单状态已变化,请勿拍单");
return;
}
GetOnlineWayBill(shop, row);
});
}
break;
case "刷新":
{
pbLoading.Visible = true;
Task.Run(() =>
{
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colOrderId"].Value.ParseToString() == orderId);
var currentStatus = UpdateOrderStatus(shop, orderId);
Invoke(new Action(() =>
{
foreach (var rw in rows)
{
rw.Cells["colOrderStatus"].Value = currentStatus;
rw.Cells["colOpResult"].Value = "订单刷新:" + DateTime.Now.ToString("HH:mm:ss");
}
pbLoading.Visible = false;
}));
if (currentStatus != "待发货" && currentStatus != "已发货")
{
BaseMsgForm.ShowError("订单状态已变化,请勿拍单");
return;
}
});
}
break;
case "":
dgvOrder.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvOrder.Rows[e.RowIndex].Cells["colCheck"].Value;
break;
default:
break;
}
}
void GetOnlineWayBill(ShopLoginInfo shop, DataGridViewRow row)
{
var orderId = row.Cells["colOrderId"].Value.ParseToString();
//Task.Run(() =>
//{
while (isOnlineWayBill)
Thread.Sleep(150);
Invoke(new Action(() => { pbLoading.Visible = true; }));
isOnlineWayBill = true;
WXPreCreateOrderWaybillOnlineParam preWaybillOnlineparam = new WXPreCreateOrderWaybillOnlineParam();
preWaybillOnlineparam.req.requestContent.Add(new preWaybillOnlineRequestContentParam()
{
ecOrderList = new List<ecOrderParam>(),
uuid = Guid.NewGuid().ParseToString(),
});
//#if DEBUG
var rst = WXOrderList.searchOnlineWaybill(shop, orderId);
if (!rst.Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "errMsg", "errorMsg", "err_msg", "error_msg");
//BaseMsgForm.ShowError("打印失败:" + error, "错误", FormLevel.LARGE);
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "打印失败:" + error;
pbLoading.Visible = false;
}));
isOnlineWayBill = false;
return;
}
if (rst.Contains("\"orderList\":[]"))
{
var url = BaseClass.BuildObjString("product/wx_get_random_after_sale_list");
var data = Work.UserLogin.GetSignaturex();
data += "&page_size=1";
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (html.Contains("\"code\":200") && !html.Contains("\"data\":[]"))
{
var obj = JsonHelper.JObjectParse(html)["data"].FirstOrDefault()["after_sale_json"];
string addressJson = obj.ParseToString();
var senderInfo = preWaybillOnlineparam.req.requestContent.FirstOrDefault().sender;
senderInfo.province = BaseRegex.GetStringJson(ref addressJson, "province_name");
senderInfo.city = BaseRegex.GetStringJson(ref addressJson, "city_name");
senderInfo.county = BaseRegex.GetStringJson(ref addressJson, "county_name");
senderInfo.street = BaseRegex.GetStringJson(ref addressJson, "street_name").ParseToString();
senderInfo.mobile = BaseRegex.GetStringJson(ref addressJson, "tel_number");
senderInfo.name = BaseRegex.GetStringJson(ref addressJson, "user_name");
senderInfo.address = BaseRegex.GetStringJson(ref addressJson, "detail_info");
senderInfo.mobile = WaybillHelper.MobileHead[Randomx.GetId(WaybillHelper.MobileHead.Count)] + Randomx.GetNumber(8);
senderInfo.name = WaybillHelper.LastName[Randomx.GetId(WaybillHelper.LastName.Count)] + (Randomx.GetId(2) == 1 ? "先生" : "女士");
}
ecOrderParam orderParam = new ecOrderParam();
orderParam.ecOrderId = orderId;
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colOrderId"].Value.ParseToString() == orderId);
foreach (var rw in rows)
{
orderParam.goodsList.Add(new orderGoodsParam
{
goodCount = rw.Cells["colCnt"].Value.ParseToInt(),
goodName = rw.Cells["colProductName"].Value.ParseToString(),
productId = rw.Cells["colSpuId"].Value.ParseToString(),
skuId = rw.Cells["colSkuId"].Value.ParseToString(),
});
}
preWaybillOnlineparam.req.requestContent.FirstOrDefault().ecOrderList.Add(orderParam);
var result = WXOrderList.preCreateOrderWaybillOnline(shop, preWaybillOnlineparam);
if (result.Contains("账号未开通在线寄件服务"))
{
//BaseMsgForm.ShowError("账号未开通在线寄件服务");
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "账号未开通在线寄件服务,无法打印";
pbLoading.Visible = false;
}));
isOnlineWayBill = false;
return;
}
if (result.Contains("订单已分配给供货商,商家无需发货"))
{
//BaseMsgForm.ShowError("订单已分配给供货商,商家无需发货");
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "订单已分配给供货商,商家无需发货";
pbLoading.Visible = false;
}));
isOnlineWayBill = false;
return;
}
if (result.Contains("订单商品已全部发货"))
{
//BaseMsgForm.ShowError("订单商品已全部发货");
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "订单商品已全部发货";
pbLoading.Visible = false;
}));
isOnlineWayBill = false;
return;
}
if (!result.Contains("\"ret\":0,"))
{
//BaseMsgForm.ShowError("打印失败:" + result, "错误", FormLevel.LARGE);
var error = BaseRegex.GetStringJsonByRegs(ref result, result, "errMsg", "errorMsg", "err_msg", "error_msg");
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "打印失败:" + error;
pbLoading.Visible = false;
}));
isOnlineWayBill = false;
return;
}
List<WxOnlineWaybillDeliveryInfo> deliverInfoLst = new List<WxOnlineWaybillDeliveryInfo>();
var jObj = JsonHelper.JObjectParse(result)["list"];
deliverInfoLst = JsonHelper.DeserializeJsonToList<WxOnlineWaybillDeliveryInfo>(jObj.ParseToString())
.Where(d => d.responseContent.FirstOrDefault()?.deliveryId == "YTO" || d.responseContent.FirstOrDefault()?.deliveryId == "YUNDA" ||
d.responseContent.FirstOrDefault()?.deliveryId == "ZTO" || d.responseContent.FirstOrDefault()?.deliveryId == "STO").ToList()
.Where(d => d.responseContent.FirstOrDefault()?.deliveryErrorMsg == "success").ToList();
var deliverInfo = deliverInfoLst[Randomx.GetId(deliverInfoLst.Count)];
WXCreateOrderWaybillOnlineParam waybillOnlineparam = new WXCreateOrderWaybillOnlineParam();
waybillOnlineparam.requestContent.Add(new WaybillOnlineRequestContentParam()
{
deliveryId = deliverInfo.responseContent.FirstOrDefault().deliveryId,
deliveryInfo = preWaybillOnlineparam.req.requestContent.FirstOrDefault().deliveryInfo,
ecOrderList = preWaybillOnlineparam.req.requestContent.FirstOrDefault().ecOrderList,
ewaybillOrderId = deliverInfo.responseContent.FirstOrDefault().ewaybillOrderId,
extInfo = preWaybillOnlineparam.req.requestContent.FirstOrDefault().extInfo,
orderVasList = preWaybillOnlineparam.req.requestContent.FirstOrDefault().orderVasList,
sender = preWaybillOnlineparam.req.requestContent.FirstOrDefault().sender,
source = preWaybillOnlineparam.req.requestContent.FirstOrDefault().source,
uuid = preWaybillOnlineparam.req.requestContent.FirstOrDefault().uuid,
});
result = WXOrderList.createOrderWaybillOnline(shop, waybillOnlineparam);
if (!result.Contains("\"ret\":0,"))
{
var error = BaseRegex.GetStringJsonByRegs(ref result, result, "errMsg", "errorMsg", "err_msg", "error_msg");
//BaseMsgForm.ShowError("打印失败:" + error, "错误", FormLevel.LARGE);
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "打印失败:" + error;
pbLoading.Visible = false;
}));
isOnlineWayBill = false;
return;
}
else
{
Invoke(new Action(() =>
{
row.Cells["colOnlineWaybillOrderId"].Value = BaseRegex.GetStringJson(ref result, "ewaybillOrderId");
row.Cells["colOnlineWaybill"].Value = "再次\r\n打印";
ShowDgvRow(row);
}));
}
}
Invoke(new Action(() =>
{
if (shop.Chat == null)
{
shop.Chat = CEFBrowser.CreateChromiumWebBrowser("https://store.weixin.qq.com/shop/waybill/allToAll", false);
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
shop.Chat.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
var lifeSapnHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
shop.Chat.LifeSpanHandler = lifeSapnHandler;
shop.Chat.KeyboardHandler = new KeyboardHandler();
shop.Chat.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
shop.Chat.AddressChanged += CefWebBrowser_AddressChanged;
shop.Chat.LoadError += CefWebBrowser_LoadError;
shop.Chat.Dock = DockStyle.Fill;
MainForm.instance.cefPanel.Controls.Add(shop.Chat);
}
shop.Chat.SendToBack();
//MainForm.instance.cefPanel.BringToFront();
MainForm.instance.cefPanel.SendToBack();
MainForm.instance.cefPanel.Visible = true;
}));
while (!shop.Chat.IsBrowserInitialized)
Thread.Sleep(100);
CEFBrowser.DeleteCookie(shop.Chat.GetCookieManager(null));
var cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies);
var t = CEFBrowser.SetCookieAsync(JsonHelper.SerializeObject(cookieLst), shop.Chat.GetCookieManager(null));
shop.Chat.Load("https://store.weixin.qq.com/shop/waybill/allToAll");
var jsStr = @"(function() {
const element = document.getElementsByName('waybill')[0];
const shadowRoot = element.shadowRoot;
//var aElements = document.getElementsByTagName('a');
//var aElements = shadowRoot.querySelector('micro-app-body').getElementsByClassName('goods_info')
var aElements = shadowRoot.querySelector('micro-app-body').getElementsByTagName('a')
for (i = 0; i <aElements.length; i++) {
var aElement = aElements[i];
if (aElement.innerHTML.indexOf('待揽收') >= 0) {
var rect = aElement.getBoundingClientRect();
aElement.click();
return rect.left + ',' + rect.top;
}
}
return '0,0';
})();";
var resultStr = "";
for (int i = 0; i < 10; i++)
{
Thread.Sleep(250);
var client = shop.Chat.GetDevToolsClient();
if (client != null)
{
var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
result.Wait(5000);
resultStr = result.Result.Result.Value.ParseToString();
if (!resultStr.IsNullOrEmpty() && !resultStr.Contains("0,0"))
{
break;
}
}
}
Thread.Sleep(500);
jsStr = @"(function() {
const element = document.getElementsByName('waybill')[0];
const shadowRoot = element.shadowRoot;
var aElements = shadowRoot.querySelector('micro-app-body').getElementsByTagName('tr');
for (i = 0; i <aElements.length; i++) {
var aElement = aElements[i];
if (aElement.innerHTML.indexOf('" + orderId + @"') >= 0) {
var chk = aElement.getElementsByClassName('weui-desktop-table_flex')[0].children[0];
var rect = chk.getBoundingClientRect();
chk.click();
return rect.left + ',' + rect.top;
}
}
return '0,0';
})();";
resultStr = "";
for (int i = 0; i < 10; i++)
{
Thread.Sleep(250);
var client = shop.Chat.GetDevToolsClient();
if (client != null)
{
var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
result.Wait(5000);
resultStr = result.Result.Result.Value.ParseToString();
if (!resultStr.IsNullOrEmpty() && !resultStr.Contains("0,0"))
{
break;
}
}
}
Thread.Sleep(1000);
jsStr = @"(function() {
const element = document.getElementsByName('waybill')[0];
const shadowRoot = element.shadowRoot;
var aElements = shadowRoot.querySelector('micro-app-body').getElementsByTagName('button');
//var aElements = document.getElementsByTagName('button');
for (i = 0; i <aElements.length; i++) {
var aElement = aElements[i];
if (aElement.innerHTML.indexOf('打印快递单') >= 0) {
var rect = aElement.getBoundingClientRect();
aElement.click();
return rect.left + ',' + rect.top;
}
}
return '0,0';
})();";
resultStr = "";
int count = 0;
for (int i = 0; i < 5; i++)
{
Thread.Sleep(500);
var client = shop.Chat.GetDevToolsClient();
if (client != null)
{
var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
result.Wait(5000);
resultStr = result.Result.Result.Value.ParseToString();
if (!resultStr.IsNullOrEmpty() && !resultStr.Contains("0,0"))
{
count++;
if (count > 1)
break;
}
}
}
Thread.Sleep(500);
jsStr = @"(function() {
const element = document.getElementsByName('waybill')[0];
const shadowRoot = element.shadowRoot;
var aElements = shadowRoot.querySelector('micro-app-body').getElementsByTagName('button');
for (i = 0; i <aElements.length; i++) {
var aElement = aElements[i];
if (aElement.innerHTML.indexOf('确认打印') >= 0) {
var rect = aElement.getBoundingClientRect();
if (rect.left > 0) {
aElement.click();
return rect.left + ',' + rect.top;
}
}
}
return '0,0';
})();";
resultStr = "";
for (int i = 0; i < 5; i++)
{
Thread.Sleep(500);
var client = shop.Chat.GetDevToolsClient();
if (client != null)
{
var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
result.Wait(5000);
resultStr = result.Result.Result.Value.ParseToString();
if (!resultStr.IsNullOrEmpty() && !resultStr.Contains("0,0"))
{
break;
}
}
}
Thread.Sleep(500);
GetRefreshPrintId();
Invoke(new Action(() => { ShowRefreshPrintId(row); }));
isOnlineWayBill = false;
//#endif
Invoke(new Action(() => { pbLoading.Visible = false; }));
//});
}
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
{
}
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
{
return false;
}
private void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
}
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
{
}
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
{
}
public string GetDecryptOrder(string sourceOrderAddressStr)
{
//黄颖飞(4559),18466134204-4559,广西壮族自治区柳州市柳南区福柳宏都8-1-701 (拨打请输入分机号4559)
var userName = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "userName"); // 黄颖飞
var extension = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "extension"); // 4559
var virtualNumber = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "virtualNumber"); // 18466134204
var provinceName = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "provinceName"); // 广西壮族自治区
var cityName = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "cityName"); // 柳州市
var countyName = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "countyName"); // 柳南区
var detailInfo = BaseRegex.GetStringJson(ref sourceOrderAddressStr, "detailInfo"); // 福柳宏都8-1-701
if (userName.IsNullOrEmpty() || extension.IsNullOrEmpty() || virtualNumber.IsNullOrEmpty() || provinceName.IsNullOrEmpty() || cityName.IsNullOrEmpty() ||
countyName.IsNullOrEmpty() || detailInfo.IsNullOrEmpty())
{
return sourceOrderAddressStr;
}
//return userName + "(" + extension + ")," + virtualNumber + "-" + extension + "," + provinceName + cityName + countyName + detailInfo + "(拨打请输入分机号" + extension + ")";
return userName + "" + extension + "," + virtualNumber + "-" + extension + "," + provinceName + cityName + countyName + detailInfo + "拨打请输入分机号" + extension + "";
}
private void btnStop_Click(object sender, EventArgs e)
{
if (this.cancellationTokenSource != null)
this.cancellationTokenSource.Cancel();
}
private void btnSearchProd_Click(object sender, EventArgs e)
{
var shopIdLst = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
if (shopIdLst.Count <= 0)
{
BaseMsgForm.ShowError("未勾选查询店铺!");
return;
}
btnSearchOrder.Enabled = false;
pbLoading.Visible = true;
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
cancellationTokenSource = new CancellationTokenSource();
dgvOrder.Rows.Clear();
Task.Run(() =>
{
GetOrderList(shopIdLst);
Invoke(new Action(() =>
{
if (cancellationTokenSource.IsCancellationRequested)
{
this.statusBar.lblTaskStatus.Text = "订单查询停止";
BaseMsgForm.ShowInfo("订单查询停止");
}
else
{
this.statusBar.lblTaskStatus.Text = "订单查询完毕";
BaseMsgForm.ShowInfo("订单查询完毕");
}
pbLoading.Visible = false;
btnSearchOrder.Enabled = true;
}));
}, cancellationTokenSource.Token);
}
void GetOrderList(List<string> shopIdLst)
{
List<ShopLoginInfo> shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
Invoke(new Action(() =>
{
this.pbLoading.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询店铺";
this.statusBar.pgbTaskProgress.Maximum = shopIdLst.Count;
this.statusBar.UpdateProgressBar(0);
}));
foreach (var shop in shopLst)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
Invoke(new Action(() =>
{
this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1);
}));
if (shop.LoginStatus != "登录成功")
{
continue;
}
for (int orderStatus = 20; orderStatus <= 30; orderStatus += 10)
{
int page = PageBegin - 1;
int totalPage = 1;
int pageSize = 30;
while (page < totalPage && page < PageEnd)
{
page++;
if (orderStatus == 20 && !chkWaitSend.Checked)
break;
if (orderStatus == 30 && !chkHasSend.Checked)
break;
if (cancellationTokenSource.IsCancellationRequested)
break;
// 查找订单
pageSize = 30;
var result = WXOrderList.orderListSearch(shop, orderStatus, page, pageSize);
if (!result.Contains("\"code\":0"))
{
ShowShopError(shop, result);
break;
}
if (result.Contains("4527181286223364098"))
{
}
totalPage = Math.Ceiling(BaseRegex.GetIntJson(ref result, "totalNum") * 1m / pageSize).ParseToInt();
List<WxOrderInfoLite> orderLst = new List<WxOrderInfoLite>();
try
{
var jArr = JsonHelper.JObjectParse(result)["orderList"];
orderLst = JsonHelper.DeserializeJsonToList<WxOrderInfoLite>(JsonHelper.SerializeObject(jArr));
}
catch (Exception ex)
{
ShowShopError(shop, ex.Message);
break;
}
Thread.Sleep(Randomx.GetId(200, 1000));
try
{
Invoke(new Action(() =>
{
this.pbLoading.Visible = true;
this.statusBar.lblTaskStatus.Text = "正在查询店铺:" + shop.ShopAccount + " " + page + "/" + Math.Min(PageEnd, totalPage);
}));
var url = BaseClass.BuildObjString("shop/wx_get_order_address");
var data = UserLogin.GetSignaturex() + "&shop_id=" + shop.ShopId;
data += "&order_ids=" + string.Join(",", orderLst.Select(o => o.commonInfo.orderId));
data += "&not_count=true";
var html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
List<WXOrderDecryptAddressInfo> orderDecryptAddressLst = new List<WXOrderDecryptAddressInfo>();
if (html.Contains("\"code\":200"))
{
var jObj = JsonHelper.JObjectParse(html)["data"];
orderDecryptAddressLst = JsonHelper.DeserializeJsonToList<WXOrderDecryptAddressInfo>(jObj.ParseToString());
}
url = BaseClass.BuildObjString("shop/wx_get_buy_url_notes");
data = UserLogin.GetSignaturex() + "&shop_id=" + shop.ShopId;
data += "&spu_codes=" + GetHtml.UrlEncodeUtf8(string.Join(",", orderLst.SelectMany(o => o.orderProductInfo.Select(p => p.spuCode)).Distinct()));
data += "&main_user_name=" + (BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName);
data += "&not_count=true";
html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
List<WXBuyUrlNotesInfo> buyUrlNotesInfoLst = new List<WXBuyUrlNotesInfo>();
if (html.Contains("\"code\":200"))
{
var jObj = JsonHelper.JObjectParse(html)["data"];
buyUrlNotesInfoLst = JsonHelper.DeserializeJsonToList<WXBuyUrlNotesInfo>(jObj.ParseToString());
}
// 查找对应商品
string getProdRst = "";
JObject prodObjs = new JObject();
try
{
if (orderLst.Count > 0)
{
int onSaleStatusCode = -1;
pageSize = 50;
string spuIds = GetHtml.UrlEncodeUtf8(string.Join(",", orderLst.SelectMany(o => o.orderProductInfo.Select(p => p.productId)).Distinct()));
//getProdRst = WXClearNoVisit.searchProduct(shop, 1, pageSize, spuIds, onSaleStatusCode);
getProdRst = WXOrderList.getSkuBySpu(shop, GetHtml.UrlDecode(spuIds));
Thread.Sleep(Randomx.GetId(50, 100));
if (!getProdRst.Contains("\"success\":true") && !getProdRst.Contains("\"code\":0"))
{
ShowShopError(shop, getProdRst);
break;
}
}
prodObjs = JsonHelper.JObjectParse(getProdRst);
}
catch { }
foreach (var order in orderLst)
{
var orStr = JsonHelper.SerializeObject(order);
if (orStr.Contains("4527181286223364098") || orStr.Contains("4527546611026165767"))
{
}
foreach (var orderProd in order.orderProductInfo)
{
decimal? currentPrice = null;
int? currentStock = null;
try
{
//var prod = prodObjs["productList"].FirstOrDefault(p => p["productId"].ParseToString() == orderProd.productId);
//if (prod != null)
//{
// var prodStr = prod.ParseToString();
// var sku = prod["skuList"].FirstOrDefault(p => p["skuId"].ParseToString() == orderProd.skuId);
// if (sku != null)
// {
// currentPrice = sku["price"].ParseToDecimal() * 0.01m;
// }
//}
var prod = prodObjs["products"].FirstOrDefault(p => p["productKey"]["productId"].ParseToString() == orderProd.productId);
if (prod != null)
{
var prodStr = prod.ParseToString();
var sku = prod["productSkus"].FirstOrDefault(p => p["skuKey"]["skuId"].ParseToString() == orderProd.skuId);
if (sku != null)
{
var skuStr = JsonHelper.SerializeObject(sku);
currentPrice = BaseRegex.GetIntJson(ref skuStr, "salePrice") * 0.01m;
currentStock = BaseRegex.GetIntJson(ref skuStr, "stockNum");
}
}
}
catch { }
var discount = orderProd.salePrice.ParseToInt() * orderProd.productCnt - orderProd.realPrice;
var orderAddresss = orderDecryptAddressLst.FirstOrDefault(a => a.order_id == order.commonInfo.orderId);
var buyUrlNotes = buyUrlNotesInfoLst.FirstOrDefault(b => b.spu_code == orderProd.spuCode);
var DecryptAddress = this.GetDecryptOrder((orderAddresss?.order_address).ParseToString());
Invoke(new Action(() =>
{
var rowIndex = this.dgvOrder.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
shop.Notes,
shop.GroupName,
"登录",
"进店",
order.commonInfo.orderId,
order.commonInfo.createTimeStr,
order.commonInfo.createTimeStr.ParseToDateTime().ToString("M/d HH:mm"),
orderProd.thumbImg,
DataGridViewExtension.defaultBitmap,
//orderProd.productId + "\r\n" + string.Join("", orderProd.title.Take(30)) + (orderProd.title.Length > 30 ? "…" : "") +
// "\r\n-----\r\n" + string.Join(";", orderProd.saleParam), // 商品信息合集
orderProd.productId + "\r\n" + orderProd.title + "\r\n-----\r\n" + string.Join(";", orderProd.saleParam), // 商品信息合集
orderProd.productId, // 商品Id
orderProd.title, // 商品名称
orderProd.spuCode, // 商品编码
orderProd.skuId, // skuId
string.Join(";", orderProd.saleParam), // sku规格
orderProd.skuCode, // sku编码
"商品编码:\r\n" + orderProd.spuCode + "\r\n" + "规格编码:\r\n" + orderProd.skuCode, // 编码信息合集
orderProd.salePrice.ParseToInt() * 0.01m,
orderProd.productCnt, // 商品数量
orderProd.salePrice.ParseToInt() * 0.01m + "\r\nx" + orderProd.productCnt, // 商品单价/数量
orderProd.realPrice * 0.01m + (discount > 0 ? "\r\n优惠\r\n-" + discount * 0.01m : ""), // 商品总价/优惠
discount > 0 ? discount * 0.01m : null, // 商品优惠
currentPrice,
currentStock,
"礼",
"优化",
"取消优惠",
order.commonInfo.statusStr, // 订单状态
"刷新",
buyUrlNotes?.buy_url_notes, // 采购地址
"编辑",
string.IsNullOrWhiteSpace(DecryptAddress) ? (order.acceptInfo.addressInfo.userName + " " + order.acceptInfo.addressInfo.telNumber + " " +
order.acceptInfo.addressInfo.provinceName + " " + order.acceptInfo.addressInfo.cityName + " " +
order.acceptInfo.addressInfo.countyName + " " + order.acceptInfo.addressInfo.detailInfo + " " +
" 未查看地址") : DecryptAddress, // 收件地址解密
"👁",
"填",
"", // 在线寄件打印单号
order.expressData?.type == 3 && order.expressData?.status != 1 ? order.expressData?.jumpPath?.Substring((order.expressData?.jumpPath).ParseToString().IndexOf("ewaybillOrderId=")).Replace("ewaybillOrderId=", "") : "",
order.expressData?.type == 3 && order.expressData?.status != 1 ? "再次\r\n打印" : "打印",
order.flagInfo.flagNotes, // 卖家备注
order.flagInfo.flagColor, // 卖家备注颜色
"修改\r\n备注",
""
);
var row = dgvOrder.Rows[rowIndex];
ShowDgvRow(row, order);
ShowRefreshPrintId(row);
}));
}
}
}
catch (Exception ex)
{
ShowShopError(shop, ex.Message);
}
}
}
}
}
private void ShowDgvRow(DataGridViewRow row, WxOrderInfoLite order = null)
{
SizeF textSize1 = TextRenderer.MeasureText(row.Cells["colProdInfo"].Value.ParseToString(), row.Cells["colProdInfo"].Style.Font,
new Size(row.Cells["colProdInfo"].ContentBounds.Width, 500), TextFormatFlags.WordBreak);
SizeF textSize2 = TextRenderer.MeasureText(row.Cells["colReceiveInfo"].Value.ParseToString(), row.Cells["colReceiveInfo"].Style.Font,
new Size(row.Cells["colReceiveInfo"].ContentBounds.Width, 500), TextFormatFlags.WordBreak);
row.Height = Math.Max(textSize2.Height, Math.Max(textSize1.Height, 80)).ParseToInt() + 20;
if (order != null)
{
// 根据卖家备注颜色显示文字颜色
row.Cells["colNotes"].Style.ForeColor = DefaultForeColor;
if (order.flagInfo.flagColor == 1)
row.Cells["colNotes"].Style.ForeColor = Color.Red;
if (order.flagInfo.flagColor == 2)
row.Cells["colNotes"].Style.ForeColor = Color.Orange;
if (order.flagInfo.flagColor == 3)
row.Cells["colNotes"].Style.ForeColor = Color.Green;
if (order.flagInfo.flagColor == 4)
row.Cells["colNotes"].Style.ForeColor = Color.Blue;
}
if (row.Cells["colReceiveInfo"].Value.ParseToString().Contains("未查看地址"))
row.Cells["colReceiveInfo"].Style.ForeColor = Color.DarkGray;
if (row.Cells["colOnlineWaybill"].Value.ParseToString() == "再次\r\n打印")
{
(row.Cells["colOnlineWaybill"] as DataGridViewLinkCell).LinkColor = Color.Red; // Color.Blue
(row.Cells["colOnlineWaybill"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed; // Color.FromArgb(255, 128, 0, 128)
(row.Cells["colOnlineWaybill"] as DataGridViewLinkCell).ActiveLinkColor = Color.Orange; // Color.Red;
}
else
{
(row.Cells["colOnlineWaybill"] as DataGridViewLinkCell).LinkColor = Color.Blue;
(row.Cells["colOnlineWaybill"] as DataGridViewLinkCell).VisitedLinkColor = Color.FromArgb(255, 128, 0, 128);
(row.Cells["colOnlineWaybill"] as DataGridViewLinkCell).ActiveLinkColor = Color.Red;
}
}
private void btnClearDgv_Click(object sender, EventArgs e)
{
var rows = this.dgvOrder.Rows.Cast<DataGridViewRow>().ToList(); //Cast后Rows做foreach循环时仍会夹花跳过,所以要ToList转一个新的数组。
foreach (var row in rows)
{
if (row.Cells["colCheck"].Value.ParseToBool() == true)
{
this.dgvOrder.Rows.Remove(row);
}
}
}
private void btnClearFilter_Click(object sender, EventArgs e)
{
chkHasSend.Checked = true;
chkWaitSend.Checked = true;
}
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 btnFiltSelect_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dgvOrder.Rows)
{
// 2,3拼多多 6抖音
if (!row.Cells["colNotes"].Value.ParseToString().StartsWith("2") && !row.Cells["colNotes"].Value.ParseToString().StartsWith("3") &&
!row.Cells["colNotes"].Value.ParseToString().StartsWith("6"))
{
row.Cells["colCheck"].Value = false;
continue;
}
// ^\d{6}.*$
string pattern1 = @"^\d{6}-\d{15}.*$"; // 定义正则表达式模式
string pattern2 = @"^\d{19}.*$"; // 定义正则表达式模式
Regex regex1 = new Regex(pattern1);
Regex regex2 = new Regex(pattern2);
if (!regex1.IsMatch(row.Cells["colNotes"].Value.ParseToString()) && !regex2.IsMatch(row.Cells["colNotes"].Value.ParseToString()))
{
row.Cells["colCheck"].Value = false;
continue;
}
row.Cells["colCheck"].Value = true;
}
}
void ShowShopError(ShopLoginInfo shop, string operateResult, bool isShowDialog = false)
{
var error = BaseRegex.GetStringJson(ref operateResult, "msg");
if (string.IsNullOrEmpty(error))
error = BaseRegex.GetStringJson(ref operateResult, "errMsg");
if (string.IsNullOrEmpty(error))
error = BaseRegex.GetStringJson(ref operateResult, "errorMsg");
if (string.IsNullOrEmpty(error))
error = operateResult;
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus != "登录成功")
{
error = "店铺掉线";
}
Invoke(new Action(() => { BindShop(shop, new List<string> { shop.ShopId }, error); }));
if (isShowDialog)
BaseMsgForm.ShowError(error);
}
private void ucCheckBox_Click(object sender, EventArgs e)
{
ucCheckBox1.Checked = false;
ucCheckBox2.Checked = false;
ucCheckBox3.Checked = false;
ucCheckBox4.Checked = false;
ucCheckBox5.Checked = false;
if (sender is UserComponent.UcCheckBox)
{
(sender as UserComponent.UcCheckBox).Checked = true;
if (sender == ucCheckBox1) lblColorTag.Text = "0";
if (sender == ucCheckBox2) lblColorTag.Text = "1";
if (sender == ucCheckBox3) lblColorTag.Text = "2";
if (sender == ucCheckBox4) lblColorTag.Text = "3";
if (sender == ucCheckBox5) lblColorTag.Text = "4";
}
}
private void btnNotesCancel_Click(object sender, EventArgs e)
{
pnlUpdateNotes.Visible = false;
}
private void btnNotesOK_Click(object sender, EventArgs e)
{
var orderIds = lblOrderId.Text.Split(';');
Task.Run(() =>
{
foreach (var orderId in orderIds)
{
var notes = txtNotes.Text.Trim();
var tagColor = lblColorTag.Text.ParseToInt();
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colOrderId"].Value.ParseToString() == orderId).ToList();
if (rows.Count == 0)
continue;
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == rows[0].Cells["colSupplierId"].Value.ParseToString());
if (shop != null)
{
var notesRst = WXOrderList.addNotes(shop, orderId, notes, tagColor);
if (notesRst.Contains("\"code\":0"))
{
Invoke(new Action(() =>
{
foreach (var row in rows)
{
row.Cells["colNotes"].Value = notes;
row.Cells["colNotesColor"].Value = tagColor;
row.Cells["colOpResult"].Value = "修改备注成功";
row.Cells["colNotes"].Style.ForeColor = DefaultForeColor;
if (tagColor == 1)
row.Cells["colNotes"].Style.ForeColor = Color.Red;
if (tagColor == 2)
row.Cells["colNotes"].Style.ForeColor = Color.Orange;
if (tagColor == 3)
row.Cells["colNotes"].Style.ForeColor = Color.Green;
if (tagColor == 4)
row.Cells["colNotes"].Style.ForeColor = Color.Blue;
}
pnlUpdateNotes.Visible = false;
}));
}
else
{
ShowShopError(shop, notesRst, true);
}
}
}
Invoke(new Action(() =>
{
pnlUpdateNotes.Visible = false;
}));
});
}
private void btnEditReceiveInfoCancel_Click(object sender, EventArgs e)
{
pnlEditReceiveInfo.Visible = false;
}
private void btnEditReceiveInfoOk_Click(object sender, EventArgs e)
{
var orderId = lblEditReceiveInfoOrderId.Text;
var address = txtEditReceiveInfoAddress.Text.Trim();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == lblEditReceiveInfoShopId.Text);
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colOrderId"].Value.ParseToString() == orderId);
var url = BaseClass.BuildObjString("shop/wx_add_mdy_order_address");
var data = UserLogin.GetSignaturex() + "&shop_id=" + shop.ShopId;
data += "&order_id=" + orderId;
data += "&order_address=" + GetHtml.UrlEncodeUtf8(address);
var html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
{
var errMsg = BaseRegex.GetStringJson(ref html, "msg");
if (errMsg.IsNullOrEmpty())
errMsg = html;
foreach (var row in rows)
{
row.Cells["colOpResult"].Value = errMsg;
}
}
else
{
pnlEditReceiveInfo.Visible = false;
foreach (var row in rows)
{
row.Cells["colOpResult"].Value = "填写收货地址成功";
row.Cells["colReceiveInfo"].Value = address;
row.Cells["colReceiveInfo"].Style.ForeColor = DefaultForeColor;
}
if (rows.FirstOrDefault() != null && rows.FirstOrDefault().Cells["colOnlineWaybillOrderId"].Value.ParseToString() != null &&
(BaseClass.UserAuthority.Contains("在线寄件") || BaseClass.ParentAuthority.Contains("在线寄件")))
{
var rst = WXOrderList.searchOnlineWaybill(shop, orderId);
if (!rst.Contains("\"code\":0"))
{
//BaseMsgForm.ShowError("打印失败:" + rst, "错误", FormLevel.LARGE);
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "errMsg", "errorMsg", "err_msg", "error_msg");
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colOpResult"].Value = "填写收货地址成功, 但查询打印失败:" + error;
pbLoading.Visible = false;
}));
return;
}
var ewaybillOrderId = BaseRegex.GetStringJson(ref rst, "ewaybillOrderId");
var waybillId = BaseRegex.GetStringJson(ref rst, "waybillId");
if (!ewaybillOrderId.IsNullOrEmpty() && !waybillId.IsNullOrEmpty() && ewaybillOrderId == rows.FirstOrDefault().Cells["colOnlineWaybillOrderId"].Value.ParseToString())
{
rst = WXOrderList.cancelOnlineWaybill(shop, ewaybillOrderId, waybillId);
if (!rst.Contains("\"code\":0"))
{
//BaseMsgForm.ShowError("打印失败:" + rst, "错误", FormLevel.LARGE);
var error = BaseRegex.GetStringJsonByRegs(ref rst, rst, "errMsg", "errorMsg", "err_msg", "error_msg");
Invoke(new Action(() =>
{
foreach (var row in rows)
row.Cells["colOpResult"].Value = "填写收货地址成功, 但取消打印失败:" + error;
pbLoading.Visible = false;
}));
return;
}
else
{
Invoke(new Action(() =>
{
foreach (var row in rows)
{
row.Cells["colOpResult"].Value = "填写收货地址成功, 取消打印成功";
row.Cells["colOnlineWaybill"].Value = "打印";
ShowDgvRow(row);
}
pbLoading.Visible = false;
}));
}
}
}
}
}
private void btnBuyUrlCancel_Click(object sender, EventArgs e)
{
pnlBuyUrl.Visible = false;
}
private void btnBuyUrlOk_Click(object sender, EventArgs e)
{
var orderId = lblBuyUrlOrderId.Text;
var buyUrl = txtBuyUrl.Text.Trim();
var spuCode = lblBuyUrlSpuCode.Text;
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == lblEditReceiveInfoShopId.Text);
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSpuCode"].Value.ParseToString() == spuCode);
var url = BaseClass.BuildObjString("shop/wx_add_mdy_buy_url_notes");
var data = UserLogin.GetSignaturex();
data += "&main_user_name=" + (BaseClass.GroupId == 3 ? BaseClass.UserName : BaseClass.ParentUserName);
data += "&spu_code=" + spuCode;
data += "&buy_url_notes=" + GetHtml.UrlEncodeUtf8(buyUrl);
var html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (!html.Contains("\"code\":200"))
{
var errMsg = BaseRegex.GetStringJson(ref html, "msg");
if (errMsg.IsNullOrEmpty())
errMsg = html;
foreach (var row in rows)
{
row.Cells["colOpResult"].Value = errMsg;
}
}
else
{
pnlBuyUrl.Visible = false;
foreach (var row in rows)
{
row.Cells["colOpResult"].Value = "编辑采购地址成功";
row.Cells["colBuyUrl"].Value = buyUrl;
}
}
}
private void btnFilterOrder_Click(object sender, EventArgs e)
{
var filterOrderId = txtFilterOrderId.Text.Trim();
var filterProdInfo = txtFilterOrderProdInfo.Text.Trim();
var filterStatus = cmbFilterOrderStatus.Text.Trim();
var filterNotesNotContainWords = txtFilterNotesNotContainWords.Text.Trim().Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
var filterTitleNotContainWords = txtFilterTitleNotContainWords.Text.Trim().Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
var filterPriceNotContainWords = txtFilterPriceNotContainWords.Text.Trim().Split(new string[] { ",", ",", " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
string group = cmbFilterOrderShopGroup.Text.Trim().Trim(';');
if (group == "全部")
group = "";
List<string> groupLst = group.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
foreach (DataGridViewRow row in dgvOrder.Rows)
{
if (!row.Cells["colSupplierName"].Value.ParseToString().Contains(txtFilterOrderShopName.Text.Trim()))
{
row.Visible = false;
row.Cells["colCheck"].Value = false;
continue;
}
if (!string.IsNullOrWhiteSpace(group) && !groupLst.Contains(row.Cells["colOrderShopGroup"].Value.ParseToString()))
{
row.Visible = false;
row.Cells["colCheck"].Value = false;
continue;
}
string orderId = row.Cells["colOrderId"].Value.ParseToString();
if (!string.IsNullOrEmpty(filterOrderId) && !orderId.Contains(filterOrderId))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
string prodInfo = row.Cells["colProdInfo"].Value.ParseToString();
if (!string.IsNullOrEmpty(filterProdInfo) && !prodInfo.Contains(filterProdInfo))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
string orderStatus = row.Cells["colOrderStatus"].Value.ParseToString();
if (!string.IsNullOrEmpty(filterStatus) && !orderStatus.Contains(filterStatus))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
string orderNotes = row.Cells["colNotes"].Value.ParseToString();
if (filterNotesNotContainWords.Count > 0 && filterNotesNotContainWords.Any(w => orderNotes.Contains(w)))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
string goodsName = row.Cells["colProductName"].Value.ParseToString();
if (filterTitleNotContainWords.Count > 0 && filterTitleNotContainWords.Any(w => goodsName.Contains(w)))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
string orderGoodsPrice = row.Cells["colSalePrice"].Value.ParseToString();
if (filterPriceNotContainWords.Count > 0 && filterPriceNotContainWords.Any(w => orderGoodsPrice.ParseToDecimal() == w.ParseToDecimal()))
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
if (chkFilterBeginTime.Checked && row.Cells["colOrderTimeFull"].Value.ParseToString().ParseToDateTime() < dtpFilterBeginTime.Value)
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
if (chkFilterEndTime.Checked && row.Cells["colOrderTimeFull"].Value.ParseToString().ParseToDateTime() > dtpFilterEndTime.Value)
{
row.Cells["colCheck"].Value = false;
row.Visible = false;
continue;
}
row.Visible = true;
}
}
private void btnRestore_Click(object sender, EventArgs e)
{
txtFilterOrderId.Text = "";
txtFilterOrderProdInfo.Text = "";
cmbFilterOrderStatus.Text = "";
txtFilterNotesNotContainWords.Text = "";
txtFilterTitleNotContainWords.Text = "";
txtFilterOrderShopName.Text = "";
txtFilterPriceNotContainWords.Text = "";
cmbFilterOrderShopGroup.Text = "全部";
chkFilterEndTime.Checked = false;
chkFilterBeginTime.Checked = false;
dtpFilterBeginTime.Value = DateTime.Now.AddDays(-1);
dtpFilterEndTime.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
btnFilterOrder_Click(null, null);
}
private void btnRefreshPrintId_Click(object sender, EventArgs e)
{
GetRefreshPrintId();
foreach (DataGridViewRow row in dgvOrder.Rows)
{
ShowRefreshPrintId(row);
}
}
void GetRefreshPrintId()
{
try
{
lstPrintLog.Clear();
string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeChatShopPrintClient\\log");
DirectoryInfo dirInfo = new DirectoryInfo(logPath); // 创建DirectoryInfo对象
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo file in files)
{
if (file.FullName.EndsWith(".log"))
{
string content = File.ReadAllText(file.FullName);
lstPrintLog.Add(content);
}
}
}
catch (Exception ex)
{
BaseMsgForm.ShowError("读取打印单号失败" + ex.Message);
}
}
void ShowRefreshPrintId(DataGridViewRow row)
{
var waybillOrderId = row.Cells["colOnlineWaybillOrderId"].Value.ParseToString();
if (!waybillOrderId.IsNullOrEmpty())
{
foreach (var fileStr in lstPrintLog)
{
//task 4527181286223364098
var index = fileStr.IndexOf("task " + waybillOrderId);
if (index > 50)
{
var str = fileStr.Substring(index - 50, 50 + ("task " + waybillOrderId).Length);
str = str.Replace("task " + waybillOrderId, "").Replace("printPage", "").Replace("requestID", "").Trim();
if (str.ParseToLong() > 0)
row.Cells["colPrintId"].Value = str;
break;
}
}
}
}
private void btnBatchOnlieWaybill_Click(object sender, EventArgs e)
{
var rows = this.dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (rows.Count == 0)
{
BaseMsgForm.ShowError("请选择订单");
return;
}
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
foreach (var row in rows)
{
var shopId = row.Cells["colSupplierId"].Value.ParseToString();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
if (shop != null)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
if (!row.Cells["colPrintId"].Value.ParseToString().IsNullOrEmpty())
{
row.Cells["colOpResult"].Value = "已打印,跳过";
continue;
}
GetOnlineWayBill(shop, row);
}
}
Invoke(new Action(() =>
{
if (cancellationTokenSource.IsCancellationRequested)
BaseMsgForm.ShowInfo("批量打印终止");
else
BaseMsgForm.ShowInfo("批量打印完成");
}));
}, cancellationTokenSource.Token);
}
private void txtEditReceiveInfoAddress_TextChanged(object sender, EventArgs e)
{
txtEditReceiveInfoAddress.TextChanged -= txtEditReceiveInfoAddress_TextChanged;
if (txtEditReceiveInfoAddress.Text.Length > 25 && txtEditReceiveInfoAddress.Text.Substring(0, 25).Contains("*******"))
{
txtEditReceiveInfoAddress.Text = txtEditReceiveInfoAddress.Text.Substring(0, 25).Replace("*******", WaybillHelper.MobileHead[Randomx.GetId(WaybillHelper.MobileHead.Count)] + Randomx.GetNumber(4)) + txtEditReceiveInfoAddress.Text.Substring(25);
}
if (txtEditReceiveInfoAddress.Text.Length > 25 && txtEditReceiveInfoAddress.Text.Substring(0, 25).Contains("****"))
{
txtEditReceiveInfoAddress.Text = txtEditReceiveInfoAddress.Text.Substring(0, 25).Replace("****", Randomx.GetNumber(4)) + txtEditReceiveInfoAddress.Text.Substring(25);
}
if (txtEditReceiveInfoAddress.Text.Length > 5 && txtEditReceiveInfoAddress.Text.Substring(0, 5).Contains("**"))
{
txtEditReceiveInfoAddress.Text = txtEditReceiveInfoAddress.Text.Substring(0, 5).Replace("**", "") + txtEditReceiveInfoAddress.Text.Substring(5);
}
if (txtEditReceiveInfoAddress.Text.Length > 4 && txtEditReceiveInfoAddress.Text.Substring(0, 4).Contains("*"))
{
txtEditReceiveInfoAddress.Text = txtEditReceiveInfoAddress.Text.Substring(0, 4).Replace("*", "") + txtEditReceiveInfoAddress.Text.Substring(4);
}
txtEditReceiveInfoAddress.Text = txtEditReceiveInfoAddress.Text.Replace("\r", " ").Replace("\n", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ");
txtEditReceiveInfoAddress.TextChanged += txtEditReceiveInfoAddress_TextChanged;
}
private void btnStopBatchOnlineWaybill_Click(object sender, EventArgs e)
{
if (this.cancellationTokenSource != null)
this.cancellationTokenSource.Cancel();
isOnlineWayBill = false;
}
string UpdateOrderStatus(ShopLoginInfo shop, string orderId)
{
var rst = WXOrderList.orderSearch(shop, orderId);
if (!rst.Contains("\"code\":0"))
{
ShowShopError(shop, rst);
return "获取\r\n失败";
}
var statusStr = BaseRegex.GetStringJson(ref rst, "statusStr");
if (string.IsNullOrEmpty(statusStr))
statusStr = "不存在";
return statusStr;
}
private void btnBatchNotes_Click(object sender, EventArgs e)
{
var rows = dgvOrder.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (rows.Count == 0)
{
BaseMsgForm.ShowError("请选择订单");
return;
}
pnlUpdateNotes.Visible = true;
pnlEditReceiveInfo.Visible = false;
pnlBuyUrl.Visible = false;
lblShopName.Text = string.Join(";", rows.Select(r => r.Cells["colSupplierName"].Value.ParseToString()).Distinct().ToList());
lblOrderId.Text = string.Join(";", rows.Select(r => r.Cells["colOrderId"].Value.ParseToString()).Distinct().ToList());
txtNotes.Text = rows[0].Cells["colNotes"].Value.ParseToString();
lblColorTag.Text = rows[0].Cells["colNotesColor"].Value.ParseToString();
ucCheckBox1.CheckBoxCheckColor = Color.Gray;
ucCheckBox1.CheckBoxBorderColor = Color.Gray;
ucCheckBox2.CheckBoxCheckColor = Color.Red;
ucCheckBox2.CheckBoxBorderColor = Color.Red;
ucCheckBox3.CheckBoxCheckColor = Color.Orange;
ucCheckBox3.CheckBoxBorderColor = Color.Orange;
ucCheckBox4.CheckBoxCheckColor = Color.Green;
ucCheckBox4.CheckBoxBorderColor = Color.Green;
ucCheckBox5.CheckBoxCheckColor = Color.Blue;
ucCheckBox5.CheckBoxBorderColor = Color.Blue;
ucCheckBox1.Checked = lblColorTag.Text == "0";
ucCheckBox2.Checked = lblColorTag.Text == "1";
ucCheckBox3.Checked = lblColorTag.Text == "2";
ucCheckBox4.Checked = lblColorTag.Text == "3";
ucCheckBox5.Checked = lblColorTag.Text == "4";
}
}
public class WXOrderList
{
/// <summary>
///
/// </summary>
/// <param name="shop"></param>
/// <param name="orderStatus">订单状态 20待发货 30已发货</param>
/// <returns></returns>
public static string orderListSearch(ShopLoginInfo shop, int orderStatus = 20, int pageNum = 1, int pageSize = 30)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string body = @"{""isSearch"":false,""pageSize"":" + pageSize +
@",""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":" + 1 +
@",""onAftersaleOrderExist"":0,""orderStatus"":" + orderStatus + @"}";
if (pageNum > 1)
body = @"{""isSearch"":false,""pageSize"":" + pageSize +
@",""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":" + 1 +
@",""onAftersaleOrderExist"":0,""orderStatus"":" + orderStatus + @",""page"":" + pageNum + @"}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string orderSearch(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
string body = @"{""isSearch"":true,""pageSize"":30,""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0,""stockoutPunishAlert"":0,
""waybillStatus"":0,""pageNum"":1,""onAftersaleOrderExist"":0,""orderStatus"":0,""orderId"":""" + orderId + @""",
""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}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string addNotes(ShopLoginInfo shop, string orderId, string notes, int tagColor = 0)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/common/cgi/batchMerchantNotes?token=&lang=zh_CN";
string body = @"{""items"":[{""orderId"":""" + orderId + @""",""merchantNotes"":""" + notes + @""",""merchantNotesTagColor"":" + tagColor + @"}]}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string EditPrice(ShopLoginInfo shop, string spuId, string skuId, int newPrice)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductlist/cgi/goods/listingUpdatePrice?token=&lang=zh_CN";
string body = @"{""skuList"":[{""spuId"":" + spuId + @",""skuId"":""" + skuId + @""",""salePrice"":" + newPrice + @"}],""uploadSource"":6}";
string refere = "https://store.weixin.qq.com/shop/goods/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string EditPrice(ShopLoginInfo shop, JObject priceData)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductlist/cgi/goods/listingUpdatePrice?token=&lang=zh_CN";
//string body = @"{""skuList"":[{""spuId"":" + spuId + @",""skuId"":""" + skuId + @""",""salePrice"":" + newPrice + @"}],""uploadSource"":6}";
string body = JsonHelper.SerializeObject(priceData);
string refere = "https://store.weixin.qq.com/shop/goods/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string decryptOrder(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/common/cgi/decryptOrder?token=&lang=zh_CN";
string body = @"{""id"":""" + orderId + @"""}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
// 预在线寄件
public static string preCreateOrderWaybillOnline(ShopLoginInfo shop, WXPreCreateOrderWaybillOnlineParam preWaybillOnlineparam)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodewaybill/alltoall/platPreCreateOrder?token=&lang=zh_CN";
//string body = @"{""deliveryIds"":[""JTSD"",""YTO"",""YUNDA"",""ZTO"",""STO"",""JD"",""DBKD"",""CNSD"",""SF""],""req"":{""requestContent"":[{""deliveryId"":"""",""orderType"":1,""ecOrderList"":[{""ecOrderId"":""3736506990289905920"",""goodsList"":[{""goodCount"":1,""goodName"":""【抢限量印签】信任养育:你的孩子本来就很好 白瑞家庭教育作品,千万父母追随,20余年经验沉淀"",""productId"":""10000852376968"",""skuId"":""15057811153""}]}],""sender"":{""name"":""陈图书"",""mobile"":""13023098035"",""province"":""安徽省"",""city"":""合肥市"",""county"":""肥西县"",""street"":"""",""address"":""上派镇中盟电子产业园8栋一单元(东电梯3楼快递指定存放点)"",""lat"":"""",""lng"":""""},""deliveryInfo"":{""appointmentType"":1,""datetime"":""20260521""},""extInfo"":{""packageWeightG"":1000},""uuid"":""37f59ae7-32fb-4e7a-89af-1d228c9d933f"",""orderVasList"":[],""source"":3}]}}";
string body = JsonHelper.SerializeObject(preWaybillOnlineparam);
string refere = "https://store.weixin.qq.com/shop/waybill/allToAll";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
//{"ret":0,"list":[{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"success","totalFee":"390","feeDetail":{"totalShippingFee":"390","totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":0,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"JTSD","orderType":1,"ewaybillOrderId":"4525894130917130247","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"success","totalFee":"440","feeDetail":{"totalShippingFee":"440","totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":0,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"YTO","orderType":1,"ewaybillOrderId":"4525894132274036739","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"success","totalFee":"440","feeDetail":{"totalShippingFee":"440","vasPriceDetail":[{"vasType":"","vasDetail":"","vasPrice":0}],"totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":1779537600,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"YUNDA","orderType":1,"ewaybillOrderId":"4525894133585330193","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"成功","totalFee":"499","feeDetail":{"totalShippingFee":"499","totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":0,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"ZTO","orderType":1,"ewaybillOrderId":"4525894130125225990","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"success","totalFee":"440","feeDetail":{"totalShippingFee":"440","totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":0,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"STO","orderType":1,"ewaybillOrderId":"4525894133215215616","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"成功","totalFee":"600","feeDetail":{"totalShippingFee":"600","totalVasFee":0,"otherFee":0,"otherFeeName":"其他费用"},"predictedArrivedTime":0,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"JD","orderType":1,"ewaybillOrderId":"4525894136920145936","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"success","totalFee":"1100","feeDetail":{"totalShippingFee":"1100","totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":1779445800,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"DBKD","orderType":1,"ewaybillOrderId":"4525894139054424087","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true},{"code":0,"responseContent":[{"retcode":1000000,"errorMsg":"","deliveryErrorMsg":"获取预估价格失败","uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"CNSD","orderType":1,"deliveryResultCode":"10002","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":false}],"showInsufficientBalance":false},{"code":0,"responseContent":[{"retcode":0,"errorMsg":"","deliveryErrorMsg":"success","totalFee":"1100","feeDetail":{"totalShippingFee":"1100","totalVasFee":0,"otherFee":0,"otherFeeName":""},"predictedArrivedTime":1779530400,"uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","deliveryId":"SF","orderType":231,"ewaybillOrderId":"4525894132961951757","deliveryResultCode":"0","errorType":0,"blockExplainUrl":{},"showInsufficientBalance":true}],"showInsufficientBalance":true}]}
return result;
}
// 设置在线寄件
public static string createOrderWaybillOnline(ShopLoginInfo shop, WXCreateOrderWaybillOnlineParam waybillOnlineparam)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodewaybill/alltoall/platCreateOrder?token=&lang=zh_CN";
//string body = @"{""payMethod"":2,""requestContent"":[{""deliveryId"":""YTO"",""ewaybillOrderId"":""4525894132274036739"",""ecOrderList"":[{""ecOrderId"":""3736528290099110144"",""goodsList"":[{""goodCount"":1,""goodName"":""荣恒教育[青春期男孩要知道的45件事]10-16岁必读告别迷茫与尴尬青春期枕边书送给孩子的成长礼物"",""productId"":""10000826945183"",""skuId"":""14514725990""}]}],""sender"":{""name"":""李"",""mobile"":""17855123321"",""province"":""江苏省"",""city"":""常州市"",""county"":""天宁区"",""street"":"""",""address"":""九洲环宇大酒店(常州青果巷火车站店)201"",""lat"":""31.779615"",""lng"":""119.974997""},""deliveryInfo"":{""appointmentType"":1,""datetime"":""20260522""},""extInfo"":{""packageWeightG"":1000},""remark"":"""",""uuid"":""1ef8b9e2-d68e-4e12-8bda-e188e246d5ae"",""orderVasList"":[],""source"":3}]}";
string body = JsonHelper.SerializeObject(waybillOnlineparam);
string refere = "https://store.weixin.qq.com/shop/waybill/allToAll";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
//{"ret":0,"code":0,"responseContent":[{"ewaybillOrderId":"4525894132274036739","retcode":0,"errorMsg":"","deliveryErrorMsg":"success","waybillId":"YT2547223870618","deliveryId":"YTO","uuid":"1ef8b9e2-d68e-4e12-8bda-e188e246d5ae","errorType":0,"deliveryResultCode":"0","blockExplainUrl":{}}],"displayNewuserTips":false,"createSuccTips":"预计 明天上门取件"}
return result;
}
public static string searchOnlineWaybill(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodewaybill/alltoall/searchBill?token=&lang=zh_CN";
string body = @"{""createMode"":1,""orderId"":""" + orderId + @""",""cosignmentOrderId"":"""",""goodsTitle"":"""",""receiverPhone"":"""",""receiverName"":"""",""billStatus"":null,""orderStatus"":null,""offset"":0,""limit"":20,""waybillId"":"""",""payMethodList"":[],""platDisplayOrderStatusList"":[],""cosignmentOrderTime"":[],""cosignmentAssignTime"":[],""storeName"":"""",""orderNote"":"""",""deliveryOrderStatusList"":[10,20,40]}";
string refere = "https://store.weixin.qq.com/shop/waybill/allToAll";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string cancelOnlineWaybill(ShopLoginInfo shop, string ewaybillOrderId, string waybillId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodewaybill/alltoall/platCancelOrder?token=&lang=zh_CN";
string body = @"{""requestContent"":[{""ewaybillOrderId"":""" + ewaybillOrderId + @""",""waybillId"":""" + waybillId + @""",""source"":1,""merchCancelReason"":""临时缺货,库存不足""}]}";
string refere = "https://store.weixin.qq.com/shop/waybill/allToAll";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string cancelActivity(ShopLoginInfo shop, JObject activityData)
{
string url = "https://store.weixin.qq.com/shop-faas/mmeckolmarketingnode/activity/cgi/updateRequestProductList?token=&lang=zh_CN";
string body = JsonHelper.SerializeObject(activityData);
string refere = "https://store.weixin.qq.com/shop/marketingkol/activity/detail?id=1016&curTab=2";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string orderSendOut(ShopLoginInfo shop, string orderId, string waybillId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/orderSendOut?token=&lang=zh_CN";
string body = @"{""orderId"":""" + orderId + @""",""deliveryProduct"":{""deliveryId"":""OTHER"",""waybillId"":""" + waybillId + @""",""isAllProduct"":true,""deliverType"":1}}";
string refere = "https://store.weixin.qq.com/shop/order/list?type=3";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string updateDeliveryInfo(ShopLoginInfo shop, UpdateDeliverInfoParam param)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/updateDeliveryInfo?token=&lang=zh_CN";
string body = JsonHelper.SerializeObject(param);
string refere = "https://store.weixin.qq.com/shop/order/list?type=3";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string initDeliveryInfo(ShopLoginInfo shop, string orderId)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/ship/cgi/initShipData?token=&lang=zh_CN";
string body = @"{""id"":""" + orderId + @"""}";
string refere = "https://store.weixin.qq.com/shop/order/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string getSkuBySpu(ShopLoginInfo shop, string spuIds)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductlist/cgi/goods/getStockBySpu?token=&lang=zh_CN";
string body = @"{""productIdList"":[" + spuIds + @"]}";
string refere = "https://store.weixin.qq.com/shop/goods/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
public static string batchUpdateStock(ShopLoginInfo shop, string spuId, string skuId, string num)
{
string url = "https://store.weixin.qq.com/shop-faas/mmecnodeproductlist/cgi/goods/batchUpdateStock?token=&lang=zh_CN";
string body = @"{""skuList"":[{""spuId"":""" + spuId + @""",""skuId"":""" + skuId + @""",""diffType"":2,""num"":" + num + "}]}";
string refere = "https://store.weixin.qq.com/shop/goods/list";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, refere);
return result;
}
}
}