Files
KJD/TEMUKJD/KJDForms/ProductForms/TemuAdsForm.cs
T
2025-12-26 09:53:29 +08:00

2441 lines
125 KiB
C#

using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using AllBase.Model.Result.TemuResult;
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.BaseForms;
using TemuKJD.BLL;
using TemuKJD.Extension;
using TemuKJD.KJDForms.ShopForms;
using TemuKJD.KJDForms.ShopForms.Statistics;
using TemuKJD.ToolForms;
using Work;
namespace TemuKJD.KJDForms.ProductForms
{
public partial class TemuAdsForm : BaseForm
{
static TemuAdsForm instance;
public static TemuAdsForm Instance { get { if (instance == null) instance = new TemuAdsForm(); return instance; } set { instance = value; } }
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
List<AdsDetailInfo> lstAdsDetailInfo = new List<AdsDetailInfo>();
List<ads_goods_info> lstAdsMallGoodsInfo = new List<ads_goods_info>();
List<WarehouseProductSubOrderInfo> lstWareHouse = new List<WarehouseProductSubOrderInfo>();
List<TemuDBProductPurchasePriceInfo> lstPurchasePrice = new List<TemuDBProductPurchasePriceInfo>();
CheckBox chkSelectAll = null;
public TemuAdsForm()
{
InitializeComponent();
instance = this;
}
private void TemuAdsForm_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.dgvAds.AddSelectorColumn("colCheck");
this.dgvShop.Columns["colAdsLoginStatus"].HeaderCell.Style.WrapMode = DataGridViewTriState.True;
this.dgvAds.Columns["colMsg"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
dgvAds.AddImgColumn("colImg", "colImgUrl");
chkCalculateRoas.Checked = true;
this.dgvAds.AddMergeColumnHeader(new List<string>() { "colWantROAS", "colChangeROAS" }, "目标ROAS");
this.dgvAds.AddMergeColumn(new List<string>() { "colWantROAS", "colChangeROAS" });
}
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.ad_login_status == "在线").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 TemuAdsForm_VisibleChanged(object sender, EventArgs e)
{
if (Visible == true)
FiltShop();
}
private void btnRefreshShop_Click(object sender, EventArgs e)
{
pbShopLoading.Visible = true;
Task.Run(() =>
{
ShopListForm.UpdateShop();
Invoke(new Action(() =>
{
FiltShop();
pbShopLoading.Visible = false;
}));
});
}
private void btnSearchShop_Click(object sender, EventArgs e)
{
FiltShop();
}
private void FiltShop()
{
// 店铺Id
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
var shopLst = GlobalConfig.ShopLoginList.ToList();
if (!string.IsNullOrWhiteSpace(txtShopId.Text.Trim()))
{
shopLst = shopLst.Where(s => ("," + txtShopId.Text.Trim() + ",").Contains("," + s.ShopId + ",") || s.ShopId.Contains(txtShopId.Text.Trim())).ToList();
}
if (!string.IsNullOrWhiteSpace(txtShopName.Text.Trim()))
{
shopLst = shopLst.Where(s => ("," + txtShopName.Text.Trim() + ",").Contains("," + s.ShopAccount + ",") || s.ShopAccount.ToLower().Contains(txtShopName.Text.Trim().ToLower())).ToList();
}
if (!string.IsNullOrWhiteSpace(txtNotes.Text.Trim()))
{
shopLst = shopLst.Where(s => ("," + txtNotes.Text.Trim() + ",").Contains("," + s.Notes + ",") || s.Notes.ToLower().Contains(txtNotes.Text.Trim().ToLower())).ToList();
}
// 获取被删除的店铺
List<DataGridViewRow> dgvRowList = dgvShop.Rows.Cast<DataGridViewRow>().Where(row
=> !shopLst.Any(s => s.ShopId == row.Cells["colShopId"]?.Value?.ToString())).ToList();
// 更新被删除的店铺列表
foreach (var row in dgvRowList)
{
dgvShop.Rows.Remove(row);
}
// 绑定其他店铺(含新导入的店铺)
foreach (ShopLoginInfo shopEntity in shopLst)
{
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 canAdsUse = shopEntity.ad_login_status == "在线";
bool canUse = shopEntity.LoginStatus2 == "国际版在线";
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(p => p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == shopEntity.ShopId);
if (row == null)
{
int id = this.dgvShop.Rows.Add(
selectShopId.Contains(shopEntity.ShopId) && canAdsUse,
shopEntity.LoginName,
shopEntity.ShopId,
shopEntity.ShopAccount,
shopEntity.Notes,
canUse ? "在线" : "离线",
canAdsUse ? "在线" : "离线",
canAdsUse,
string.Empty
);
row = dgvShop.Rows[id];
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightGreen : Color.OrangeRed;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkGreen : Color.DarkRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canAdsUse ? Color.Green : Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = canAdsUse ? Color.Green : Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canAdsUse ? Color.LightGreen : Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canAdsUse ? Color.DarkGreen : Color.DarkRed;
}
else
{
row.Cells["colSelect"].Value = selectShopId.Contains(shopEntity.ShopId) && canAdsUse;
row.Cells["colShopLoginName"].Value = shopEntity.LoginName;
row.Cells["colShopName"].Value = shopEntity.ShopAccount;
row.Cells["colShopNotes"].Value = shopEntity.Notes;
row.Cells["colLoginStatus"].Value = canUse ? "在线" : "离线";
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Green : Color.Red;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightGreen : Color.OrangeRed;
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkGreen : Color.DarkRed;
row.Cells["colAdsLoginStatus"].Value = canAdsUse ? "在线" : "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canAdsUse ? Color.Green : Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = canAdsUse ? Color.Green : Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canAdsUse ? Color.LightGreen : Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canAdsUse ? Color.DarkGreen : Color.DarkRed;
row.Cells["colCanUse"].Value = canAdsUse;
}
}
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.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("店铺推广直通车未登录!");
return;
}
break;
case "colLoginStatus":
{
ShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus2 == "国际版在线")
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.manage;
shopLoginForm.WindowState = FormWindowState.Maximized;
shopLoginForm.InitUrl = "https://agentseller.temu.com";
shopLoginForm.Show();
}
else
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
FiltShop();
}
}
break;
case "colAdsLoginStatus":
ShopListForm.Instance.CheckShopAdsLogin(shop);
if (shop.ad_login_status == "在线" && !string.IsNullOrEmpty(shop.ad_url))
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.ads;
shopLoginForm.InitUrl = shop.ad_url;
shopLoginForm.Show();
}
else
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.IsAdsLogin = true;
shopLoginForm.ShowDialog();
FiltShop();
}
break;
}
}
private void btnCheckAdsLogin_Click(object sender, EventArgs e)
{
var shopIds = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSelect"].Value.ParseToBool() == true).Select(r => r.Cells["colShopId"].Value.ParseToString()).ToList();
if(shopIds.Count <= 0)
{
BaseMsgForm.ShowError("请选中店铺!");
return;
}
ShopListForm.Instance.CheckShopAdsLogin(shopIds, pbShopLoading, statusBar);
this.FiltShop();
}
public static string getAdsGoodsList(ShopLoginInfo shop, int page = 1, int pageSize = 20)
{
//"is_gray" true则显示不可用商品
string url = "https://ads.temu.com/api/v1/coconut/ad/query_mall_goods_list";
string body = @"{""page_number"":" + page + @",""page_size"":" + pageSize + @",""is_gray"":true,""list_id"":""fc1dd2d3-cab6-44c6-91b6-2f951c5c6f2f""}";
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/create-ads.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string GetAdsDetailList(ShopLoginInfo shop, long startTime, long endTime, int page = 1, int pageSize = 50)
{
page = Math.Max(page, 1);
string url = "https://ads.temu.com/api/v1/coconut/ad/ads_detail";
string body;
body = "{\"ad_status\":[],\"ad_advice_types\":[],\"page_size\":" + pageSize + ",\"page_number\":" + page +
",\"specific_query_info\":\"\",\"sort_by\":0,\"sort_type\":\"desc\",\"start_time\":" +
startTime + "," + "\"end_time\":" + endTime +
",\"need_calculate_goods_summary\":true,\"list_id\":\"dc582b8d-ae93-4f4d-94e4-031590a245fa\",\"ad_phase\":-1}";
//refere = "https://ads.temu.com/ad-list.html?_x_sessn_id=vmkt5y1lqe&refer_page_name=home&refer_page_id=22941_1764131076104_dfy9mxx891&refer_page_sn=22941";
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/ad-list.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string CreateAds(ShopLoginInfo shop, CreateAdsParam data)
{
string url = "https://ads.temu.com/api/v1/coconut/ad/create_ads/create";
string body;
//body = @"{""create_ad_reqs"":[{""goods_id"":""601099667164131"",""site_id"":129,""roas"":77700,""budget"":12300}]}";
body = JsonHelper.SerializeObject(data);
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/create-ads.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string MdyAds(ShopLoginInfo shop, MdyAdsParam data)
{
string url = "https://ads.temu.com/api/v1/coconut/ad/modify_ads";
string body;
//body = @"{""modify_ad_dtos"":[{""ad_id"":""300000013237119567"",""roas"":100000,""goods_id"":""601099667071702""}]}";
body = JsonHelper.SerializeObject(data);
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/ad-list.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string PauseAds(ShopLoginInfo shop, List<string> idList)
{
string url = "https://ads.temu.com/api/v1/coconut/ad/modify_ads";
string body;
//body = "{\"ad_ids\":[\"" + string.Join("\",\"", idList) + "\"],\"status\":2}";
body = "{\"modify_ad_dtos\":[";
foreach(var goods_id in idList)
{
body += "{\"goods_id\":\"" + goods_id + "\",\"status\":2},";
}
body = body.TrimEnd(',');
body += "]}";
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/ad-list.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string continueAds(ShopLoginInfo shop, List<string> idList)
{
string url = "https://ads.temu.com/api/v1/coconut/ad/modify_ads";
string body;
//body = "{\"ad_ids\":[\"" + string.Join("\",\"", idList) + "\"],\"status\":0}";
body = "{\"modify_ad_dtos\":[";
foreach (var goods_id in idList)
{
body += "{\"goods_id\":\"" + goods_id + "\",\"status\":0},";
}
body = body.TrimEnd(',');
body += "]}";
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/ad-list.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string DelAds(ShopLoginInfo shop, List<string> idList)
{
string url = "https://ads.temu.com/api/v1/coconut/ad/modify_ads";
string body;
//body = "{\"ad_ids\":[\"" + string.Join("\",\"", idList) + "\"],\"status\":3}";
body = "{\"modify_ad_dtos\":[";
foreach (var goods_id in idList)
{
body += "{\"goods_id\":\"" + goods_id + "\",\"status\":3},";
}
body = body.TrimEnd(',');
body += "]}";
string refere = shop.ad_url.Replace("https://ads.temu.com/index.html", "https://ads.temu.com/ad-list.html");
return HttpResponseBLL.PostResponseAds(shop, url, body, refere);
}
private string GetWarehouseListBySpuIds(ShopLoginInfo shop, string spuIds, int page = 1, int pageSize = 40)
{
page = Math.Max(page, 1);
string url = "https://agentseller.temu.com/mms/venom/api/supplier/sales/management/listWarehouse";
string body = @"{""pageNo"":" + page + @",""pageSize"":" + pageSize + @",""isLack"":0,""selectStatusList"":[12],""priceAdjustRecentDays"":7," +
@"""productIdList"":[" + spuIds + @"]}";
string refere = "https://agentseller.temu.com/stock/fully-mgt/sale-manage/main";
return HttpResponseBLL.PostResponse2(shop, url, body, refere);
}
private List<WarehouseProductSubOrderInfo> GetWareHouseList(ShopLoginInfo shop, List<string> spuIdList, out string errMsg)
{
errMsg = "";
string html = GetWarehouseListBySpuIds(shop, string.Join(",", spuIdList));
if (!html.Contains("\"success\":true"))
{
string errStr = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(errStr))
errStr = errStr = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(errStr))
errStr = html;
if (errStr.Contains("Invalid Login State") || errStr.Contains("指定的值含有无效的控制字符") || 1 == 1)
{
ShopListForm.Instance.CheckShopLogin(new string[] { shop.LoginName }, false);
}
Thread.Sleep(Randomx.GetId(100, 200));
errMsg = errStr;
return new List<WarehouseProductSubOrderInfo>();
}
var jArr = new JArray();
try
{
var jObj = JObject.Parse(html);
jArr = jObj["result"]["subOrderList"] as JArray;
if (jArr == null)
jArr = new JArray();
}
catch (Exception ex)
{
errMsg = ex.Message;
return new List<WarehouseProductSubOrderInfo>();
}
List<WarehouseProductSubOrderInfo> subOrderInfoLstTmp = new List<WarehouseProductSubOrderInfo>();
foreach (var item in jArr)
{
string sItem = item.ToString();
WarehouseProductSubOrderInfo sInfo = JsonHelper.DeserializeJsonToObject<WarehouseProductSubOrderInfo>(sItem); // 反序列化得到类
if (sInfo != null)
{
subOrderInfoLstTmp.Add(sInfo);
}
}
return subOrderInfoLstTmp;
}
List<TemuDBProductPurchasePriceInfo> GetPurchasePriceList(List<string> productIdList)
{
List<TemuDBProductPurchasePriceInfo> list = new List<TemuDBProductPurchasePriceInfo>();
for (int i = 0; i < productIdList.Count; i++)
{
productIdList[i] = productIdList[i].Replace(",", "").Replace("'", "").Replace("\"", "");
}
var url = BaseClass.BuildObjString("price/get_purchase_price_list");
var data = UserLogin.GetSignaturex();
data += "&page=1";
data += "&page_size=" + productIdList.Count;
data += "&in_spu_id=" + string.Join(",", productIdList);
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
return list;
}
if (!html.Contains("data"))
return list;
var jArr = JObject.Parse(html)["data"];
if (jArr.Count() == 0)
return list;
list = JsonHelper.DeserializeJsonToList<TemuDBProductPurchasePriceInfo>(jArr.ToString());
foreach (var pPrice in list)
{
pPrice.dbSkuPurchasePriceList = JsonHelper.DeserializeJsonToList<TemuDBSkuPurchasePriceInfo>(pPrice.sku_purchase_price_json);
if (pPrice.dbSkuPurchasePriceList == null)
pPrice.dbSkuPurchasePriceList = new List<TemuDBSkuPurchasePriceInfo>();
else
{
pPrice.price_text = "¥" + (pPrice.dbSkuPurchasePriceList.Min(s => s.purchasePriceValue) * 0.01).ParseToDecimal().ToString("0.00") + "~"
+ "¥" + (pPrice.dbSkuPurchasePriceList.Max(s => s.purchasePriceValue) * 0.01).ParseToDecimal().ToString("0.00");
}
}
return list;
}
private void btnSearchProduct_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;
}
isAddAds = false;
List<string> newAdsColName = new List<string> { "colCate", "colCreateTime", "colSaleCount" };
List<string> existAdsColName = new List<string> { "colAdStatus", "colBudget", "colWantROAS", "colChangeROAS", "colTotalCost", "colSaleVolume",
"colROAS", "colRate", "colPerSaleCost", "colExposureCount", "colClickCount", "colOrderCount", "colGoodsNum", "colCTR", "colCVR", "colInCart" };
foreach (DataGridViewColumn column in dgvAds.Columns)
{
if (newAdsColName.Contains(column.Name))
{
column.Visible = false;
}
else if (existAdsColName.Contains(column.Name))
{
column.Visible = true;
}
}
lstAdsDetailInfo.Clear();
lstWareHouse.Clear();
lstPurchasePrice.Clear();
dgvAds.Rows.Clear();
var dgvRows = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
foreach (var row in dgvRows)
{
row.Cells["colMessage"].Value = "";
}
ucGroupBoxEx2.Enabled = false;
ucGroupBoxEx3.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var lstShopIdTemp = new List<string>();
lstShopIdTemp.AddRange(lstShopId);
int i = 0;
foreach (var shopId in lstShopIdTemp)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在查询...";
this.statusBar.pgbTaskProgress.Maximum = lstShopIdTemp.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 (shop.ad_login_status != "在线")
{
continue;
}
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
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 total = 0;
int totalPage = 1;
int pageSize = 40;
bool isError = false;
string errMsg = "";
while (page <= totalPage)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
int tryCount = 0;
tryAgain:
Thread.Sleep(100 + Randomx.GetId(200));
var startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date);
var endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now);
if (chkYesterday.Checked)
{
startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-1));
endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date) - 1;
}
else if (chk7Days.Checked)
{
startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-7));
endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now);
}
else if (chk30Days.Checked)
{
startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-30));
endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now);
}
string jsonStr = GetAdsDetailList(shop, startTime, endTime, page, pageSize);
//eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..239DkQh2tOmakDpH.P4o6IPrjql1GrM5-AgfVRCsQeJvfzN_bZXtQUVhZjpZmGreQuoCR3Dn5Q1PEuM7JaTjUV6HXojNKdRPx_zXDOtni6fyelErJYxjskpPR7hiEdrSASOPVUz-PMwOTlT7DrrYKppclzCv97nMnovKGTrsZIsB98eeI2fgvF9jehPtnEFwE7_eu1EwRC-vd-zPedIJoxwc_B2Hlwi10O1Db-AAUYTL6qZqRPbrH9FtEJffD1qsfwy5L-iMaO_aK9eyz0WmF0E0K6wLhmGknPwpytm5Iz_ekUCsjEbrlYe4tOTD_K3rKePer_y2-9MHZ3Hk_0pObdVostRNwOXyimkGBdow0x96kC8U5BMcWX_jvAVXfuokRJv_LOYtj1qi_zM4pjJa1ySPEdDUfAgp1GmFIRRjGDG-bE7uwbZK_4eN0w5txs0MN9AbEYdD4BYVUQwE.YWnmDgmj14CEoz0FYxBPGQ
//eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..A2mlig51hgFP7JXx.RDqzwYzKc8jEyg_DY2qkk0VrhdPUPnpx1nAS8GA7QtGSPe3Lfe3LZsZneOWsBMIvERXZa9iiF7X_8dSr3NIiHpAG4Q6Vp1cqzO_BG-KY-B31Z46H5EDzzj9Hfi3r24HFWhHU7E1E-Bug8k_ytczY1YqfK5SiiGPm0TYWKbG3CYrVx2kFCGfeu8u8qPNfx6k5ZqYpxh_3ExgYQQKSI-DV47ti3KYyHB2JkcxvDRVRT6LhxW1tcusLsEXUskY5M1CNV3UIxUvnpKK7kB_Juz3WQcpLX5jf5wKE5dQG_UaBywV7yRjsScHeUjG8jFl_SM2zxXcd2wLy6u1dM4sBGpOhZrIe8L6mZOIuFlYHh3Y4wZT-N_Eq_wDqKbSmjyw3QZzQzQruICtU2uF7xLZJr1-c_Yg7adtR2TJatjaQPIimzBHCs-QDHtICKHON0wGdmuA.bnXgv0qN4PgRNhFeN9UOQA
if (jsonStr.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
{
tryCount++;
Thread.Sleep(Randomx.GetId(500, 1000));
goto tryAgain;
}
if (!jsonStr.Contains("\"success\":true"))
{
isError = true;
string sErr = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
errMsg += sErr + " ";
page++;
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
break;
}
else
continue;
}
if (jsonStr.Contains("\"success\":true"))
{
var jArr = new JArray();
try
{
var jObj = JObject.Parse(jsonStr);
jArr = jObj["result"]?["ads_detail"] as JArray;
if (jArr == null)
jArr = new JArray();
}
catch (Exception ex)
{
BaseMsgForm.ShowError(ex.Message);
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 = "直通车查询失败 " + ex.Message;
}
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "店铺 " + shop.ShopAccount + " 直通车查询失败 " + ex.Message;
}));
page++;
Thread.Sleep(1000);
continue;
}
List<string> spuIdLst = new List<string>();
foreach (var item in jArr)
{
string sItem = item.ToString();
AdsDetailInfo adsInfo = JsonHelper.DeserializeJsonToObject<AdsDetailInfo>(sItem); // 反序列化得到类
if (adsInfo != null && !lstAdsDetailInfo.Any(a => a.ad_id == adsInfo.ad_id))
{
adsInfo.shopId = shop.ShopId;
lstAdsDetailInfo.Add(adsInfo);
spuIdLst.Add(adsInfo.spu_id);
//string url = pInfo.image.Replace("https", "http");
//var image = Image.FromStream(WebRequest.Create(url).GetResponse().GetResponseStream());
Invoke(new Action(() =>
{
int rowId = this.dgvAds.Rows.Add(
true,
adsInfo.shopId,
shop.ShopAccount,
adsInfo.goods_image_url.Replace("https", "http").Replace("img.kwcdn.com", "img.cdnfe.com"),
DataGridViewExtension.defaultBitmap,//image, // skc图片
adsInfo.goods_id,
adsInfo.spu_id,
adsInfo.goods_title,
string.Join("、", adsInfo.site_name_list),
adsInfo.goods_min_price + "~" + adsInfo.goods_max_price,
"类目",
"创建时间",
"销量",
"", //"设置", // 成本
"", //"设置", // 折扣
GetAdsShowStatus(adsInfo.ad_show_status.ParseToInt()) + (" " + adsInfo.forbid_reason).TrimEnd(),
adsInfo.budget_str, // 广告日预算
adsInfo.roas_str, // 目标roas
"改",
adsInfo.reports_summary_dto.ad_spend_all.trans_val, //adsInfo.used_budget * 0.01, // 总花费
adsInfo.reports_summary_dto.order_pay_amt_all.trans_val, //adsInfo.supply_price_sale.ParseToInt() * 0.01, // 申报价销售额
adsInfo.reports_summary_dto.roas_all.trans_val, //adsInfo.real_roas * 0.001, // 广告投资回报率 (ROAS)
adsInfo.reports_summary_dto.acos_all.trans_val, //adsInfo.acos * 0.01, // 广告费比(广告)
adsInfo.reports_summary_dto.transaction_cost.trans_val, // 每笔成交花费
adsInfo.reports_summary_dto.impr_cnt_all.trans_val, //adsInfo.impr_num, // 曝光量
adsInfo.reports_summary_dto.clk_cnt_all.trans_val, // 点击量
adsInfo.reports_summary_dto.order_pay_cnt_all.trans_val, // 订单量
adsInfo.reports_summary_dto.goods_num.trans_val, // 件数
adsInfo.reports_summary_dto.ctr_all.trans_val, // 点击率(CTR)
adsInfo.reports_summary_dto.cvr.trans_val, // 转化率(CVR)
adsInfo.reports_summary_dto.cart_cnt_all.trans_val, // 加入购物车数
"" // 操作结果,状态
); ;
dgvAds.Rows[rowId].Height = 50;
if (adsInfo.ad_show_status != 8)
{
dgvAds.Rows[rowId].Cells["colAdStatus"].Style.ForeColor = Color.Red;
}
else
{
dgvAds.Rows[rowId].Cells["colAdStatus"].Style.ForeColor = Color.Green;
}
}));
}
}
Thread.Sleep(100 + Randomx.GetId(200));
string error = "";
var wareHouses = GetWareHouseList(shop, spuIdLst, out error);
if(!string.IsNullOrEmpty(error))
{
BaseMsgForm.ShowError(error);
this.FiltShop();
}
lstWareHouse.AddRange(wareHouses);
Thread.Sleep(100 + Randomx.GetId(200));
var purchasePrices = this.GetPurchasePriceList(spuIdLst);
lstPurchasePrice.AddRange(purchasePrices);
foreach(var spuId in spuIdLst)
{
var purchase = purchasePrices.FirstOrDefault(p => p.spu_id == spuId);
var row = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colSpuId"].Value.ParseToString() == spuId);
if (row != null)
{
if (purchase != null)
{
row.Cells["colSetCost"].Value = purchase.price_text;
row.Cells["colSetDiscount"].Value = (purchase.discount * 0.01).ToString("0.00");
}
else
{
row.Cells["colSetCost"].Value = "设置";
row.Cells["colSetDiscount"].Value = "设置";
}
}
}
total = BaseRegex.GetStringJson(ref jsonStr, "total").ParseToInt();
totalPage = Math.Ceiling(1.0 * total / pageSize).ParseToInt();
}
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在查询店铺 " + shop.ShopAccount + " 直通车商品 " + page + "/" + totalPage + " 共 " + total + " 件";
}));
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;
}
}
}));
}
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);
}
bool isAddAds = false;
private void pnlAdd_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;
}
if (txtBudget.Text.ParseToDecimal() <= 0 && chkLimitValue.Checked)
{
BaseMsgForm.ShowInfo("请正确填写日预算!");
return;
}
if (BaseMsgForm.ShowConfirm("确定要将全店商品添加到直通车?").DialogResult == DialogResult.Cancel)
return;
isAddAds = true;
List<string> newAdsColName = new List<string> { "colCate", "colCreateTime", "colSaleCount" };
List<string> existAdsColName = new List<string> { "colAdStatus", "colBudget", "colWantROAS", "colChangeROAS", "colTotalCost", "colSaleVolume",
"colROAS", "colRate", "colPerSaleCost", "colExposureCount", "colClickCount", "colOrderCount", "colGoodsNum", "colCTR", "colCVR", "colInCart" };
foreach (DataGridViewColumn column in dgvAds.Columns)
{
if (existAdsColName.Contains(column.Name))
{
column.Visible = false;
}
else if (newAdsColName.Contains(column.Name))
{
column.Visible = true;
}
}
lstAdsMallGoodsInfo.Clear();
dgvAds.Rows.Clear();
var dgvRows = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
foreach (var row in dgvRows)
{
row.Cells["colMessage"].Value = "";
}
ucGroupBoxEx2.Enabled = false;
ucGroupBoxEx3.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var lstShopIdTemp = new List<string>();
lstShopIdTemp.AddRange(lstShopId);
int i = 0;
foreach (var shopId in lstShopIdTemp)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在查询...";
this.statusBar.pgbTaskProgress.Maximum = lstShopIdTemp.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 (shop.ad_login_status != "在线")
{
continue;
}
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
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;
int pageSize = 40;
bool isError = false;
string errMsg = "";
while (page <= totalPage)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
int tryCount = 0;
tryAgain:
Thread.Sleep(100 + Randomx.GetId(200));
string jsonStr = getAdsGoodsList(shop, page, pageSize);
for (int rt = 0; rt < 3 && !jsonStr.Contains("\"success\":true"); rt++)
{
Thread.Sleep(100 + Randomx.GetId(200));
jsonStr = getAdsGoodsList(shop, page, pageSize);
}
Thread.Sleep(Randomx.GetId(300, 800));
if (jsonStr.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
{
tryCount++;
Thread.Sleep(Randomx.GetId(500, 1000));
goto tryAgain;
}
if (!jsonStr.Contains("\"success\":true"))
{
isError = true;
string sErr = BaseRegex.GetStringJson(ref jsonStr, "errorMsg");
if (!string.IsNullOrWhiteSpace(sErr) && !errMsg.Contains(sErr))
errMsg += sErr + " ";
page++;
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
break;
}
else
continue;
}
if (jsonStr.Contains("\"success\":true"))
{
var jArr = new JArray();
try
{
var jObj = JObject.Parse(jsonStr);
jArr = jObj["result"]?["goods_info_list"] as JArray;
if (jArr == null)
jArr = new JArray();
}
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
CreateAdsParam createAds = new CreateAdsParam();
createAds.create_ad_reqs = new List<create_ad_req_param>();
List<string> spuIdLst = new List<string>();
foreach (var item in jArr)
{
string sItem = item.ToString();
ads_goods_info adsGoodsInfo = JsonHelper.DeserializeJsonToObject<ads_goods_info>(sItem); // 反序列化得到类
if (adsGoodsInfo != null && !lstAdsMallGoodsInfo.Any(a => a.goods_id == adsGoodsInfo.goods_id))
{
//if (adsGoodsInfo.gray_reason != null)
// continue;
adsGoodsInfo.shopId = shop.ShopId;
lstAdsMallGoodsInfo.Add(adsGoodsInfo);
spuIdLst.Add(adsGoodsInfo.spu_id);
if (adsGoodsInfo.gray_reason == null)
{
var create_ad_req_param = new create_ad_req_param()
{
budget = chkLimitValue.Checked ? (txtBudget.Text.ParseToDecimal() * 100).ParseToInt() : -1,
goods_id = adsGoodsInfo.goods_id.ParseToString(),
site_id = adsGoodsInfo.site_list.FirstOrDefault().ParseToInt(),
roas = (txtSameRoas.Text.ParseToDecimal() * 10000).ParseToInt(),
};
createAds.create_ad_reqs.Add(create_ad_req_param);
}
Invoke(new Action(() =>
{
int rowId = this.dgvAds.Rows.Add(
true,
adsGoodsInfo.shopId,
shop.ShopAccount,
adsGoodsInfo.thumb_url.Replace("https", "http").Replace("img.kwcdn.com", "img.cdnfe.com"),
DataGridViewExtension.defaultBitmap,//image, // skc图片
adsGoodsInfo.goods_id,
adsGoodsInfo.spu_id,
adsGoodsInfo.goods_name,
string.Join("、", adsGoodsInfo.site_name_list),
adsGoodsInfo.supply_price_min + "~" + adsGoodsInfo.supply_price_max,
adsGoodsInfo.category_name_list.LastOrDefault().ParseToString(), // "类目",
BaseClass.StampToDateTime((int)(adsGoodsInfo.create_timestamp.ParseToLong() / 1000)).ToString(), // "创建时间",
adsGoodsInfo.sales, // "销量",
"", //"设置", // 成本
"", //"设置", // 折扣
"推广状态",
"广告日预算",
"目标roas",
"修改roas",
"总花费",
"申报价销售额",
"广告投资回报率 (ROAS)",
"广告费比(广告)",
"每笔成交花费",
"曝光量",
"点击量",
"订单量",
"件数",
"点击率(CTR)",
"转化率(CVR)",
"加入购物车数",
adsGoodsInfo.gray_reason == null ? "" : string.Join(",", adsGoodsInfo.gray_reason.Select(g => g.reason)) // 操作结果,状态
);
dgvAds.Rows[rowId].Height = 50;
}));
}
}
if (createAds.create_ad_reqs.Count > 0)
{
Thread.Sleep(100 + Randomx.GetId(200));
string error = "";
var wareHouses = GetWareHouseList(shop, spuIdLst, out error);
if (!string.IsNullOrEmpty(error))
{
BaseMsgForm.ShowError(error);
this.FiltShop();
}
lstWareHouse.AddRange(wareHouses);
Thread.Sleep(100 + Randomx.GetId(200));
var purchasePrices = this.GetPurchasePriceList(spuIdLst);
lstPurchasePrice.AddRange(purchasePrices);
// 根据期望利润率估算目标回报率
if (chkCalculateRoas.Checked)
{
//(申报价销售额 × 活动折扣) ÷ ((申报价销售额 × 活动折扣) - 产品成本 - (申报价销售额 × 活动折扣) × 目标利润率)
foreach (var create_ad_req_param in createAds.create_ad_reqs)
{
var adsGoodsInfo = lstAdsMallGoodsInfo.FirstOrDefault(g => g.goods_id.ParseToString() == create_ad_req_param.goods_id);
if (adsGoodsInfo == null)
continue;
var purchasePrice = lstPurchasePrice.FirstOrDefault(p => p.spu_id == adsGoodsInfo.spu_id);
if (purchasePrice != null)
{
var avgPrice = purchasePrice.dbSkuPurchasePriceList.Sum(p => p.priceValue.ParseToInt()) * 0.01m / purchasePrice.dbSkuPurchasePriceList.Count;
var avgPurchasePrice = purchasePrice.dbSkuPurchasePriceList.Sum(p => p.purchasePriceValue.ParseToInt()) * 0.01m / purchasePrice.dbSkuPurchasePriceList.Count;
var discount = purchasePrice.discount * 0.01m;
var discountPrice = avgPrice * discount;
var profitRate = txtCalculateProfitRate.Text.ParseToDecimal();
if (discountPrice - avgPurchasePrice - discountPrice * profitRate * 0.01m > 0)
{
var roas = discountPrice / (discountPrice - avgPurchasePrice - discountPrice * profitRate * 0.01m);
create_ad_req_param.roas = (roas * 10000).ParseToInt();
}
}
}
}
foreach (var spuId in spuIdLst)
{
var purchase = purchasePrices.FirstOrDefault(p => p.spu_id == spuId);
var row = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colSpuId"].Value.ParseToString() == spuId);
if (row != null)
{
if (purchase != null)
{
row.Cells["colSetCost"].Value = purchase.price_text;
row.Cells["colSetDiscount"].Value = (purchase.discount * 0.01).ToString("0.00");
}
else
{
row.Cells["colSetCost"].Value = "设置";
row.Cells["colSetDiscount"].Value = "设置";
}
}
}
Thread.Sleep(Randomx.GetId(500, 2000));
var createRst = CreateAds(shop, createAds);
//{"success":true,"error_code":1000000,"error_msg":null,"result":{"success":false,"error_code":null,"error_msg":null,"result":null,"success_create_product_num":1,"already_created_goods_num":1,"success_goods_id_lists":null,"create_goods_fail_map":{}}}
//{"success":true,"error_code":1000000,"error_msg":null,"result":{"success":false,"error_code":null,"error_msg":null,"result":null,"success_create_product_num":0,"already_created_goods_num":0,"success_goods_id_lists":null,"create_goods_fail_map":{"601099667164131":"广告已创建"}}}
if (createRst.Contains("\"success\":true"))
{
foreach (var adsReqItem in createAds.create_ad_reqs)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsReqItem.goods_id);
if (dgvRow == null)
continue;
var failInfo = BaseRegex.GetStringJson(ref createRst, "" + adsReqItem.goods_id);
if (string.IsNullOrEmpty(failInfo))
{
dgvRow.Cells["colMsg"].Value = "创建直通车成功";
}
else
{
dgvRow.Cells["colMsg"].Value = failInfo;
}
}
}
else
{
foreach (var adsReqItem in createAds.create_ad_reqs)
{
string sErr = BaseRegex.GetStringJson(ref createRst, "errorMsg");
if (string.IsNullOrEmpty(sErr))
sErr = BaseRegex.GetStringJson(ref createRst, "error_msg");
if (string.IsNullOrEmpty(sErr))
sErr = createRst;
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsReqItem.goods_id);
if (dgvRow == null)
continue;
dgvRow.Cells["colMsg"].Value = sErr;
}
break;
}
}
int total = BaseRegex.GetStringJson(ref jsonStr, "total").ParseToInt();
if (totalPage == 1)
totalPage = Math.Ceiling(1.0 * total / pageSize).ParseToInt();
bool hasMore = BaseRegex.GetBoolJson(ref jsonStr, "has_more");
if (hasMore && totalPage == page)
{
totalPage++;
}
}
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;
}
}
}));
}
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);
}
private void chkLimitValue_CheckedChanged(object sender, EventArgs e)
{
chkNoLimit.Checked = !chkLimitValue.Checked;
txtBudget.Visible = lblBudget.Visible = chkLimitValue.Checked;
}
private void chkNoLimit_CheckedChanged(object sender, EventArgs e)
{
chkLimitValue.Checked = !chkNoLimit.Checked;
}
private void dgvAds_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvAds.Columns[e.ColumnIndex].HeaderText;
long spuId = dgvAds.Rows[e.RowIndex].Cells["colSpuId"].Value.ParseToLong();
long shopId = dgvAds.Rows[e.RowIndex].Cells["colSupplierId"].Value.ParseToLong();
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId.ToString());
var row = dgvAds.Rows[e.RowIndex];
switch (headerText)
{
case "删除":
break;
case "图片":
{
string url = dgvAds.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString();
ShowImgForm imgFrom = new ShowImgForm(url);
imgFrom.ShowDialog();
}
break;
case "改":
var point = dgvAds.PointToClient(Control.MousePosition);
if (point.X + gbxSoloChangeRoas.Width > dgvAds.Width)
point.X -= gbxSoloChangeRoas.Width;
if (point.Y + gbxSoloChangeRoas.Height > dgvAds.Height)
point.Y -= gbxSoloChangeRoas.Height;
gbxSoloChangeRoas.Visible = true;
gbxSoloChangeRoas.Location = new Point(point.X, point.Y);
lblGoodsId.Text = row.Cells["colGoodsId"].Value.ParseToString();
lblShopId.Text = row.Cells["colSupplierId"].Value.ParseToString();
break;
case "成本":
case "折扣":
var order = lstWareHouse.FirstOrDefault(r => r.productId == spuId);
if (order == null)
{
BaseMsgForm.ShowError("商品详情不可用,请重新登录后再试!");
return;
}
var purchasePrice = lstPurchasePrice.FirstOrDefault(p => p.spu_id == spuId.ParseToString());
if (purchasePrice != null)
{
order.purchasePriceInfo = purchasePrice;
order.discount = purchasePrice.discount;
foreach (var sku in order.skuQuantityDetailList)
{
var purchaseSku = purchasePrice.dbSkuPurchasePriceList.FirstOrDefault(s => s.productSkuId == sku.productSkuId);
if (purchaseSku != null)
{
sku.purchasePrice = purchaseSku.purchasePriceValue.ParseToInt();
}
}
}
foreach (var sku in order.skuQuantityDetailList)
{
if (sku.purchasePrice == 0)
sku.purchasePrice = sku.supplierPrice.ParseToInt();
}
ShopSetPurchasePriceForm detailForm = new ShopSetPurchasePriceForm(shop, order);
detailForm.ShowDialog();
//更新列表显示
var newPurchasePrices = this.GetPurchasePriceList(new List<string>() { order.productId.ParseToString() });
if (purchasePrice != null)
lstPurchasePrice.Remove(purchasePrice);
lstPurchasePrice.AddRange(newPurchasePrices);
var newPurchase = newPurchasePrices.FirstOrDefault();
if (newPurchase != null)
{
row.Cells["colSetCost"].Value = newPurchase.price_text;
row.Cells["colSetDiscount"].Value = (newPurchase.discount * 0.01).ToString("0.00");
}
else
{
row.Cells["colSetCost"].Value = "设置";
row.Cells["colSetDiscount"].Value = "设置";
}
break;
case "":
dgvAds.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvAds.Rows[e.RowIndex].Cells["colCheck"].Value;
break;
default:
break;
}
}
private void chkSameRoas_CheckedChanged(object sender, EventArgs e)
{
chkCalculateRoas.Checked = !chkSameRoas.Checked;
}
private void chkCalculateRoas_CheckedChanged(object sender, EventArgs e)
{
chkSameRoas.Checked = !chkCalculateRoas.Checked;
lblCalculateRoas.Visible = lblCalculateRoasPercentSign.Visible = txtCalculateProfitRate.Visible = chkCalculateRoas.Checked;
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (isAddAds == true)
{
BaseMsgForm.ShowInfo("请先查询直通车商品再调整数值!");
return;
}
var adsGoodsIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colGoodsId"]?.Value.ToString()).ToList();
var shopIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSupplierId"]?.Value.ToString()).Distinct().ToList();
if (shopIdLst.Count == 0 || adsGoodsIdLst.Count == 0)
{
BaseMsgForm.ShowInfo("请选择商品!");
return;
}
if (txtBudget.Text.ParseToDecimal() <= 0 && chkLimitValue.Checked)
{
BaseMsgForm.ShowInfo("日预算数值需要大于等于100元!");
return;
}
EditAds(adsGoodsIdLst, shopIdLst);
}
void EditAds(List<string> adsGoodsIdLst, List<string> shopIdLst, bool isBatch = true)
{
var adsDetailLst = lstAdsDetailInfo.Where(ad => adsGoodsIdLst.Contains(ad.goods_id.ParseToString())).ToList();
var shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
var dgvRowLst = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
foreach (var row in dgvRowLst)
{
row.Cells["colMessage"].Value = "";
}
dgvRowLst = this.dgvAds.Rows.Cast<DataGridViewRow>().Where(r => adsGoodsIdLst.Contains(r.Cells["colGoodsId"].Value.ParseToString())).ToList();
foreach (var row in dgvRowLst)
{
row.Cells["colMsg"].Value = "";
}
ucGroupBoxEx2.Enabled = false;
ucGroupBoxEx3.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var tmpShopIdLst = new List<string>();
tmpShopIdLst.AddRange(shopIdLst);
int i = 0;
foreach (var shopId in tmpShopIdLst)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在操作...";
this.statusBar.pgbTaskProgress.Maximum = tmpShopIdLst.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 (shop.ad_login_status != "在线")
{
continue;
}
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
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 = "正在查询";
}
}));
bool isError = false;
string errMsg = "";
var shopAdsDetailLst = adsDetailLst.Where(ad => ad.shopId == shop.ShopId).ToList();
while (shopAdsDetailLst.Count > 0)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
var tmpAdsDetailLst = shopAdsDetailLst.Take(20).ToList();
foreach (var ads in tmpAdsDetailLst)
{
shopAdsDetailLst.Remove(ads);
}
int tryCount = 0;
tryAgain:
Thread.Sleep(100 + Randomx.GetId(200));
MdyAdsParam mdyAdsParam = new MdyAdsParam();
mdyAdsParam.modify_ad_dtos = new List<modify_ad_dto_param>();
foreach (var ads in tmpAdsDetailLst)
{
modify_ad_dto_param modify_ad_dto_param = new modify_ad_dto_param()
{
budget = chkLimitValue.Checked ? (txtBudget.Text.ParseToDecimal() * 100).ParseToInt() : -1,
goods_id = ads.goods_id.ParseToString(),
ad_id = ads.ad_id,
roas = (txtSameRoas.Text.ParseToDecimal() * 10000).ParseToInt(),
};
// 根据期望利润率估算目标回报率
if (chkCalculateRoas.Checked)
{
//(申报价销售额 × 活动折扣) ÷ ((申报价销售额 × 活动折扣) - 产品成本 - (申报价销售额 × 活动折扣) × 目标利润率)
var purchasePrice = lstPurchasePrice.FirstOrDefault(p => p.spu_id == ads.spu_id);
if (purchasePrice != null)
{
var avgPrice = purchasePrice.dbSkuPurchasePriceList.Sum(p => p.priceValue.ParseToInt()) * 0.01m / purchasePrice.dbSkuPurchasePriceList.Count;
var avgPurchasePrice = purchasePrice.dbSkuPurchasePriceList.Sum(p => p.purchasePriceValue.ParseToInt()) * 0.01m / purchasePrice.dbSkuPurchasePriceList.Count;
var discount = purchasePrice.discount * 0.01m;
var discountPrice = avgPrice * discount;
var profitRate = txtCalculateProfitRate.Text.ParseToDecimal();
if (discountPrice - avgPurchasePrice - discountPrice * profitRate * 0.01m > 0)
{
var roas = discountPrice / (discountPrice - avgPurchasePrice - discountPrice * profitRate * 0.01m);
modify_ad_dto_param.roas = (roas * 10000).ParseToInt();
}
}
}
// 如果不是批量处理,使用小框内的设置
if (!isBatch)
{
modify_ad_dto_param.roas = (txtSameRoas2.Text.ParseToDecimal() * 10000).ParseToInt();
modify_ad_dto_param.budget = null;
// 根据期望利润率估算目标回报率
if (chkCalculateRoas2.Checked)
{
//(申报价销售额 × 活动折扣) ÷ ((申报价销售额 × 活动折扣) - 产品成本 - (申报价销售额 × 活动折扣) × 目标利润率)
var purchasePrice = lstPurchasePrice.FirstOrDefault(p => p.spu_id == ads.spu_id);
if (purchasePrice != null)
{
var avgPrice = purchasePrice.dbSkuPurchasePriceList.Sum(p => p.priceValue.ParseToInt()) * 0.01m / purchasePrice.dbSkuPurchasePriceList.Count;
var avgPurchasePrice = purchasePrice.dbSkuPurchasePriceList.Sum(p => p.purchasePriceValue.ParseToInt()) * 0.01m / purchasePrice.dbSkuPurchasePriceList.Count;
var discount = purchasePrice.discount * 0.01m;
var discountPrice = avgPrice * discount;
var profitRate = txtCalculateProfitRate2.Text.ParseToDecimal();
if (discountPrice - avgPurchasePrice - discountPrice * profitRate * 0.01m > 0)
{
var roas = discountPrice / (discountPrice - avgPurchasePrice - discountPrice * profitRate * 0.01m);
modify_ad_dto_param.roas = (roas * 10000).ParseToInt();
}
}
}
}
mdyAdsParam.modify_ad_dtos.Add(modify_ad_dto_param);
if (modify_ad_dto_param.budget == ads.budget)
{
modify_ad_dto_param.budget = null;
}
if (modify_ad_dto_param.roas == ads.roas)
{
modify_ad_dto_param.roas = null;
}
}
MdyAdsParam tmpMdyAdsParam = new MdyAdsParam();
tmpMdyAdsParam.modify_ad_dtos = mdyAdsParam.modify_ad_dtos.Where(m => m.roas != null || m.budget != null).ToList();
string mdyRst = MdyAds(shop, tmpMdyAdsParam);
if (mdyRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
{
tryCount++;
Thread.Sleep(Randomx.GetId(500, 1000));
goto tryAgain;
}
if (!mdyRst.Contains("\"success\":true"))
{
string sErr = BaseRegex.GetStringJson(ref mdyRst, "errorMsg");
if (string.IsNullOrEmpty(sErr))
sErr = BaseRegex.GetStringJson(ref mdyRst, "error_msg");
if (string.IsNullOrEmpty(sErr))
sErr = mdyRst;
errMsg += sErr + " ";
foreach (var adsReqItem in mdyAdsParam.modify_ad_dtos)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsReqItem.goods_id);
if (dgvRow == null)
continue;
dgvRow.Cells["colMsg"].Value = sErr;
}
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
break;
}
else
continue;
}
if (mdyRst.Contains("\"success\":true"))
{
foreach (var adsReqItem in mdyAdsParam.modify_ad_dtos)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsReqItem.goods_id);
if (dgvRow == null)
continue;
if (adsReqItem.budget == null && adsReqItem.roas == null)
{
dgvRow.Cells["colMsg"].Value = "无需调整";
continue;
}
var failInfo = BaseRegex.GetStringJson(ref mdyRst, "" + adsReqItem.goods_id);
if (string.IsNullOrEmpty(failInfo))
{
dgvRow.Cells["colMsg"].Value = "调整直通车成功";
if (adsReqItem.roas != null)
dgvRow.Cells["colWantROAS"].Value = (adsReqItem.roas.Value * 0.0001).ToString("0.00");
if (adsReqItem.budget != null)
dgvRow.Cells["colBudget"].Value = adsReqItem.budget.Value < 0 ? "不限" : "¥" + (adsReqItem.budget.Value * 0.01).ToString("0.00");
}
else
{
dgvRow.Cells["colMsg"].Value = failInfo;
}
}
}
}
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;
}
}
}));
}
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);
}
private void btnDelAds_Click(object sender, EventArgs e)
{
if (isAddAds == true)
{
BaseMsgForm.ShowInfo("请先查询直通车商品再调整数值!");
return;
}
var adsGoodsIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colGoodsId"]?.Value.ToString()).ToList();
var shopIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSupplierId"]?.Value.ToString()).Distinct().ToList();
if (shopIdLst.Count == 0 || adsGoodsIdLst.Count == 0)
{
BaseMsgForm.ShowInfo("请选择直通车商品!");
return;
}
if (BaseMsgForm.ShowConfirm("确定要删除选中直通车?").DialogResult == DialogResult.Cancel)
return;
var adsDetailLst = lstAdsDetailInfo.Where(ad => adsGoodsIdLst.Contains(ad.goods_id.ParseToString())).ToList();
var shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
var dgvRowLst = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
foreach (var row in dgvRowLst)
{
row.Cells["colMessage"].Value = "";
}
dgvRowLst = this.dgvAds.Rows.Cast<DataGridViewRow>().Where(r => adsGoodsIdLst.Contains(r.Cells["colGoodsId"].Value.ParseToString())).ToList();
foreach (var row in dgvRowLst)
{
row.Cells["colMsg"].Value = "";
}
ucGroupBoxEx2.Enabled = false;
ucGroupBoxEx3.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var tmpShopIdLst = new List<string>();
tmpShopIdLst.AddRange(shopIdLst);
int i = 0;
foreach (var shopId in tmpShopIdLst)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在操作...";
this.statusBar.pgbTaskProgress.Maximum = tmpShopIdLst.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 (shop.ad_login_status != "在线")
{
continue;
}
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
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 = "正在查询";
}
}));
bool isError = false;
string errMsg = "";
var shopAdsDetailLst = adsDetailLst.Where(ad => ad.shopId == shop.ShopId).ToList();
while (shopAdsDetailLst.Count > 0)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
var tmpAdsDetailLst = shopAdsDetailLst.Take(20).ToList();
foreach (var ads in tmpAdsDetailLst)
{
shopAdsDetailLst.Remove(ads);
}
int tryCount = 0;
tryAgain:
Thread.Sleep(100 + Randomx.GetId(200));
//var adIdLst = tmpAdsDetailLst.Select(a => a.ad_id).ToList();
//string mdyRst = DelAds(shop, adIdLst);
var goodsIdLst = tmpAdsDetailLst.Select(a => a.goods_id).ToList();
string mdyRst = DelAds(shop, goodsIdLst);
if (mdyRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
{
tryCount++;
Thread.Sleep(Randomx.GetId(500, 1000));
goto tryAgain;
}
if (!mdyRst.Contains("\"success\":true"))
{
string sErr = BaseRegex.GetStringJson(ref mdyRst, "errorMsg");
if (string.IsNullOrEmpty(sErr))
sErr = BaseRegex.GetStringJson(ref mdyRst, "error_msg");
if (string.IsNullOrEmpty(sErr))
sErr = mdyRst;
errMsg += sErr + " ";
foreach (var adsDetail in tmpAdsDetailLst)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsDetail.goods_id);
if (dgvRow == null)
continue;
dgvRow.Cells["colMsg"].Value = sErr;
}
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
break;
}
else
continue;
}
if (mdyRst.Contains("\"success\":true"))
{
foreach (var adsDetailItem in tmpAdsDetailLst)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsDetailItem.goods_id);
if (dgvRow == null)
continue;
var failInfo = BaseRegex.GetStringJson(ref mdyRst, "" + adsDetailItem.goods_id);
if (string.IsNullOrEmpty(failInfo))
{
dgvRow.Cells["colMsg"].Value = "删除直通车成功";
}
else
{
dgvRow.Cells["colMsg"].Value = failInfo;
}
}
}
}
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;
}
}
}));
}
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);
}
private void btnPauseAds_Click(object sender, EventArgs e)
{
if (isAddAds == true)
{
BaseMsgForm.ShowInfo("请先查询直通车商品再调整数值!");
return;
}
var adsGoodsIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colGoodsId"]?.Value.ToString()).ToList();
var shopIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSupplierId"]?.Value.ToString()).Distinct().ToList();
if (shopIdLst.Count == 0 || adsGoodsIdLst.Count == 0)
{
BaseMsgForm.ShowInfo("请选择直通车商品!");
return;
}
var adsDetailLst = lstAdsDetailInfo.Where(ad => adsGoodsIdLst.Contains(ad.goods_id.ParseToString())).ToList();
var shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
var dgvRowLst = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
foreach (var row in dgvRowLst)
{
row.Cells["colMessage"].Value = "";
}
dgvRowLst = this.dgvAds.Rows.Cast<DataGridViewRow>().Where(r => adsGoodsIdLst.Contains(r.Cells["colGoodsId"].Value.ParseToString())).ToList();
foreach (var row in dgvRowLst)
{
row.Cells["colMsg"].Value = "";
}
ucGroupBoxEx2.Enabled = false;
ucGroupBoxEx3.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var tmpShopIdLst = new List<string>();
tmpShopIdLst.AddRange(shopIdLst);
int i = 0;
foreach (var shopId in tmpShopIdLst)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在操作...";
this.statusBar.pgbTaskProgress.Maximum = tmpShopIdLst.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 (shop.ad_login_status != "在线")
{
continue;
}
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
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 = "正在查询";
}
}));
bool isError = false;
string errMsg = "";
var shopAdsDetailLst = adsDetailLst.Where(ad => ad.shopId == shop.ShopId).ToList();
while (shopAdsDetailLst.Count > 0)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
var tmpAdsDetailLst = shopAdsDetailLst.Take(20).ToList();
foreach (var ads in tmpAdsDetailLst)
{
shopAdsDetailLst.Remove(ads);
}
int tryCount = 0;
tryAgain:
Thread.Sleep(100 + Randomx.GetId(200));
//var adIdLst = tmpAdsDetailLst.Select(a => a.ad_id).ToList();
//string mdyRst = PauseAds(shop, adIdLst);
var goodIdLst = tmpAdsDetailLst.Select(a => a.goods_id).ToList();
string mdyRst = PauseAds(shop, goodIdLst);
if (mdyRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
{
tryCount++;
Thread.Sleep(Randomx.GetId(500, 1000));
goto tryAgain;
}
if (!mdyRst.Contains("\"success\":true"))
{
string sErr = BaseRegex.GetStringJson(ref mdyRst, "errorMsg");
if (string.IsNullOrEmpty(sErr))
sErr = BaseRegex.GetStringJson(ref mdyRst, "error_msg");
if (string.IsNullOrEmpty(sErr))
sErr = mdyRst;
errMsg += sErr + " ";
foreach (var adsDetail in tmpAdsDetailLst)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsDetail.goods_id);
if (dgvRow == null)
continue;
dgvRow.Cells["colMsg"].Value = sErr;
}
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
break;
}
else
continue;
}
if (mdyRst.Contains("\"success\":true"))
{
foreach (var adsDetailItem in tmpAdsDetailLst)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsDetailItem.goods_id);
if (dgvRow == null)
continue;
var failInfo = BaseRegex.GetStringJson(ref mdyRst, "" + adsDetailItem.goods_id);
if (string.IsNullOrEmpty(failInfo))
{
dgvRow.Cells["colMsg"].Value = "暂停直通车成功";
}
else
{
dgvRow.Cells["colMsg"].Value = failInfo;
}
}
}
}
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;
}
}
}));
}
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);
}
private void btnContinueAds_Click(object sender, EventArgs e)
{
if (isAddAds == true)
{
BaseMsgForm.ShowInfo("请先查询直通车商品再调整数值!");
return;
}
var adsGoodsIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colGoodsId"]?.Value.ToString()).ToList();
var shopIdLst = dgvAds.Rows.Cast<DataGridViewRow>().Where(row
=> row.Cells["colCheck"]?.Value.ParseToBool() == true).Select(r => r.Cells["colSupplierId"]?.Value.ToString()).Distinct().ToList();
if (shopIdLst.Count == 0 || adsGoodsIdLst.Count == 0)
{
BaseMsgForm.ShowInfo("请选择直通车商品!");
return;
}
var adsDetailLst = lstAdsDetailInfo.Where(ad => adsGoodsIdLst.Contains(ad.goods_id.ParseToString())).ToList();
var shopLst = GlobalConfig.ShopLoginList.Where(s => shopIdLst.Contains(s.ShopId)).ToList();
var dgvRowLst = this.dgvShop.Rows.Cast<DataGridViewRow>();//.Where(r => lstShopId.Contains(r.Cells["colShopId"].Value.ParseToString()));
foreach (var row in dgvRowLst)
{
row.Cells["colMessage"].Value = "";
}
dgvRowLst = this.dgvAds.Rows.Cast<DataGridViewRow>().Where(r => adsGoodsIdLst.Contains(r.Cells["colGoodsId"].Value.ParseToString())).ToList();
foreach (var row in dgvRowLst)
{
row.Cells["colMsg"].Value = "";
}
ucGroupBoxEx2.Enabled = false;
ucGroupBoxEx3.Enabled = false;
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
var tmpShopIdLst = new List<string>();
tmpShopIdLst.AddRange(shopIdLst);
int i = 0;
foreach (var shopId in tmpShopIdLst)
{
this.Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "正在操作...";
this.statusBar.pgbTaskProgress.Maximum = tmpShopIdLst.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 (shop.ad_login_status != "在线")
{
continue;
}
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
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 = "正在查询";
}
}));
bool isError = false;
string errMsg = "";
var shopAdsDetailLst = adsDetailLst.Where(ad => ad.shopId == shop.ShopId).ToList();
while (shopAdsDetailLst.Count > 0)
{
if (cancellationTokenSource.IsCancellationRequested)
break;
var tmpAdsDetailLst = shopAdsDetailLst.Take(20).ToList();
foreach (var ads in tmpAdsDetailLst)
{
shopAdsDetailLst.Remove(ads);
}
int tryCount = 0;
tryAgain:
Thread.Sleep(100 + Randomx.GetId(200));
//var adIdLst = tmpAdsDetailLst.Select(a => a.ad_id).ToList();
//string mdyRst = continueAds(shop, adIdLst);
var goodsIdLst = tmpAdsDetailLst.Select(a => a.goods_id).ToList();
string mdyRst = continueAds(shop, goodsIdLst);
if (mdyRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
{
tryCount++;
Thread.Sleep(Randomx.GetId(500, 1000));
goto tryAgain;
}
if (!mdyRst.Contains("\"success\":true"))
{
string sErr = BaseRegex.GetStringJson(ref mdyRst, "errorMsg");
if (string.IsNullOrEmpty(sErr))
sErr = BaseRegex.GetStringJson(ref mdyRst, "error_msg");
if (string.IsNullOrEmpty(sErr))
sErr = mdyRst;
errMsg += sErr + " ";
foreach (var adsDetail in tmpAdsDetailLst)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsDetail.goods_id);
if (dgvRow == null)
continue;
dgvRow.Cells["colMsg"].Value = sErr;
}
ShopListForm.Instance.CheckShopAdsLogin(new List<string> { shop.ShopId });
if (shop.ad_login_status != "在线")
{
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 = "店铺直通车掉线";
row.Cells["colAdsLoginStatus"].Value = "离线";
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).LinkColor = Color.Red;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = Color.OrangeRed;
(row.Cells["colAdsLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = Color.DarkRed;
row.Cells["colCanUse"].Value = false;
}
}));
break;
}
else
continue;
}
if (mdyRst.Contains("\"success\":true"))
{
foreach (var adsDetailItem in tmpAdsDetailLst)
{
var dgvRow = this.dgvAds.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colGoodsId"].Value.ParseToString() ==
adsDetailItem.goods_id);
if (dgvRow == null)
continue;
var failInfo = BaseRegex.GetStringJson(ref mdyRst, "" + adsDetailItem.goods_id);
if (string.IsNullOrEmpty(failInfo))
{
dgvRow.Cells["colMsg"].Value = "开启直通车成功";
}
else
{
dgvRow.Cells["colMsg"].Value = failInfo;
}
}
}
}
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;
}
}
}));
}
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);
}
private void btnSelectFilter_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dgvAds.Rows)
{
if (row.Cells["colOrderCount"].Value.ParseToString().Replace(",", "").ParseToInt() < txtSelectFilter.Text.Trim().ParseToInt())
row.Cells["colCheck"].Value = true;
else
row.Cells["colCheck"].Value = false;
}
}
string GetAdsShowStatus(int statusId)
{
if (statusId == 8)
return "投放中";
if (statusId == 7)
return "手动暂停";
if (statusId == 5)
return "审核驳回";
if (statusId == 0)
return "账户资金不足";
return "未投放 详情请后台查看";
}
private void chkToday_CheckedChanged(object sender, EventArgs e)
{
if (chkToday.Checked == true)
{
chkToday.Enabled = false;
chkYesterday.Checked = chk7Days.Checked = chk30Days.Checked = false;
chkYesterday.Enabled = chk7Days.Enabled = chk30Days.Enabled = true;
}
}
private void chkYesterday_CheckedChanged(object sender, EventArgs e)
{
if (chkYesterday.Checked == true)
{
chkYesterday.Enabled = false;
chkToday.Checked = chk7Days.Checked = chk30Days.Checked = false;
chkToday.Enabled = chk7Days.Enabled = chk30Days.Enabled = true;
}
}
private void chk7Days_CheckedChanged(object sender, EventArgs e)
{
if (chk7Days.Checked == true)
{
chk7Days.Enabled = false;
chkToday.Checked = chkYesterday.Checked = chk30Days.Checked = false;
chkToday.Enabled = chkYesterday.Enabled = chk30Days.Enabled = true;
}
}
private void chk30Days_CheckedChanged(object sender, EventArgs e)
{
if (chk30Days.Checked == true)
{
chk30Days.Enabled = false;
chkToday.Checked = chkYesterday.Checked = chk7Days.Checked = false;
chkToday.Enabled = chkYesterday.Enabled = chk7Days.Enabled = true;
}
}
private void btnCancelSoloChangeRoas_Click(object sender, EventArgs e)
{
gbxSoloChangeRoas.Visible = false;
}
private void btnSoloChangeRoas_Click(object sender, EventArgs e)
{
List<string> goodsIds = new List<string>() { lblGoodsId.Text };
List<string> shopIds = new List<string>() { lblShopId.Text };
EditAds(goodsIds, shopIds, false);
gbxSoloChangeRoas.Visible = false;
}
private void chkSameRoas2_CheckedChanged(object sender, EventArgs e)
{
chkCalculateRoas2.Checked = !chkSameRoas2.Checked;
}
private void chkCalculateRoas2_CheckedChanged(object sender, EventArgs e)
{
chkSameRoas2.Checked = !chkCalculateRoas2.Checked;
lblCalculateRoas2.Visible = lblCalculateRoasPercentSign2.Visible = txtCalculateProfitRate2.Visible = chkCalculateRoas2.Checked;
}
private void btnEmpty_Click(object sender, EventArgs e)
{
txtNotes.Text = txtShopId.Text = txtShopName.Text = "";
FiltShop();
}
private void panelEx1_Click(object sender, EventArgs e)
{
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
}
}
public class CreateAdsParam
{
public List<create_ad_req_param> create_ad_reqs { get; set; }
}
public class create_ad_req_param
{
public string goods_id { get; set; } // "601099667164131"
public int site_id { get; set; } // 129,
public int roas { get; set; } // 77700,
public int budget { get; set; } // 12300 //单位分
}
public class MdyAdsParam
{
public List<modify_ad_dto_param> modify_ad_dtos { get; set; }
}
public class modify_ad_dto_param
{
public string ad_id { get; set; } // "300000013237119567",
public int? roas { get; set; } // 77700, //实际设置值7.77 * 10000
public int? budget { get; set; } // 12300 //单位分
public string goods_id { get; set; } // "601099667164131"
}
}