淘宝买手拍单 订单补发包裹。

This commit is contained in:
wule committed 2026-10-05 18:23:15 +08:00
1 parent d18460c83f
commit c11dda0341
13 files changed
+753 -188

No files matched your search

@@ -1,3 +1,4 @@
using _29WxOrderWpf.BaseWindows;
using _29WxOrderWpf.CefHelper;
using _29WxOrderWpf.Commands;
using _29WxOrderWpf.ViewModels;
@@ -14,6 +15,7 @@ using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Policy;
using System.Text;
@@ -25,6 +27,7 @@ using TemuKJD.ToolForms;
using Work;
using Work._29Tools.BLL;
using Work._29Tools.CefTools;
using Work.BaseForms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using static WPFCommon.Interop.InteropValues;
@@ -56,11 +59,38 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
private oms_wei_order_item_info orderItem = null;
WXBuyMapSkusInfo buymapSkuInfo = null;
WXBuyMapInfo buyMapInfo = null;
pddFrontGoods3Lite pddFrontGoodsLite = null;
/// <summary>
/// 直发direct 中转transit
/// </summary>
public string BuyType { get; set; } = "transit";
public TransitWarehouseParam transitWarehouse { get; set; }
/// <summary>
/// 异常重拍的原中转仓订单信息
/// </summary>
public oms_wei_external_procurement_log_info AbnormalTransitWarehouseOrderInfo { get; set; } = null;
private string currentUrl = "";
private volatile bool _isWindowLoaded = false;
#region 界面绑定属性
public bool Enabled
{
get { return this.GetValue(x => x.Enabled); }
set { this.SetValue(x => x.Enabled, value); }
}
public Visibility BuyInfoVisivility
{
get { return this.GetValue(x => x.BuyInfoVisivility); }
set { this.SetValue(x => x.BuyInfoVisivility, value); }
}
public Visibility MapInfoVisivility
{
get { return this.GetValue(x => x.MapInfoVisivility); }
set { this.SetValue(x => x.MapInfoVisivility, value); }
}
/// <summary>用户名</summary>
public string UserName
{
@@ -82,6 +112,48 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
set { this.SetValue(x => x.Address, value); }
}
public string txtShopGoodsNameVal
{
get { return this.GetValue(x => x.txtShopGoodsNameVal); }
set { this.SetValue(x => x.txtShopGoodsNameVal, value); }
}
public string txtShopSpecNameVal
{
get { return this.GetValue(x => x.txtShopSpecNameVal); }
set { this.SetValue(x => x.txtShopSpecNameVal, value); }
}
public string txtShopGoodsIdVal
{
get { return this.GetValue(x => x.txtShopGoodsIdVal); }
set { this.SetValue(x => x.txtShopGoodsIdVal, value); }
}
public string txtShopSkuIdVal
{
get { return this.GetValue(x => x.txtShopSkuIdVal); }
set { this.SetValue(x => x.txtShopSkuIdVal, value); }
}
public string txtSpuCodeVal
{
get { return this.GetValue(x => x.txtSpuCodeVal); }
set { this.SetValue(x => x.txtSpuCodeVal, value); }
}
public string txtSkuCodeVal
{
get { return this.GetValue(x => x.txtSkuCodeVal); }
set { this.SetValue(x => x.txtSkuCodeVal, value); }
}
public string txtShopOrderItemCntVal
{
get { return this.GetValue(x => x.txtShopOrderItemCntVal); }
set { this.SetValue(x => x.txtShopOrderItemCntVal, value); }
}
public string txtShopOrderItemPriceVal
{
get { return this.GetValue(x => x.txtShopOrderItemPriceVal); }
set { this.SetValue(x => x.txtShopOrderItemPriceVal, value); }
}
/// <summary>拍单商品Id</summary>
public string txtBuyGoodsIdVal
{
@@ -118,6 +190,24 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
get { return this.GetValue(x => x.txtBuyPriceVal); }
set { this.SetValue(x => x.txtBuyPriceVal, value); }
}
public string txtBuyOrderIdVal
{
get { return this.GetValue(x => x.txtBuyOrderIdVal); }
set { this.SetValue(x => x.txtBuyOrderIdVal, value); }
}
public string txtSourceCodeVal
{
get { return this.GetValue(x => x.txtSourceCodeVal); }
set { this.SetValue(x => x.txtSourceCodeVal, value); }
}
/// <summary>
/// 中专仓地址
/// </summary>
public string txtBuyTransitWarehouseVal
{
get { return this.GetValue(x => x.txtBuyTransitWarehouseVal); }
set { this.SetValue(x => x.txtBuyTransitWarehouseVal, value); }
}
/// <summary>关联商品名称</summary>
public string txtMapGoodsNameVal
@@ -164,6 +254,8 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
public ICommand CopyUserNameCommand { get; }
public ICommand CopyPasswordCommand { get; }
public ICommand UpdateTransitWarehouseCommand { get; }
#endregion
public TaobaoBuyOrderViewModel(BuyerLoginInfo buyerInfo, oms_wei_order_item_info orderItemInfo)
@@ -180,6 +272,28 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
StopCommand = new DelegateCommand(StopButton);
CopyUserNameCommand = new DelegateCommand(CopyUserName);
CopyPasswordCommand = new DelegateCommand(CopyPassword);
UpdateTransitWarehouseCommand = new DelegateCommand(UpdateTransitWarehouse);
this.txtShopSkuIdVal = orderItem.sku_id;
this.txtShopGoodsIdVal = orderItem.product_id;
this.txtSpuCodeVal = orderItem.out_product_id.IsNullOrEmpty() ? orderItem.product_id : orderItem.out_product_id;
this.txtSkuCodeVal = orderItem.out_sku_id.IsNullOrEmpty() ? orderItem.sku_attr_str : orderItem.out_sku_id;
this.txtShopGoodsNameVal = orderItem.title;
this.txtShopSpecNameVal = orderItem.sku_attr_str;
this.txtShopOrderItemCntVal = orderItem.sku_cnt.ParseToString();
this.txtShopOrderItemPriceVal = (orderItem.real_price * 0.01m + orderItem.ItemOrder?.postage_price * 0.01m / orderItem.ItemOrder?.orderItems?.Count).ParseToString();
this.buyMapInfo = orderItem.TbBuyMap;
if (buyMapInfo != null)
{
BuyInfoVisivility = Visibility.Visible;
MapInfoVisivility = Visibility.Collapsed;
}
else
{
BuyInfoVisivility = Visibility.Collapsed;
MapInfoVisivility = Visibility.Visible;
}
}
/// <summary>
@@ -191,7 +305,7 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
if (CloseAfterSecond > 0)
{
Task.Run(() =>
_ = Task.Run(() =>
{
Thread.Sleep(1000 * CloseAfterSecond);
if (_isWindowLoaded)
@@ -204,7 +318,50 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
}
});
}
await AutoLogin();
if (buyMapInfo != null)
{
this.txtMapGoodsNameVal = buyMapInfo.map_goods_name;
this.txtMapSkuNameVal = buyMapInfo.map_spec_name;
this.txtMapGoodsIdVal = buyMapInfo.map_goods_id;
this.txtMapSkuIdVal = buyMapInfo.map_sku_id;
this.txtSendProvinceVal = buyMapInfo.map_send_address;
this.transitWarehouse = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransId == buyMapInfo.transit_warehouse_id);
// 异常单重新拍单
if (AbnormalTransitWarehouseOrderInfo != null)
{
transitWarehouse = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransId == AbnormalTransitWarehouseOrderInfo.platform);
}
if (transitWarehouse != null && this.BuyType == "transit")
{
cmbTransitWarehouseVal = transitWarehouse?.TransName + " " + transitWarehouse?.TransDetailAddress;
txtBuyTransitWarehouseVal = transitWarehouse?.TransDetailAddress;
}
else
{
txtBuyTransitWarehouseVal = orderItem.ItemOrder.AddressStr;
}
}
var transit = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransDetailAddress == txtBuyTransitWarehouseVal);
if (AbnormalTransitWarehouseOrderInfo != null)
{
txtSourceCodeVal = AbnormalTransitWarehouseOrderInfo.random_code;
}
else if (buyMapInfo != null && transit != null)
{
var sourceCodeRst = GetSourceCode(transit);
if (sourceCodeRst.Contains("失败"))
{
CefWebBrowser.Visibility = Visibility.Collapsed;
BaseMsgWindow.ShowError(sourceCodeRst);
return;
}
}
await AutoSearchGoods();
}
/// <summary>
@@ -218,7 +375,7 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
/// <summary>
/// 自动登录店铺后台
/// </summary>
private async Task AutoLogin()
private async Task AutoSearchGoods()
{
if (buyer == null)
return;
@@ -490,7 +647,7 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
this.buymapSkuInfo = new WXBuyMapSkusInfo()
{
source_platform = "tb",
platform = "tb",
map_goods_id = BaseRegex.GetStringJson(ref loaderData, "itemId"),
map_goods_name = BaseRegex.GetStringJson(ref goodsItemStr, "title"),
map_url = "929536442189",
@@ -534,8 +691,6 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
var oneGoodsPrice = sku.oldGroupPrice.ParseToInt();
var buyCnt = orderItem.sku_cnt;
var buyPrice = oneGoodsPrice * buyCnt;
var orderSn = "";
// 自动填写关联信息界面
this.txtMapGoodsIdVal = goodsId.ParseToString();
@@ -586,6 +741,214 @@ namespace _29WxOrderWpf.Ctrls.BuyerCtrls
if (this.currentUrl != buyerLoginUrl)
this.CefWebBrowser?.Load(buyerLoginUrl);
}
private 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))
{
txtSourceCodeVal = randomCode;
return randomCode;
}
else
{
return "获取失败,请关闭拍单窗口重试 " + BaseRegex.GetStringXml(ref sourceCodeRst, "msg", sourceCodeRst);
}
}
private async void UpdateTransitWarehouse()
{
var sendProvince = txtSendProvinceVal;
if (transitWarehouse == null && !cmbTransitWarehouseVal.IsNullOrEmpty())
{
transitWarehouse = TransitWarehouseData.TransitWarehouseList.FirstOrDefault(t => t.TransName + " " + t.TransDetailAddress == cmbTransitWarehouseVal.ParseToString());
}
if (transitWarehouse == null)
{
BaseMsgWindow.ShowError("仓库不能为空");
return;
}
this.pddFrontGoodsLite = JsonHelper.DeserializeJsonToObject<pddFrontGoods3Lite>(buymapSkuInfo?.map_skus);
// 通过map反查商品,淘宝暂时不需要
//if ((this.pddFrontGoodsLite?.goodsId).IsNullOrZero() || (this.pddFrontGoodsLite?.mallId).IsNullOrZero())
//{
// await Task.Run(() =>
// {
// var jsStr = "document.getElementById('orderGoodsBlock').getElementsByTagName('div')[0].click();";
// var host = CefWebBrowser.GetBrowser().GetHost();
// var client = CefWebBrowser.GetDevToolsClient();
// var ts1 = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
// ts1.Wait(500);
// for (int i = 0; i < 80; i++)
// {
// if (!(this.pddFrontGoodsLite?.mallId).IsNullOrZero())
// break;
// Thread.Sleep(100);
// }
// });
//}
this.Enabled = false;
if (!this.CefWebBrowser.Address.StartsWith("https://mobile.yangkeduo.com/order.html?order_sn=") && (this.pddFrontGoodsLite?.goodsId).ParseToString() == txtMapGoodsIdVal.Trim())
{
}
string url;
string upSpuCode = txtSpuCodeVal.Trim();
string upSkuCode = txtSkuCodeVal.Trim();
// 保存sku及商品关联信息
var data = UserLogin.GetSignaturex()
+ "&spu_code=" + GetHtml.UrlEncodeUtf8(upSpuCode)
+ "&sku_code=" + GetHtml.UrlEncodeUtf8(upSkuCode)
+ "&main_user_name=" + BaseClass.MainUserName
+ "&map_goods_name=" + txtMapGoodsNameVal.Trim()
+ "&map_spec_name=" + txtMapSkuNameVal.Trim()
+ "&map_goods_id=" + txtMapGoodsIdVal.Trim()
+ "&map_sku_id=" + txtMapSkuIdVal.Trim()
+ "&map_send_address=" + sendProvince
+ "&transit_warehouse_id=" + transitWarehouse?.TransId;
// 关联平台为淘宝
data += "&platform=tb";
if (!(this.pddFrontGoodsLite?.mallId).IsNullOrZero() && this.pddFrontGoodsLite.goodsId.ParseToString() == txtMapGoodsIdVal.Trim())
{
// 保存商品关联信息
data += "&map_skus=" + GetHtml.UrlEncodeUtf8(JsonHelper.SerializeObject(pddFrontGoodsLite));
url = BaseClass.Build29WxObjString("order/wx_add_mdy_buy_prod_map_skus");
var skusRst = await GetHtml.PostUtf8Async(url, data);
if (!skusRst.Contains("\"code\":200"))
skusRst = await GetHtml.PostUtf8Async(url, data);
// 存完立即读取
//wx_get_buy_pord_map_skus
var dataTest = UserLogin.GetSignaturex() + "&spu_codes=" + GetHtml.UrlEncodeUtf8(upSpuCode);
dataTest += "&main_user_name=" + BaseClass.MainUserName;
url = BaseClass.Build29WxObjString("order/wx_get_buy_pord_map_skus");
var resultSkusMap = await GetHtml.PostUtf8Async(url, dataTest);
if (string.IsNullOrEmpty(resultSkusMap) || !resultSkusMap.Contains("\"code\":200"))
{
resultSkusMap = await GetHtml.PostUtf8Async(url, dataTest);
}
if (string.IsNullOrEmpty(resultSkusMap) || !resultSkusMap.Contains("\"code\":200"))
{
}
else
{
List<WXBuyMapSkusInfo> buyMapSkuList = new List<WXBuyMapSkusInfo>();
try
{
buyMapSkuList = JsonHelper.DeserializeJsonToList<WXBuyMapSkusInfo>(JObject.Parse(resultSkusMap)["data"].ParseToString());
GlobalConfig.BuyMapSkusList.RemoveAll(b => buyMapSkuList.Any(map => b.spu_code == map.spu_code));
GlobalConfig.BuyMapSkusList.AddRange(buyMapSkuList);
foreach (var order in GlobalConfig.lstOrder)
{
if (order.IsWaitBuy)
{
foreach (var item in order.orderItems)
{
if (item.out_product_id == upSpuCode || item.product_id == upSpuCode)
{
item.PddBuyMapSkus = buyMapSkuList.Where(s => s.platform == "pdd").ToList();
item.TbBuyMapSkus = buyMapSkuList.Where(s => s.platform == "tb").ToList();
//if (filterOrderAction != null)
//{
// item.SetOrderItemTextProperty();
// filterOrderAction(order, false);
//}
}
}
}
}
}
catch
{
}
}
}
url = BaseClass.Build29WxObjString("order/wx_add_mdy_buy_prod_map");
var result = await GetHtml.PostUtf8Async(url, data);
if (!result.Contains("\"code\":200"))
result = await GetHtml.PostUtf8Async(url, data);
if (!result.Contains("\"code\":200"))
{
this.Enabled = true;
BaseMsgWindow.ShowError("保存失败" + BaseRegex.GetStringJson(ref result, "msg") + ",请稍后重试");
}
else
{
var urlMap = BaseClass.Build29WxObjString("order/wx_get_buy_prod_map");
var dataMap = UserLogin.GetSignaturex()
+ "&spu_codes=" + upSpuCode;
//dataMap += "&sku_codes=" + upSkuCode;
dataMap += "&main_user_name=" + BaseClass.MainUserName;
var resultMap = await GetHtml.PostUtf8Async(urlMap, dataMap);
if (string.IsNullOrEmpty(resultMap) || !resultMap.Contains("\"code\":200"))
resultMap = await GetHtml.PostUtf8Async(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());
GlobalConfig.BuyMapList.RemoveAll(b => buyMapList.Any(map => b.spu_code == map.spu_code && b.sku_code == map.sku_code));
GlobalConfig.BuyMapList.AddRange(buyMapList);
}
catch
{
}
var tbBuyMap = buyMapList.FirstOrDefault(b => b.spu_code == upSpuCode && b.sku_code == upSkuCode && b.platform == "tb");
if (tbBuyMap != null)
{
foreach (var order in GlobalConfig.lstOrder)
{
if (order.IsWaitBuy)
{
foreach (var item in order.orderItems)
{
if ((item.out_product_id == tbBuyMap.spu_code && item.out_sku_id == tbBuyMap.sku_code) ||
(item.out_product_id == tbBuyMap.spu_code && item.sku_attr_str == tbBuyMap.sku_code) ||
(item.product_id == tbBuyMap.spu_code && item.out_sku_id == tbBuyMap.sku_code) ||
(item.product_id == tbBuyMap.spu_code && item.sku_attr_str == tbBuyMap.sku_code))
{
item.TbBuyMap = tbBuyMap;
item.SetOrderItemTextProperty();
MainWindow.Instance.orderListCtrl.FilterOneOrder(order, false);
}
}
}
}
}
}
BaseMsgWindow.ShowInfo("保存成功!");
if (_isWindowLoaded)
{
Application.Current?.Dispatcher.Invoke(new Action(() =>
{
if (_isWindowLoaded)
RequestClose?.Invoke();
}));
}
}
}
}
public class TaoBaoSku2Info