其他平台买手拍单发送功能 店铺筛选功能逻辑优化

This commit is contained in:
wule committed 2026-05-15 19:27:52 +08:00
1 parent 2dece676c1
commit aa45b35145
46 files changed
+4038 -2223

No files matched your search

@@ -40,15 +40,12 @@ namespace TemuKJD.WXForms.ProductForms
bool isInit = false;
CheckBox chkSelectAll = null;
ConcurrentList<AuthInfo> lstShopAuthInfo = new ConcurrentList<AuthInfo>();
ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
public NaiBa.Util.ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new NaiBa.Util.ConcurrentList<TemuDBProductSelect>();
NaiBa.Util.ConcurrentList<AddPriceRule> lstAddPriceRule = new NaiBa.Util.ConcurrentList<AddPriceRule>();
ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new ConcurrentList<TemuDBProductSelect>();
ConcurrentList<AddPriceRule> lstAddPriceRule = new ConcurrentList<AddPriceRule>();
AddPriceRule defaultAddPriceRule = null;
WXUploadRule wxUploadRule = null;
//public Dictionary<string, List<string>> dicCheckedShopIdList = new Dictionary<string, List<string>>();
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
public Dictionary<string, WxShopUploadInfo> dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
public string pdd_product_cates = "";
public List<string> forceFilteKeyWords = new List<string>()
{
@@ -64,15 +61,9 @@ namespace TemuKJD.WXForms.ProductForms
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
{
this.splitContainer1.Dock = DockStyle.Fill;
this.panel1.Location = new Point(40, 30);
this.panel1.Width = this.Width - 80;
this.panel1.Height = this.Height - 60;
this.panel1.SendToBack();
lstShopAuthInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<AuthInfo>>("wx_shop_auth_list");
if (lstShopAuthInfo == null)
lstShopAuthInfo = new ConcurrentList<AuthInfo>();
GlobalConfig.lstWxShopAuthInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<AuthInfo>>("wx_shop_auth_list");
if (GlobalConfig.lstWxShopAuthInfo == null)
GlobalConfig.lstWxShopAuthInfo = new ConcurrentList<AuthInfo>();
lstWXShopTokenInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<NaiBa.Util.ConcurrentList<WXShopTokenInfo>>("wx_shop_token_list");
if (lstWXShopTokenInfo == null)
@@ -117,9 +108,10 @@ namespace TemuKJD.WXForms.ProductForms
dicCheckedShopId = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, bool>>("wx_checked_shop_dic");
if (dicCheckedShopId == null)
dicCheckedShopId = new Dictionary<string, bool>();
dicShopUpload = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, WxShopUploadInfo>>("wx_shop_upload_info");
if (dicShopUpload == null)
dicShopUpload = new Dictionary<string, WxShopUploadInfo>();
GlobalConfig.dicWxShopUploadInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, WxShopUploadInfo>>("wx_shop_upload_info");
if (GlobalConfig.dicWxShopUploadInfo == null)
GlobalConfig.dicWxShopUploadInfo = new Dictionary<string, WxShopUploadInfo>();
defaultAddPriceRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<AddPriceRule>("wx_default_add_price_rule");
if (defaultAddPriceRule == null)
@@ -222,7 +214,6 @@ namespace TemuKJD.WXForms.ProductForms
}));
});
this.panel1.SendToBack();
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
dgvShop.Columns["colSelect"].HeaderText = "";
//chkSelectAll.Width = chkSelectAll.Height = 13;
@@ -357,7 +348,7 @@ namespace TemuKJD.WXForms.ProductForms
List<Task> tList = new List<Task>();
if (idRefreshTodayHasGet)
lstShopAuthInfo.RemoveAll(s => updateIds.Contains(s.ShopId));
GlobalConfig.lstWxShopAuthInfo.RemoveAll(s => updateIds.Contains(s.ShopId));
foreach (var shop in GlobalConfig.ShopLoginList.Where(s => updateIds.Contains(s.ShopId)))
{
Invoke(new Action(() => { BindShop(shop, selectIds, ""); }));
@@ -371,10 +362,10 @@ namespace TemuKJD.WXForms.ProductForms
return;
}
var authInfo = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
var authInfo = GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
if (idRefreshTodayHasGet || authInfo == null || authInfo?.UpdateTime.Date != DateTime.Now.Date)
{
lstShopAuthInfo.RemoveAll(sa => sa.ShopId == shop.ShopId);
GlobalConfig.lstWxShopAuthInfo.RemoveAll(sa => sa.ShopId == shop.ShopId);
var rst = WXUpload.GetApiServiceList(shop);
if (!rst.Contains("\"code\":0"))
{
@@ -385,7 +376,7 @@ namespace TemuKJD.WXForms.ProductForms
return;
}
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = DateTime.Now });
GlobalConfig.lstWxShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = DateTime.Now });
Invoke(new Action(() => { BindShop(shop, selectIds, "授权查询失败"); }));
return;
}
@@ -396,13 +387,13 @@ namespace TemuKJD.WXForms.ProductForms
if (itemObj["serviceName"].ParseToString() == "店统领供应链-商品管理")
{
var expiresTick = itemObj["expireTime"].ParseToLong();
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = BaseClass.StampToDateTime(expiresTick.ParseToInt()) });
GlobalConfig.lstWxShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = BaseClass.StampToDateTime(expiresTick.ParseToInt()) });
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
return;
}
}
// 没找到指定服务
lstShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = DateTime.Now });
GlobalConfig.lstWxShopAuthInfo.Add(new AuthInfo() { ShopId = shop.ShopId, UpdateTime = DateTime.Now, ExpiresTime = DateTime.Now });
Invoke(new Action(() => { BindShop(shop, selectIds, "已查询"); }));
}
}
@@ -414,7 +405,7 @@ namespace TemuKJD.WXForms.ProductForms
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 20) { Thread.Sleep(100); }
}
while (tList.Where(ta => !ta.IsFaulted && !ta.IsCompleted).Count() >= 1) { Thread.Sleep(100); }
NaiBa.Util.Helper.ConfigHelper.SaveConfig( "wx_shop_auth_list", lstShopAuthInfo);
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_auth_list", GlobalConfig.lstWxShopAuthInfo);
Invoke(new Action(() => { pbLoadingShop.Visible = false; }));
});
}
@@ -583,11 +574,15 @@ namespace TemuKJD.WXForms.ProductForms
BindShop(shopEntity, selectIds);
}
cmbFilterShopNotes.Items.Clear();
//cmbFilterShopNotes.Items.Add("");
foreach (var note in GlobalConfig.ShopLoginList.Select(s => s.Notes).Where(s => !s.IsNullOrEmpty()).Distinct())
{
cmbFilterShopNotes.Items.Add(note);
}
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 = "")
@@ -612,14 +607,15 @@ namespace TemuKJD.WXForms.ProductForms
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.Notes,
shopEntity.GroupName,
"选择商品",
canUse ? "在线" : "掉线",
lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期",
canUse,
dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
dicShopUpload[shopEntity.ShopId].DicDayUploadCount[day] : 0,
dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
dicShopUpload[shopEntity.ShopId].OnSaleCount : 0,
GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) && GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].DicDayUploadCount[day] : 0,
GlobalConfig.dicWxShopUploadInfo.ContainsKey(shopEntity.ShopId) && GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
GlobalConfig.dicWxShopUploadInfo[shopEntity.ShopId].OnSaleCount : 0,
shopEntity.AddProductRemaining,
msg
);
@@ -633,12 +629,10 @@ namespace TemuKJD.WXForms.ProductForms
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "掉线";
row.Cells["colLoginStatus"].Style.ForeColor = canUse ? Color.Green : Color.Red;
row.Cells["colCanUse"].Value = canUse;
row.Cells["colApi"].Value = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shopEntity.ShopId)?.ExpiresTime > DateTime.Now.AddMinutes(5) ? "可用" : "过期";
row.Cells["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 = dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].DicDayUploadCount.ContainsKey(day) ?
dicShopUpload[shopEntity.ShopId].DicDayUploadCount[day] : 0;
row.Cells["colOnSaleNum"].Value = dicShopUpload.ContainsKey(shopEntity.ShopId) && dicShopUpload[shopEntity.ShopId].OnSaleRefreshDay == DateTime.Now.ToString("yyyyMMdd").ParseToInt() ?
dicShopUpload[shopEntity.ShopId].OnSaleCount : 0;
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;
}
@@ -1798,7 +1792,7 @@ namespace TemuKJD.WXForms.ProductForms
token = new WXShopTokenInfo();
if (token.isExpire || string.IsNullOrEmpty(token.accessToken))
{
AuthInfo auth = lstShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
AuthInfo auth = GlobalConfig.lstWxShopAuthInfo.FirstOrDefault(sa => sa.ShopId == shop.ShopId);
if (auth != null && auth.ExpiresTime > DateTime.Now.AddMinutes(5))
{
token = new WxApiBLL().GetShopWxToken(shop);
@@ -2635,6 +2629,7 @@ namespace TemuKJD.WXForms.ProductForms
var addressArr = JsonHelper.JObjectParse(expressRst)["freightTemplateList"];
foreach (var addressObj in addressArr)
{
var addressStr = JsonHelper.SerializeObject(addressObj);
if (addressObj["isDefault"].ParseToInt() == 1)
{
string templateId = addressObj["templateId"].ParseToString();
@@ -2643,6 +2638,11 @@ namespace TemuKJD.WXForms.ProductForms
break;
}
}
if (upProdParam.product.info.expressInfo == null)
{
upProdParam.product.info.expressInfo = new expressInfoParam();
upProdParam.product.info.expressInfo.templateId = BaseRegex.GetStringJson(ref expressRst, "templateId");
}
}
catch (Exception ex)
{
@@ -4238,22 +4238,22 @@ namespace TemuKJD.WXForms.ProductForms
if (dgvShopRow != null)
{
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
if (!dicShopUpload.ContainsKey(shop.ShopId))
dicShopUpload[shop.ShopId] = new WxShopUploadInfo();
if (!dicShopUpload[shop.ShopId].DicDayUploadCount.ContainsKey(day))
dicShopUpload[shop.ShopId].DicDayUploadCount[day] = 0;
dicShopUpload[shop.ShopId].DicDayUploadCount[day] += 1;
if (!GlobalConfig.dicWxShopUploadInfo.ContainsKey(shop.ShopId))
GlobalConfig.dicWxShopUploadInfo[shop.ShopId] = new WxShopUploadInfo();
if (!GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.ContainsKey(day))
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] = 0;
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] += 1;
// 删除45天前的记录
var removeKeys = dicShopUpload[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt()).ToList();
var removeKeys = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt()).ToList();
foreach (var key in removeKeys)
{
dicShopUpload[shop.ShopId].DicDayUploadCount.Remove(key);
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Remove(key);
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", dicShopUpload);
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", GlobalConfig.dicWxShopUploadInfo);
Invoke(new Action(() =>
{
dgvShopRow.Cells["colUploadCount"].Value = dicShopUpload[shop.ShopId].DicDayUploadCount[day];
dgvShopRow.Cells["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day];
}));
}
@@ -4902,22 +4902,22 @@ namespace TemuKJD.WXForms.ProductForms
if (dgvShopRow != null)
{
var day = DateTime.Now.ToString("yyyyMMdd").ParseToInt();
if (!dicShopUpload.ContainsKey(shop.ShopId))
dicShopUpload[shop.ShopId] = new WxShopUploadInfo();
if (!dicShopUpload[shop.ShopId].DicDayUploadCount.ContainsKey(day))
dicShopUpload[shop.ShopId].DicDayUploadCount[day] = 0;
dicShopUpload[shop.ShopId].DicDayUploadCount[day] += 1;
if (!GlobalConfig.dicWxShopUploadInfo.ContainsKey(shop.ShopId))
GlobalConfig.dicWxShopUploadInfo[shop.ShopId] = new WxShopUploadInfo();
if (!GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.ContainsKey(day))
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] = 0;
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day] += 1;
// 删除45天前的记录
var removeKeys = dicShopUpload[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt());
var removeKeys = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Keys.Where(s => s < DateTime.Now.AddDays(-45).ToString("yyyyMMdd").ParseToInt());
foreach (var key in removeKeys)
{
dicShopUpload[shop.ShopId].DicDayUploadCount.Remove(key);
GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount.Remove(key);
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", dicShopUpload);
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_upload_info", GlobalConfig.dicWxShopUploadInfo);
Invoke(new Action(() =>
{
dgvShopRow.Cells["colUploadCount"].Value = dicShopUpload[shop.ShopId].DicDayUploadCount[day];
dgvShopRow.Cells["colUploadCount"].Value = GlobalConfig.dicWxShopUploadInfo[shop.ShopId].DicDayUploadCount[day];
}));
}
}
@@ -5135,13 +5135,18 @@ namespace TemuKJD.WXForms.ProductForms
private void btnFilterShop_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dgvShop.Rows)
{
string notes = cmbFilterShopNotes.Text.Trim().Trim(';');
if (notes == "全部")
notes = "";
List<string> notesLst = notes.Split(new string[] { ";", ";", ",", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
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;
@@ -5154,6 +5159,12 @@ namespace TemuKJD.WXForms.ProductForms
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;
}
}
@@ -5162,6 +5173,7 @@ namespace TemuKJD.WXForms.ProductForms
{
txtFilterShopName.Text = "";
cmbFilterShopNotes.Text = "全部";
cmbFilterShopGroup.Text = "全部";
btnFilterShop_Click(null, null);
}
@@ -5181,16 +5193,24 @@ namespace TemuKJD.WXForms.ProductForms
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 == true)
{
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
{
row.Cells["colSelect"].Value = true;
}
}
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;
}
}
@@ -5201,16 +5221,24 @@ namespace TemuKJD.WXForms.ProductForms
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 == true)
{
if (row.Cells["colShopName"].Value.ParseToString().Contains(txtFilterShopName.Text.Trim()) &&
(string.IsNullOrWhiteSpace(notes) || notesLst.Contains(row.Cells["colShopNotes"].Value.ParseToString())))
{
row.Cells["colSelect"].Value = false;
}
}
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;
}
}