测试数据库服务接口文件, 店铺活动报名功能
This commit is contained in:
1 parent
85ed4137d2
commit
7556b63d10
18 files changed
+687
-158
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.Param.SalesManage;
|
||||
using AllBase.Model.Result;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -25,6 +26,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||||
public List<TemuActivityThematicInfo> lstActivityThematic { get; set; } = new List<TemuActivityThematicInfo>();
|
||||
public List<string> lstShopIdSelect = new List<string>();
|
||||
public List<string> lstActivityIdSelect = new List<string>();
|
||||
public List<int> lstDiscount = new List<int>() { 60, 70, 80, 85 };
|
||||
public Dictionary<string, List<SubOrderInfo>> dicNoSaleProd = new Dictionary<string, List<SubOrderInfo>>();
|
||||
|
||||
@@ -158,7 +160,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
switch (columnName)
|
||||
{
|
||||
case "colSelect":
|
||||
if (row.Cells["colCanUse"].Value.ParseToBool())
|
||||
if (row.Cells["colCanUse"].Value.ParseToBool() || row.Cells["colSelect"].Value.ParseToBool())
|
||||
{
|
||||
row.Cells["colSelect"].Value = !row.Cells["colSelect"].Value.ParseToBool();
|
||||
|
||||
@@ -459,6 +461,9 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
i++;
|
||||
}));
|
||||
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
if (actInfo == null)
|
||||
continue;
|
||||
|
||||
@@ -512,7 +517,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
tryAgain:
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
string jsonRst = GetActivityMatch(shop, actInfo.activityThematicId.ParseToLong());
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符"))
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符") || jsonRst.Contains("login") || jsonRst.Contains("Login"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
@@ -531,9 +536,6 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
tryCount++;
|
||||
goto tryAgain;
|
||||
}
|
||||
if (jsonRst.Contains("当前操作人数太多,请稍后重试"))
|
||||
{
|
||||
}
|
||||
if (!jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
//isError = true;
|
||||
@@ -593,7 +595,7 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||||
}
|
||||
}
|
||||
if(string.IsNullOrEmpty(actInfo.discount))
|
||||
if(string.IsNullOrEmpty(actInfo.discount) && !cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
@@ -649,22 +651,21 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
lstShopIdSelect.Clear();
|
||||
lstShopIdSelect.AddRange(lstShopId);
|
||||
lstActivityIdSelect.Clear();
|
||||
lstActivityIdSelect.AddRange(lstActivityId);
|
||||
#endregion
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (chkNoSaleProd.Checked)
|
||||
GetNoSaleProd();
|
||||
|
||||
SignActivity();
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
ucGroupBoxEx2.Enabled = true;
|
||||
ucGroupBoxEx3.Enabled = true;
|
||||
string sRst = "查询结束!";
|
||||
string sRst = "已完成活动报名!";
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
sRst = "已取消查询!";
|
||||
sRst = "已取消活动报名!";
|
||||
|
||||
BaseMsgForm.ShowInfo(sRst);
|
||||
this.statusBar.lblTaskStatus.Text = sRst;
|
||||
@@ -672,14 +673,112 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
},cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
public void GetNoSaleProd()
|
||||
/// <summary>
|
||||
/// 查询店铺未出单商品,返回商品id列表
|
||||
/// </summary>
|
||||
public List<string> GetNoSaleProd(string shopId)
|
||||
{
|
||||
//int i = 0;
|
||||
//foreach (var shopId in lstShopIdSelect)
|
||||
//{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "正在查询无销量商品...";
|
||||
this.statusBar.pgbTaskProgress.Maximum = lstShopIdSelect.Count;
|
||||
//this.statusBar.UpdateProgressBar(i + 1);
|
||||
//i++;
|
||||
}));
|
||||
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
return new List<string>();
|
||||
|
||||
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
|
||||
if (shop == null)
|
||||
return new List<string>();
|
||||
var shopRow = this.dgvShop.Rows.Cast<DataGridViewRow>()
|
||||
.FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||||
if (shopRow == null)
|
||||
return new List<string>();
|
||||
|
||||
if (!CheckLogin(shop))
|
||||
return new List<string>();
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
shopRow.Cells["colMessage"].Value = "正在查询无销量商品";
|
||||
}));
|
||||
|
||||
this.dicNoSaleProd[shop.ShopId] = new List<SubOrderInfo>();
|
||||
int page = 0;
|
||||
int totalPage = 1;
|
||||
while (page < totalPage)
|
||||
{
|
||||
page++;
|
||||
string jsonRst = GetNoSaleProd(shop, numNoSaleDays.Value.ParseToInt(), page);
|
||||
|
||||
if (!jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
string sErr = BaseRegex.GetStringJson(ref jsonRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(sErr))
|
||||
sErr = BaseRegex.GetStringJson(ref jsonRst, "err_msg");
|
||||
if (string.IsNullOrEmpty(sErr))
|
||||
sErr = jsonRst;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
shopRow.Cells["colMessage"].Value = sErr;
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
var jArr = new JArray();
|
||||
try
|
||||
{
|
||||
var jObj = JObject.Parse(jsonRst);
|
||||
jArr = jObj["result"]["subOrderList"] as JArray;
|
||||
if (jArr == null)
|
||||
jArr = new JArray();
|
||||
|
||||
foreach (var item in jArr)
|
||||
{
|
||||
string sItem = item.ToString();
|
||||
SubOrderInfo sInfo = JsonHelper.DeserializeJsonToObject<SubOrderInfo>(sItem); // 反序列化得到类
|
||||
if (sInfo != null)
|
||||
{
|
||||
this.dicNoSaleProd[shop.ShopId].Add(sInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError(ex.Message);
|
||||
}
|
||||
|
||||
int total = BaseRegex.GetStringJson(ref jsonRst, "total").ParseToInt();
|
||||
totalPage = Math.Ceiling(total / 40.0).ParseToInt();
|
||||
}
|
||||
//}
|
||||
try
|
||||
{
|
||||
return this.dicNoSaleProd[shop.ShopId].Select(p => p.productId.ParseToString()).ToList();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SignActivity()
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var shopId in lstShopIdSelect)
|
||||
{
|
||||
List<string> noSaleProdIdLst = new List<string>();
|
||||
if (chkNoSaleProd.Checked)
|
||||
noSaleProdIdLst.AddRange(GetNoSaleProd(shopId));
|
||||
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.statusBar.lblTaskStatus.Text = "正在查询无销量商品...";
|
||||
this.statusBar.lblTaskStatus.Text = "正在报名活动商品...";
|
||||
this.statusBar.pgbTaskProgress.Maximum = lstShopIdSelect.Count;
|
||||
this.statusBar.UpdateProgressBar(i + 1);
|
||||
i++;
|
||||
@@ -695,17 +794,42 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
.FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||||
if (shopRow == null)
|
||||
continue;
|
||||
|
||||
if (!CheckLogin(shop))
|
||||
continue;
|
||||
|
||||
this.dicNoSaleProd[shop.ShopId] = new List<SubOrderInfo>();
|
||||
int page = 0;
|
||||
int totalPage = 1;
|
||||
while (page < totalPage)
|
||||
foreach (var activityId in lstActivityIdSelect)
|
||||
{
|
||||
page++;
|
||||
string jsonRst = GetNoSaleProd(shop, numNoSaleDays.Value.ParseToInt(), page);
|
||||
var activity = lstActivityThematic.FirstOrDefault(a => a.activityThematicId.ParseToString() == activityId);
|
||||
if (activity == null)
|
||||
continue;
|
||||
var actRow = this.dgvActivity.Rows.Cast<DataGridViewRow>()
|
||||
.FirstOrDefault(r => r.Cells["colActivityId"].Value.ParseToLong() == activity.activityThematicId);
|
||||
if (actRow == null)
|
||||
continue;
|
||||
|
||||
int tryCount = 0;
|
||||
tryAgain:
|
||||
Thread.Sleep(100 + Randomx.GetId(200));
|
||||
var jsonRst = GetActivityMatch(shop, activity.activityThematicId, string.Join(",", noSaleProdIdLst));
|
||||
if (jsonRst.Contains("指定的值含有无效的控制字符") || jsonRst.Contains("login") || jsonRst.Contains("Login"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var shopRows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopLoginName"].Value.ToString() == shop.LoginName);
|
||||
foreach (var r in shopRows)
|
||||
{
|
||||
r.Cells["colMessage"].Value = "店铺掉线";
|
||||
r.Cells["colLoginStatus"].Value = "国际版未登录";
|
||||
r.Cells["colCanUse"].Value = false;
|
||||
}
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
if (jsonRst.Contains("当前操作人数太多,请稍后重试") && tryCount < 5)
|
||||
{
|
||||
tryCount++;
|
||||
goto tryAgain;
|
||||
}
|
||||
|
||||
if (!jsonRst.Contains("\"success\":true"))
|
||||
{
|
||||
@@ -716,48 +840,134 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
sErr = jsonRst;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
actRow.Cells["colActivityMsg"].Value = sErr;
|
||||
shopRow.Cells["colMessage"].Value = sErr;
|
||||
}));
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
var jArr = new JArray();
|
||||
try
|
||||
{
|
||||
var jObj = JObject.Parse(jsonRst);
|
||||
jArr = jObj["result"]["subOrderList"] as JArray;
|
||||
jArr = jObj["result"]?["matchList"] as JArray;
|
||||
if (jArr == null)
|
||||
jArr = new JArray();
|
||||
}
|
||||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||||
|
||||
foreach (var item in jArr)
|
||||
if (jArr.Count() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string str = JsonHelper.SerializeObject(jArr);
|
||||
var prodLst = JsonHelper.DeserializeJsonToList<TemuActivityMatchProductInfo>(str);
|
||||
var prodSubmitRows = new List<DataGridViewRow>();
|
||||
|
||||
TemuActivityParam activityParam = new TemuActivityParam();
|
||||
activityParam.activityType = 13;
|
||||
activityParam.activityThematicId = activity.activityThematicId;
|
||||
activityParam.productList = new List<ActProductListItem>();
|
||||
|
||||
foreach (var prod in prodLst)
|
||||
{
|
||||
string sItem = item.ToString();
|
||||
SubOrderInfo sInfo = JsonHelper.DeserializeJsonToObject<SubOrderInfo>(sItem); // 反序列化得到类
|
||||
if (sInfo != null)
|
||||
int discount = this.GetNearDiscount(activity.discount.ParseToInt());
|
||||
var discountCtrl = this.actDiscount60;
|
||||
if (discount == 70)
|
||||
discountCtrl = this.actDiscount70;
|
||||
if (discount == 80)
|
||||
discountCtrl = this.actDiscount80;
|
||||
if (discount == 85)
|
||||
discountCtrl = this.actDiscount85;
|
||||
// 如果是默认库存或者库存小于推荐值,使用推荐库存
|
||||
int inventory = discountCtrl.Inventory;
|
||||
if (inventory < prod.suggestActivityStock || discountCtrl.IsDefaultInventory)
|
||||
inventory = prod.suggestActivityStock.ParseToInt();
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.dicNoSaleProd[shop.ShopId].Add(sInfo);
|
||||
int rowId = dgvProduct.Rows.Add(
|
||||
true,
|
||||
shop.ShopId,
|
||||
shop.ShopAccount,
|
||||
activity.activityThematicId,
|
||||
activity.activityThematicName,
|
||||
null,//prod.pictureUrl,
|
||||
prod.productName,
|
||||
prod.productId,
|
||||
prod.skcList.FirstOrDefault()?.skcId,
|
||||
prod.skcList.FirstOrDefault()?.extCode,
|
||||
activity.discount.Trim('0') + "折",
|
||||
prod.suggestActivityStock,
|
||||
activity.discount.Trim('0') + "折",
|
||||
inventory
|
||||
);
|
||||
dgvProduct.Rows[rowId].Height = 30;
|
||||
prodSubmitRows.Add(dgvProduct.Rows[rowId]);
|
||||
}));
|
||||
|
||||
ActProductListItem activityProditem = new ActProductListItem();
|
||||
activityProditem.productId = prod.productId;
|
||||
activityProditem.activityStock = inventory;
|
||||
activityProditem.skcList = new List<ActSkcListItem>();
|
||||
|
||||
ActSkcListItem actSkcListItem = new ActSkcListItem();
|
||||
actSkcListItem.skcId = prod.skcList.FirstOrDefault()?.skcId;
|
||||
actSkcListItem.skuList = new List<ActSkuListItem>();
|
||||
foreach (var skuInfo in prod.skcList.FirstOrDefault()?.skuList)
|
||||
{
|
||||
actSkcListItem.skuList.Add(new ActSkuListItem
|
||||
{
|
||||
activityPrice = skuInfo.suggestActivityPrice,
|
||||
skuId = skuInfo.skuId,
|
||||
});
|
||||
}
|
||||
activityProditem.skcList.Add(actSkcListItem);
|
||||
activityParam.productList.Add(activityProditem);
|
||||
}
|
||||
string data = JsonHelper.SerializeObject(activityParam);
|
||||
string submitRst = "";
|
||||
submitRst = SubmitActivity(shop, activityParam.activityThematicId, data);
|
||||
|
||||
if (!submitRst.Contains("\"success\":true"))
|
||||
{
|
||||
string sSubmitErr = BaseRegex.GetStringJson(ref submitRst, "errorMsg");
|
||||
if (string.IsNullOrEmpty(sSubmitErr))
|
||||
sSubmitErr = BaseRegex.GetStringJson(ref submitRst, "err_msg");
|
||||
if (string.IsNullOrEmpty(sSubmitErr))
|
||||
sSubmitErr = jsonRst;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach(var submitRow in prodSubmitRows)
|
||||
{
|
||||
submitRow.Cells["colMsg"].Value = sSubmitErr;
|
||||
}
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
foreach (var submitRow in prodSubmitRows)
|
||||
{
|
||||
submitRow.Cells["colMsg"].Value = "提交活动成功";
|
||||
}
|
||||
}));
|
||||
|
||||
// 如果提交成功且还有更多商品可报名,继续重复报名(已报名商品不会出现在搜索结果列表)
|
||||
if (submitRst.Contains("\"success\":true") && jsonRst.Contains("\"hasMore\":true"))
|
||||
{
|
||||
tryCount = 0;
|
||||
goto tryAgain;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError(ex.Message);
|
||||
}
|
||||
|
||||
int total = BaseRegex.GetStringJson(ref jsonRst, "total").ParseToInt();
|
||||
totalPage = Math.Ceiling(total / 40.0).ParseToInt();
|
||||
catch (Exception ex) { BaseMsgForm.ShowError(ex.Message); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SignActivity()
|
||||
{
|
||||
foreach (var shopId in lstShopIdSelect)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckLogin(ShopLoginInfo shop)
|
||||
{
|
||||
if (shop.LoginStatus2 != "国际版在线")
|
||||
@@ -783,6 +993,12 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
return true;
|
||||
}
|
||||
|
||||
private void btnStop_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (cancellationTokenSource != null)
|
||||
cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取活动列表
|
||||
/// </summary>
|
||||
@@ -801,12 +1017,35 @@ namespace TemuKJD.KJDForms.SalesCenterForms
|
||||
/// 获取符合店铺的活动
|
||||
/// </summary>
|
||||
/// <param name="shop"></param>
|
||||
/// <param name="thematicId"></param>
|
||||
/// <param name="spuIds">多个用逗号隔开</param>
|
||||
/// <returns></returns>
|
||||
private string GetActivityMatch(ShopLoginInfo shop, long? thematicId)
|
||||
private string GetActivityMatch(ShopLoginInfo shop, long? thematicId, string spuIds="")
|
||||
{
|
||||
string url = "https://agentseller.temu.com/api/kiana/gamblers/marketing/enroll/scroll/match";
|
||||
string body;
|
||||
body = @"{""activityType"":13,""activityThematicId"":" + thematicId + @",""rowCount"":50}";
|
||||
if (!string.IsNullOrWhiteSpace(spuIds))
|
||||
{
|
||||
body = @"{""activityType"":13,""activityThematicId"":" + thematicId +
|
||||
@",""rowCount"":50,""productIds"":[" + spuIds + @"],""productSkcExtCodes"":[]}";
|
||||
}
|
||||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=13&thematicId=" + thematicId;
|
||||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提交活动报名
|
||||
/// </summary>
|
||||
/// <param name="shop"></param>
|
||||
/// <param name="thematicId"></param>
|
||||
/// <param name="_body"></param>
|
||||
/// <returns></returns>
|
||||
private string SubmitActivity(ShopLoginInfo shop, long? thematicId, string _body)
|
||||
{
|
||||
string url = "https://agentseller.temu.com/api/kiana/gamblers/marketing/enroll/submit";
|
||||
string body;
|
||||
body = _body;
|
||||
string refere = "https://agentseller.temu.com/activity/marketing-activity/detail-new?type=13&thematicId=" + thematicId;
|
||||
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user