Files
KJD_WebService/TEMUKJD/KJDForms/SalesCenterForms/FullMinusForm.cs
T
2025-07-09 10:09:32 +08:00

1056 lines
49 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 CefSharp.WinForms;
using TemuKJD.Extension;
using TemuKJD.Helper;
using TemuKJD.KJDForms.BaseForms;
using TemuKJD.KJDForms.ShopForms;
using NaiBa.CefHelper;
using NaiBa.CefHelper.Handler;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TemuKJD.KJDForms.SalesCenterForms
{
public partial class FullMinusForm : Form
{
public FullMinusForm()
{
InitializeComponent();
}
private CheckBox chkSelectAll = null;
private List<string> lstShopId = new List<string>();
public ChromiumWebBrowser webBrowser = null;
public CancellationTokenSource cancellationTokenSource = null;
private void FullMinusForm_Load(object sender, EventArgs e)
{
this.ucTabControl1.TabPages.Clear();
chkSelectAll = dgvShop.Columns["colSelect"].AddHeaderCheckBox(HorizontalAlignment.Center, 0, 0, null, null, false);
dgvShop.Columns["colSelect"].HeaderText = "";
chkSelectAll.Width = chkSelectAll.Height = 13;
chkSelectAll.CheckedChanged += chkSelectAll_CheckedChanged;
dptStartTime.Value = DateTime.Now;
dptEndTime.Value = dptStartTime.Value.AddDays(1).AddSeconds(-1);
}
private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
if (!chkSelectAll.Checked)
{
lstShopId.Clear();
foreach (DataGridViewRow row in dgvShop.Rows)
{
row.Cells["colSelect"].Value = false;
}
}
else
{
lstShopId.Clear();
var list = GlobalConfig.ShopLoginList.Where(s => s.ApiAuthStatus == "授权成功" && s.LoginStatus == "登录成功").Select(ss => ss.ShopId);
lstShopId.AddRange(list);
foreach (DataGridViewRow row in dgvShop.Rows)
{
if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
row.Cells["colSelect"].Value = true;
}
}
}
private void FullMinusForm_VisibleChanged(object sender, EventArgs e)
{
if (Visible == true)
RefreshShop();
}
private void RefreshShop()
{
// 更新选中的上货店铺Id
lstShopId = lstShopId.Where(id => GlobalConfig.ShopLoginList.Any(s => s.ShopId == id && s.LoginStatus == "已授权")).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)
{
BindShop(shopEntity);
}
}
private void BindShop(ShopLoginInfo shopEntity)
{
if (shopEntity == null)
return;
bool canUse = shopEntity.ApiAuthStatus == "授权成功" && shopEntity.LoginStatus == "登录成功";
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
if (row == null)
{
this.dgvShop.Rows.Add(
lstShopId.Contains(shopEntity.ShopId) && canUse,
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.ApiAuthStatus,
shopEntity.LoginStatus,
canUse,
string.Empty
);
}
else
{
row.Cells["colSelect"].Value = lstShopId.Contains(shopEntity.ShopId) && canUse;
if (!row.Cells["colSelect"].Value.ParseToBool())
chkSelectAll.Checked = false;
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
row.Cells["colAuthStatus"].Value = shopEntity.ApiAuthStatus;
row.Cells["colLoginStatus"].Value = shopEntity.LoginStatus;
row.Cells["colCanUse"].Value = canUse;
}
}
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;
long shopId = dgvShop.Rows[e.RowIndex].Cells["colShopId"].Value.ParseToLong();
string shopName = dgvShop.Rows[e.RowIndex].Cells["colShopId"].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();
if (dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value.ParseToBool())
{
if (lstShopId.Any(p => p == shopId.ToString()))
lstShopId.RemoveAll(p => p == shopId.ToString());
lstShopId.Add(shopId.ToString());
}
else
lstShopId.Remove(shopId.ToString());
if (dgvShop.Rows.Cast<DataGridViewRow>().All(r => r.Cells["colSelect"].Value.ParseToBool()))
chkSelectAll.Checked = true;
else
chkSelectAll.Checked = false;
}
else
{
BaseMsgForm.ShowInfo("店铺未授权或未登录!");
}
break;
}
}
private void rdoOverYuan_CheckedChanged(object sender, EventArgs e)
{
if (rdoOverPieces.Checked)
{
ucGroupBoxEx3.Visible = false;
ucGroupBoxEx4.Location = new Point(ucGroupBoxEx3.Location.X, ucGroupBoxEx3.Location.Y);
ucGroupBoxEx4.Visible = true;
if (rdoDiscount.Checked)
{
panel12.Visible = false;
panel16.Visible = true;
}
else if (rdoReduction.Checked)
{
panel12.Visible = true;
panel16.Visible = false;
}
}
else if (rdoOverYuan.Checked)
{
ucGroupBoxEx3.Visible = true;
ucGroupBoxEx4.Visible = false;
}
}
private void btnAdd1_Click(object sender, EventArgs e)
{
if (btnAdd1.Text == "增加规则(1/5)")
{
panel3.Visible = true;
btnRemove1.Enabled = true;
btnAdd1.Text = "增加规则(2/5)";
}
else if (btnAdd1.Text == "增加规则(2/5)")
{
panel4.Visible = true;
btnAdd1.Text = "增加规则(3/5)";
}
else if (btnAdd1.Text == "增加规则(3/5)")
{
panel6.Visible = true;
btnAdd1.Text = "增加规则(4/5)";
}
else if (btnAdd1.Text == "增加规则(4/5)")
{
panel7.Visible = true;
btnAdd1.Text = "增加规则(5/5)";
btnAdd1.Enabled = false;
}
}
public string getbtnAdd1(string str)
{
var res = "增加规则(1/5)";
if (str == "增加规则(5/5)")
res = "增加规则(4/5)";
else if (str == "增加规则(4/5)")
res = "增加规则(3/5)";
else if (str == "增加规则(3/5)")
res = "增加规则(2/5)";
return res;
}
private void btnRemove1_Click(object sender, EventArgs e)
{
if (panel7.Visible)
{
txtP1.Text = txtP3.Text;
txtP2.Text = txtP4.Text;
txtP3.Text = txtP5.Text;
txtP4.Text = txtP6.Text;
txtP5.Text = txtP7.Text;
txtP6.Text = txtP8.Text;
txtP7.Text = txtP9.Text;
txtP8.Text = txtP10.Text;
txtP9.Text = txtP10.Text = string.Empty;
panel7.Visible = false;
}
else if (panel6.Visible)
{
txtP1.Text = txtP3.Text;
txtP2.Text = txtP4.Text;
txtP3.Text = txtP5.Text;
txtP4.Text = txtP6.Text;
txtP5.Text = txtP7.Text;
txtP6.Text = txtP8.Text;
txtP7.Text = txtP8.Text = string.Empty;
panel6.Visible = false;
}
else if (panel4.Visible)
{
txtP1.Text = txtP3.Text;
txtP2.Text = txtP4.Text;
txtP3.Text = txtP5.Text;
txtP4.Text = txtP6.Text;
txtP5.Text = txtP6.Text = string.Empty;
panel4.Visible = false;
}
else if (panel3.Visible)
{
txtP1.Text = txtP3.Text;
txtP2.Text = txtP4.Text;
txtP3.Text = txtP4.Text = string.Empty;
panel3.Visible = false;
btnRemove1.Enabled = false;
}
btnAdd1.Text = getbtnAdd1(btnAdd1.Text);
if (!btnAdd1.Enabled)
btnAdd1.Enabled = true;
}
private void btnRemove2_Click(object sender, EventArgs e)
{
if (panel7.Visible)
{
txtP3.Text = txtP5.Text;
txtP4.Text = txtP6.Text;
txtP5.Text = txtP7.Text;
txtP6.Text = txtP8.Text;
txtP7.Text = txtP9.Text;
txtP8.Text = txtP10.Text;
txtP9.Text = txtP10.Text = string.Empty;
panel7.Visible = false;
}
else if (panel6.Visible)
{
txtP3.Text = txtP5.Text;
txtP4.Text = txtP6.Text;
txtP5.Text = txtP7.Text;
txtP6.Text = txtP8.Text;
txtP7.Text = txtP8.Text = string.Empty;
panel6.Visible = false;
}
else if (panel4.Visible)
{
txtP3.Text = txtP5.Text;
txtP4.Text = txtP6.Text;
txtP5.Text = txtP6.Text = string.Empty;
panel4.Visible = false;
}
else
{
txtP3.Text = txtP4.Text = string.Empty;
panel3.Visible = false;
}
btnAdd1.Text = getbtnAdd1(btnAdd1.Text);
if (!btnAdd1.Enabled)
btnAdd1.Enabled = true;
}
private void btnRemove3_Click(object sender, EventArgs e)
{
if (panel7.Visible)
{
txtP5.Text = txtP7.Text;
txtP6.Text = txtP8.Text;
txtP7.Text = txtP9.Text;
txtP8.Text = txtP10.Text;
txtP9.Text = txtP10.Text = string.Empty;
panel7.Visible = false;
}
else if (panel6.Visible)
{
txtP5.Text = txtP7.Text;
txtP6.Text = txtP8.Text;
txtP7.Text = txtP8.Text = string.Empty;
panel6.Visible = false;
}
else
{
txtP5.Text = txtP6.Text = string.Empty;
panel4.Visible = false;
}
btnAdd1.Text = getbtnAdd1(btnAdd1.Text);
if (!btnAdd1.Enabled)
btnAdd1.Enabled = true;
}
private void btnRemove4_Click(object sender, EventArgs e)
{
if (panel7.Visible)
{
txtP7.Text = txtP9.Text;
txtP8.Text = txtP10.Text;
txtP9.Text = txtP10.Text = string.Empty;
panel7.Visible = false;
}
else
{
txtP7.Text = txtP8.Text = string.Empty;
panel6.Visible = false;
}
btnAdd1.Text = getbtnAdd1(btnAdd1.Text);
if (!btnAdd1.Enabled)
btnAdd1.Enabled = true;
}
private void btnRemove5_Click(object sender, EventArgs e)
{
txtP9.Text = txtP10.Text = string.Empty;
panel7.Visible = false;
btnAdd1.Text = "增加规则(4/5)";
if (!btnAdd1.Enabled)
btnAdd1.Enabled = true;
}
private void btnAdd2_Click(object sender, EventArgs e)
{
if (btnAdd2.Text == "增加规则(1/3)")
{
panel10.Visible = true;
btnRemove6.Enabled = true;
btnAdd2.Text = "增加规则(2/3)";
}
else if (btnAdd2.Text == "增加规则(2/3)")
{
panel11.Visible = true;
btnAdd2.Text = "增加规则(3/3)";
btnAdd2.Enabled = false;
}
}
public string getbtnAdd2(string str)
{
var res = "增加规则(1/3)";
if (str == "增加规则(3/3)")
res = "增加规则(2/3)";
return res;
}
private void btnRemove6_Click(object sender, EventArgs e)
{
if (panel11.Visible)
{
txtP11.Text = txtP13.Text;
txtP12.Text = txtP14.Text;
txtP13.Text = txtP15.Text;
txtP14.Text = txtP16.Text;
txtP15.Text = txtP16.Text = string.Empty;
panel11.Visible = false;
}
else if (panel10.Visible)
{
txtP11.Text = txtP13.Text;
txtP12.Text = txtP14.Text;
txtP13.Text = txtP14.Text = string.Empty;
panel10.Visible = false;
btnRemove6.Enabled = false;
}
btnAdd2.Text = getbtnAdd2(btnAdd2.Text);
if (!btnAdd2.Enabled)
btnAdd2.Enabled = true;
}
private void btnRemove7_Click(object sender, EventArgs e)
{
if (panel11.Visible)
{
txtP13.Text = txtP15.Text;
txtP14.Text = txtP16.Text;
txtP15.Text = txtP16.Text = string.Empty;
panel11.Visible = false;
}
else
{
txtP13.Text = txtP14.Text = string.Empty;
panel10.Visible = false;
btnRemove6.Enabled = false;
}
btnAdd2.Text = getbtnAdd2(btnAdd2.Text);
if (!btnAdd2.Enabled)
btnAdd2.Enabled = true;
}
private void btnRemove8_Click(object sender, EventArgs e)
{
txtP15.Text = txtP16.Text = string.Empty;
panel11.Visible = false;
btnAdd2.Text = "增加规则(2/3)";
if (!btnAdd2.Enabled)
btnAdd2.Enabled = true;
}
private void btnAdd3_Click(object sender, EventArgs e)
{
if (btnAdd3.Text == "增加规则(1/3)")
{
panel14.Visible = true;
btnRemove9.Enabled = true;
btnAdd3.Text = "增加规则(2/3)";
}
else if (btnAdd3.Text == "增加规则(2/3)")
{
panel13.Visible = true;
btnAdd3.Text = "增加规则(3/3)";
btnAdd3.Enabled = false;
}
}
private void btnRemove9_Click(object sender, EventArgs e)
{
if (panel13.Visible)
{
txtP17.Text = txtP19.Text;
txtP18.Text = txtP20.Text;
txtP19.Text = txtP21.Text;
txtP20.Text = txtP22.Text;
txtP21.Text = txtP22.Text = string.Empty;
panel13.Visible = false;
}
else if (panel14.Visible)
{
txtP17.Text = txtP19.Text;
txtP18.Text = txtP20.Text;
txtP19.Text = txtP20.Text = string.Empty;
panel14.Visible = false;
btnRemove9.Enabled = false;
}
btnAdd3.Text = getbtnAdd2(btnAdd3.Text);
if (!btnAdd3.Enabled)
btnAdd3.Enabled = true;
}
private void btnRemove10_Click(object sender, EventArgs e)
{
if (panel13.Visible)
{
txtP19.Text = txtP21.Text;
txtP20.Text = txtP22.Text;
txtP21.Text = txtP22.Text = string.Empty;
panel13.Visible = false;
}
else
{
txtP19.Text = txtP20.Text = string.Empty;
panel14.Visible = false;
btnRemove9.Enabled = false;
}
btnAdd3.Text = getbtnAdd2(btnAdd3.Text);
if (!btnAdd3.Enabled)
btnAdd3.Enabled = true;
}
private void btnRemove11_Click(object sender, EventArgs e)
{
txtP21.Text = txtP22.Text = string.Empty;
panel13.Visible = false;
btnAdd3.Text = "增加规则(2/3)";
if (!btnAdd3.Enabled)
btnAdd3.Enabled = true;
}
private void rdoDiscount_CheckedChanged(object sender, EventArgs e)
{
if (rdoReduction.Checked)
{
panel12.Visible = true;
panel16.Visible = false;
}
else
{
panel12.Visible = false;
panel16.Visible = true;
}
}
private void btnGetProduct_Click(object sender, EventArgs e)
{
if (lstShopId.Count == 0)
{
BaseMsgForm.ShowInfo("请选择店铺!");
return;
}
btnManagerAct.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
foreach (var shopId in lstShopId)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
if (shop == null)
continue;
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopLogin(new string[] { shop.ShopAccount }, false);
if (shop.LoginStatus != "登录成功")
{
Invoke(new Action(() =>
{
var row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopId);
if (row != null)
{
row.Cells["colLoginStatus"].Value = "未登录";
row.Cells["colCanUse"].Value = false;
}
}));
continue;
}
FullMinusShopForm fullMinusShopForm = null;
Invoke(new Action(() =>
{
var tab = this.ucTabControl1.TabPages.Cast<TabPage>().FirstOrDefault(t => t.Text == shop.ShopAccount && t.Name == "tab" + shop.ShopId);
if (tab == null)
{
tab = new TabPage();
tab.Name = "tab" + shop.ShopId;
tab.Text = shop.ShopAccount;
ucTabControl1.TabPages.Add(tab);
FullMinusShopForm fullMinusShop = new FullMinusShopForm(shop);
fullMinusShop.fullMinusForm = this;
fullMinusShop.TopLevel = false;
fullMinusShop.Left = 0;
fullMinusShop.Top = 0;
fullMinusShop.FormBorderStyle = FormBorderStyle.None;
fullMinusShop.AutoSize = true;
fullMinusShop.Dock = DockStyle.Fill;
fullMinusShop.Show();
tab.Controls.Add(fullMinusShop);
}
if (tab.Controls.Count > 0)
{
fullMinusShopForm = tab.Controls[0] as FullMinusShopForm;
ucTabControl1.SelectedTab = tab;
}
}));
if (fullMinusShopForm != null)
{
fullMinusShopForm.GetProduct();
}
}
Invoke(new Action(() => { btnManagerAct.Enabled = true; }));
}, cancellationTokenSource.Token);
}
public void GetProductByCef(ShopLoginInfo shop)
{
if (webBrowser == null)
{
Invoke(new Action(() =>
{
webBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
webBrowser.KeyboardHandler = new KeyboardHandler();
webBrowser.Dock = DockStyle.Fill;
Helper.CustomResourceRequestHandlerLocal resourceRequestHandler = new Helper.CustomResourceRequestHandlerLocal();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadCompleteEvent;
webBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
webBrowser.LifeSpanHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
webBrowser.SendToBack();
splitContainer3.Panel1.Controls.Add(webBrowser);
}));
}
while (webBrowser.Tag != null)
Thread.Sleep(Randomx.GetId(50, 100));
if (cancellationTokenSource.IsCancellationRequested)
return;
webBrowser.Tag = shop;
while (!webBrowser.IsBrowserInitialized || webBrowser.IsLoading)
continue;
var cookie = shop.Cookies;
CEFBrowser.DeleteCookie(webBrowser.RequestContext.GetCookieManager(null));
var t = CEFBrowser.SetCookieAsync("jinritemai.com", cookie, webBrowser.RequestContext.GetCookieManager(null));
t.Wait(2000);
Thread.Sleep(500);
var targetUrl = "https://fxg.jinritemai.com/market/center/tools/moneyoff";
webBrowser.Load(targetUrl);
while (webBrowser.IsLoading)
{
Thread.Sleep(1000);
}
Thread.Sleep(3000);
while (webBrowser.Tag != null)
{
Thread.Sleep(Randomx.GetId(50, 100));
}
Thread.Sleep(3000);
}
private void RequestHandler_ResourceLoadCompleteEvent(object sender, string url, string postData, string responseData, CefSharp.IRequest iRequest)
{
if (url.StartsWith("https://fxg.jinritemai.com/marketing/activity/v1/query_full_discount_activity?activity_status="))
{
if (webBrowser.Tag != null)
{
var listUrl = url;
var referrerUrl = iRequest.ReferrerUrl;
var result = responseData;
Dictionary<string, string> headers = new Dictionary<string, string>();
foreach (var hk in iRequest.Headers.AllKeys)
{
headers[hk] = iRequest.Headers[hk];
}
var shop = webBrowser.Tag as ShopLoginInfo;
var tab = this.ucTabControl1.TabPages.Cast<TabPage>().FirstOrDefault(t => t.Text == shop.ShopAccount && t.Name == "tab" + shop.ShopId);
if (tab != null && this.btnManagerAct.Enabled == false)
{
var minusShopForm = tab.Controls[0] as FullMinusShopForm;
Task.Run(() =>
{
var cookies = CEFBrowser.GetCookie("", webBrowser.RequestContext.GetCookieManager(null));
if (minusShopForm != null)
minusShopForm.GetProductSim(listUrl, referrerUrl, headers, result, dptStartTime.Value.ToString(), dptEndTime.Value.ToString());
webBrowser.Tag = null;
Thread.Sleep(1000);
});
}
else
{
tab = this.ucTabControl1.TabPages.Cast<TabPage>().FirstOrDefault(t => t.Text == shop.ShopAccount + "活动管理" && t.Name == "tab" + shop.ShopId + "Active");
if (tab != null)
{
var activeForm = tab.Controls[0] as FullMinusActiveForm;
Task.Run(() =>
{
if (activeForm != null)
activeForm.GetActiveSim(listUrl, referrerUrl, headers, result);
webBrowser.Tag = null;
Thread.Sleep(1000);
});
}
}
}
}
}
private void btnStopGetProduct_Click(object sender, EventArgs e)
{
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
webBrowser.Tag = null;
}
private void btnSubAct_Click(object sender, EventArgs e)
{
if (lstShopId.Count <= 0)
{
BaseMsgForm.ShowInfo("请选择要设置的店铺!");
return;
}
//活动名称
var actName = txtActName.Text.Trim();
if (actName == string.Empty)
actName = "活动" + "-" + DateTime.Now.ToString("ssffff");
else if (actName.Length > 10)
{
if (BaseMsgForm.ShowConfirm("活动名称不能超过十个字,确定继续使用该名称吗?").DialogResult == DialogResult.OK)
actName = actName.Substring(0, 10);
else
return;
}
var enable_use_coupon = rdoAllow.Checked;
if (dptStartTime.Value >= dptEndTime.Value)
{
BaseMsgForm.ShowInfo("活动时间设置有误!");
return;
}
Task.Run(() =>
{
foreach (var shopId in lstShopId)
{
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
if (shop == null)
continue;
var cookies = shop.Cookies;
if (ucTabControl1.TabPages["tab" + shopId] != null && ucTabControl1.TabPages["tab" + shopId].Controls.Count > 0)
{
var minusForm = ucTabControl1.TabPages["tab" + shopId].Controls[0] as FullMinusShopForm;
if (minusForm != null)
{
Invoke(new Action(() => { minusForm.statusBar.lblTaskStatus.Text = "正在创建活动"; }));
List<string> strList = minusForm.lstProductId;
if (strList.Count == 0)
{
BaseMsgForm.ShowInfo("请选择店铺 " + shop.ShopAccount + " 参加活动的商品!");
return;
}
else
{
try
{
var postData = string.Empty;
int activity_type = 1;
int discount_type = 3;
if (rdoOverPieces.Checked)
{
activity_type = 2;
if (rdoDiscount.Checked)
discount_type = 1;
}
postData = postData + "{\"full_discount_activity\":{\"activity_type\":" + activity_type + ",\"discount_type\":" + discount_type + ",\"start_time\":" + BaseClass.DateTimeToTimestampSeconds(dptStartTime.Value) + ",\"end_time\":" + BaseClass.DateTimeToTimestampSeconds(dptEndTime.Value) + ",\"discounts\":[";
if (rdoOverYuan.Checked)
{
var overP1 = txtP1.Text.Trim(); var disP2 = txtP2.Text.Trim();
if (overP1 == string.Empty || overP1.ParseToDouble() <= 0 || overP1.ParseToDouble() > 99999 || disP2 == string.Empty || disP2.ParseToDouble() <= 0 || disP2.ParseToDouble() >= overP1.ParseToDouble())
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,金额需大于0小于100000,小数点后最多2位,!"); }));
return;
}
postData = postData + "{\"condition_value\":\"" + overP1.ParseToDouble() * 100 + "\",\"discount\":\"" + disP2.ParseToDouble() * 100 + "\"}";
if (panel3.Visible && txtP3.Text.Trim() != string.Empty && txtP4.Text.Trim() != string.Empty)
{
var overP3 = txtP3.Text.Trim().ParseToDouble(); var disP4 = txtP4.Text.Trim().ParseToDouble();
if (overP3 <= overP1.ParseToDouble() || overP3 > 99999 || disP4 <= disP2.ParseToDouble() || disP4 >= overP3)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,金额需大于0小于100000,小数点后最多2位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP3 * 100 + "\",\"discount\":\"" + disP4 * 100 + "\"}";
if (panel4.Visible && txtP5.Text.Trim() != string.Empty && txtP6.Text.Trim() != string.Empty)
{
var overP5 = txtP5.Text.Trim().ParseToDouble(); var disP6 = txtP6.Text.Trim().ParseToDouble();
if (overP5 <= overP3 || overP5 > 99999 || disP6 <= disP4 || disP6 >= overP5)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,金额需大于0小于100000,小数点后最多2位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP5 * 100 + "\",\"discount\":\"" + disP6 * 100 + "\"}";
if (panel6.Visible && txtP7.Text.Trim() != string.Empty && txtP8.Text.Trim() != string.Empty)
{
var overP7 = txtP7.Text.Trim().ParseToDouble(); var disP8 = txtP8.Text.Trim().ParseToDouble();
if (overP7 <= overP5 || overP7 > 99999 || disP8 <= disP6 || disP8 >= overP7)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,金额需大于0小于100000,小数点后最多2位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP7 * 100 + "\",\"discount\":\"" + disP8 * 100 + "\"}";
if (panel7.Visible && txtP9.Text.Trim() != string.Empty && txtP10.Text.Trim() != string.Empty)
{
var overP9 = txtP9.Text.Trim().ParseToDouble(); var disP10 = txtP10.Text.Trim().ParseToDouble();
if (overP9 <= overP7 || overP9 > 99999 || disP10 <= disP8 || disP10 >= overP9)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,金额需大于0小于100000,小数点后最多2位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP9 * 100 + "\",\"discount\":\"" + disP10 * 100 + "\"}";
}
}
}
}
}
else
{
if (rdoDiscount.Checked)
{
var overP11 = txtP11.Text.Trim(); var disP12 = txtP12.Text.Trim();
if (overP11 == string.Empty || disP12 == string.Empty || overP11.ParseToLong() < 2 || overP11.ParseToLong() > 999 || disP12.ParseToDouble() <= 0 || disP12.ParseToDouble() >= 10)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,件数需大于1小于1000,打折需大于0小于10,小数点后最多1位!"); }));
return;
}
postData = postData + "{\"condition_value\":\"" + overP11 + "\",\"discount\":\"" + disP12.ParseToDouble() * 10 + "\"}";
if (panel10.Visible && txtP13.Text.Trim() != string.Empty && txtP14.Text.Trim() != string.Empty)
{
var overP13 = txtP13.Text.Trim().ParseToLong(); var disP14 = txtP14.Text.Trim().ParseToDouble();
if (overP13 <= overP11.ParseToLong() || overP13 > 999 || disP14 >= disP12.ParseToDouble() || disP14 <= 0)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,件数需大于1小于1000,打折需大于0小于10,小数点后最多1位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP13 + "\",\"discount\":\"" + disP14 * 10 + "\"}";
if (panel11.Visible && txtP15.Text.Trim() != string.Empty && txtP16.Text.Trim() != string.Empty)
{
var overP15 = txtP15.Text.Trim().ParseToLong(); var disP16 = txtP16.Text.Trim().ParseToDouble();
if (overP15 <= overP13 || overP15 > 999 || disP16 >= disP14 || disP16 <= 0)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,件数需大于1小于1000,打折需大于0小于10,小数点后最多1位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP15 + "\",\"discount\":\"" + disP16 * 10 + "\"}";
}
}
}
else
{
var overP17 = txtP17.Text.Trim(); var disP18 = txtP18.Text.Trim();
if (overP17 == string.Empty || disP18 == string.Empty || overP17.ParseToLong() < 2 || overP17.ParseToLong() > 999 || disP18.ParseToDouble() <= 0 || disP18.ParseToDouble() > 99999)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,件数需大于1小于1000,金额需大于0小于100000,小数点后最多2位!"); }));
return;
}
postData = postData + "{\"condition_value\":\"" + overP17 + "\",\"discount\":\"" + disP18.ParseToDouble() * 100 + "\"}";
if (panel14.Visible && txtP19.Text.Trim() != string.Empty && txtP20.Text.Trim() != string.Empty)
{
var overP19 = txtP19.Text.Trim().ParseToLong(); var disP20 = txtP20.Text.Trim().ParseToDouble();
if (overP19 <= overP17.ParseToLong() || overP19 > 999 || disP20 <= disP18.ParseToDouble() || disP20 > 99999)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,件数需大于1小于1000,金额需大于0小于100000,小数点后最多2位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP19 + "\",\"discount\":\"" + disP20 * 100 + "\"}";
if (panel13.Visible && txtP21.Text.Trim() != string.Empty && txtP22.Text.Trim() != string.Empty)
{
var overP21 = txtP21.Text.Trim().ParseToLong(); var disP22 = txtP22.Text.Trim().ParseToDouble();
if (overP21 <= overP19 || overP21 > 999 || disP22 <= disP20 || disP22 > 99999)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("优惠设置有误,件数需大于1小于1000,金额需大于0小于100000,小数点后最多2位,下一层级的【优惠】要大于上一层级!"); }));
return;
}
postData = postData + ",{\"condition_value\":\"" + overP21 + "\",\"discount\":\"" + disP22 * 100 + "\"}";
}
}
}
}
postData = postData + "],\"activity_name\":\"" + actName + "\",\"enable_use_coupon\":" + enable_use_coupon.ToString().ToLower() + ",\"activity_products\":[";
if (strList.Count > 100)
strList = strList.Take(100).ToList();
foreach (var id in strList)
{
DouProductPromotionListInfo info = minusForm.productList.FirstOrDefault(q => q.product_id == id);
if (info != null)
{
postData = postData + "{\"product_id\":\"" + info.product_id + "\",\"name\":\"" + info.name + "\",\"img\":\"" + info.img + "\",\"stock_num\":" + info.stock_num + ",\"max_price\":" + info.max_price + ",\"min_price\":" + info.min_price + "},";
}
}
postData = postData.TrimEnd(',') + "]}}";
string checkPro = minusForm.checkFullDiscountActivity(postData, cookies);
if (checkPro.Contains(",\"msg\":\"成功\",\"st\":0"))
{
string createPro = minusForm.createFullDiscountActivity(postData, cookies);
if (createPro.Contains(",\"msg\":\"成功\",\"st\":0"))
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage("活动" + actName + "创建成功。"); }));
if (dptStartTime.Value <= DateTime.Now && dptEndTime.Value > DateTime.Now)
minusForm.RefreshdgvProduct(strList);
var tab1 = this.ucTabControl1.TabPages.Cast<TabPage>().FirstOrDefault(t => t.Text == shop.ShopAccount + "活动管理" && t.Name == "tab" + shop.ShopId + "Active");
if (tab1 != null)
{
FullMinusActiveForm actForm = tab1.Controls[0] as FullMinusActiveForm;
actForm.activeList.Clear();
}
}
else
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage(actName + "活动创建失败!原因:" + BaseRegex.GetStringJson(ref createPro, "msg")); }));
}
}
else
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage(actName + "活动创建失败!原因:" + BaseRegex.GetStringJson(ref checkPro, "msg")); }));
}
}
catch (Exception ex)
{
Invoke(new Action(() => { minusForm.ShowVisitorMessage(actName + "活动创建失败!原因:" + ex.Message); }));
}
}
Invoke(new Action(() => { minusForm.statusBar.lblTaskStatus.Text = "活动创建结束"; }));
}
}
}
});
}
private void btnManagerAct_Click(object sender, EventArgs e)
{
if (lstShopId.Count == 0)
{
BaseMsgForm.ShowInfo("请选择店铺!");
return;
}
btnGetProduct.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
foreach (var shopId in lstShopId)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
if (shop == null)
continue;
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopLogin(new string[] { shop.ShopAccount }, false);
if (shop.LoginStatus != "登录成功")
{
Invoke(new Action(() =>
{
var row = this.dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ToString() == shop.ShopId);
if (row != null)
{
row.Cells["colLoginStatus"].Value = "未登录";
row.Cells["colCanUse"].Value = false;
}
}));
continue;
}
FullMinusActiveForm actForm = null;
Invoke(new Action(() =>
{
var tab = this.ucTabControl1.TabPages.Cast<TabPage>().FirstOrDefault(t => t.Text == shop.ShopAccount + "活动管理" && t.Name == "tab" + shop.ShopId + "Active");
if (tab == null)
{
tab = new TabPage();
tab.Name = "tab" + shop.ShopId + "Active";
tab.Text = shop.ShopAccount + "活动管理";
this.ucTabControl1.TabPages.Add(tab);
var minusActiveForm = new FullMinusActiveForm(shop);
minusActiveForm.fullMinusForm = this;
minusActiveForm.TopLevel = false;
minusActiveForm.Left = 0;
minusActiveForm.Top = 0;
minusActiveForm.FormBorderStyle = FormBorderStyle.None;
minusActiveForm.AutoSize = true;
minusActiveForm.Dock = DockStyle.Fill;
minusActiveForm.Show();
tab.Controls.Add(minusActiveForm);
}
if (tab.Controls.Count > 0)
{
actForm = tab.Controls[0] as FullMinusActiveForm;
this.ucTabControl1.SelectedTab = tab;
}
}));
if (actForm != null)
{
actForm.GetActive();
}
}
Invoke(new Action(() => { btnGetProduct.Enabled = true; }));
}, cancellationTokenSource.Token);
}
public void GetActiveByCef(ShopLoginInfo shop)
{
GetProductByCef(shop);
}
private void btnClear_Click(object sender, EventArgs e)
{
if (BaseMsgForm.ShowConfirm("确定要清空结果吗?清空后需要重新获取!").DialogResult == DialogResult.OK)
{
foreach (TabPage tp in ucTabControl1.TabPages)
{
if (tp.Controls.Count > 0)
{
if (tp.Text.Contains("活动管理"))
{
var managerActiveForm = tp.Controls[0] as FullMinusActiveForm;
if (managerActiveForm != null)
managerActiveForm.ClearData();
}
else
{
var salesForm = tp.Controls[0] as FullMinusShopForm;
if (salesForm != null)
salesForm.ClearData();
}
}
}
}
}
}
}