优化活动报名,官方大促暂时不能报名待修复
This commit is contained in:
1 parent
abf3cfbd89
commit
738ec76bf1
4 files changed
+215
-126
No files matched your search
@@ -26,7 +26,7 @@ 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<string> lstActivityIdSelect = new List<string>();
|
||||
public List<string> lstActivityThematicIdSelect = 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>>();
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
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();
|
||||
long activityId = dgvActivity.Rows[e.RowIndex].Cells["colActivityThematicId"].Value.ParseToLong();
|
||||
var activity = lstActivityThematic.FirstOrDefault(s => s.activityThematicId == activityId);
|
||||
var row = dgvActivity.Rows[e.RowIndex];
|
||||
switch (columnName)
|
||||
@@ -340,24 +340,60 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
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)
|
||||
foreach (var item in jArr)
|
||||
{
|
||||
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;
|
||||
string sItem = item.ToString();
|
||||
TemuActivityInfo pActivity = JsonHelper.DeserializeJsonToObject<TemuActivityInfo>(sItem); // 反序列化得到类
|
||||
//if (pActivity == null || pActivity.activityName != "大促进阶-限时活动")
|
||||
// continue;
|
||||
if (pActivity.activityType == 51 || pActivity.activityName == "跨店满减") // 51 跨店满减平台补贴活动直接跳过
|
||||
continue;
|
||||
if (pActivity.benefitLabelName.Contains("平台补贴"))
|
||||
continue;
|
||||
if (pActivity.activityType == 52)
|
||||
{
|
||||
}
|
||||
|
||||
if (pActivity.thematicList.Count == 0)
|
||||
{
|
||||
pActivity.thematicList.Add(new TemuActivityThematicInfo()
|
||||
{
|
||||
activityType = pActivity.activityType, // 一级活动类型
|
||||
activityTypeName = pActivity.activityName, // 一级活动名称
|
||||
activityLabelDesc = pActivity.activityLabelDesc,
|
||||
activityLabelList = new List<TemuActivityLabelInfo>(),
|
||||
activityLabelTag = pActivity.activityLabelTag,
|
||||
activityThematicContent = pActivity.activityContent,
|
||||
activityThematicId = pActivity.activityType,
|
||||
activityThematicName = pActivity.activityName,
|
||||
benefitLabelName = pActivity.benefitLabelName,
|
||||
canEnrollTotal = null,
|
||||
discount = "",
|
||||
durationDays = 0,
|
||||
endTime = pActivity.sessionEndTime,
|
||||
startTime = pActivity.sessionStartTime,
|
||||
enrollDeadLine = null,
|
||||
enrolledCount = null,
|
||||
enrollSource = null,
|
||||
enrollStartAt = null,
|
||||
salePromotionLabel = null,
|
||||
sites = new List<TemuActivitySiteInfo>(),
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var pActThematic in pActivity.thematicList)
|
||||
{
|
||||
pActThematic.activityType = pActivity.activityType;
|
||||
pActThematic.activityTypeName = pActivity.activityName;
|
||||
lstActivityThematic.Add(pActThematic);
|
||||
string name = pActThematic.activityThematicName;
|
||||
pActThematic.discount = BaseRegex.GetMatchRegexString(ref name, "(\\d{1,3}折)").ParseToString();
|
||||
pActThematic.discount = pActThematic.discount.Replace("折", "");
|
||||
pActThematic.discount = string.IsNullOrWhiteSpace(pActThematic.discount) ? "" : pActThematic.discount;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||||
|
||||
int total = BaseRegex.GetStringJson(ref jsonRst, "total").ParseToInt();
|
||||
totalPage = Math.Ceiling(total / 10.0).ParseToInt();
|
||||
@@ -388,24 +424,33 @@ 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 = "";
|
||||
string sActivityTime = "-";
|
||||
if (actInfo.startTime.ParseToLong() > 0 && actInfo.endTime.ParseToLong() > 0)
|
||||
{
|
||||
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 + "秒后截止";
|
||||
if (timeRemaining.TotalSeconds > 0)
|
||||
{
|
||||
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.activityType,
|
||||
actInfo.activityTypeName,
|
||||
actInfo.activityThematicId,
|
||||
actInfo.activityThematicName,
|
||||
sActivityTime,
|
||||
@@ -468,7 +513,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
continue;
|
||||
|
||||
var actRow = this.dgvActivity.Rows.Cast<DataGridViewRow>()
|
||||
.FirstOrDefault(r => r.Cells["colActivityId"].Value.ParseToLong() == actInfo?.activityThematicId);
|
||||
.FirstOrDefault(r => r.Cells["colActivityThematicId"].Value.ParseToLong() == actInfo.activityThematicId);
|
||||
if (actRow == null)
|
||||
continue;
|
||||
|
||||
@@ -516,7 +561,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
int tryCount = 0;
|
||||
tryAgain:
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
string jsonRst = GetActivityMatch(shop, actInfo.activityThematicId.ParseToLong());
|
||||
string jsonRst = GetActivityMatch(shop, actInfo.activityType, actInfo.activityThematicId);
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符") || jsonRst.Contains("login") || jsonRst.Contains("Login"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
@@ -632,7 +677,8 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
}
|
||||
|
||||
var lstActivityId = dgvActivity.Rows.Cast<DataGridViewRow>().Where(row
|
||||
=> row.Cells["colCheckActivity"]?.Value.ParseToBool() == true).Select(r => r.Cells["colActivityId"]?.Value.ToString()).ToList();
|
||||
=> row.Cells["colCheckActivity"]?.Value.ParseToBool() == true)
|
||||
.Select(r => r.Cells["colActivityThematicId"]?.Value.ToString()).ToList();
|
||||
if (lstActivityId.Count == 0)
|
||||
{
|
||||
BaseMsgForm.ShowInfo("请选择活动!");
|
||||
@@ -651,8 +697,8 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
lstShopIdSelect.Clear();
|
||||
lstShopIdSelect.AddRange(lstShopId);
|
||||
lstActivityIdSelect.Clear();
|
||||
lstActivityIdSelect.AddRange(lstActivityId);
|
||||
lstActivityThematicIdSelect.Clear();
|
||||
lstActivityThematicIdSelect.AddRange(lstActivityId);
|
||||
#endregion
|
||||
|
||||
Task.Run(() =>
|
||||
@@ -805,20 +851,20 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
if (!CheckLogin(shop))
|
||||
continue;
|
||||
|
||||
foreach (var activityId in lstActivityIdSelect)
|
||||
foreach (var activityId in lstActivityThematicIdSelect)
|
||||
{
|
||||
var activity = lstActivityThematic.FirstOrDefault(a => a.activityThematicId.ParseToString() == activityId);
|
||||
if (activity == null)
|
||||
continue;
|
||||
var actRow = this.dgvActivity.Rows.Cast<DataGridViewRow>()
|
||||
.FirstOrDefault(r => r.Cells["colActivityId"].Value.ParseToLong() == activity.activityThematicId);
|
||||
.FirstOrDefault(r => r.Cells["colActivityThematicId"].Value.ParseToLong() == activity.activityThematicId);
|
||||
if (actRow == null)
|
||||
continue;
|
||||
|
||||
int tryCount = 0;
|
||||
tryAgain:
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
var jsonRst = GetActivityMatch(shop, activity.activityThematicId, string.Join(",", noSaleProdIdLst));
|
||||
var jsonRst = GetActivityMatch(shop, activity.activityType, activity.activityThematicId, string.Join(",", noSaleProdIdLst));
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符") || jsonRst.Contains("login") || jsonRst.Contains("Login"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
@@ -877,8 +923,10 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
var prodSubmitRows = new List<DataGridViewRow>();
|
||||
|
||||
TemuActivityParam activityParam = new TemuActivityParam();
|
||||
activityParam.activityType = 13;
|
||||
activityParam.activityThematicId = activity.activityThematicId;
|
||||
activityParam.activityType = activity.activityType;
|
||||
// 相同的是主活动,不需要activityThematicId就可以报名。
|
||||
if (activity.activityThematicId != activity.activityType)
|
||||
activityParam.activityThematicId = activity.activityThematicId;
|
||||
activityParam.productList = new List<ActProductListItem>();
|
||||
|
||||
foreach (var prod in prodLst)
|
||||
@@ -939,11 +987,11 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
string data = JsonHelper.SerializeObject(activityParam);
|
||||
string submitRst = "";
|
||||
Thread.Sleep(Randomx.GetId(1000, 5000));
|
||||
submitRst = SubmitActivity(shop, activityParam.activityThematicId, data);
|
||||
submitRst = SubmitActivity(shop, activityParam.activityType, activityParam.activityThematicId, data);
|
||||
for (int j = 0; j < 4 && (jsonRst.Contains("当前操作人数太多,请稍后重试") || jsonRst.Contains("too quickly")); j++)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(5000, 7500));
|
||||
submitRst = SubmitActivity(shop, activityParam.activityThematicId, data);
|
||||
submitRst = SubmitActivity(shop, activityParam.activityType, activityParam.activityThematicId, data);
|
||||
}
|
||||
|
||||
if (!submitRst.Contains("\"success\":true"))
|
||||
@@ -1035,17 +1083,24 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
/// <param name="thematicId"></param>
|
||||
/// <param name="spuIds">多个用逗号隔开</param>
|
||||
/// <returns></returns>
|
||||
private string GetActivityMatch(ShopLoginInfo shop, long? thematicId, string spuIds="")
|
||||
private string GetActivityMatch(ShopLoginInfo shop,int? activityType, long? thematicId, string spuIds="")
|
||||
{
|
||||
string url = "https://agentseller.temu.com/api/kiana/gamblers/marketing/enroll/scroll/match";
|
||||
string body;
|
||||
body = @"{""activityType"":13,""activityThematicId"":" + thematicId + @",""rowCount"":50}";
|
||||
body = "{\"activityType\":" + activityType;
|
||||
if (thematicId != activityType)
|
||||
body += ",\"activityThematicId\":" + thematicId;
|
||||
body += ",\"rowCount\":50}";
|
||||
if (!string.IsNullOrWhiteSpace(spuIds))
|
||||
{
|
||||
body = @"{""activityType"":13,""activityThematicId"":" + thematicId +
|
||||
@",""rowCount"":50,""productIds"":[" + spuIds + @"],""productSkcExtCodes"":[]}";
|
||||
body = "{\"activityType\":" + activityType;
|
||||
if (thematicId != activityType)
|
||||
body += ",\"activityThematicId\":" + thematicId;
|
||||
body += ",\"rowCount\":50,\"productIds\":[" + spuIds + "],\"productSkcExtCodes\":[]}";
|
||||
}
|
||||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=13&thematicId=" + thematicId;
|
||||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=" + activityType;
|
||||
if (thematicId != activityType)
|
||||
refere += "&thematicId=" + thematicId;
|
||||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||||
}
|
||||
|
||||
@@ -1056,12 +1111,14 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
/// <param name="thematicId"></param>
|
||||
/// <param name="_body"></param>
|
||||
/// <returns></returns>
|
||||
private string SubmitActivity(ShopLoginInfo shop, long? thematicId, string _body)
|
||||
private string SubmitActivity(ShopLoginInfo shop, int? activityType, long? thematicId, string _body)
|
||||
{
|
||||
string url = "https://agentseller.temu.com/api/kiana/gamblers/marketing/enroll/submit";
|
||||
string body;
|
||||
body = _body;
|
||||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=13&thematicId=" + thematicId;
|
||||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=" + activityType;
|
||||
if (thematicId != activityType)
|
||||
refere += "&thematicId=" + thematicId;
|
||||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user