832 lines
35 KiB
C#
832 lines
35 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.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.KJDForms.BaseForms;
|
||
using TemuKJD.KJDForms.ShopForms;
|
||
|
||
namespace TemuKJD.KJDForms.SalesCenterForms
|
||
{
|
||
public partial class MarketingActivityForm : Form
|
||
{
|
||
private CheckBox chkSelectAll = null;
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||
public List<TemuActivityThematicInfo> lstActivityThematic { get; set; } = new List<TemuActivityThematicInfo>();
|
||
public List<string> lstShopIdSelect = new List<string>();
|
||
public List<int> lstDiscount = new List<int>() { 60, 70, 80, 85 };
|
||
public Dictionary<string, List<SubOrderInfo>> dicNoSaleProd = new Dictionary<string, List<SubOrderInfo>>();
|
||
|
||
public MarketingActivityForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void MarketingActivityForm_Load(object sender, EventArgs e)
|
||
{
|
||
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;
|
||
|
||
this.dgvActivity.AddSelectorColumn("colCheckActivity");
|
||
this.dgvProduct.AddSelectorColumn("colCheckProduct");
|
||
}
|
||
|
||
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.LoginStatus2 == "国际版在线").Select(ss => ss.ShopId);
|
||
foreach (DataGridViewRow row in dgvShop.Rows)
|
||
{
|
||
if (list.Any(l => l == row.Cells["colShopId"]?.Value?.ToString()))
|
||
row.Cells["colSelect"].Value = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
private void MarketingActivityForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
if (this.Visible)
|
||
RefreshShop();
|
||
}
|
||
|
||
private void btnRefreshShop_Click(object sender, EventArgs e)
|
||
{
|
||
RefreshShop();
|
||
}
|
||
|
||
private void RefreshShop()
|
||
{
|
||
// 店铺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);
|
||
}
|
||
}
|
||
|
||
private void BindShop(ShopLoginInfo shopEntity, List<string> selectShopId = null)
|
||
{
|
||
if (shopEntity == null)
|
||
return;
|
||
if (selectShopId == null)
|
||
selectShopId = new List<string>();
|
||
|
||
bool canUse = shopEntity.LoginStatus2 == "国际版在线";
|
||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
|
||
if (row == null)
|
||
{
|
||
this.dgvShop.Rows.Add(
|
||
selectShopId.Contains(shopEntity.ShopId) && canUse,
|
||
shopEntity.LoginName,
|
||
shopEntity.ShopId,
|
||
shopEntity.ShopAccount,
|
||
shopEntity.LoginStatus2 == "国际版在线" ? "在线" : "未登录",
|
||
canUse,
|
||
string.Empty
|
||
);
|
||
}
|
||
else
|
||
{
|
||
row.Cells["colSelect"].Value = selectShopId.Contains(shopEntity.ShopId) && canUse;
|
||
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
|
||
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
|
||
row.Cells["colLoginStatus"].Value = shopEntity.LoginStatus2 == "国际版在线" ? "在线" : "未登录";
|
||
row.Cells["colCanUse"].Value = canUse;
|
||
}
|
||
}
|
||
|
||
private void dgvShop_CellClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string columnName = dgvShop.Columns[e.ColumnIndex].Name;
|
||
switch (columnName)
|
||
{
|
||
case "colSelect":
|
||
dgvShop.CellContentClick -= dgvShop_CellContentClick;
|
||
dgvShop_CellContentClick(sender, e);
|
||
break;
|
||
default:
|
||
dgvShop.CellContentClick -= dgvShop_CellContentClick;
|
||
dgvShop.CellContentClick += dgvShop_CellContentClick;
|
||
break;
|
||
}
|
||
}
|
||
|
||
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 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("店铺国际版未登录!");
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void dgvActivity_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvActivity.Columns[e.ColumnIndex].HeaderText;
|
||
string columnName = dgvActivity.Columns[e.ColumnIndex].Name;
|
||
long activityId = dgvActivity.Rows[e.RowIndex].Cells["colActivityId"].Value.ParseToLong();
|
||
var activity = lstActivityThematic.FirstOrDefault(s => s.activityThematicId == activityId);
|
||
var row = dgvActivity.Rows[e.RowIndex];
|
||
switch (columnName)
|
||
{
|
||
case "colCheckActivity":
|
||
row.Cells["colCheckActivity"].Value = !row.Cells["colCheckActivity"].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;
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void chkFullShop_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (chkFullShop.Checked)
|
||
chkNoSaleProd.Checked = false;
|
||
else
|
||
chkNoSaleProd.Checked = true;
|
||
}
|
||
private void chkNoSaleProd_CheckedChanged(object sender, EventArgs e)
|
||
{
|
||
if (chkNoSaleProd.Checked)
|
||
{
|
||
chkFullShop.Checked = false;
|
||
panel1.Visible = true;
|
||
}
|
||
else
|
||
{
|
||
chkFullShop.Checked = true;
|
||
panel1.Visible = false;
|
||
}
|
||
}
|
||
|
||
private void btnSearchActivity_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;
|
||
}
|
||
|
||
#region 重置控件
|
||
lstActivityThematic.Clear();
|
||
dgvActivity.Rows.Clear();
|
||
var dgvRows = this.dgvShop.Rows.Cast<DataGridViewRow>();
|
||
foreach (var row in dgvRows)
|
||
{
|
||
row.Cells["colMessage"].Value = "";
|
||
}
|
||
ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
#endregion
|
||
|
||
Task.Run(() =>
|
||
{
|
||
lstShopIdSelect.Clear();
|
||
lstShopIdSelect.AddRange(lstShopId);
|
||
int i = 0;
|
||
|
||
foreach (var shopId in lstShopIdSelect)
|
||
{
|
||
if (lstActivityThematic.Count > 0)
|
||
break;
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在查询活动...";
|
||
this.statusBar.pgbTaskProgress.Maximum = lstShopIdSelect.Count;
|
||
this.statusBar.UpdateProgressBar(i + 1);
|
||
i++;
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
|
||
#region 检测登录
|
||
if (!CheckLogin(shop))
|
||
continue;
|
||
#endregion
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ToString() == shop.ShopId);
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMessage"].Value = "正在查询";
|
||
}
|
||
}));
|
||
|
||
int page = 1;
|
||
int totalPage = 1;
|
||
bool isError = false;
|
||
string errMsg = "";
|
||
while (page <= totalPage)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
int tryCount = 0;
|
||
tryAgain:
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
string jsonRst = GetActivityList(shop);
|
||
if (jsonRst.Contains("指定的值含有无效的控制字符"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].Value.ToString() == shop.LoginName);
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMessage"].Value = "店铺掉线";
|
||
row.Cells["colLoginStatus"].Value = "国际版未登录";
|
||
row.Cells["colCanUse"].Value = false;
|
||
}
|
||
}));
|
||
errMsg = "店铺可能已掉线,指定的值含有无效的控制字符";
|
||
isError = true;
|
||
break;
|
||
}
|
||
if (jsonRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||
{
|
||
tryCount++;
|
||
goto tryAgain;
|
||
}
|
||
|
||
if (!jsonRst.Contains("\"success\":true"))
|
||
{
|
||
isError = true;
|
||
string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||
if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
|
||
errMsg += sErr + " ";
|
||
page++;
|
||
continue;
|
||
}
|
||
|
||
if (jsonRst.Contains("\"success\":true"))
|
||
{
|
||
var jArr = new JArray();
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonRst);
|
||
jArr = jObj["result"]?["activityList"] as JArray;
|
||
if (jArr == null)
|
||
jArr = new JArray();
|
||
}
|
||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||
foreach (var item in jArr)
|
||
{
|
||
string sItem = item.ToString();
|
||
TemuActivityInfo pActivity = JsonHelper.DeserializeJsonToObject<TemuActivityInfo>(sItem); // 反序列化得到类
|
||
if (pActivity == null || pActivity.activityName != "大促进阶-限时活动")
|
||
continue;
|
||
|
||
foreach (var pInfo in pActivity.thematicList)
|
||
{
|
||
lstActivityThematic.Add(pInfo);
|
||
string name = pInfo.activityThematicName;
|
||
pInfo.discount = BaseRegex.GetMatchRegexString(ref name, "(\\d{1,3}折)").ParseToString();
|
||
pInfo.discount = pInfo.discount.Replace("折", "");
|
||
pInfo.discount = string.IsNullOrWhiteSpace(pInfo.discount) ? "" : pInfo.discount;
|
||
}
|
||
}
|
||
|
||
int total = BaseRegex.GetStringJson(ref jsonRst, "total").ParseToInt();
|
||
totalPage = Math.Ceiling(total / 10.0).ParseToInt();
|
||
}
|
||
page++;
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ToString() == shop.ShopId);
|
||
|
||
if (!isError)
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMessage"].Value = "已查询";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMessage"].Value = "查询失败 " + errMsg;
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
|
||
foreach (var actInfo in lstActivityThematic)
|
||
{
|
||
string sActivityTime = BaseClass.StampToDateTime((int)(actInfo.startTime.ParseToLong() / 1000)).ToString("yyyy/MM/dd HH:mm:ss") + "~" +
|
||
BaseClass.StampToDateTime((int)(actInfo.endTime.ParseToLong() / 1000)).ToString("yyyy/MM/dd HH:mm:ss") + "(" +
|
||
actInfo.durationDays + "天)";
|
||
string sActivityRemaining = "";
|
||
TimeSpan timeRemaining = BaseClass.StampToDateTime((int)(actInfo.enrollDeadLine.ParseToLong() / 1000)) - DateTime.Now;
|
||
if (timeRemaining.Days >= 1)
|
||
sActivityRemaining = timeRemaining.Days + "天后截止";
|
||
else if (timeRemaining.Hours >= 1)
|
||
sActivityRemaining = timeRemaining.Hours + "小时后截止";
|
||
else if (timeRemaining.Minutes >= 1)
|
||
sActivityRemaining = timeRemaining.Minutes + "分钟后截止";
|
||
else
|
||
sActivityRemaining = timeRemaining.Seconds + "秒后截止";
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
int rowId = this.dgvActivity.Rows.Add(
|
||
false,
|
||
actInfo.activityThematicId,
|
||
actInfo.activityThematicName,
|
||
sActivityTime,
|
||
sActivityRemaining,
|
||
string.IsNullOrEmpty(actInfo.discount)? "-" : actInfo.discount.TrimEnd('0') + "折"
|
||
);
|
||
|
||
dgvActivity.Rows[rowId].Height = 40;
|
||
}));
|
||
}
|
||
|
||
//进详情页查询折扣比例信息,因部分活动可能无符合条件商品,查询可能速度较慢
|
||
if(chkGetDiscount.Checked)
|
||
GetDiscount();
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
string sRst = "查询结束!";
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
sRst = "已取消查询!";
|
||
|
||
BaseMsgForm.ShowInfo(sRst);
|
||
this.statusBar.lblTaskStatus.Text = sRst;
|
||
}));
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
// 查询活动折扣
|
||
void GetDiscount()
|
||
{
|
||
foreach (var shopId in lstShopIdSelect)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
shop.LastRefreshDate = "";
|
||
}
|
||
|
||
int i = 0;
|
||
// 查询所有活动是否有店铺可以报名,可报名的才显示
|
||
foreach (var actInfo in lstActivityThematic)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在查询活动折扣" + (i + 1) + "...";
|
||
this.statusBar.pgbTaskProgress.Maximum = lstActivityThematic.Count;
|
||
this.statusBar.UpdateProgressBar(i + 1);
|
||
i++;
|
||
}));
|
||
|
||
if (actInfo == null)
|
||
continue;
|
||
|
||
var actRow = this.dgvActivity.Rows.Cast<DataGridViewRow>()
|
||
.FirstOrDefault(r => r.Cells["colActivityId"].Value.ParseToLong() == actInfo?.activityThematicId);
|
||
if (actRow == null)
|
||
continue;
|
||
|
||
if (!string.IsNullOrWhiteSpace(actInfo.discount))
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
actRow.Cells["colActivityMsg"].Value = "折扣查询成功";
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
actRow.Cells["colActivityMsg"].Value = "正在查询折扣...";
|
||
}));
|
||
|
||
foreach (var shopId in lstShopIdSelect)
|
||
{
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
|
||
var shopRow = this.dgvShop.Rows.Cast<DataGridViewRow>()
|
||
.FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||
if (shopRow == null)
|
||
continue;
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
shopRow.Cells["colMessage"].Value = "查询折扣,活动:" + actInfo.activityThematicName;
|
||
}));
|
||
|
||
#region 检测登录
|
||
if (shop.LastRefreshDate == "")
|
||
{
|
||
if (!CheckLogin(shop))
|
||
continue;
|
||
}
|
||
#endregion
|
||
|
||
int tryCount = 0;
|
||
tryAgain:
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
string jsonRst = GetActivityMatch(shop, actInfo.activityThematicId.ParseToLong());
|
||
if (jsonRst.Contains("指定的值含有无效的控制字符"))
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var shopRows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].Value.ToString() == shop.LoginName);
|
||
foreach (var r in shopRows)
|
||
{
|
||
r.Cells["colMessage"].Value = "店铺掉线";
|
||
r.Cells["colLoginStatus"].Value = "国际版未登录";
|
||
r.Cells["colCanUse"].Value = false;
|
||
}
|
||
}));
|
||
continue;
|
||
}
|
||
if (jsonRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||
{
|
||
tryCount++;
|
||
goto tryAgain;
|
||
}
|
||
if (jsonRst.Contains("当前操作人数太多,请稍后重试"))
|
||
{
|
||
}
|
||
if (!jsonRst.Contains("\"success\":true"))
|
||
{
|
||
//isError = true;
|
||
//string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||
//if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
|
||
// errMsg += sErr + " ";
|
||
//page++;
|
||
string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||
if (string.IsNullOrEmpty(sErr))
|
||
sErr = BaseRegex.GetStringJson(ref jsonRst, "err_msg");
|
||
if (string.IsNullOrEmpty(sErr))
|
||
sErr = jsonRst;
|
||
Invoke(new Action(() =>
|
||
{
|
||
actRow.Cells["colActivityMsg"].Value = sErr;
|
||
shopRow.Cells["colMessage"].Value = "";
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
if (jsonRst.Contains("\"success\":true"))
|
||
{
|
||
var jArr = new JArray();
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonRst);
|
||
jArr = jObj["result"]?["matchList"] as JArray;
|
||
if (jArr == null)
|
||
jArr = new JArray();
|
||
}
|
||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||
|
||
if (jArr.Count() == 0)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
shopRow.Cells["colMessage"].Value = "";
|
||
}));
|
||
continue;
|
||
}
|
||
|
||
try
|
||
{
|
||
var skuObj = jArr[0]["skcList"][0]["skuList"][0];
|
||
var suggestActivityPrice = skuObj["suggestActivityPrice"].ParseToInt();
|
||
var dailyPrice = skuObj["dailyPrice"].ParseToInt();
|
||
var discount = suggestActivityPrice * 100.0 / dailyPrice;
|
||
actInfo.discount = Math.Round(discount) + "";
|
||
Invoke(new Action(() =>
|
||
{
|
||
actRow.Cells["colDiscount"].Value = string.IsNullOrEmpty(actInfo.discount) ? "-" : actInfo.discount.TrimEnd('0') + "折";
|
||
actRow.Cells["colActivityMsg"].Value = "折扣查询成功";
|
||
shopRow.Cells["colMessage"].Value = "";
|
||
}));
|
||
break;
|
||
}
|
||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||
}
|
||
}
|
||
if(string.IsNullOrEmpty(actInfo.discount))
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
actRow.Cells["colActivityMsg"].Value = "没有活动可用商品,折扣查询失败";
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
int GetNearDiscount(int discount)
|
||
{
|
||
if (lstDiscount.Count <= 0)
|
||
return 100;
|
||
if (discount < lstDiscount.First())
|
||
return lstDiscount.First();
|
||
if (discount >= lstDiscount.Last())
|
||
return lstDiscount.Last();
|
||
for (int i = 0; i < lstDiscount.Count - 2; i++)
|
||
{
|
||
if (discount >= lstDiscount[i] && discount < lstDiscount[i + 1])
|
||
return lstDiscount[i];
|
||
}
|
||
return lstDiscount.Last();
|
||
}
|
||
|
||
private void btnSignActivity_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;
|
||
}
|
||
|
||
var lstActivityId = dgvActivity.Rows.Cast<DataGridViewRow>().Where(row
|
||
=> row.Cells["colCheckActivity"]?.Value.ParseToBool() == true).Select(r => r.Cells["colActivityId"]?.Value.ToString()).ToList();
|
||
if (lstActivityId.Count == 0)
|
||
{
|
||
BaseMsgForm.ShowInfo("请选择活动!");
|
||
return;
|
||
}
|
||
|
||
#region 重置控件数据
|
||
dgvProduct.Rows.Clear();
|
||
var shopRows = this.dgvShop.Rows.Cast<DataGridViewRow>();
|
||
foreach (var r in shopRows)
|
||
{
|
||
r.Cells["colMessage"].Value = "";
|
||
}
|
||
ucGroupBoxEx2.Enabled = false;
|
||
ucGroupBoxEx3.Enabled = false;
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
lstShopIdSelect.Clear();
|
||
lstShopIdSelect.AddRange(lstShopId);
|
||
#endregion
|
||
|
||
Task.Run(() =>
|
||
{
|
||
if (chkNoSaleProd.Checked)
|
||
GetNoSaleProd();
|
||
|
||
SignActivity();
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
ucGroupBoxEx2.Enabled = true;
|
||
ucGroupBoxEx3.Enabled = true;
|
||
string sRst = "查询结束!";
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
sRst = "已取消查询!";
|
||
|
||
BaseMsgForm.ShowInfo(sRst);
|
||
this.statusBar.lblTaskStatus.Text = sRst;
|
||
}));
|
||
},cancellationTokenSource.Token);
|
||
}
|
||
|
||
public void GetNoSaleProd()
|
||
{
|
||
int i = 0;
|
||
foreach (var shopId in lstShopIdSelect)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在查询无销量商品...";
|
||
this.statusBar.pgbTaskProgress.Maximum = lstShopIdSelect.Count;
|
||
this.statusBar.UpdateProgressBar(i + 1);
|
||
i++;
|
||
}));
|
||
|
||
if (cancellationTokenSource.IsCancellationRequested)
|
||
break;
|
||
|
||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||
if (shop == null)
|
||
continue;
|
||
var shopRow = this.dgvShop.Rows.Cast<DataGridViewRow>()
|
||
.FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||
if (shopRow == null)
|
||
continue;
|
||
|
||
if (!CheckLogin(shop))
|
||
continue;
|
||
|
||
this.dicNoSaleProd[shop.ShopId] = new List<SubOrderInfo>();
|
||
int page = 0;
|
||
int totalPage = 1;
|
||
while (page < totalPage)
|
||
{
|
||
page++;
|
||
string jsonRst = GetNoSaleProd(shop, numNoSaleDays.Value.ParseToInt(), page);
|
||
|
||
if (!jsonRst.Contains("\"success\":true"))
|
||
{
|
||
string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||
if (string.IsNullOrEmpty(sErr))
|
||
sErr = BaseRegex.GetStringJson(ref jsonRst, "err_msg");
|
||
if (string.IsNullOrEmpty(sErr))
|
||
sErr = jsonRst;
|
||
Invoke(new Action(() =>
|
||
{
|
||
shopRow.Cells["colMessage"].Value = sErr;
|
||
}));
|
||
break;
|
||
}
|
||
|
||
var jArr = new JArray();
|
||
try
|
||
{
|
||
var jObj = JObject.Parse(jsonRst);
|
||
jArr = jObj["result"]["subOrderList"] as JArray;
|
||
if (jArr == null)
|
||
jArr = new JArray();
|
||
|
||
foreach (var item in jArr)
|
||
{
|
||
string sItem = item.ToString();
|
||
SubOrderInfo sInfo = JsonHelper.DeserializeJsonToObject<SubOrderInfo>(sItem); // 反序列化得到类
|
||
if (sInfo != null)
|
||
{
|
||
this.dicNoSaleProd[shop.ShopId].Add(sInfo);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
BaseMsgForm.ShowError(ex.Message);
|
||
}
|
||
|
||
int total = BaseRegex.GetStringJson(ref jsonRst, "total").ParseToInt();
|
||
totalPage = Math.Ceiling(total / 40.0).ParseToInt();
|
||
}
|
||
}
|
||
}
|
||
|
||
public void SignActivity()
|
||
{
|
||
foreach (var shopId in lstShopIdSelect)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
public bool CheckLogin(ShopLoginInfo shop)
|
||
{
|
||
if (shop.LoginStatus2 != "国际版在线")
|
||
{
|
||
return false;
|
||
}
|
||
if (ShopListForm.Instance == null) ShopListForm.Instance = new ShopListForm();
|
||
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||
if (shop.LoginStatus2 != "国际版在线")
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].Value.ToString() == shop.LoginName);
|
||
foreach (var row in rows)
|
||
{
|
||
row.Cells["colMessage"].Value = "店铺掉线";
|
||
row.Cells["colLoginStatus"].Value = "国际版未登录";
|
||
row.Cells["colCanUse"].Value = false;
|
||
}
|
||
}));
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取活动列表
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <returns></returns>
|
||
private string GetActivityList(ShopLoginInfo shop)
|
||
{
|
||
string url = "https://agentseller.temu.com/api/kiana/gamblers/marketing/enroll/activity/list";
|
||
string body;
|
||
body = @"{""needCanEnrollCnt"":true}";
|
||
string refere = "https://agentseller.temu.com/activity/marketing-activity";
|
||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取符合店铺的活动
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <returns></returns>
|
||
private string GetActivityMatch(ShopLoginInfo shop, long? thematicId)
|
||
{
|
||
string url = "https://agentseller.temu.com/api/kiana/gamblers/marketing/enroll/scroll/match";
|
||
string body;
|
||
body = @"{""activityType"":13,""activityThematicId"":" + thematicId + @",""rowCount"":50}";
|
||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=13&thematicId=" + thematicId;
|
||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="shop"></param>
|
||
/// <param name="onSalesDays">加入站点天数</param>
|
||
/// <param name="page"></param>
|
||
/// <returns></returns>
|
||
private string GetNoSaleProd(ShopLoginInfo shop, int onSalesDays, int page=1)
|
||
{
|
||
string url = "https://agentseller.temu.com/mms/venom/api/supplier/sales/management/listWarehouse";
|
||
string body;
|
||
body = @"{""pageNo"":" + page + @",""pageSize"":40,""isLack"":0,""selectStatusList"":[12],""priceAdjustRecentDays"":7,
|
||
""thirtyDaysSaleVolumMax"":0,""onSalesDurationOfflineGte"":" + onSalesDays + "}";
|
||
string refere = "https://agentseller.temu.com/stock/fully-mgt/sale-manage/main";
|
||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||
}
|
||
}
|
||
}
|