479 lines
21 KiB
C#
479 lines
21 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.Param;
|
||
using AllBase.Model.Result;
|
||
using AllBase.Model.Result.PDDResult;
|
||
using AllBase.Model.Result.WXResult;
|
||
using NaiBa.Util;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.BLL;
|
||
using TemuKJD.Extension;
|
||
using TemuKJD.PDDForms.ProductSelectForms;
|
||
using TemuKJD.PDDForms.ShopForms;
|
||
using TemuKJD.ToolForms;
|
||
using Work;
|
||
|
||
namespace TemuKJD.WXForms.TalkForms
|
||
{
|
||
public partial class BuyerOrderListForm : BaseGeneralForm
|
||
{
|
||
private static BuyerOrderListForm instance = null;
|
||
public static BuyerOrderListForm Instance { get { if (instance == null || instance.IsDisposed || instance.Disposing) instance = new BuyerOrderListForm(); return instance; } }
|
||
ShopLoginInfo currentShop { get { return this.lblCurrentShop.Tag as ShopLoginInfo; } }
|
||
ConcurrentList<WxOrderInfoLite> lstWxOrderInfoLite { get; set; } = new ConcurrentList<WxOrderInfoLite>();
|
||
public CancellationTokenSource cancellationTokenSource { get; set; } = new CancellationTokenSource();
|
||
public bool loadComplate = false;
|
||
public bool firstVisible = false;
|
||
public DateTime nextGetOrderTime = DateTime.Now;
|
||
|
||
public BuyerOrderListForm()
|
||
{
|
||
InitializeComponent();
|
||
instance = this;
|
||
}
|
||
|
||
private void ProductListForm_Load(object sender, EventArgs e)
|
||
{
|
||
dtpStartTime.Value = DateTime.Now.Date.AddMonths(-1);
|
||
dtpEndTime.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
|
||
dgvBuyer.AddSelectorColumn("colSelect");
|
||
|
||
GetBuyer();
|
||
AutoGetOrder();
|
||
loadComplate = true;
|
||
}
|
||
|
||
private void ProductListForm_VisibleChanged(object sender, EventArgs e)
|
||
{
|
||
}
|
||
|
||
void GetBuyer()
|
||
{
|
||
var ids = dgvBuyer.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSelect"].Value.ParseToBool() == true).Select(s => s.Cells["colBuyerId"].Value.ParseToString()).ToList();
|
||
Invoke(new Action(() => { pbLoading.Visible = true; }));
|
||
|
||
Task.Run(() =>
|
||
{
|
||
var url = BaseClass.BuildPDDObjString("user/get_buyer");
|
||
var data = UserLogin.GetSignaturex();
|
||
data += "&page_size=200";
|
||
|
||
var result = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(result) || !result.Contains("\"code\":200"))
|
||
result = GetHtml.PostUtf8(url, data);
|
||
|
||
if (result.Contains("\"code\":200"))
|
||
{
|
||
List<BuyerLoginInfo> loginInfoLst = JsonHelper.DeserializeJsonToList<BuyerLoginInfo>(JsonHelper.JObjectParse(result)["data"].ParseToString());
|
||
GlobalConfig.BuyerLoginList.Clear();
|
||
GlobalConfig.BuyerLoginList.AddRange(loginInfoLst);
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvBuyer.Rows.Clear();
|
||
}));
|
||
|
||
foreach (var buyer in GlobalConfig.BuyerLoginList)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rowIndex = this.dgvBuyer.Rows.Add(
|
||
ids.Contains(buyer.buyer_id),
|
||
buyer.buyer_id,
|
||
buyer.buyer_name,
|
||
buyer.buyer_nick,
|
||
buyer.notes,
|
||
"访问",
|
||
buyer.status
|
||
);
|
||
}));
|
||
}
|
||
}
|
||
|
||
Invoke(new Action(() =>
|
||
{
|
||
pbLoading.Visible = false;
|
||
}));
|
||
});
|
||
}
|
||
|
||
void AutoGetOrder()
|
||
{
|
||
Task.Run(() =>
|
||
{
|
||
while (true)
|
||
{
|
||
if (DateTime.Now > nextGetOrderTime)
|
||
{
|
||
nextGetOrderTime = DateTime.Now.AddMinutes(30);
|
||
GetOrder();
|
||
}
|
||
Thread.Sleep(1000);
|
||
Invoke(new Action(() =>
|
||
{
|
||
var ticks = nextGetOrderTime - DateTime.Now;
|
||
btnSearch.Text = "刷新订单 " + ticks.Minutes + ":" + ticks.Seconds;
|
||
}));
|
||
}
|
||
});
|
||
}
|
||
|
||
void GetOrder()
|
||
{
|
||
cancellationTokenSource = new CancellationTokenSource();
|
||
Task.Run(() =>
|
||
{
|
||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||
{
|
||
|
||
}
|
||
}, cancellationTokenSource.Token);
|
||
}
|
||
|
||
private void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
nextGetOrderTime = DateTime.Now.AddMinutes(30);
|
||
GetOrder();
|
||
}
|
||
|
||
private void pnlEmpty_Click(object sender, EventArgs e)
|
||
{
|
||
this.txtOrderSn.Text = "";
|
||
}
|
||
|
||
private void dgvDbProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
string headerText = dgvDbProduct.Columns[e.ColumnIndex].HeaderText;
|
||
//var dbId = dgvDbProduct.Rows[e.RowIndex].Cells["col_db_id"].Value.ParseToString();
|
||
//var dbProduct = lstTemuDbProduct.FirstOrDefault(p => p.id.ToString() == dbId);
|
||
|
||
switch (headerText)
|
||
{
|
||
case "详情":
|
||
case "编辑/详情":
|
||
//PDDDBProdEditForm editForm = new PDDDBProdEditForm(dbProduct);
|
||
//if (BaseClass.MainPath != "binxixi")
|
||
//{
|
||
// editForm.pnlSkuOption.Visible = false;
|
||
// editForm.txtProductName.ReadOnly = true;
|
||
// editForm.txtExtCode.ReadOnly = true;
|
||
// editForm.lblSkcId.Text = "仓库编码";
|
||
//}
|
||
//editForm.ShowDialog();
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["col_notes"].Value = dbProduct.notes;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["col_ext_code"].Value = dbProduct.ext_code;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colHeadWords"].Value = dbProduct.head_words;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colEndWords"].Value = dbProduct.end_words;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colFissionWords"].Value = dbProduct.fission_words;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["col_product_name"].Value = dbProduct.product_name;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colSkuReplaceImgUrl"].Value = dbProduct.sku_img_replace_url;
|
||
break;
|
||
case "主图":
|
||
ShowImgForm imgFrom = new ShowImgForm(dgvDbProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("?imageView2/2/w/90/h/90", ""));
|
||
imgFrom.ShowDialog();
|
||
break;
|
||
case "":
|
||
dgvDbProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvDbProduct.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void dgvDbProduct_Scroll(object sender, ScrollEventArgs e)
|
||
{
|
||
}
|
||
|
||
private void btnStopStop_Click(object sender, EventArgs e)
|
||
{
|
||
if (cancellationTokenSource != null)
|
||
cancellationTokenSource.Cancel();
|
||
Task.Run(() =>
|
||
{
|
||
Thread.Sleep(3000);
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
||
pbLoading.Visible = false;
|
||
}));
|
||
});
|
||
}
|
||
|
||
private void PDDDBProdListForm_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
}
|
||
|
||
private void PDDDBProdListForm_KeyUp(object sender, KeyEventArgs e)
|
||
{
|
||
}
|
||
|
||
private void WXUserProdListForm_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
this.Hide();
|
||
e.Cancel = true;
|
||
}
|
||
|
||
private void btnAddBuyler_Click(object sender, EventArgs e)
|
||
{
|
||
PddMobileLoginForm buyerLoginForm = new PddMobileLoginForm(null);
|
||
buyerLoginForm.openType = EnumOpenType.login;
|
||
buyerLoginForm.InitUrl = "https://mobile.yangkeduo.com/login.html?from=https%3A%2F%2Fmobile.yangkeduo.com%2Fpersonal.html";
|
||
buyerLoginForm.ShowDialog();
|
||
GetBuyer();
|
||
}
|
||
|
||
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
|
||
string headerText = dgvBuyer.Columns[e.ColumnIndex].HeaderText;
|
||
var buyerId = dgvBuyer.Rows[e.RowIndex].Cells["colBuyerId"].Value.ParseToString();
|
||
var buyer = GlobalConfig.BuyerLoginList.FirstOrDefault(p => p.buyer_id.ToString() == buyerId);
|
||
|
||
switch (headerText)
|
||
{
|
||
case "状态":
|
||
case "登录":
|
||
CheckBuyerLogin(new List<BuyerLoginInfo> { buyer }, false);
|
||
if (buyer.status == "在线")
|
||
{
|
||
PddMobileLoginForm shopLoginForm = new PddMobileLoginForm(buyer);
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://mobile.yangkeduo.com";
|
||
shopLoginForm.Show();
|
||
}
|
||
else
|
||
{
|
||
PddMobileLoginForm shopLoginForm = new PddMobileLoginForm(buyer);
|
||
shopLoginForm.openType = EnumOpenType.login;
|
||
shopLoginForm.InitUrl = "https://mobile.yangkeduo.com/login.html?from=https%3A%2F%2Fmobile.yangkeduo.com%2Fpersonal.html";
|
||
shopLoginForm.ShowDialog();
|
||
GetBuyer();
|
||
}
|
||
break;
|
||
case "访问":
|
||
{
|
||
PddMobileLoginForm shopLoginForm = new PddMobileLoginForm(buyer);
|
||
shopLoginForm.openType = EnumOpenType.manage;
|
||
shopLoginForm.WindowState = FormWindowState.Maximized;
|
||
shopLoginForm.InitUrl = "https://mobile.yangkeduo.com";
|
||
shopLoginForm.Show();
|
||
}
|
||
break;
|
||
case "详情":
|
||
case "编辑/详情":
|
||
//PDDDBProdEditForm editForm = new PDDDBProdEditForm(dbProduct);
|
||
//if (BaseClass.MainPath != "binxixi")
|
||
//{
|
||
// editForm.pnlSkuOption.Visible = false;
|
||
// editForm.txtProductName.ReadOnly = true;
|
||
// editForm.txtExtCode.ReadOnly = true;
|
||
// editForm.lblSkcId.Text = "仓库编码";
|
||
//}
|
||
//editForm.ShowDialog();
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["col_notes"].Value = dbProduct.notes;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["col_ext_code"].Value = dbProduct.ext_code;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colHeadWords"].Value = dbProduct.head_words;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colEndWords"].Value = dbProduct.end_words;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colFissionWords"].Value = dbProduct.fission_words;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["col_product_name"].Value = dbProduct.product_name;
|
||
//dgvDbProduct.Rows[e.RowIndex].Cells["colSkuReplaceImgUrl"].Value = dbProduct.sku_img_replace_url;
|
||
break;
|
||
case "":
|
||
case "全选":
|
||
dgvBuyer.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvBuyer.Rows[e.RowIndex].Cells["colSelect"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
public void CheckBuyerLogin(List<BuyerLoginInfo> checkBuyers, bool isShowProgress = true)
|
||
{
|
||
for (int i = 0; i < checkBuyers.Count; i++)
|
||
{
|
||
var buyer = GlobalConfig.BuyerLoginList.FirstOrDefault(v => v.buyer_id == checkBuyers[i].buyer_id);
|
||
var buys = GlobalConfig.BuyerLoginList.Where(v => v.buyer_id == checkBuyers[i].buyer_id).ToList();
|
||
if (buyer == null)
|
||
continue;
|
||
|
||
// 先从服务端取最新cookie
|
||
var url = BaseClass.BuildPDDObjString("user/get_buyer");
|
||
var data = UserLogin.GetSignaturex();
|
||
data += "&buyer_id=" + buyer.buyer_id;
|
||
data += "&page_size=1";
|
||
var result = GetHtml.PostUtf8(url, data);
|
||
if (string.IsNullOrEmpty(result) || !result.Contains("\"code\":200"))
|
||
result = GetHtml.PostUtf8(url, data);
|
||
if (!result.Contains("\"code\":200"))
|
||
continue;
|
||
List<BuyerLoginInfo> loginInfoLst = JsonHelper.DeserializeJsonToList<BuyerLoginInfo>(JsonHelper.JObjectParse(result)["data"].ParseToString());
|
||
|
||
var serverBuyer = loginInfoLst.FirstOrDefault();
|
||
if (buyer != null && serverBuyer != null)
|
||
{
|
||
buyer.cookie = serverBuyer.cookie;
|
||
foreach (var buy in buys)
|
||
{
|
||
buy.cookie = serverBuyer.cookie;
|
||
}
|
||
}
|
||
|
||
if (buyer != null)
|
||
{
|
||
var loginResult = CheckBuyerLogin(buyer);
|
||
if (loginResult.Contains("\"success\":true") && !loginResult.Contains("\"login\":true"))
|
||
{
|
||
buyer.cookie = "[]";
|
||
foreach (var buy in buys)
|
||
{
|
||
buy.status = "掉线";
|
||
buy.cookie = "[]";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var buy in buys)
|
||
{
|
||
buy.status = "在线";
|
||
}
|
||
}
|
||
UpdateServerBuyerCookies(buyer); // 店铺cookie和状态写入服务端
|
||
}
|
||
if (this.Created && isShowProgress)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在检测...";
|
||
this.statusBar.pgbTaskProgress.Value = (i + 1);
|
||
this.statusBar.pgbTaskProgress.Text = (i + 1) + "/" + checkBuyers.Count;
|
||
}));
|
||
}
|
||
}
|
||
}
|
||
|
||
public static string CheckBuyerLogin(BuyerLoginInfo buyer, string refere = "https://mobile.yangkeduo.com/goods.html")
|
||
{
|
||
string url = "https://mobile.yangkeduo.com/proxy/api/api/apollo/v3/user/me?pdduid=" + buyer.buyer_id;
|
||
return YkdHttpResponseBLL.YangkeduoGetResponse(buyer, url, refere);
|
||
}
|
||
|
||
public static string UpdateServerBuyerCookies(BuyerLoginInfo buyer, string fromTool = null)
|
||
{
|
||
var url = BaseClass.BuildPDDObjString("user/mdy_buyer_cookie");
|
||
var data = UserLogin.GetSignaturex()
|
||
+ "&status=" + buyer.status
|
||
+ "&cookie=" + GetHtml.UrlEncodeUtf8(buyer.cookie)
|
||
+ "&buyer_id=" + buyer.buyer_id;
|
||
var result = GetHtml.PostUtf8(url, data);
|
||
if (!result.Contains("\"code\":200"))
|
||
result = GetHtml.PostUtf8(url, data);
|
||
return result;
|
||
}
|
||
|
||
private void btnRefresh_Click(object sender, EventArgs e)
|
||
{
|
||
GetBuyer();
|
||
}
|
||
|
||
private void btnCheck_Click(object sender, EventArgs e)
|
||
{
|
||
var ids = dgvBuyer.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSelect"].Value.ParseToBool() == true).Select(s => s.Cells["colBuyerId"].Value.ParseToString()).ToList();
|
||
var buyers = GlobalConfig.BuyerLoginList.Where(b => ids.Contains(b.buyer_id)).ToList();
|
||
Task.Run(() => {
|
||
CheckBuyerLogin(buyers);
|
||
GetBuyer();
|
||
});
|
||
}
|
||
|
||
private void btnDel_Click(object sender, EventArgs e)
|
||
{
|
||
if (BaseMsgForm.ShowConfirm("确定删除吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||
return;
|
||
|
||
var ids = dgvBuyer.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colSelect"].Value.ParseToBool() == true).Select(s => s.Cells["colBuyerId"].Value.ParseToString()).ToList();
|
||
var buyers = GlobalConfig.BuyerLoginList.Where(b => ids.Contains(b.buyer_id)).ToList();
|
||
this.statusBar.pgbTaskProgress.Maximum = buyers.Count;
|
||
pbLoading.Visible = true;
|
||
|
||
Task.Run(() =>
|
||
{
|
||
int i = 0;
|
||
foreach (var buyer in buyers)
|
||
{
|
||
i++;
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "正在删除...";
|
||
this.statusBar.pgbTaskProgress.Value = i;
|
||
this.statusBar.pgbTaskProgress.Text = i + "/" + buyers.Count;
|
||
}));
|
||
|
||
var url = BaseClass.BuildPDDObjString("user/del_buyer");
|
||
var data = UserLogin.GetSignaturex()
|
||
+ "&buyer_id=" + buyer.buyer_id;
|
||
var result = GetHtml.PostUtf8(url, data);
|
||
|
||
Thread.Sleep(100);
|
||
}
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
this.statusBar.lblTaskStatus.Text = "删除完成";
|
||
this.statusBar.pgbTaskProgress.Value = buyers.Count;
|
||
this.statusBar.pgbTaskProgress.Text = buyers.Count + "/" + buyers.Count;
|
||
}));
|
||
GetBuyer();
|
||
});
|
||
}
|
||
}
|
||
|
||
public class YkdBuyerOrder
|
||
{
|
||
|
||
}
|
||
|
||
public class WxOrder
|
||
{
|
||
// orderStatus:20待发货 0售后中 30已发货
|
||
public static string OrderSeach(ShopLoginInfo shop, string orderId, string telNumber, int orderStatus = 20, int page = 1, string startTime="", string endTime="")
|
||
{
|
||
if (string.IsNullOrWhiteSpace(startTime))
|
||
startTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddMonths(-1)).ToString();
|
||
if (string.IsNullOrWhiteSpace(endTime))
|
||
endTime = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date).ToString();
|
||
|
||
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN";
|
||
string referer = "https://store.weixin.qq.com/shop/order/list";
|
||
string body = @"{""isSearch"":true,""pageSize"":100,""overTime"":0,""pengingShipOneDay"":0,""pengingShipSixHour"":0,""expediteDelivery"":0," +
|
||
@"""stockoutPunishAlert"":0,""waybillStatus"":0,""pageNum"":1,""onAftersaleOrderExist"":0,""orderStatus"":" + orderStatus +
|
||
@",""page"":" + page + @",""orderId"":""" + orderId + @""",""orderTime"":{""type"":0,""time"":[" + startTime + @"," + endTime + @"]}," +
|
||
@"""telNumber"":""" + telNumber + @""",""title"":"""",""receiverName"":"""",""finderNickName"":"""",""merchantNotes"":""""," +
|
||
@"""merchantNotesTagColor"":0,""waybillId"":"""",""productCode"":"""",""inspectStatus"":"""",""finderWay"":0,""searchOrderType"":0," +
|
||
@"""payMethod"":0,""orderChannel"":0,""bulkbuyActivityId"":"""",""deliveryNegotiationFlag"":0,""transactionId"":""""," +
|
||
@"""startCreateTime"":" + startTime + @",""endCreateTime"":" + endTime + @"}";
|
||
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
|
||
return result;
|
||
}
|
||
}
|
||
}
|