952 lines
44 KiB
C#
952 lines
44 KiB
C#
using AllBase;
|
|
using AllBase.Helper;
|
|
using AllBase.Model;
|
|
using AllBase.Model.DBModel;
|
|
using AllBase.Model.Result;
|
|
using CefSharp;
|
|
using CefSharp.DevTools.IO;
|
|
using CefSharp.WinForms;
|
|
using DevComponents.WinForms.Drawing;
|
|
|
|
//using TemuKJD.DashBoardForms;
|
|
using Microsoft.Win32;
|
|
using NaiBa.CefHelper;
|
|
using NaiBa.CefHelper.Handler;
|
|
using NaiBa.Util.Enum;
|
|
using NaiBa.Util.Extension;
|
|
using NaiBa.Util.Model;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
//using System.Web.Hosting;
|
|
using System.Windows.Forms;
|
|
using Work;
|
|
using Work._29Tools.BLL;
|
|
using Work._29Tools.CefTools;
|
|
using Work.BaseForms;
|
|
|
|
namespace TemuKJD.ToolForms
|
|
{
|
|
|
|
public partial class PddMobileBuyOrderForm : BaseGeneralForm
|
|
{
|
|
public bool IsAutoBuy { get; set; } = true;
|
|
public bool IsFormLoad { get; set; } = false;
|
|
|
|
public int CloseAfterSecond { get; set; }
|
|
public string InitUrl = "";
|
|
private string shopCookieHead = "yangkeduo.com";
|
|
private string shopMainUrl = "https://mobile.yangkeduo.com/index.html";
|
|
private ChromiumWebBrowser cefWebBrowser = null;
|
|
private string currentUrl = "";
|
|
|
|
private bool IsSoldOut = false;
|
|
|
|
// 当前买手
|
|
private BuyerLoginInfo buyer = null;
|
|
// 订单商品
|
|
private oms_wei_order_item_info orderItem = null;
|
|
// 关联商品
|
|
private WXBuyMapInfo buyMap = null;
|
|
// 订单仓库
|
|
private TransitWarehouseParam transitWarehouse = null;
|
|
// (拍单后)回调函数
|
|
private Action<oms_wei_order_info, bool> filterOrderAction = null;
|
|
|
|
|
|
public PddMobileBuyOrderForm(Action<oms_wei_order_info, bool> filterOrder, oms_wei_order_item_info orderItemInfo, BuyerLoginInfo buyerInfo, WXBuyMapInfo buy_map = null)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.buyer = buyerInfo;
|
|
this.orderItem = orderItemInfo;
|
|
this.buyMap = buy_map;
|
|
|
|
filterOrderAction = filterOrder;
|
|
}
|
|
|
|
private void PddBuyOrderForm_Load(object sender, EventArgs e)
|
|
{
|
|
//splitContainer1.Dock = DockStyle.Fill;
|
|
this.Height = SystemInformation.WorkingArea.Height - 80;
|
|
this.CenterToScreen();
|
|
|
|
chkAutoChangeWarehouseAddress.Checked = GlobalConfig.BuyConfig.IsAutoChangeWarehouseAddress;
|
|
chkUseAppBalance.Checked = GlobalConfig.BuyConfig.IsUseAppBalance;
|
|
|
|
//chkUseAppBalance.Checked = false;
|
|
//chkUseAppBalance.Visible = false;
|
|
//GlobalConfig.BuyConfig.IsUseAppBalance = false;
|
|
|
|
if (CloseAfterSecond > 0)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(1000 * CloseAfterSecond);
|
|
if (this.Created)
|
|
{
|
|
Invoke(new Action(() => { this.Close(); }));
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
if (buyMap != null)
|
|
{
|
|
this.txtMapGoodsName.Text = buyMap.map_goods_name;
|
|
this.txtMapSkuName.Text = buyMap.map_spec_name;
|
|
this.txtMapGoodsId.Text = buyMap.map_goods_id;
|
|
this.txtMapSkuId.Text = buyMap.map_sku_id;
|
|
txtSendProvince.Text = buyMap.map_send_address;
|
|
|
|
this.transitWarehouse = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransId == buyMap.transit_warehouse_id);
|
|
if (transitWarehouse != null)
|
|
{
|
|
cmbTransitWarehouse.Text = transitWarehouse?.TransName + " " + transitWarehouse?.TransDetailAddress;
|
|
txtBuyTransitWarehouse.Text = transitWarehouse?.TransDetailAddress;
|
|
}
|
|
}
|
|
|
|
pictureBox1.ImageLocation = orderItem.thumb_img;
|
|
this.txtShopSkuId.Text = orderItem.sku_id;
|
|
this.txtShopGoodsId.Text = orderItem.product_id;
|
|
this.txtUpSpuCode.Text = orderItem.out_product_id.IsNullOrEmpty() ? orderItem.product_id : orderItem.out_product_id;
|
|
this.txtUpSkuCode.Text = orderItem.out_sku_id.IsNullOrEmpty() ? orderItem.sku_attr_str : orderItem.out_sku_id;
|
|
this.txtShopGoodsName.Text = orderItem.title;
|
|
this.txtShopSpecName.Text = orderItem.sku_attr_str;
|
|
this.txtShopOrderItemCnt.Text = orderItem.sku_cnt.ParseToString();
|
|
this.txtShopOrderItemPrice.Text = (orderItem.real_price * 0.01m).ParseToString();
|
|
|
|
this.txtOrderId.Text = orderItem.order_id;
|
|
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ErpShopId == orderItem.shop_id.ParseToString());
|
|
this.txtShopName.Text = shop?.ShopAccount;
|
|
|
|
|
|
foreach (var warehouse in TransitWarehouseData.TransitWarehouseList)
|
|
{
|
|
this.cmbTransitWarehouse.Items.Add(warehouse.TransName + " " + warehouse.TransDetailAddress);
|
|
}
|
|
|
|
Task.Run(() =>
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
LoadCef();
|
|
}));
|
|
});
|
|
IsFormLoad = true;
|
|
}
|
|
|
|
private void Rb_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
transitWarehouse = (sender as RadioButton)?.Tag as TransitWarehouseParam;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自动登录店铺后台
|
|
/// </summary>
|
|
private void LoadCef()
|
|
{
|
|
if (cefWebBrowser == null)
|
|
{
|
|
//cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
|
|
if (!string.IsNullOrEmpty(InitUrl))
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(InitUrl, true, true);
|
|
else
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(shopMainUrl, false);
|
|
LocalResourceRequestHandler resourceRequestHandler = new LocalResourceRequestHandler();
|
|
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
|
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
|
|
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
|
var lifeSapnHandler = new LocalLifeSpanHandler(PopWindowType.SelfWindow);
|
|
cefWebBrowser.LifeSpanHandler = lifeSapnHandler;
|
|
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
|
|
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
|
|
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
|
|
cefWebBrowser.LoadError += CefWebBrowser_LoadError;
|
|
cefWebBrowser.Dock = DockStyle.Fill;
|
|
|
|
//js绑定C#对象
|
|
//PDDShopBrowserObject shopObj = new PDDShopBrowserObject();
|
|
//shopObj.OnInfoReceived += ShopObj_OnInfoReceived;
|
|
//CefSharpSettings.WcfEnabled = true;
|
|
//cefWebBrowser.JavascriptObjectRepository.Register(
|
|
// name: "shopObj",
|
|
// objectToBind: shopObj,
|
|
// isAsync: false,
|
|
// options: new BindingOptions { Binder = BindingOptions.DefaultBinder.Binder /*CamelCaseJavascriptNames = false*/ /*cef79*/ }
|
|
//);
|
|
|
|
//if (buyer.cookie == null)
|
|
// buyer.cookie = "";
|
|
|
|
List<Cookie> cookieLst = new List<Cookie>();
|
|
try
|
|
{
|
|
if (buyer != null)
|
|
{
|
|
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(buyer?.cookie);
|
|
if (cookieLst == null)
|
|
cookieLst = new List<Cookie>();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
Task.Run(() =>
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
splitContainer1.Panel1.Controls.Add(cefWebBrowser);
|
|
//cefWebBrowser.Load(shopMainUrl);
|
|
}));
|
|
// cef138必须init后方可设置或删除cookie
|
|
while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
|
Thread.Sleep(20);
|
|
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null), "mobile.yangkeduo.com");
|
|
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null), "yangkeduo.com");
|
|
|
|
//if (cookieLst.Any(c => c.Value.StartsWith("windows_1")))
|
|
// cefWebBrowser.ExecuteScriptAsync("navigator.__defineGetter__('userAgent', function() { return 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.5.40.8 Safari/537.36 PddWorkbench-Online PddBrowser pdd_windows_version/3.0.3.12'; });");
|
|
|
|
//cef 138 如果没有设置RequestContext 可能为空,直接getCookieManager
|
|
//if (this.openType != EnumOpenType.login)
|
|
{
|
|
var t = CEFBrowser.SetCookieAsync(JsonHelper.SerializeObject(cookieLst), cefWebBrowser.GetCookieManager(null));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(InitUrl))
|
|
cefWebBrowser.Load(InitUrl);
|
|
else
|
|
cefWebBrowser.Load(shopMainUrl);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
|
|
{
|
|
if (this.Created && !this.Disposing && !this.IsDisposed)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
currentUrl = e.Address;
|
|
txtAddress.Text = e.Address;
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
|
{
|
|
//js绑定C#对象 html页面内声明绑定的C#对象
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("(function(){");
|
|
sb.Append("CefSharp.BindObjectAsync('shopObj');");
|
|
sb.Append("})();");
|
|
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
|
|
}
|
|
|
|
//public Func<object, string, string, request, bool> BeforeResourceLoadEvent; // sender, requestUrl, postData, request, true(表示取消执行)
|
|
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
|
{
|
|
if (url.StartsWith("https://mobile.yangkeduo.com/proxy/api/api/origenes/address_info") && chkAutoChangeWarehouseAddress.Checked && transitWarehouse != null)
|
|
{
|
|
//var address = BaseRegex.GetStringJson(ref postData, "address");
|
|
JObject jObj = JsonHelper.JObjectParse(postData);
|
|
jObj["province_id"] = transitWarehouse.province_id;
|
|
jObj["city_id"] = transitWarehouse.city_id;
|
|
jObj["district_id"] = transitWarehouse.district_id;
|
|
jObj["address"] = transitWarehouse.TransDetailAddress + Randomx.GetId(1, 35) + Randomx.GetId(1, 9).ToString().PadLeft(2, '0') + "室" + txtSourceCode.Text;
|
|
jObj["mobile"] = WaybillHelper.MobileHead[Randomx.GetId(WaybillHelper.MobileHead.Count)] + Randomx.GetNumber(8);
|
|
jObj["name"] = WaybillHelper.LastName[Randomx.GetId(WaybillHelper.LastName.Count)] + (Randomx.GetId(2) == 1 ? "先生" : "女士");
|
|
postData = JsonHelper.SerializeObject(jObj);
|
|
request.PostData.Elements[0].Bytes = System.Text.Encoding.UTF8.GetBytes(postData);
|
|
|
|
HasChangeAddress = true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//static int GetAntiContentsTimes = 40;
|
|
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
|
{
|
|
|
|
if (url.StartsWith("https://mobile.yangkeduo.com/order_checkout.html") && responseData.Contains("该商品已下架"))
|
|
{
|
|
IsSoldOut = true;
|
|
}
|
|
|
|
// 个人页面
|
|
if (url.Contains("https://mobile.yangkeduo.com/personal.html"))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
//var data = responseData;
|
|
});
|
|
}
|
|
|
|
// 商品页面 获取发货地信息,如果页面没有去客服页面询问
|
|
if (url.StartsWith("https://mobile.yangkeduo.com/goods.html?goods_id="))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var sendProvince = "";
|
|
var data = responseData;
|
|
var sendProvinceIndex = data.IndexOf("{\"key\":\"发货地\",\"values\":[");
|
|
if (sendProvinceIndex > 0)
|
|
{
|
|
sendProvince = data.Substring(sendProvinceIndex + "{\"key\":\"发货地\",\"values\":[".Length);
|
|
sendProvince = sendProvince.Substring(0, sendProvince.IndexOf("]"));
|
|
sendProvince = sendProvince.Trim('\"');
|
|
Invoke(new Action(() => { this.txtSendProvince.Text = sendProvince; }));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(sendProvince) && this.transitWarehouse == null)
|
|
{
|
|
MatchTransitWarehouse(sendProvince);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 订单详情页面 获取关联信息和拍单信息(已拍过单但是因某种原因未成功绑定仓库)
|
|
if (url.StartsWith("https://mobile.yangkeduo.com/order.html?order_sn="))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var data = responseData;
|
|
var goodsId = BaseRegex.GetLongJson(ref data, "goodsId");
|
|
var skuId = BaseRegex.GetLongJson(ref data, "skuId");
|
|
var goodsName = BaseRegex.GetStringJson(ref data, "goodsName");
|
|
var spec = BaseRegex.GetStringJson(ref data, "spec");
|
|
var oneGoodsPrice = BaseRegex.GetIntJson(ref data, "goodsPrice");
|
|
var buyCnt = BaseRegex.GetIntJson(ref data, "goodsNumber");
|
|
var buyPrice = BaseRegex.GetIntJson(ref data, "payAmount");
|
|
if (buyPrice.IsNullOrZero())
|
|
buyPrice = BaseRegex.GetIntJson(ref data, "orderAmount");
|
|
var orderSn = BaseRegex.GetIntJson(ref data, "orderSn");
|
|
Invoke(new Action(() =>
|
|
{
|
|
// 自动填写关联信息界面
|
|
this.txtMapGoodsId.Text = goodsId.ParseToString();
|
|
this.txtMapSkuId.Text = skuId.ParseToString();
|
|
this.txtMapGoodsName.Text = goodsName;
|
|
this.txtMapSkuName.Text = spec;
|
|
this.txtSendProvince.Text = "";
|
|
this.cmbTransitWarehouse.Text = "";
|
|
|
|
// 自动填写拍单信息界面
|
|
this.txtBuyGoodsId.Text = goodsId.ParseToString();
|
|
this.txtBuySkuId.Text = skuId.ParseToString();
|
|
this.txtBuyGoodsName.Text = goodsName;
|
|
this.txtBuySkuName.Text = spec;
|
|
this.txtBuyCnt.Text = buyCnt.ParseToString();
|
|
this.txtBuyPrice.Text = (buyPrice * 0.01m).ParseToString();
|
|
}));
|
|
});
|
|
}
|
|
|
|
// 待提交订单确认界面,填写拍单信息 两个接口都有可能有值,通过返回值内信息和url是否含有sku_id综合判断
|
|
//https://mobile.yangkeduo.com/proxy/api/api/morgan/confirm/render?pdduid=8161628055192
|
|
//https://mobile.yangkeduo.com/order_checkout.html?sku_id=1917755178967&group_id=168599782729&goods_id=966934985983&goods_number=1&page_from=0&detail_id=27322663212&_oak_rcto=YWJun7Qe7qhenWIlxgKO3uhsoi0WMIkr6Sb3iSrTsNPiwo_AHzvFVWwZ36KSfBTSAX-QF_CD92G9rA&order_extra_type=1&refer_page_element=open_btn&source_channel=0&refer_page_name=goods_detail&refer_page_id=10014_1782220402115_blxn1wofgo&refer_page_sn=10014
|
|
//https://mobile.yangkeduo.com/order_checkout.html?sku_id=1914416497946&group_id=168211384489&goods_id=964481496910&goods_number=2&page_from=23&detail_id=27475863056&_oc_refer_ad=0&_oak_rcto=YWJQMioxuzYiHEIW34yn103Toi0WMIkr6SaYUDjBkmkvOAtI8c-ZcKMw36KSfBTSAX-QF_CD92G9rA&order_extra_type=1&refer_page_element=open_btn&source_channel=0&_x_query=%E4%B8%AD%E5%9B%BD%E5%8F%A4%E4%BB%A3%E7%AE%97%E6%9C%AF%E6%B3%95%E8%80%81%E7%89%88%E6%9C%AC%E6%B4%AA%E4%B8%95%E8%B0%9F%E8%91%97%E5%91%BD%E7%90%86%E5%AD%A6%E7%A0%94%E7%A9%B6%E5%85%A5%E9%97%A8%E9%A3%8E%E6%B0%B4%E5%AD%A6%E4%B9%A6%E7%B1%8D%E5%85%A5%E9%97%A8%E5%B1%85%E5%AE%B6&refer_page_name=goods_detail&refer_page_id=10014_1782275100226_pojdmxgpty&refer_page_sn=10014
|
|
if (responseData.Contains("\"goods_id\"") && (url.StartsWith("https://mobile.yangkeduo.com/proxy/api/api/morgan/confirm/render?pdduid=") || url.Contains("sku_id=")))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var data = responseData;
|
|
|
|
if (data.Contains("\"goods_id\""))
|
|
{
|
|
var goodsId = BaseRegex.GetLongJson(ref data, "goods_id");
|
|
var skuId = BaseRegex.GetLongJson(ref data, "sku_id");
|
|
var goodsName = BaseRegex.GetStringJson(ref data, "goods_name");
|
|
if (string.IsNullOrEmpty(goodsName))
|
|
goodsName = BaseRegex.GetStringJson(ref data, "goodsName");
|
|
var specifications = BaseRegex.GetMatchRegexString(ref data, @"""specifications"":\[([^']*?)\]");
|
|
var spec = string.IsNullOrEmpty(specifications) ? "" : specifications;
|
|
if (spec.IsNullOrEmpty())
|
|
{
|
|
var specMatch = BaseRegex.GetMatchRegex(ref data, @"""spec_value"":""([^']+?)""");
|
|
foreach (var match in specMatch)
|
|
{
|
|
var matchStr = match.ParseToString();
|
|
spec += ("," + BaseRegex.GetStringJson(ref matchStr, "spec_value"));
|
|
}
|
|
spec = spec.Trim(',');
|
|
}
|
|
var oneGoodsPrice = BaseRegex.GetIntJson(ref data, "goodsPrice");
|
|
var buyCnt = BaseRegex.GetIntJson(ref data, "goods_number");
|
|
var buyPrice = BaseRegex.GetIntJson(ref data, "pay_price");
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.txtBuyGoodsId.Text = goodsId.ParseToString();
|
|
this.txtBuySkuId.Text = skuId.ParseToString();
|
|
this.txtBuyGoodsName.Text = goodsName;
|
|
this.txtBuySkuName.Text = spec;
|
|
this.txtBuyCnt.Text = buyCnt.ParseToString();
|
|
this.txtBuyPrice.Text = (buyPrice * 0.01m).ParseToString();
|
|
}));
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
// 自动修改收货地址为中转仓
|
|
var transit = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransDetailAddress == txtBuyTransitWarehouse.Text.Trim());
|
|
if (transit != null && IsChangeAddress == false && HasChangeAddress == false)
|
|
{
|
|
if(!IsSoldOut)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
IsChangeAddress = true;
|
|
Thread.Sleep(1000);
|
|
var sourceCodeRst = GetSourceCode(transit);
|
|
if (sourceCodeRst.Contains("失败"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.cefWebBrowser.Visible = false;
|
|
BaseMsgForm.ShowError(sourceCodeRst);
|
|
}));
|
|
return;
|
|
}
|
|
ChangeAddress(transit);
|
|
IsChangeAddress = false;
|
|
|
|
});
|
|
}
|
|
}
|
|
// 自动下单
|
|
if (IsAutoBuy)
|
|
{
|
|
if (!IsSoldOut)
|
|
{
|
|
if (HasChangeAddress == true)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
|
|
// 订单提交接口
|
|
if (url.StartsWith("https://mobile.yangkeduo.com/proxy/api/order/prepay?pdduid="))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var data = postData;
|
|
Invoke(new Action(() =>
|
|
{
|
|
txtBuyOrderId.Text = BaseRegex.GetStringJson(ref data, "order_sn");
|
|
}));
|
|
});
|
|
}
|
|
|
|
if (url.Contains("alipay.com") && responseData.Contains("支付成功"))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var uri = url;
|
|
var pData = postData;
|
|
var rData = responseData;
|
|
Invoke(new Action(() =>
|
|
{
|
|
//txtBuyOrderId.Text = BaseRegex.GetStringJson(ref data, "order_sn");
|
|
btnManualUpdateBuyOrder_Click(null, null);
|
|
}));
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取溯源码
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetSourceCode(TransitWarehouseParam transit)
|
|
{
|
|
JObject body = new JObject();
|
|
body["province"] = transit.province_name;
|
|
body["city"] = transit.city_name;
|
|
body["warehouseCode"] = transit.TransId;
|
|
body["matchType"] = 1;
|
|
var url = "https://po.e57.cn/prod-api/api/oms-api/external_procurement/getRandomTraceCode";
|
|
var dataStr = JsonHelper.SerializeObject(body);
|
|
var sourceCodeRst = HttpResponseWXBLL.e57PostResponse(url, dataStr, "");
|
|
var randomCode = BaseRegex.GetStringXml(ref sourceCodeRst, "randomCode");
|
|
if (!string.IsNullOrEmpty(randomCode))
|
|
{
|
|
Invoke(new Action(() => { txtSourceCode.Text = randomCode; }));
|
|
return randomCode;
|
|
}
|
|
else
|
|
{
|
|
return "获取失败,请关闭拍单窗口重试 " + BaseRegex.GetStringXml(ref sourceCodeRst, "msg", sourceCodeRst);
|
|
}
|
|
}
|
|
|
|
bool IsChangeAddress = false;
|
|
bool HasChangeAddress = false;
|
|
/// <summary>
|
|
/// 自动填写地址
|
|
/// </summary>
|
|
/// <param name="transit"></param>
|
|
/// <returns></returns>
|
|
public string ChangeAddress(TransitWarehouseParam transit)
|
|
{
|
|
Thread.Sleep(1000);
|
|
var host = cefWebBrowser.GetBrowser().GetHost();
|
|
var client = cefWebBrowser.GetDevToolsClient();
|
|
if (host == null || client == null)
|
|
{
|
|
return "页面未加载";
|
|
}
|
|
|
|
// 点击图片搜索图标
|
|
var jsStr1 = @"(function() { var element = document.getElementsByClassName('oc-address-info')[0];
|
|
//for (i=0; i< elements.length;i++){
|
|
// var element = elements[i];
|
|
// if (element.outerHTML.indexOf('当前收货地址为') >= 0) {
|
|
element.click();
|
|
// break;
|
|
// }
|
|
//}
|
|
})();";
|
|
var ts1 = client.Runtime.EvaluateAsync(jsStr1, null, true, null, null, true, null, true);
|
|
ts1.Wait(5000);
|
|
Thread.Sleep(Randomx.GetId(1500, 2500));
|
|
|
|
jsStr1 = @"(function() { var elements = document.getElementsByTagName('span');
|
|
for (i=0; i< elements.length;i++){
|
|
var element = elements[i];
|
|
if (element.innerHTML.indexOf('修改') == 0) {
|
|
element.click();
|
|
break;
|
|
}
|
|
}
|
|
})();";
|
|
ts1 = client.Runtime.EvaluateAsync(jsStr1, null, true, null, null, true, null, true);
|
|
ts1.Wait(5000);
|
|
Thread.Sleep(Randomx.GetId(1500, 2500));
|
|
|
|
jsStr1 = @"(function() { var elements = document.getElementsByTagName('span');
|
|
for (i=0; i< elements.length;i++){
|
|
var element = elements[i];
|
|
if (element.innerHTML.indexOf('保存') == 0) {
|
|
element.click();
|
|
break;
|
|
}
|
|
}
|
|
})();";
|
|
ts1 = client.Runtime.EvaluateAsync(jsStr1, null, true, null, null, true, null, true);
|
|
ts1.Wait(5000);
|
|
Thread.Sleep(Randomx.GetId(1500, 2500));
|
|
|
|
jsStr1 = @"(function() { var elements = document.getElementsByTagName('div');
|
|
for (i = elements.length - 1; i >= 0; i--){
|
|
var element = elements[i];
|
|
if (element.innerHTML.indexOf('" + txtBuyTransitWarehouse.Text.Trim() + @"') >= 0) {
|
|
element.click();
|
|
break;
|
|
}
|
|
}
|
|
})();";
|
|
ts1 = client.Runtime.EvaluateAsync(jsStr1, null, true, null, null, true, null, true);
|
|
ts1.Wait(5000);
|
|
Thread.Sleep(Randomx.GetId(1500, 2500));
|
|
|
|
return "";
|
|
}
|
|
|
|
|
|
|
|
private void btnManualUpdateSendProvince_Click(object sender, EventArgs e)
|
|
{
|
|
var sendProvince = txtSendProvince.Text.Trim();
|
|
MatchTransitWarehouse(sendProvince);
|
|
}
|
|
|
|
void MatchTransitWarehouse(string sendProvince)
|
|
{
|
|
bool isAutoGetWarehouse = false;
|
|
//foreach (var control in this.flowLayoutPanel1.Controls)
|
|
//{
|
|
// if (control is RadioButton rb)
|
|
// {
|
|
// if (rb.Tag is TransitWarehouseParam warehouseParam)
|
|
// {
|
|
// if (warehouseParam.TransDetailAddress.Contains(sendProvince))
|
|
// {
|
|
// Invoke(new Action(() =>
|
|
// {
|
|
// rb.Checked = true;
|
|
// }));
|
|
// isAutoGetWarehouse = true;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
foreach (var item in this.cmbTransitWarehouse.Items)
|
|
{
|
|
TransitWarehouseParam warehouseParam = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransName + " " + t.TransDetailAddress == item.ParseToString());
|
|
if (warehouseParam == null)
|
|
{
|
|
continue;
|
|
}
|
|
if (warehouseParam.TransDetailAddress.Contains(sendProvince))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
cmbTransitWarehouse.Text = warehouseParam.TransName + " " + warehouseParam.TransDetailAddress;
|
|
}));
|
|
transitWarehouse = warehouseParam;
|
|
isAutoGetWarehouse = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!isAutoGetWarehouse)
|
|
{
|
|
//黄导家庭父母5天训练营-《父母5天成为孩子成长的引路人》+《不内卷养育》2本书
|
|
Invoke(new Action(() =>
|
|
{
|
|
cmbTransitWarehouse.Text = "";
|
|
BaseMsgForm.ShowError("匹配仓库失败,请手动选择");
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void ShopLoginForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
//OnSaveComplete(shop);
|
|
Task.Run(() => {
|
|
Thread.Sleep(500);
|
|
if (!this.Disposing && !this.IsDisposed)
|
|
{
|
|
//MainForm.instance.Invoke(new Action(() => { this.Dispose(); }));
|
|
}
|
|
});
|
|
}
|
|
|
|
private void txtAddress_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (cefWebBrowser != null)
|
|
{
|
|
cefWebBrowser.Load(txtAddress.Text);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnManualUpdateTransitWarehouse_Click(object sender, EventArgs e)
|
|
{
|
|
if (transitWarehouse == null && !cmbTransitWarehouse.Text.Trim().IsNullOrEmpty())
|
|
{
|
|
transitWarehouse = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransName + " " + t.TransDetailAddress == cmbTransitWarehouse.Text.Trim().ParseToString());
|
|
}
|
|
|
|
if (transitWarehouse == null)
|
|
{
|
|
BaseMsgForm.ShowError("仓库不能为空");
|
|
return;
|
|
}
|
|
|
|
var url = BaseClass.Build29WxObjString("order/wx_add_mdy_buy_prod_map");
|
|
var data = UserLogin.GetSignaturex()
|
|
+ "&spu_code=" + GetHtml.UrlEncodeUtf8(txtUpSpuCode.Text.Trim())
|
|
+ "&sku_code=" + GetHtml.UrlEncodeUtf8(txtUpSkuCode.Text.Trim())
|
|
+ "&main_user_name=" + BaseClass.MainUserName
|
|
+ "&map_goods_name=" + txtMapGoodsName.Text.Trim()
|
|
+ "&map_spec_name=" + txtMapSkuName.Text.Trim()
|
|
+ "&map_goods_id=" + txtMapGoodsId.Text.Trim()
|
|
+ "&map_sku_id=" + txtMapSkuId.Text.Trim()
|
|
+ "&map_send_address=" + txtSendProvince.Text.Trim()
|
|
+ "&transit_warehouse_id=" + transitWarehouse?.TransId;
|
|
var result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
result = GetHtml.PostUtf8(url, data);
|
|
if (!result.Contains("\"code\":200"))
|
|
{
|
|
BaseMsgForm.ShowError("保存失败" + BaseRegex.GetStringJson(ref result, "msg"));
|
|
}
|
|
else
|
|
{
|
|
var urlMap = BaseClass.Build29WxObjString("order/wx_get_buy_prod_map");
|
|
var dataMap = UserLogin.GetSignaturex()
|
|
+ "&spu_codes=" + txtUpSpuCode.Text.Trim();
|
|
//dataMap += "&sku_codes=" + txtUpSkuCode.Text.Trim();
|
|
dataMap += "&main_user_name=" + BaseClass.MainUserName;
|
|
var resultMap = GetHtml.PostUtf8(urlMap, dataMap);
|
|
if (string.IsNullOrEmpty(resultMap) || !resultMap.Contains("\"code\":200"))
|
|
resultMap = GetHtml.PostUtf8(urlMap, dataMap);
|
|
if (string.IsNullOrEmpty(resultMap) || !resultMap.Contains("\"code\":200"))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
List<WXBuyMapInfo> buyMapList = new List<WXBuyMapInfo>();
|
|
try { buyMapList = JsonHelper.DeserializeJsonToList<WXBuyMapInfo>(JObject.Parse(resultMap)["data"].ParseToString()); } catch { }
|
|
var map = buyMapList.FirstOrDefault(b => b.spu_code == txtUpSpuCode.Text.Trim() && b.sku_code == txtUpSkuCode.Text.Trim());
|
|
if (map != null)
|
|
{
|
|
foreach (var order in GlobalConfig.lstOrder)
|
|
{
|
|
if (order.IsWaitBuy)
|
|
{
|
|
foreach (var item in order.orderItems)
|
|
{
|
|
if ((item.out_product_id == map.spu_code && item.out_sku_id == map.sku_code) ||
|
|
(item.out_product_id == map.spu_code && item.sku_attr_str == map.sku_code) ||
|
|
(item.product_id == map.spu_code && item.out_sku_id == map.sku_code) ||
|
|
(item.product_id == map.spu_code && item.sku_attr_str == map.sku_code))
|
|
{
|
|
item.BuyMap = map;
|
|
|
|
if (filterOrderAction != null)
|
|
{
|
|
GlobalConfig.lstFilterOrder.Remove(order);
|
|
filterOrderAction(order, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
BaseMsgForm.ShowInfo("保存成功!");
|
|
this.Close();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private async void btnManualUpdateBuyOrder_Click(object sender, EventArgs e)
|
|
{
|
|
if (txtSourceCode.Text.Trim().Length != 6)
|
|
{
|
|
BaseMsgForm.ShowError("溯源码长度错误!");
|
|
return;
|
|
}
|
|
var client = cefWebBrowser.GetDevToolsClient();
|
|
if (client == null)
|
|
{
|
|
BaseMsgForm.ShowError("页面未加载!");
|
|
return;
|
|
}
|
|
var sourceCode = txtSourceCode.Text.Trim();
|
|
var jsStr1 = @"(function() { var elements = document.getElementsByTagName('div');
|
|
for (i = elements.length - 1; i >= 0; i--){
|
|
var element = elements[i];
|
|
if (element.innerHTML.indexOf('" + sourceCode + @"') >= 0) {
|
|
return 'success';
|
|
}
|
|
}
|
|
return '';
|
|
})();";
|
|
var ts1 = client.Runtime.EvaluateAsync(jsStr1, null, true, null, null, true, null, true);
|
|
await ts1;
|
|
// 付款页面没法匹配,暂时注释
|
|
//if (ts1.Result?.Result?.Value.ParseToString() != "success")
|
|
//{
|
|
// BaseMsgForm.ShowError("溯源码不匹配!");
|
|
// return;
|
|
//}
|
|
|
|
|
|
if (string.IsNullOrEmpty(txtBuyTransitWarehouse.Text.Trim()))
|
|
{
|
|
BaseMsgForm.ShowError("缺少中转地址,请重新绑定商品并选择仓库地址");
|
|
return;
|
|
}
|
|
var transit = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransDetailAddress == txtBuyTransitWarehouse.Text.Trim());
|
|
if (transit == null)
|
|
{
|
|
BaseMsgForm.ShowError("中转地址对应的中转仓不存在,请核对");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(txtBuyOrderId.Text.Trim()))
|
|
{
|
|
BaseMsgForm.ShowError("缺少拍单订单号,请拍单后再提交");
|
|
return;
|
|
}
|
|
if ((txtBuyPrice.Text.ParseToDecimal() * 100).ParseToInt().IsNullOrZero())
|
|
{
|
|
BaseMsgForm.ShowError("缺少拍单金额,请拍单后再提交");
|
|
return;
|
|
}
|
|
|
|
btnManualUpdateBuyOrder.Enabled = false;
|
|
|
|
JObject body = new JObject();
|
|
body["orderNo"] = orderItem.order_id;
|
|
body["orderSkuId"] = orderItem.sku_id;
|
|
body["outOrderNo"] = txtBuyOrderId.Text.Trim();
|
|
body["outAmount"] = (txtBuyPrice.Text.ParseToDecimal() * 100).ParseToInt() + "";
|
|
body["buyerAccount"] = buyer.buyer_nick; // 买手昵称
|
|
body["purchaserNote"] = BaseClass.NickName; // 购买软件账户备注
|
|
body["express1Company"] = ""; // 物流公司编号
|
|
body["express1Waybill"] = ""; // 物流编号
|
|
body["platform"] = transit.TransId; // 中转仓ID
|
|
body["orderPlatformCode"] = "WEISHOP";
|
|
body["randomCode"] = txtSourceCode.Text.Trim();
|
|
if (GlobalConfig.BuyConfig.IsUseAppBalance)
|
|
{
|
|
body["userName"] = BaseClass.UserName; // 软件端用户名
|
|
body["purchaserNote"] = BaseClass.UserName + "-" + BaseClass.NickName; // 购买软件账户备注
|
|
}
|
|
var url = "https://po.e57.cn/prod-api/api/oms-api/externalProcurement/saveOrUpdate";
|
|
var dataStr = JsonHelper.SerializeObject(body);
|
|
//dataStr = "{\"orderNo\":\"3737339733954942720\",\"outOrderNo\":\"2606846854564\",\"buyerAccount\":\"测试\",\"outAmount\":\"2000\",\"purchaserNote\":\"测试\",\"express1Company\":\"\"" +
|
|
// ",\"express1Waybill\":\"\",\"platform\":\"XDYSHC\",\"orderPlatformCode\":\"WEISHOP\"}";
|
|
var exportRst = HttpResponseWXBLL.e57PostResponse(url, dataStr, "");
|
|
//<AjaxResult><msg>保存成功</msg><code>200</code></AjaxResult>
|
|
//<AjaxResult><msg>订单不存在:373733973395494272</msg><code>500</code></AjaxResult>
|
|
if (!exportRst.ParseToString().Contains("<code>200</code>"))
|
|
{
|
|
string msg = "";
|
|
string code = "";
|
|
try
|
|
{
|
|
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
|
|
xmlDoc.LoadXml(exportRst);
|
|
code = xmlDoc["AjaxResult"]["code"].InnerText;
|
|
msg = xmlDoc["AjaxResult"]["msg"].InnerText;
|
|
}
|
|
catch
|
|
{
|
|
msg = exportRst.ParseToString();
|
|
}
|
|
BaseMsgForm.ShowError("拍单保存失败,服务端返回 " + msg, "拍单信息保存失败");
|
|
btnManualUpdateBuyOrder.Enabled = true;
|
|
return;
|
|
}
|
|
|
|
url = BaseClass.Build29WxObjString("user/get_all_user");
|
|
var data = UserLogin.GetSignaturex();
|
|
data += "&search_user_name=" + BaseClass.UserName;
|
|
var html = GetHtml.PostUtf8(url, data);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
|
html = GetHtml.PostUtf8(url, data);
|
|
if (html.Contains("\"code\":200"))
|
|
BaseClass.Balance = BaseRegex.GetDecimalJson(ref html, "balance");
|
|
|
|
orderItem.ItemTransitOrders.Insert(0, new oms_wei_external_procurement_log_info()
|
|
{
|
|
buyer_account = buyer.buyer_nick,
|
|
id = 0,
|
|
order_no = orderItem.order_id,
|
|
order_sku_id = orderItem.sku_id,
|
|
out_amount = (txtBuyPrice.Text.ParseToDecimal() * 100).ParseToInt(),
|
|
out_order_no = txtBuyOrderId.Text.Trim(),
|
|
purchaser_note = body["purchaserNote"].ParseToString(),
|
|
});
|
|
// 利润计算重置为最小值,控件Resource更新时将计算利润
|
|
orderItem.ProfitCount = decimal.MinValue;
|
|
var order = orderItem.ItemOrder;
|
|
if (filterOrderAction != null)
|
|
{
|
|
GlobalConfig.lstFilterOrder.Remove(order);
|
|
filterOrderAction(order, true);
|
|
}
|
|
|
|
//// 前一天的订单直接提前取号
|
|
//if (DateTime.Now.Date > BaseClass.StampToDateTime(order.create_time).Date)
|
|
//{
|
|
// JObject data = new JObject();
|
|
// data["outOrderNo"] = txtBuyOrderId.Text.Trim();
|
|
// data["warehouseCode"] = transit.TransId; // 中转仓仓库对应编码 XDYSZC XDYYWC ...
|
|
// //data["warehouseCode"] = txtBuyOrderId.Text.Trim(); // 中转仓仓库对应编码
|
|
// data["platform"] = "WEISHOP";
|
|
// var getVirtualTicketUrl = "https://po.e57.cn/prod-api/api/oms-api/external_procurement/order/virtual/create";
|
|
// var getVirtualTicketDataStr = JsonHelper.SerializeObject(data);
|
|
|
|
// var getVirtualTicketRst = HttpResponseWXBLL.e57PostResponse(getVirtualTicketUrl, getVirtualTicketDataStr, "");
|
|
// if (!getVirtualTicketRst.ParseToString().Contains("<code>200</code>") && !getVirtualTicketRst.ParseToString().Contains("<code>0</code>"))
|
|
// {
|
|
// string msg = "";
|
|
// string code = "";
|
|
// try
|
|
// {
|
|
// System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
|
|
// xmlDoc.LoadXml(getVirtualTicketRst);
|
|
// code = xmlDoc["AjaxResult"]["code"].InnerText;
|
|
// msg = xmlDoc["AjaxResult"]["msg"].InnerText;
|
|
// }
|
|
// catch
|
|
// {
|
|
// msg = getVirtualTicketRst.ParseToString();
|
|
// }
|
|
// BaseMsgForm.ShowError("拍单信息保存成功,接收到服务端传递的错误消息:" + msg, "订单提前取号失败");
|
|
// btnManualUpdateBuyOrder.Enabled = true;
|
|
// return;
|
|
// }
|
|
//}
|
|
|
|
BaseMsgForm.ShowInfo("拍单信息保存成功");
|
|
this.Close();
|
|
}
|
|
|
|
private void pictureBox1_Click(object sender, EventArgs e)
|
|
{
|
|
if (pictureBox1.Size.Width == 100)
|
|
{
|
|
pictureBox1.Size = new Size(430, 430);
|
|
pictureBox1.BringToFront();
|
|
}
|
|
else
|
|
{
|
|
pictureBox1.Size = new Size(100, 100);
|
|
}
|
|
}
|
|
|
|
private void btnJumpOrderList_Click(object sender, EventArgs e)
|
|
{
|
|
cefWebBrowser.Load("https://mobile.yangkeduo.com/orders.html");
|
|
}
|
|
|
|
private void btnReMap_Click(object sender, EventArgs e)
|
|
{
|
|
transitWarehouse = null;
|
|
pnlMap.Visible = true;
|
|
}
|
|
|
|
private void cmbTransitWarehouse_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
transitWarehouse = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransName + " " + t.TransDetailAddress == cmbTransitWarehouse.Text);
|
|
}
|
|
|
|
private void chkAutoChangeWarehouseAddress_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (IsFormLoad)
|
|
{
|
|
GlobalConfig.BuyConfig.IsAutoChangeWarehouseAddress = chkAutoChangeWarehouseAddress.Checked;
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("buy_config_260708", GlobalConfig.BuyConfig);
|
|
}
|
|
}
|
|
|
|
private void chkUseAppBalance_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (IsFormLoad)
|
|
{
|
|
GlobalConfig.BuyConfig.IsUseAppBalance = chkUseAppBalance.Checked;
|
|
NaiBa.Util.Helper.ConfigHelper.SaveConfig("buy_config_260708", GlobalConfig.BuyConfig);
|
|
}
|
|
}
|
|
}
|
|
}
|