temu客户端程序
This commit is contained in:
commit
4aaf264e89
694 files changed
+263780
No files matched your search
@@ -0,0 +1,353 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.Result;
|
||||
using LittleRabbit.LittleRabbitForms.BaseForms;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace LittleRabbit.LittleRabbitForms.SalesCenterForms
|
||||
{
|
||||
public partial class FullMinusActiveForm : Form
|
||||
{
|
||||
private DouShopLoginInfo shop = null;
|
||||
public List<long> lstActiveId = new List<long>();
|
||||
public FullMinusForm fullMinusForm = null;
|
||||
private string _signature = "";
|
||||
private string _underline = "";
|
||||
public bool isGetActiveSuccess = false;
|
||||
public List<FullMinusActiveInfo> activeList = new List<FullMinusActiveInfo>();
|
||||
|
||||
public FullMinusActiveForm(DouShopLoginInfo _shop = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
shop = _shop;
|
||||
}
|
||||
|
||||
private void FullMinusActiveForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
cmbActState.SelectedIndex = 0;
|
||||
txtActName.Focus();
|
||||
}
|
||||
|
||||
private void dgvActive_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||||
return;
|
||||
string columnName = dgvActive.Columns[e.ColumnIndex].Name;
|
||||
long ActiveId = dgvActive.Rows[e.RowIndex].Cells["colActiveId"].Value.ParseToLong();
|
||||
var row = dgvActive.Rows[e.RowIndex];
|
||||
switch (columnName)
|
||||
{
|
||||
case "colSelect":
|
||||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||||
if (dgvActive.Rows[e.RowIndex].Cells["colSelect"].Value.ParseToBool())
|
||||
{
|
||||
if (lstActiveId.Any(p => p == ActiveId))
|
||||
lstActiveId.RemoveAll(p => p == ActiveId);
|
||||
lstActiveId.Add(ActiveId);
|
||||
}
|
||||
else
|
||||
lstActiveId.Remove(ActiveId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetActive()
|
||||
{
|
||||
if (shop == null)
|
||||
return;
|
||||
|
||||
ShowVisitorMessage("");
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (shop.LoginStatus == "登录成功")
|
||||
fullMinusForm.GetActiveByCef(this.shop);
|
||||
|
||||
var rowsTemp = dgvActive.Rows.Cast<DataGridViewRow>().ToList();
|
||||
rowsTemp.Reverse();
|
||||
});
|
||||
}
|
||||
|
||||
public void GetActiveSim(string listUrl, string referrerUrl, Dictionary<string, string> headers, string firstPageData = "")
|
||||
{
|
||||
ShowVisitorMessage("");
|
||||
|
||||
int total = -1;
|
||||
int number = 0;
|
||||
string result = "";
|
||||
if (!string.IsNullOrEmpty(firstPageData))
|
||||
result = firstPageData;
|
||||
|
||||
//获取所有活动
|
||||
if (string.IsNullOrEmpty(_underline))
|
||||
_underline = BaseRegex.GetMatchRegexString(ref listUrl, "&_=([\\s\\S]+?)&");
|
||||
if (string.IsNullOrEmpty(_underline))
|
||||
_underline = BaseRegex.GetMatchRegexString(ref listUrl, "&_=([\\s\\S]+?)");
|
||||
if (string.IsNullOrEmpty(_underline))
|
||||
_underline = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now).ToString();
|
||||
if (string.IsNullOrEmpty(_signature))
|
||||
_signature = BaseRegex.GetMatchRegexString(ref listUrl, "&_signature=([\\s\\S]+?)&");
|
||||
if (string.IsNullOrEmpty(_signature))
|
||||
{
|
||||
var listUrl2 = listUrl + "&";
|
||||
_signature = BaseRegex.GetMatchRegexString(ref listUrl2, "&_signature=([\\s\\S]+?)&");
|
||||
}
|
||||
listUrl = "https://fxg.jinritemai.com/marketing/activity/v1/query_full_discount_activity?activity_status=0&page=1&pageSize=20&_bid=ecom_market_shop&appid=1&_=" + _underline + "&_signature=" + _signature;
|
||||
for (int i = 1; i < 9999; i++)
|
||||
{
|
||||
number += 20;
|
||||
for (int j = 0; j < 3 && !result.Contains("\"st\":0"); j++)
|
||||
{
|
||||
CommonSimRequest simRequest = new CommonSimRequest();
|
||||
simRequest.Accept = "application/json, text/plain, */*";
|
||||
if (headers.ContainsKey("Accept"))
|
||||
simRequest.Accept = headers["Accept"];
|
||||
if (headers.ContainsKey("UserAgent"))
|
||||
simRequest.UserAgent = headers["UserAgent"];
|
||||
var cookie = shop.Cookies;
|
||||
|
||||
var rUrl = listUrl.Replace("page=1", "page=" + i);
|
||||
result = simRequest.Request_Get(rUrl, referrerUrl, new Dictionary<string, string>(), cookie);
|
||||
if (j > 0)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (result.Contains(",\"msg\":\"成功\",\"st\":0") && !fullMinusForm.cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
this.isGetActiveSuccess = true;
|
||||
|
||||
if (total == -1)
|
||||
{
|
||||
total = BaseRegex.GetIntJson(ref result, "total");
|
||||
}
|
||||
|
||||
var jObj = JObject.Parse(result);
|
||||
var aList = JsonHelper.DeserializeJsonToList<FullMinusActiveInfo>(jObj["data"]["data"]?.ToString());
|
||||
foreach (var info in aList)
|
||||
{
|
||||
if (this.activeList.Any(p => p.activity_id == info.activity_id))
|
||||
this.activeList.RemoveAll(p => p.activity_id == info.activity_id);
|
||||
this.activeList.Add(info);
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(1500, 2000));
|
||||
}
|
||||
else
|
||||
{
|
||||
isGetActiveSuccess = false;
|
||||
break;
|
||||
}
|
||||
result = "";
|
||||
if (number >= total)
|
||||
break;
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (fullMinusForm.cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "获取中断";
|
||||
}
|
||||
else if (!isGetActiveSuccess)
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "获取活动信息失败";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "获取完成";
|
||||
}
|
||||
this.statusBar.pgbTaskProgress.Value = 0;
|
||||
this.statusBar.pgbTaskProgress.Text = 0 + "/" + 0;
|
||||
this.statusBar.pgbTaskProgress.Maximum = 0;
|
||||
}));
|
||||
}
|
||||
|
||||
public void ShowVisitorMessage(string msg)
|
||||
{
|
||||
Invoke(new Action(() => { this.label1.Text = msg; }));
|
||||
}
|
||||
|
||||
private void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
ShowVisitorMessage("");
|
||||
ShowVisitorMessage("查询开始");
|
||||
if (this.activeList.Count == 0)
|
||||
{
|
||||
if (fullMinusForm.cancellationTokenSource.IsCancellationRequested)
|
||||
fullMinusForm.cancellationTokenSource = new CancellationTokenSource();
|
||||
GetActiveSim("https://fxg.jinritemai.com/marketing/activity/v1/query_full_discount_activity?page=1&pageSize=20&activity_status=0&_bid=ecom_market_shop&appid=1&_=" + _underline + "&_signature=" + _signature, "https://fxg.jinritemai.com/market/center/tools/moneyoff", new Dictionary<string, string>());
|
||||
}
|
||||
var name = txtActName.Text.Trim();
|
||||
var stateText = cmbActState.SelectedItem.ToString();
|
||||
var stateVal = stateText == "全部" ? "0" : (stateText == "进行中" ? "2" : (stateText == "已结束" ? "3" : (stateText == "未开始" ? "1" : "4")));
|
||||
if ((name == "" && stateVal == "0" && this.dgvActive.Rows.Count == this.activeList.Count) || this.activeList.Count == 0)
|
||||
{
|
||||
ShowVisitorMessage("查询完成!");
|
||||
return;
|
||||
}
|
||||
Task.Run(() => {
|
||||
List<FullMinusActiveInfo> infos = new List<FullMinusActiveInfo>();
|
||||
infos = this.activeList;
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
infos = infos.Where(x => x.activity_name == name).ToList();
|
||||
if (stateVal != "0")
|
||||
infos = infos.Where(x => x.activity_status == stateVal.ParseToInt()).ToList();
|
||||
int totals = infos.Count;
|
||||
Invoke(new Action(() => {
|
||||
this.dgvActive.Rows.Clear();
|
||||
for (int j = 0; j < totals; j++)
|
||||
{
|
||||
var info = infos[j];
|
||||
var status = info.activity_status == 3 ? "已结束" : (info.activity_status == 2 ? "进行中" : (info.activity_status == 1 ? "未开始" : "已失效"));
|
||||
string activeOff = string.Empty;
|
||||
if (info.discounts != null)
|
||||
{
|
||||
if (info.activity_type == 1)
|
||||
{
|
||||
foreach (var dis in info.discounts)
|
||||
{
|
||||
activeOff += "满" + dis.condition_value.ParseToDecimal() / 100 + "元减" + dis.discount.ParseToDecimal() / 100 + "元;";
|
||||
}
|
||||
}
|
||||
else if (info.discount_type == 1)
|
||||
{
|
||||
foreach (var dis in info.discounts)
|
||||
{
|
||||
activeOff += "满" + dis.condition_value + "件打" + dis.discount.ParseToDecimal() / 10 + "折;";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var dis in info.discounts)
|
||||
{
|
||||
activeOff += "满" + dis.condition_value + "件减" + dis.discount.ParseToDecimal() / 100 + "元;";
|
||||
}
|
||||
}
|
||||
activeOff = activeOff.TrimEnd(';');
|
||||
}
|
||||
string activePro = string.Empty;
|
||||
if (info.activity_products != null)
|
||||
{
|
||||
foreach (var pro in info.activity_products)
|
||||
{
|
||||
activePro += pro.name + ";";
|
||||
}
|
||||
activePro = activePro.TrimEnd(';');
|
||||
}
|
||||
if (lstActiveId.Contains(info.activity_id.ParseToLong()))
|
||||
this.dgvActive.Rows.Add(true, info.activity_id, info.activity_name, activeOff, activePro, BaseClass.StampToDateTime(info.start_time.ParseToInt()), BaseClass.StampToDateTime(info.end_time.ParseToInt()), status);
|
||||
else
|
||||
this.dgvActive.Rows.Add(false, info.activity_id, info.activity_name, activeOff, activePro, BaseClass.StampToDateTime(info.start_time.ParseToInt()), BaseClass.StampToDateTime(info.end_time.ParseToInt()), status);
|
||||
}
|
||||
}));
|
||||
ShowVisitorMessage("查询完成!");
|
||||
});
|
||||
}
|
||||
|
||||
private void btnFailed_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dgvActive.Rows.Count == 0 || lstActiveId.Count == 0)
|
||||
{
|
||||
BaseMsgForm.ShowInfo("请选择待失效的活动!");
|
||||
return;
|
||||
}
|
||||
if (BaseMsgForm.ShowConfirm("确定将该活动设置为失效?").DialogResult == DialogResult.OK)
|
||||
{
|
||||
var failUrl = "https://fxg.jinritemai.com/marketing/activity/v1/disable_product_activity?activity_id={0}&_bid=ecom_market_shop&appid=1&_=" + _underline + "&_signature=" + _signature;
|
||||
var cookies = shop.Cookies;
|
||||
Task.Run(() =>
|
||||
{
|
||||
for (int i = 0; i < dgvActive.Rows.Count; i++)
|
||||
{
|
||||
DataGridViewRow row = dgvActive.Rows[i];
|
||||
long ActiveId = row.Cells["colActiveId"].Value.ParseToLong();
|
||||
if (lstActiveId.Any(p => p == ActiveId))
|
||||
{
|
||||
string name = row.Cells["colActiveName"].Value.ToString();
|
||||
var colActiveState = row.Cells["colActiveState"].Value.ToString();
|
||||
if (colActiveState != "进行中" && colActiveState != "未开始")
|
||||
{
|
||||
Invoke(new Action(() => { row.Cells["colMessage"].Value = name + "活动" + colActiveState + ",无需设置失效!"; }));
|
||||
continue;
|
||||
}
|
||||
CommonSimRequest request = new CommonSimRequest();
|
||||
request.ContentType = "application/json";
|
||||
Dictionary<string, string> dicts = new Dictionary<string, string>();
|
||||
var reqUrl = string.Format(failUrl, ActiveId);
|
||||
string result = request.Request_Get(reqUrl, "https://fxg.jinritemai.com/market/center/tools/moneyoff", dicts, cookies);
|
||||
if (result.Contains(",\"msg\":\"成功\",\"st\":0"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var activeInfo = activeList.Where(x => x.activity_id == ActiveId.ToString()).FirstOrDefault();
|
||||
if (activeInfo != null)
|
||||
{
|
||||
activeInfo.activity_status = 4;
|
||||
row.Cells["colActiveState"].Value = "已失效";
|
||||
row.Cells["colMessage"].Value = "设置失效已完成!";
|
||||
}
|
||||
}));
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
Invoke(new Action(() => { row.Cells["colMessage"].Value = "设置失效失败 :" + BaseRegex.GetStringJson(ref result, "msg"); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
this.lstActiveId.Clear();
|
||||
this.activeList.Clear();
|
||||
this.dgvActive.Rows.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class FullMinusActiveInfo
|
||||
{
|
||||
public string activity_id { get; set; }
|
||||
public int activity_type { get; set; }
|
||||
public string activity_name { get; set; }
|
||||
public long start_time { get; set; }
|
||||
public long end_time { get; set; }
|
||||
public int discount_type { get; set; }
|
||||
public int activity_status { get; set; }
|
||||
public string enable_use_coupon { get; set; }
|
||||
public List<ActiveDiscounts> discounts { get; set; }
|
||||
public List<ActiveProducts> activity_products { get; set; }
|
||||
}
|
||||
public class ActiveDiscounts
|
||||
{
|
||||
public long activity_id { get; set; }
|
||||
public long discount_id { get; set; }
|
||||
public int condition_type { get; set; }
|
||||
public string condition_value { get; set; }
|
||||
public int discount_type { get; set; }
|
||||
public string discount { get; set; }
|
||||
public int discount_level { get; set; }
|
||||
}
|
||||
public class ActiveProducts
|
||||
{
|
||||
public string activity_id { get; set; }
|
||||
public long shop_id { get; set; }
|
||||
public string product_id { get; set; }
|
||||
public int status { get; set; }
|
||||
public string name { get; set; }
|
||||
public string img { get; set; }
|
||||
public long stock_num { get; set; }
|
||||
public long max_price { get; set; }
|
||||
public long min_price { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user