活动报名逻辑优化
This commit is contained in:
1 parent
d01d3bc306
commit
8fb90422a2
15 files changed
+1736
-291
No files matched your search
@@ -36,6 +36,12 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
public partial class PDDShopLoginForm : LRBaseForm
|
||||
{
|
||||
public static PDDShopLoginForm shopLoginInstance { get; set; } = null;
|
||||
public ProductSelectForms.PDDDBProdUserSelectForm prodUserSelectForm { get; set; } = null;
|
||||
public static string pddUploadGoodsData = "";
|
||||
//public static AllBase.Model.Param.PDDProdParam.PDDProductUploadParam prodParam = null;
|
||||
public static string pddSourceGoodsData = "";
|
||||
public static string pddSourceGoodsDataTemp = "";
|
||||
//public static AllBase.Model.Result.PDDResult.PDDProductDetailInfo prodInfo = null;
|
||||
|
||||
public int CloseAfterSecond { get; set; }
|
||||
public EnumOpenType openType = EnumOpenType.manage;
|
||||
@@ -43,14 +49,12 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
public string MultiLoginCookieName = "";
|
||||
public string InitUrl = "";
|
||||
private string shopCookieHead = "pinduoduo.com";
|
||||
private string shopCookieHead2 = "temu.com";
|
||||
private string shopLoginUrl = "https://mms.pinduoduo.com/login";
|
||||
private string shopMainUrl = "https://mms.pinduoduo.com/home";
|
||||
private ChromiumWebBrowser cefWebBrowser = null;
|
||||
private ShopLoginInfo shop = null;
|
||||
private List<ShopCompany> lstShopCompany = new List<ShopCompany>();
|
||||
private string currentUrl = "";
|
||||
private long currentSupplierId = 0;
|
||||
|
||||
public PDDShopLoginForm(ShopLoginInfo shopInfo)
|
||||
{
|
||||
@@ -70,6 +74,8 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
private void ShopLoginForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.splitContainer1.SplitterDistance = this.splitContainer1.Height - 62;
|
||||
this.pnlUploadOpBtns.Visible = this.prodUserSelectForm != null;
|
||||
pddSourceGoodsDataTemp = "";
|
||||
|
||||
if (isMultiLogin && shop != null)
|
||||
{
|
||||
@@ -433,27 +439,53 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
|
||||
private void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
||||
{
|
||||
//if (!cefWebBrowser.IsBrowserInitialized) return;
|
||||
|
||||
//currentUrl = e.Url;
|
||||
//if (currentUrl.StartsWith("https://fxg.jinritemai.com/ffa/multiShop"))
|
||||
//{
|
||||
// Thread.Sleep(Randomx.GetId(500, 800));
|
||||
//}
|
||||
//if (currentUrl.StartsWith("https://fxg.jinritemai.com/ffa/mshop/homepage/index"))
|
||||
//{
|
||||
// Task.Run(() =>
|
||||
// {
|
||||
//
|
||||
// });
|
||||
//}
|
||||
|
||||
//js绑定C#对象 html页面内声明绑定的C#对象
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("(function(){");
|
||||
sb.Append("CefSharp.BindObjectAsync('shopObj');");
|
||||
sb.Append("})();");
|
||||
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
|
||||
|
||||
// 库存上传按钮 pdd不需要
|
||||
if (1 == 2 && currentUrl.StartsWith("https://mms.pinduoduo.com/goods/goods_list"))
|
||||
{
|
||||
Task.Run(() => {
|
||||
string sAddInputJs = @"
|
||||
document.addEventListener('wheel', function(event) {
|
||||
// 检查滚动方向
|
||||
//if (event.deltaY < 0) {
|
||||
// console.log('向上滚动');
|
||||
//} else {
|
||||
// console.log('向下滚动');
|
||||
//}
|
||||
// 或者使用 event.deltaX 来检查水平滚动
|
||||
//if (event.deltaX < 0) {
|
||||
// console.log('向左滚动');
|
||||
//} else if (event.deltaX > 0) {
|
||||
// console.log('向右滚动');
|
||||
//}
|
||||
|
||||
// 阻止默认的滚动行为(如果有需要)
|
||||
//event.preventDefault();
|
||||
|
||||
addGetProdButton();
|
||||
});
|
||||
addGetProdButton();
|
||||
|
||||
function addGetProdButton() {
|
||||
var productLst = document.getElementsByClassName('goods-id');
|
||||
for(i=0; i<productLst.length; i++) {
|
||||
var addBtnItem = productLst[i].parentElement.parentElement;
|
||||
if (addBtnItem.parentElement.innerHTML.indexOf('库存上传') < 0 && addBtnItem.parentElement.innerHTML.indexOf('ID:') >= 0) {
|
||||
var sSpuId = addBtnItem.innerText.replace('\r','').replace('\n','').replace('ID: ', '');
|
||||
addBtnItem.outerHTML = addBtnItem.outerHTML.replace(""<section>"",""<section style=\""display:inline; float:left; \"">"")
|
||||
.replace(""</section>"", ""</section><input type=\""button\"" style=\""display:inline; width:60px; margin-left:10px; margin-top:0px; cursor:pointer; border:1px solid\"" value =\""库存上传\"" onclick=\""shopObj.getThirdProduct('"" + sSpuId + ""','" + this.shop.ShopId + @"')\"">"");
|
||||
}
|
||||
}
|
||||
}";
|
||||
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sAddInputJs);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static int GetAntiContentsTimes = 40;
|
||||
@@ -462,38 +494,20 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
var antiContent = request.Headers.AllKeys.Contains("Anti-Content") ? request.Headers["Anti-Content"] : "";
|
||||
if (shop != null && !url.StartsWith("https://mms.pinduoduo.com/janus/api/userinfo") && !string.IsNullOrEmpty(antiContent))
|
||||
{
|
||||
GetAntiContentsTimes++;
|
||||
Invoke(new Action(() => { this.TitleText = "店铺登录 - " + GetAntiContentsTimes; }));
|
||||
shop.AntiContents.Add(antiContent);
|
||||
while (shop.AntiContents.Count > 50)
|
||||
shop.AntiContents.RemoveAt(0);
|
||||
if (!string.IsNullOrEmpty(shop.ShopId) && GetAntiContentsTimes > 500)
|
||||
Task.Run(() =>
|
||||
{
|
||||
GetAntiContentsTimes = 0;
|
||||
Task.Run(() =>
|
||||
GetAntiContentsTimes++;
|
||||
Invoke(new Action(() => { try { this.TitleText = "店铺登录 - " + GetAntiContentsTimes; } catch { return; } }));
|
||||
shop.AntiContents.Add(antiContent);
|
||||
while (shop.AntiContents.Count > 50)
|
||||
shop.AntiContents.RemoveAt(0);
|
||||
if (!string.IsNullOrEmpty(shop.ShopId) && GetAntiContentsTimes > 500)
|
||||
{
|
||||
GetAntiContentsTimes = 0;
|
||||
ShopBLL.MdyAntiContent(shop);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
var data = responseData;
|
||||
if (data.Contains("\"validate_message\""))
|
||||
{
|
||||
|
||||
}
|
||||
//if (data.Contains("supplierId") && data.Contains("\"success\":true"))
|
||||
//{
|
||||
// var supplierIds = BaseRegex.GetMatchRegex(ref data, "\"supplierId\":\\d{5,20}");
|
||||
// if (supplierIds.Count > 0 && supplierIds[0].Groups.Count > 0)
|
||||
// {
|
||||
// var supplierId = supplierIds[0].Groups[0].Value.Replace("\"supplierId\":", "").ParseToLong();
|
||||
// if (supplierId > 0)
|
||||
// this.currentSupplierId = supplierId;
|
||||
// }
|
||||
//}
|
||||
});
|
||||
if (url == "https://mms.pinduoduo.com/janus/api/userinfo")
|
||||
{
|
||||
Task.Run(() =>
|
||||
@@ -528,44 +542,35 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
}
|
||||
});
|
||||
}
|
||||
// 库存上传按钮
|
||||
if (1 == 1 && currentUrl.StartsWith("https://mms.pinduoduo.com/goods/goods_list"))
|
||||
if (prodUserSelectForm != null && url.StartsWith("https://mms.pinduoduo.com/glide/mms/goodsCommit/action/edit"))
|
||||
{
|
||||
Task.Run(() => {
|
||||
string sAddInputJs = @"
|
||||
document.addEventListener('wheel', function(event) {
|
||||
// 检查滚动方向
|
||||
//if (event.deltaY < 0) {
|
||||
// console.log('向上滚动');
|
||||
//} else {
|
||||
// console.log('向下滚动');
|
||||
//}
|
||||
// 或者使用 event.deltaX 来检查水平滚动
|
||||
//if (event.deltaX < 0) {
|
||||
// console.log('向左滚动');
|
||||
//} else if (event.deltaX > 0) {
|
||||
// console.log('向右滚动');
|
||||
//}
|
||||
|
||||
// 阻止默认的滚动行为(如果有需要)
|
||||
//event.preventDefault();
|
||||
|
||||
addGetProdButton();
|
||||
});
|
||||
addGetProdButton();
|
||||
|
||||
function addGetProdButton() {
|
||||
var productLst = document.getElementsByClassName('goods-id0000000000');
|
||||
for(i=0; i<productLst.length; i++) {
|
||||
var addBtnItem = productLst[i].parentElement.parentElement;
|
||||
if (addBtnItem.parentElement.innerHTML.indexOf('库存上传') < 0 && addBtnItem.parentElement.innerHTML.indexOf('ID:') >= 0) {
|
||||
var sSpuId = addBtnItem.innerText.replace('\r','').replace('\n','').replace('ID: ', '');
|
||||
addBtnItem.outerHTML = addBtnItem.outerHTML.replace(""<section>"",""<section style=\""display:inline; float:left; \"">"")
|
||||
.replace(""</section>"", ""</section><input type=\""button\"" style=\""display:inline; width:60px; margin-left:10px; margin-top:0px; cursor:pointer; border:1px solid\"" value =\""库存上传\"" onclick=\""shopObj.getThirdProduct('"" + sSpuId + ""','" + this.shop.ShopId + @"')\"">"");
|
||||
}
|
||||
}
|
||||
}";
|
||||
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sAddInputJs);
|
||||
try
|
||||
{
|
||||
pddUploadGoodsData = System.Text.Encoding.UTF8.GetString(request.PostData.Elements[0].Bytes);
|
||||
var prodParam = JsonHelper.DeserializeJsonToObject<AllBase.Model.Param.PDDProdParam.PDDProductUploadParam>(pddUploadGoodsData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
pddUploadGoodsData = "";
|
||||
//prodParam = null;
|
||||
}
|
||||
}
|
||||
if (prodUserSelectForm != null && url.StartsWith("https://mms.pinduoduo.com/glide/v2/mms/query/commit/detail"))
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
pddSourceGoodsDataTemp = responseData;
|
||||
try
|
||||
{
|
||||
JObject jObj = JObject.Parse(pddSourceGoodsDataTemp);
|
||||
var prodInfoStr = JsonHelper.SerializeObject(jObj["result"]);
|
||||
var prodInfo = JsonHelper.DeserializeJsonToObject<AllBase.Model.Result.PDDResult.PDDProductDetailInfo>(prodInfoStr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
pddSourceGoodsDataTemp = "";
|
||||
//prodInfo = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1011,5 +1016,225 @@ function getElementWithText(sText)
|
||||
//ReturnPackageDetailForm form = new ReturnPackageDetailForm(this.shop);
|
||||
//form.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnSaveSourceGoodsData_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pddSourceGoodsDataTemp))
|
||||
{
|
||||
BaseMsgForm.ShowError("未捕获到商品详情!");
|
||||
return;
|
||||
}
|
||||
pddSourceGoodsData = pddSourceGoodsDataTemp;
|
||||
|
||||
try
|
||||
{
|
||||
JObject jObj = JObject.Parse(pddSourceGoodsData);
|
||||
var prodInfoStr = JsonHelper.SerializeObject(jObj["result"]);
|
||||
var prodInfo = JsonHelper.DeserializeJsonToObject<AllBase.Model.Result.PDDResult.PDDProductDetailInfo>(prodInfoStr);
|
||||
|
||||
var skuimgs = prodInfo.sku.Select(s => s.thumb_url).Distinct().ToList();
|
||||
while (skuimgs.Count < 8)
|
||||
skuimgs.Add("");
|
||||
this.pictureBox1.ImageLocation = skuimgs[0].Replace("https://", "http://");
|
||||
this.pictureBox2.ImageLocation = skuimgs[1].Replace("https://", "http://");
|
||||
this.pictureBox3.ImageLocation = skuimgs[2].Replace("https://", "http://");
|
||||
this.pictureBox4.ImageLocation = skuimgs[3].Replace("https://", "http://");
|
||||
this.pictureBox5.ImageLocation = skuimgs[4].Replace("https://", "http://");
|
||||
this.pictureBox6.ImageLocation = skuimgs[5].Replace("https://", "http://");
|
||||
this.pictureBox7.ImageLocation = skuimgs[6].Replace("https://", "http://");
|
||||
this.pictureBox8.ImageLocation = skuimgs[7].Replace("https://", "http://");
|
||||
|
||||
this.numMinPrice.Value = prodInfo.sku.Min(s => s.multi_price).ParseToDecimal() / 100m;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError("暂存图片失败:" + ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
BaseMsgForm.ShowInfo("暂存图片成功!");
|
||||
}
|
||||
|
||||
private void btnRestoreSkuImg_Click(object sender, EventArgs e)
|
||||
{
|
||||
var commitId = BaseRegex.GetStringQuery(ref currentUrl, "id");
|
||||
var goodsId = BaseRegex.GetStringQuery(ref currentUrl, "goods_id");
|
||||
AllBase.Model.Result.PDDResult.PDDProductDetailInfo prodInfo = null;
|
||||
AllBase.Model.Param.PDDProdParam.PDDProductUploadParam prodParam = null;
|
||||
if (string.IsNullOrEmpty(commitId) || string.IsNullOrEmpty(goodsId))
|
||||
{
|
||||
BaseMsgForm.ShowError("不是商品编辑页面!");
|
||||
return;
|
||||
}
|
||||
if (prodUserSelectForm == null)
|
||||
{
|
||||
BaseMsgForm.ShowError("不是从上传界面进入!");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(pddSourceGoodsData))
|
||||
{
|
||||
BaseMsgForm.ShowError("未捕获到商品详情!");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(pddUploadGoodsData))
|
||||
{
|
||||
BaseMsgForm.ShowError("未捕获到商品上传记录!无法还原!");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
JObject jObj = JObject.Parse(pddSourceGoodsData);
|
||||
var prodInfoStr = JsonHelper.SerializeObject(jObj["result"]);
|
||||
prodInfo = JsonHelper.DeserializeJsonToObject<AllBase.Model.Result.PDDResult.PDDProductDetailInfo>(prodInfoStr);
|
||||
prodParam = JsonHelper.DeserializeJsonToObject<AllBase.Model.Param.PDDProdParam.PDDProductUploadParam>(pddUploadGoodsData);
|
||||
if (prodInfo.goods_id != prodParam.goods_id || prodInfo.goods_id != goodsId.ParseToLong())
|
||||
{
|
||||
BaseMsgForm.ShowError("来源商品和还原商品不一致!无法还原!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError("商品数据格式还原失败:" + ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
var prodParamObj = JObject.Parse(pddUploadGoodsData);
|
||||
prodParamObj["goods_commit_id"] = commitId;
|
||||
foreach (var skuObj in prodParamObj["skus"])
|
||||
{
|
||||
var specNames = "";
|
||||
foreach (var spec in skuObj["spec"])
|
||||
{
|
||||
specNames += spec["spec_name"] + ",";
|
||||
}
|
||||
specNames = specNames.TrimEnd(',');
|
||||
|
||||
var sourceSku = prodInfo.sku.FirstOrDefault(s => string.Join(",", s.spec.Select(sp => sp.spec_name)) == specNames);
|
||||
if (sourceSku != null)
|
||||
{
|
||||
skuObj["thumb_url"] = sourceSku.thumb_url;
|
||||
skuObj["thumb_url_file_id"] = sourceSku.thumb_url_file_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseMsgForm.ShowError("商品数据格式还原失败:有未能匹配的sku");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var newData = JsonHelper.SerializeObject(prodParamObj);
|
||||
var saveProdRst = prodUserSelectForm.save_goods_edit_data(shop, newData, goodsId, commitId, false, "edit");
|
||||
if (!saveProdRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref saveProdRst, "error_msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = saveProdRst;
|
||||
BaseMsgForm.ShowError("保存失败 " + error);
|
||||
return;
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(100, 600));
|
||||
var submitProdRst = prodUserSelectForm.submit_goods_edit(shop, goodsId, commitId, false, "edit");
|
||||
if (!submitProdRst.Contains("\"success\":true"))
|
||||
{
|
||||
var error = BaseRegex.GetStringJson(ref submitProdRst, "error_msg");
|
||||
if (string.IsNullOrEmpty(error))
|
||||
error = submitProdRst;
|
||||
BaseMsgForm.ShowError("提交失败 " + error);
|
||||
return;
|
||||
}
|
||||
cefWebBrowser.Load("https://mms.pinduoduo.com/goods/goods_list?msfrom=mms_sidenav");
|
||||
BaseMsgForm.ShowInfo("还原并提交成功!");
|
||||
}
|
||||
|
||||
private void btnSignActivity_Click(object sender, EventArgs e)
|
||||
{
|
||||
var commitId = BaseRegex.GetStringQuery(ref currentUrl, "id");
|
||||
var goodsId = BaseRegex.GetStringQuery(ref currentUrl, "goods_id");
|
||||
AllBase.Model.Result.PDDResult.PDDProductDetailInfo prodInfo = null;
|
||||
AllBase.Model.Param.PDDProdParam.PDDProductUploadParam prodParam = null;
|
||||
if (string.IsNullOrEmpty(commitId) || string.IsNullOrEmpty(goodsId))
|
||||
{
|
||||
BaseMsgForm.ShowError("不是商品编辑页面!");
|
||||
return;
|
||||
}
|
||||
if (prodUserSelectForm == null)
|
||||
{
|
||||
BaseMsgForm.ShowError("不是从上传界面进入!");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(pddSourceGoodsData))
|
||||
{
|
||||
BaseMsgForm.ShowError("未捕获到商品详情!");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(pddUploadGoodsData))
|
||||
{
|
||||
BaseMsgForm.ShowError("未捕获到商品上传记录!无法报名!");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
JObject jObj = JObject.Parse(pddSourceGoodsData);
|
||||
var prodInfoStr = JsonHelper.SerializeObject(jObj["result"]);
|
||||
prodInfo = JsonHelper.DeserializeJsonToObject<AllBase.Model.Result.PDDResult.PDDProductDetailInfo>(prodInfoStr);
|
||||
prodParam = JsonHelper.DeserializeJsonToObject<AllBase.Model.Param.PDDProdParam.PDDProductUploadParam>(pddUploadGoodsData);
|
||||
if (prodInfo.goods_id != prodParam.goods_id || prodInfo.goods_id != goodsId.ParseToLong())
|
||||
{
|
||||
BaseMsgForm.ShowError("来源商品和还原商品不一致!无法报名!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError("一键报名活动失败:" + ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
btnSignActivity.Text = "报名中请稍候";
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var sku in prodParam.skus)
|
||||
{
|
||||
sku.multi_price = (numMinPrice.Value * 100).ParseToInt();
|
||||
sku.price = sku.multi_price + 100;
|
||||
}
|
||||
var result = prodUserSelectForm.SignAcitvity(shop, prodParam);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
btnSignActivity.Text = "一键报名活动";
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
BaseMsgForm.ShowError(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseMsgForm.ShowInfo("一键报名活动成功");
|
||||
}
|
||||
}));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
var pb = sender as PictureBox;
|
||||
if (!string.IsNullOrEmpty(pb?.ImageLocation))
|
||||
{
|
||||
ToolForms.ShowImgForm imgFrom = new ToolForms.ShowImgForm(pb.ImageLocation);
|
||||
imgFrom.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void label3_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user