994 lines
46 KiB
C#
994 lines
46 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Result;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net.Http;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.ToolForms;
|
||
using Work;
|
||
using TemuKJD.BLL;
|
||
using System.Text.RegularExpressions;
|
||
using TemuKJD.PDDForms.ProductSelectForms;
|
||
using TemuKJD.WXForms.ShopForms;
|
||
using AllBase.Model.Result.PDDResult;
|
||
using AllBase.Model.Param.WXParam;
|
||
using AllBase.Model.Result.WXResult;
|
||
using Newtonsoft.Json;
|
||
using NaiBa.Util;
|
||
using AllBase.Model.Config;
|
||
using TemuKJD.BLL.Wx;
|
||
|
||
namespace TemuKJD.WXForms.ProductForms
|
||
{
|
||
public partial class WXOrderConsignmentForm : BaseForm
|
||
{
|
||
int PageBegin = 1;
|
||
int PageEnd = 1000;
|
||
string OnSaleStatus = "在售";
|
||
|
||
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 WXOrderConsignmentForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
|
||
{
|
||
this.splitContainer1.Dock = DockStyle.Fill;
|
||
|
||
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.dgvSelectProduct.AddSelectorColumn("colCheck");
|
||
|
||
dgvSelectProduct.AddImgColumn("colProductSkcPic", "colImgUrl");
|
||
|
||
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 note in GlobalConfig.ShopLoginList.Select(s => s.GroupName).Where(s => !s.IsNullOrEmpty()).Distinct())
|
||
{
|
||
cmbFilterShopGroup.Items.Add(note);
|
||
}
|
||
}
|
||
|
||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null, string msg = "")
|
||
{
|
||
if (shopEntity == null)
|
||
return;
|
||
if (shopEntity.is_point_shop_expire)
|
||
return;
|
||
if (selectShopId == null)
|
||
selectShopId = new List<string>();
|
||
|
||
bool canUse = shopEntity.LoginStatus == "登录成功";
|
||
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 = dgvSelectProduct.Columns[e.ColumnIndex].HeaderText;
|
||
var shopId = dgvSelectProduct.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToString();
|
||
var draftId = dgvSelectProduct.Rows[e.RowIndex].Cells["colDraftId"].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.InitUrl = "https://store.weixin.qq.com/shop/order/consignment";
|
||
shopLoginForm.Show();
|
||
}
|
||
else
|
||
{
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.ShowDialog();
|
||
RefreshShopLogin();
|
||
}
|
||
}
|
||
break;
|
||
case "图片":
|
||
{
|
||
ShowImgForm imgFrom = new ShowImgForm(dgvSelectProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString());
|
||
imgFrom.ShowDialog();
|
||
break;
|
||
}
|
||
case "操作":
|
||
{
|
||
if (BaseMsgForm.ShowConfirm("确认要取消分配吗?取消分配后,订单将回到待分配状态").DialogResult != DialogResult.OK)
|
||
return;
|
||
this.pbLoading.Visible = true;
|
||
Task.Run(() =>
|
||
{
|
||
CancelConsignment(new List<DataGridViewRow>() { dgvSelectProduct.Rows[e.RowIndex] });
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = false;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
break;
|
||
}
|
||
case "":
|
||
dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvSelectProduct.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
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();
|
||
dgvSelectProduct.Rows.Clear();
|
||
Task.Run(() =>
|
||
{
|
||
GetConsignmentOrder(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 GetConsignmentOrder(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;
|
||
}
|
||
|
||
var onRst = WXOrderConsignment.getConsignmentOnOffStatus(shop);
|
||
if (!onRst.Contains("\"isOpen\":true}"))
|
||
continue;
|
||
|
||
int page = PageBegin - 1;
|
||
int totalPage = 1;
|
||
int pageSize = 30;
|
||
while (page < totalPage && page < PageEnd)
|
||
{
|
||
page++;
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
// 查找订单
|
||
pageSize = 30;
|
||
var result = WXOrderConsignment.searchConsignmentOrder(shop, page, pageSize, rbWaitDivide.Checked);
|
||
if (!result.Contains("\"code\":0"))
|
||
{
|
||
ShowShopError(shop, result);
|
||
break;
|
||
}
|
||
totalPage = Math.Ceiling(BaseRegex.GetIntJson(ref result, "totalCount") * 1m / pageSize).ParseToInt();
|
||
List<WxConsignmentOrderInfo> consignmentOrderLst = new List<WxConsignmentOrderInfo>();
|
||
try
|
||
{
|
||
var jArr = JsonHelper.JObjectParse(result)["orderList"];
|
||
consignmentOrderLst = JsonHelper.DeserializeJsonToList<WxConsignmentOrderInfo>(JsonHelper.SerializeObject(jArr));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowShopError(shop, ex.Message);
|
||
break;
|
||
}
|
||
Thread.Sleep(Randomx.GetId(200, 1000));
|
||
|
||
// 查找对应商品
|
||
string getProdOnSaleRst = "";
|
||
if (consignmentOrderLst.Count > 0 && consignmentOrderLst.All(c => !c.commonInfo.cosignmentOrderId.IsNullOrEmpty()))
|
||
{
|
||
int onSaleStatusCode = -1;
|
||
if (OnSaleStatus == "在售")
|
||
onSaleStatusCode = 5;
|
||
else if (OnSaleStatus == "下架")
|
||
onSaleStatusCode = 11;
|
||
else if (OnSaleStatus == "审核待处理")
|
||
onSaleStatusCode = 3;
|
||
else if (OnSaleStatus == "草稿箱")
|
||
onSaleStatusCode = 1;
|
||
else if (OnSaleStatus == "回收站")
|
||
onSaleStatusCode = 6;
|
||
pageSize = 50;
|
||
string spuIds = string.Join(",", consignmentOrderLst.Select(r => string.Join(",", r.productsList.Select(p => p.productId))));
|
||
getProdOnSaleRst = WXClearNoVisit.searchProduct(shop, 1, pageSize, spuIds, onSaleStatusCode);
|
||
Thread.Sleep(Randomx.GetId(50, 100));
|
||
if (!getProdOnSaleRst.Contains("\"success\":true"))
|
||
{
|
||
ShowShopError(shop, getProdOnSaleRst);
|
||
break;
|
||
}
|
||
}
|
||
|
||
try
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在查询店铺:" + shop.ShopAccount + " " + page + "/" + Math.Min(PageEnd, totalPage);
|
||
}));
|
||
var prodObjs = JsonHelper.JObjectParse(getProdOnSaleRst);
|
||
foreach (var order in consignmentOrderLst)
|
||
{
|
||
foreach (var prodLite in order.productsList)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var spuCode = prodLite.spuCode;
|
||
var prod = prodObjs["productList"].FirstOrDefault(p => p["productId"].ParseToString() == prodLite.productId);
|
||
if (prod != null)
|
||
{
|
||
var pStr = JsonHelper.SerializeObject(prod);
|
||
spuCode = prod["spuCode"].ParseToString();
|
||
}
|
||
|
||
var rowIndex = this.dgvSelectProduct.Rows.Add(
|
||
false,
|
||
shop.ShopId,
|
||
shop.ShopAccount,
|
||
"登录",
|
||
"进店",
|
||
order.commonInfo.cosignmentOrderId,
|
||
order.commonInfo.supplierName,
|
||
order.commonInfo.createTimeStr,
|
||
order.commonInfo.orderId,
|
||
order.commonInfo.orderCreateTimeStrForB.ParseToDateTime().ToString("M/d HH:mm"),
|
||
prodLite.productId,
|
||
prodLite.skuId,
|
||
prodLite.thumbImg,
|
||
DataGridViewExtension.defaultBitmap,
|
||
prodLite.title + string.Join(";", prodLite.saleParam), // 商品名称
|
||
spuCode, // 商品编号
|
||
prodLite.realPrice * 0.01m + "\r\nx" + prodLite.productCnt, // 商品单价/数量
|
||
order.commonInfo.statusStr,
|
||
order.notesInfo.merchantNotes,
|
||
"取消分配",
|
||
""
|
||
);
|
||
|
||
dgvSelectProduct.Rows[rowIndex].Height = 60;
|
||
//Color color = Color.Red;
|
||
//if (dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Value.ParseToString() == "在售")
|
||
// color = Color.Blue;
|
||
//if (dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Value.ParseToString() == "下架")
|
||
// color = Color.Purple;
|
||
//if (dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Value.ParseToString() == "草稿箱")
|
||
// color = Color.DarkOrange;
|
||
//if (dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Value.ParseToString() == "回收站")
|
||
// color = Color.Gray;
|
||
//dgvSelectProduct.Rows[rowIndex].Cells["colMsg"].Style.ForeColor = color;
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnClearDgv_Click(object sender, EventArgs e)
|
||
{
|
||
var rows = this.dgvSelectProduct.Rows.Cast<DataGridViewRow>().ToList(); //Cast后Rows做foreach循环时仍会夹花跳过,所以要ToList转一个新的数组。
|
||
foreach (var row in rows)
|
||
{
|
||
if (row.Cells["colCheck"].Value.ParseToBool() == true)
|
||
{
|
||
//var draft_id = row.Cells["colDraftId"].Value.ParseToString();
|
||
//upload_draft_product_lst.RemoveAll(p => p.draft_id == draft_id);
|
||
|
||
this.dgvSelectProduct.Rows.Remove(row);
|
||
}
|
||
}
|
||
//NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_select_upload_draft_products", upload_draft_product_lst);
|
||
}
|
||
|
||
private void btnClearFilter_Click(object sender, EventArgs e)
|
||
{
|
||
}
|
||
|
||
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 btnCancelConsignment_Click(object sender, EventArgs e)
|
||
{
|
||
var rowLst = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
|
||
if (rowLst.Count <= 0)
|
||
{
|
||
BaseMsgForm.ShowError("请勾选需要操作的订单!");
|
||
return;
|
||
}
|
||
|
||
if (BaseMsgForm.ShowConfirm("确认要取消分配吗?取消分配后,订单将回到待分配状态").DialogResult != DialogResult.OK)
|
||
return;
|
||
|
||
this.pbLoading.Visible = true;
|
||
if (cancellationTokenSource != null && !cancellationTokenSource.IsCancellationRequested)
|
||
cancellationTokenSource.Cancel();
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
CancelConsignment(rowLst);
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "取消分配中断";
|
||
BaseMsgForm.ShowInfo("取消分配中断");
|
||
}
|
||
else
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "取消分配完毕";
|
||
BaseMsgForm.ShowInfo("取消分配完毕");
|
||
}
|
||
|
||
this.pbLoading.Visible = false;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
void CancelConsignment(List<DataGridViewRow> rowLst)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.pbLoading.Visible = true;
|
||
this.statusBar.lblTaskStatus.Text = "正在取消分配" + "...".Substring(0, DateTime.Now.Second % 4);
|
||
this.statusBar.pgbTaskProgress.Maximum = rowLst.Count;
|
||
this.statusBar.UpdateProgressBar(0);
|
||
}));
|
||
|
||
while (rowLst.Count > 0)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var r0 = rowLst.FirstOrDefault();
|
||
var shopId = r0.Cells["colSupplierId"].Value.ParseToString();
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
var rowLstTmp = rowLst.Where(r => r.Cells["colSupplierId"].Value.ParseToString() == shopId).Take(1).ToList();
|
||
|
||
foreach (var r in rowLstTmp)
|
||
{
|
||
rowLst.RemoveAll(rw => rw.Cells["colConsignmentOrderId"].Value == r.Cells["colConsignmentOrderId"].Value);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在取消分配" + "...".Substring(0, DateTime.Now.Second % 4);
|
||
this.statusBar.UpdateProgressBar(this.statusBar.pgbTaskProgress.Value + 1);
|
||
r.Cells["colOpResult"].Value = "";
|
||
}));
|
||
}
|
||
if (shop == null)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var r in rowLstTmp)
|
||
{
|
||
r.Cells["colOpResult"].Value = "店铺不存在";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var r in rowLstTmp)
|
||
{
|
||
r.Cells["colOpResult"].Value = "店铺掉线";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
//{"cosignmentOrderId":"4436464658179189760","cosignmentProductList":[{"spuId":"10000826730228","skuId":"14511204738","cancelScene":2}],"orderId":"3736464645960385280"}
|
||
JObject cancelAssignOrderData = new JObject();
|
||
foreach (var row in rowLstTmp)
|
||
{
|
||
cancelAssignOrderData["cosignmentOrderId"] = row.Cells["colConsignmentOrderId"].Value.ParseToString();
|
||
var jArr = new JArray();
|
||
var dgvrs = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(dgvr => dgvr.Cells["colConsignmentOrderId"] == row.Cells["colConsignmentOrderId"]).ToList();
|
||
foreach (var dgvr in dgvrs)
|
||
{
|
||
JObject jProd = new JObject();
|
||
jProd["spuId"] = dgvr.Cells["colDraftId"].Value.ParseToString();
|
||
jProd["skuId"] = dgvr.Cells["colSkuId"].Value.ParseToString();
|
||
jProd["cancelScene"] = 2;
|
||
jArr.Add(jProd);
|
||
}
|
||
cancelAssignOrderData["cosignmentProductList"] = jArr;
|
||
cancelAssignOrderData["orderId"] = row.Cells["colOrderId"].Value.ParseToString();
|
||
}
|
||
|
||
var cancelRst = WXOrderConsignment.cancelConsignmentOrder(shop, cancelAssignOrderData);
|
||
Thread.Sleep(Randomx.GetId(500, 1000));
|
||
if (!cancelRst.Contains("\"code\":0"))
|
||
{
|
||
if (cancelRst.Contains("biz magic invalid"))
|
||
{
|
||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||
if (shop.LoginStatus != "登录成功")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rowLstTmp)
|
||
{
|
||
row.Cells["colOpResult"].Value = "店铺掉线";
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
}
|
||
|
||
var errmsg = BaseRegex.GetStringJson(ref cancelRst, "msg");
|
||
if (string.IsNullOrWhiteSpace(errmsg))
|
||
errmsg = cancelRst;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rowLstTmp)
|
||
{
|
||
var dgvrs = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(dgvr => dgvr.Cells["colConsignmentOrderId"] == row.Cells["colConsignmentOrderId"]).ToList();
|
||
foreach (var dgvr in dgvrs)
|
||
dgvr.Cells["colOpResult"].Value = errmsg;
|
||
}
|
||
}));
|
||
}
|
||
|
||
if (cancelRst.Contains("\"code\":0"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
foreach (var row in rowLstTmp)
|
||
{
|
||
var dgvrs = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(dgvr => dgvr.Cells["colConsignmentOrderId"] == row.Cells["colConsignmentOrderId"]).ToList();
|
||
foreach (var dgvr in dgvrs)
|
||
dgvr.Cells["colOpResult"].Value = "取消分配成功";
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
private void btnFiltSelect_Click(object sender, EventArgs e)
|
||
{
|
||
foreach (DataGridViewRow row in dgvSelectProduct.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)
|
||
{
|
||
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 != "登录成功")
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, new List<string> { shop.ShopId }, "店铺掉线"); }));
|
||
}
|
||
else
|
||
{
|
||
Invoke(new Action(() => { BindShop(shop, new List<string> { shop.ShopId }, error); }));
|
||
}
|
||
}
|
||
}
|
||
|
||
public class WXOrderConsignment
|
||
{
|
||
public static string getConsignmentOnOffStatus(ShopLoginInfo shop)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodesuppliercosignment/associate/cgi/getOpenStatus?token=&lang=zh_CN";
|
||
string data = "{}";
|
||
string refere = "https://store.weixin.qq.com/shop/order/consignment";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, refere);
|
||
return result;
|
||
}
|
||
|
||
public static string searchConsignmentOrder(ShopLoginInfo shop, int pageNum, int pageSize = 30, bool isWaitDevide = false)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodesuppliercosignment/order/cgi/orderSearch?token=&lang=zh_CN";
|
||
string data = @"{""pageSize"":" + pageSize + @",""page"":" + pageNum + @",""tab"":1}";
|
||
if (isWaitDevide)
|
||
data = @"{""pageSize"":" + pageSize + @",""page"":" + pageNum + @",""orderStatus"":20,""availCosignment"":true}";
|
||
|
||
//string body = @"{""pageSize"":30,""page"":1,""startCreateTime"":"""",""endCreateTime"":"""",""orderId"":"""",""title"":"""",""productCode"":"""",""merchantNotes"":"""",""orderStatus"":20,""availCosignment"":true}";
|
||
//string body = @"{""pageSize"":30,""page"":1,""beginTime"":"""",""endTime"":"""",""createBeginTime"":"""",""createEndTime"":"""",""orderId"":"""",""consignmentOrderId"":"""",""waybillId"":"""",""supplierName"":"""",""productCode"":"""",""spuName"":"""",""note"":"""",""tab"":1}";
|
||
|
||
string refere = "https://store.weixin.qq.com/shop/order/consignment";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, refere);
|
||
return result;
|
||
}
|
||
public static string addConsignmentOrder(ShopLoginInfo shop, JObject dataObj)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodesuppliercosignment/order/cgi/cancelAssignOrder?token=&lang=zh_CN";
|
||
string data = JsonHelper.SerializeObject(dataObj);
|
||
|
||
//{"appid":"wx154836518ed19b88","assignCosignmentList":[{"orderId":"3736464645960385280","cosignmentProductList":[{"spuId":"10000826730228","skuId":"14511204738"}]}]}
|
||
|
||
string refere = "https://store.weixin.qq.com/shop/order/consignment";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, refere);
|
||
return result;
|
||
}
|
||
public static string cancelConsignmentOrder(ShopLoginInfo shop, JObject dataObj)
|
||
{
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodesuppliercosignment/order/cgi/cancelAssignOrder?token=&lang=zh_CN";
|
||
string data = JsonHelper.SerializeObject(dataObj);
|
||
|
||
//{"cosignmentOrderId":"4436464658179189760","cosignmentProductList":[{"spuId":"10000826730228","skuId":"14511204738","cancelScene":2}],"orderId":"3736464645960385280"}
|
||
|
||
string refere = "https://store.weixin.qq.com/shop/order/consignment";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, data, refere);
|
||
return result;
|
||
}
|
||
}
|
||
|
||
}
|