1店铺折扣活动逻辑 2数据库选品上货记录每次提交的draft_id以备后续使用
This commit is contained in:
1 parent
f73f56eea4
commit
85ed4137d2
13 files changed
+861
-104
No files matched your search
@@ -25,6 +25,8 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
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()
|
||||
{
|
||||
@@ -200,11 +202,23 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
|
||||
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)
|
||||
@@ -257,27 +271,8 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
continue;
|
||||
|
||||
#region 检测登录
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
if (!CheckLogin(shop))
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
Invoke(new Action(() =>
|
||||
@@ -301,8 +296,8 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
int tryCount = 0;
|
||||
tryAgain:
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
string jsonStr = GetActivityList(shop);
|
||||
if (jsonStr.Contains("指定的值含有无效的控制字符"))
|
||||
string jsonRst = GetActivityList(shop);
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
@@ -318,28 +313,28 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
isError = true;
|
||||
break;
|
||||
}
|
||||
if (jsonStr.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||||
if (jsonRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||||
{
|
||||
tryCount++;
|
||||
goto tryAgain;
|
||||
}
|
||||
|
||||
if (!jsonStr.Contains("\"success\":true"))
|
||||
if (!jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
isError = true;
|
||||
string sErr = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
|
||||
string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||||
if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
|
||||
errMsg += sErr + " ";
|
||||
page++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (jsonStr.Contains("\"success\":true"))
|
||||
if (jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
var jArr = new JArray();
|
||||
try
|
||||
{
|
||||
var jObj = JObject.Parse(jsonStr);
|
||||
var jObj = JObject.Parse(jsonRst);
|
||||
jArr = jObj["result"]?["activityList"] as JArray;
|
||||
if (jArr == null)
|
||||
jArr = new JArray();
|
||||
@@ -356,12 +351,13 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
{
|
||||
lstActivityThematic.Add(pInfo);
|
||||
string name = pInfo.activityThematicName;
|
||||
pInfo.discount = BaseRegex.GetMatchRegexString(ref name, "(\\d{1,3}折)");
|
||||
pInfo.discount = string.IsNullOrWhiteSpace(pInfo.discount) ? "-" : pInfo.discount;
|
||||
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 jsonStr, "total").ParseToInt();
|
||||
int total = BaseRegex.GetStringJson(ref jsonRst, "total").ParseToInt();
|
||||
totalPage = Math.Ceiling(total / 10.0).ParseToInt();
|
||||
}
|
||||
page++;
|
||||
@@ -390,17 +386,29 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
|
||||
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,
|
||||
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 + "天)",
|
||||
(BaseClass.StampToDateTime((int)(actInfo.enrollDeadLine.ParseToLong() / 1000)) - DateTime.Now).Days + "天后截止",
|
||||
actInfo.discount
|
||||
sActivityTime,
|
||||
sActivityRemaining,
|
||||
string.IsNullOrEmpty(actInfo.discount)? "-" : actInfo.discount.TrimEnd('0') + "折"
|
||||
);
|
||||
|
||||
dgvActivity.Rows[rowId].Height = 40;
|
||||
@@ -459,7 +467,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
if (actRow == null)
|
||||
continue;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(actInfo.discount) && actInfo.discount != "-")
|
||||
if (!string.IsNullOrWhiteSpace(actInfo.discount))
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
@@ -493,35 +501,18 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
}));
|
||||
|
||||
#region 检测登录
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ShopListForm.Instance == null)
|
||||
ShopListForm.Instance = new ShopListForm();
|
||||
if (shop.LastRefreshDate == "")
|
||||
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
{
|
||||
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 (!CheckLogin(shop))
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
int tryCount = 0;
|
||||
tryAgain:
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
string jsonStr = GetActivityMatch(shop, actInfo.activityThematicId.ParseToLong());
|
||||
if (jsonStr.Contains("指定的值含有无效的控制字符"))
|
||||
string jsonRst = GetActivityMatch(shop, actInfo.activityThematicId.ParseToLong());
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
@@ -535,26 +526,26 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
if (jsonStr.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||||
if (jsonRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||||
{
|
||||
tryCount++;
|
||||
goto tryAgain;
|
||||
}
|
||||
if (jsonStr.Contains("当前操作人数太多,请稍后重试"))
|
||||
if (jsonRst.Contains("当前操作人数太多,请稍后重试"))
|
||||
{
|
||||
}
|
||||
if (!jsonStr.Contains("\"success\":true"))
|
||||
if (!jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
//isError = true;
|
||||
//string sErr = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
|
||||
//string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||||
//if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
|
||||
// errMsg += sErr + " ";
|
||||
//page++;
|
||||
string sErr = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
|
||||
string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(sErr))
|
||||
sErr = BaseRegex.GetStringJson(ref jsonStr, "err_msg");
|
||||
sErr = BaseRegex.GetStringJson(ref jsonRst, "err_msg");
|
||||
if (string.IsNullOrEmpty(sErr))
|
||||
sErr = jsonStr;
|
||||
sErr = jsonRst;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
actRow.Cells["colActivityMsg"].Value = sErr;
|
||||
@@ -563,12 +554,12 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
continue;
|
||||
}
|
||||
|
||||
if (jsonStr.Contains("\"success\":true"))
|
||||
if (jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
var jArr = new JArray();
|
||||
try
|
||||
{
|
||||
var jObj = JObject.Parse(jsonStr);
|
||||
var jObj = JObject.Parse(jsonRst);
|
||||
jArr = jObj["result"]?["matchList"] as JArray;
|
||||
if (jArr == null)
|
||||
jArr = new JArray();
|
||||
@@ -590,10 +581,10 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
var suggestActivityPrice = skuObj["suggestActivityPrice"].ParseToInt();
|
||||
var dailyPrice = skuObj["dailyPrice"].ParseToInt();
|
||||
var discount = suggestActivityPrice * 100.0 / dailyPrice;
|
||||
actInfo.discount = Math.Round(discount) + "折";
|
||||
actInfo.discount = Math.Round(discount) + "";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
actRow.Cells["colDiscount"].Value = actInfo.discount;
|
||||
actRow.Cells["colDiscount"].Value = string.IsNullOrEmpty(actInfo.discount) ? "-" : actInfo.discount.TrimEnd('0') + "折";
|
||||
actRow.Cells["colActivityMsg"].Value = "折扣查询成功";
|
||||
shopRow.Cells["colMessage"].Value = "";
|
||||
}));
|
||||
@@ -602,7 +593,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||||
}
|
||||
}
|
||||
if(string.IsNullOrEmpty(actInfo.discount) || !actInfo.discount.Contains("折"))
|
||||
if(string.IsNullOrEmpty(actInfo.discount))
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
@@ -612,6 +603,186 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
@@ -639,5 +810,22 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user