From 259b8027d3f71a394cd65540d176b3f6f4d1ec2b Mon Sep 17 00:00:00 2001 From: wule Date: Sun, 27 Sep 2026 11:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8B=8D=E5=8D=95=E4=BB=A3?= =?UTF-8?q?=E5=8F=91=E7=9B=B8=E5=85=B3=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderCtrls/OrderListRowItemCtrl.xaml.cs | 339 ++++++++++-------- 29WxOrderWpf/MainWindow.xaml.cs | 20 +- Work/_29Tools/Forms/PddMobileBuyOrderForm.cs | 2 + 3 files changed, 211 insertions(+), 150 deletions(-) diff --git a/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs b/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs index 6c70119..94ae036 100644 --- a/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs +++ b/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs @@ -15,6 +15,8 @@ using AllBase.Model.Result; using CefSharp.DevTools.DOM; using NaiBa.Util.Extension; using Newtonsoft.Json.Linq; +using NPOI.SS.Formula.PTG; +using Org.BouncyCastle.Asn1.Cmp; using System; using System.Collections.Generic; using System.Linq; @@ -477,77 +479,23 @@ namespace _29WxOrderWpf.Ctrls.OrderCtrls shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/supply/consignmentOrderList"; shopLoginForm.IsGetSupplierPage = true; shopLoginForm.ShowDialog(); - - // 不是立即生效的,不用立即刷新 - //var is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierList(orderItem.Shop); - //if (!is29SupplierRst.Contains("\"code\":0")) - // is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierList(orderItem.Shop); - //if (is29SupplierRst.Contains("\"code\":0") && is29SupplierRst.Contains("\"name\":\"29供货商\"")) - //{ - // orderItem.Shop.Is29Supplier = true; - //} - //else - //{ - // ShopBLL.CheckShopLogin(orderItem.Shop); - // orderItem.Shop.Is29Supplier = false; - //} - //foreach (var order in GlobalConfig.lstFilterOrder.Where(o => o.shop_id.ParseToString() == orderItem.Shop.ErpShopId).ToList()) - //{ - // // 更新代发管理情况 - // foreach (var o in order.orderItems) - // Dispatcher.Invoke(new Action(() => { o.UpdateOrderItemBuyButton(); })); - //} } return; } // Api检测是否加入代发 - if (orderItem.BuyGoodsBtnTxt == "云仓拍单" && !isAbnormalOrder) - { - string supplierId = "", supplierName=""; - try - { - var apiSearchDropship = new WxApiBLL().WxApiDropshipSearch(orderItem.Shop, orderItem.order_id, 100); - if (!apiSearchDropship.Contains("\"errcode\":0")) - throw new Exception("查询代发失败!" + BaseRegex.GetStringJson(ref apiSearchDropship, "msg")); - - var dsOrderId = JsonHelper.JObjectParse(apiSearchDropship)["ds_order_id_list"].FirstOrDefault().ParseToString(); - if (!string.IsNullOrEmpty(dsOrderId)) - { - var apiSearchDropshipDetail = new WxApiBLL().WxApiDropshipSearchDetail(orderItem.Shop, dsOrderId); - if (!apiSearchDropshipDetail.Contains("\"errcode\":0")) - throw new Exception("查询代发失败!" + BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "msg")); - - supplierId = BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "supplier_appid"); - supplierName = BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "supplier_name"); - if (!string.IsNullOrEmpty(supplierId) && !supplierId.Contains("wxfc630d60a1af6c6f") && !supplierName.Contains("29供货商")) - { - var apiCancelDropship = await new WxApiBLL().WxApiDropshipCancel(orderItem.Shop, orderItem.ItemOrder, dsOrderId); - if (!apiCancelDropship.Contains("\"errcode\":0")) - throw new Exception("取消其他代发失败!请确认商品未加入其他代发!" + BaseRegex.GetStringJsonByRegs(ref apiCancelDropship, apiCancelDropship, "errmsg")); - dsOrderId = ""; - supplierId = ""; - supplierName = ""; - } - } - - if (!supplierId.Contains("wxfc630d60a1af6c6f") && !supplierName.Contains("29供货商")) - { - // 设置29供货商代发 - var apiAddDropship = new WxApiBLL().WxApiDropshipAssign(orderItem.Shop, orderItem.order_id, orderItem.product_id, orderItem.sku_id, orderItem.sku_cnt.ParseToInt()); - if (!apiAddDropship.Contains("\"errcode\":0")) - { - throw new Exception("设置代发失败!请确商品已加入29供货商代发!" + BaseRegex.GetStringJson(ref apiAddDropship, "msg")); - } - } - } - catch(Exception ex) - { - BaseMsgWindow.ShowError(ex.Message); - return; - } - - } + //if (orderItem.BuyGoodsBtnTxt == "云仓拍单" && !isAbnormalOrder) // 异常拍单不改变订单供应商 + //{ + // try + // { + // await SetSendOrderSupplier(orderItem, "wxfc630d60a1af6c6f", "29供货商"); + // } + // catch(Exception ex) + // { + // BaseMsgWindow.ShowError(ex.Message); + // return; + // } + //} // 掉线提示重登 if (orderItem.Shop?.LoginStatus != "登录成功") @@ -605,10 +553,108 @@ namespace _29WxOrderWpf.Ctrls.OrderCtrls buyOrderForm.AbnormalTransitWarehouseOrderInfo = orderItem.ItemTransitOrder; buyOrderForm.ShowDialog(); OrderListCtrl.IsAutoBuy = buyOrderForm.IsAutoBuy; + + if (buyOrderForm.IsBuySuccess) + { + Task.Run(async () => + { + if (orderItem.BuyGoodsBtnTxt == "云仓拍单" && !isAbnormalOrder) // 异常拍单不改变订单供应商 + { + try + { + await SetSendOrderSupplier(orderItem, "wxfc630d60a1af6c6f", "29供货商"); + } + catch (Exception ex) + { + BaseMsgWindow.ShowError(ex.Message); + return; + } + } + }); + } })); }); } + /// + /// + /// + /// 要发货的订单物品 + /// targetSupplierId 和 targetSupplierName 都为空表示取消代发 + /// targetSupplierId 和 targetSupplierName 都为空表示取消代发 + /// + /// + public static async Task SetSendOrderSupplier(oms_wei_order_item_info orderItem, string targetSupplierId, string targetSupplierName) + { + string supplierId = "", supplierName = ""; + try + { + // 查询代发列表 + var apiSearchDropship = new WxApiBLL().WxApiDropshipSearch(orderItem.Shop, orderItem.order_id, 100); + if (!apiSearchDropship.Contains("\"errcode\":0")) + throw new Exception("查询代发失败!" + BaseRegex.GetStringJsonByRegs(ref apiSearchDropship, apiSearchDropship, "msg", "errmsg")); + + var dsOrderId = JsonHelper.JObjectParse(apiSearchDropship)["ds_order_id_list"].FirstOrDefault().ParseToString(); + + // 取消代发判断 + if (targetSupplierId.IsNullOrEmpty() && targetSupplierName.IsNullOrEmpty()) + { + if (!string.IsNullOrEmpty(dsOrderId)) + { + var apiCancelDropship = await new WxApiBLL().WxApiDropshipCancel(orderItem.Shop, orderItem.ItemOrder, dsOrderId); + if (!apiCancelDropship.Contains("\"errcode\":0")) + { + var errMsg = BaseRegex.GetStringJsonByRegs(ref apiCancelDropship, apiCancelDropship, "msg", "errmsg"); + throw new Exception("取消代发失败!请手动取消代发!" + errMsg); + } + } + return; + } + + // 更换或新增代发判断 + if (!string.IsNullOrEmpty(dsOrderId)) + { + // 查询代发详情 + var apiSearchDropshipDetail = new WxApiBLL().WxApiDropshipSearchDetail(orderItem.Shop, dsOrderId); + if (!apiSearchDropshipDetail.Contains("\"errcode\":0")) + throw new Exception("查询代发失详情失败!" + BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "msg")); + + supplierId = BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "supplier_appid"); + supplierName = BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "supplier_name"); + if (!string.IsNullOrEmpty(supplierId) && !supplierId.Contains(targetSupplierId) && !supplierName.Contains(targetSupplierName)) + { + // 取消代发 + var apiCancelDropship = await new WxApiBLL().WxApiDropshipCancel(orderItem.Shop, orderItem.ItemOrder, dsOrderId); + if (!apiCancelDropship.Contains("\"errcode\":0")) + { + var errMsg = BaseRegex.GetStringJsonByRegs(ref apiCancelDropship, apiCancelDropship, "msg", "errmsg"); + throw new Exception("取消其他代发失败!请确认商品加入的是 " + targetSupplierName + " 代发!" + errMsg); + } + dsOrderId = ""; + supplierId = ""; + supplierName = ""; + } + } + + // 设置或新增代发 + if (!supplierId.Contains(targetSupplierId) && !supplierName.Contains(targetSupplierName)) + { + // 设置29供货商代发wxfc630d60a1af6c6f或其他代发 + var apiAddDropship = new WxApiBLL().WxApiDropshipAssign(orderItem.Shop, orderItem.order_id, orderItem.product_id, orderItem.sku_id, orderItem.sku_cnt.ParseToInt(), targetSupplierId); + if (!apiAddDropship.Contains("\"errcode\":0")) + { + throw new Exception("设置代发失败!请确认商品已加入" + targetSupplierName + "代发!" + BaseRegex.GetStringJson(ref apiAddDropship, "msg")); + } + } + } + catch (Exception ex) + { + throw new Exception(ex.Message); + //BaseMsgWindow.ShowError(ex.Message); + //return; + } + } + private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.DataContext is oms_wei_order_item_info order_item) @@ -1283,84 +1329,46 @@ namespace _29WxOrderWpf.Ctrls.OrderCtrls if (CheckIsRefund(orderItem)) return; - if (GlobalConfig.BuyConfig.IsSyncDirectBuyOrderWaybill == true) - { - // 设置同步物流单代发 - //var rst = new WxApiBLL().GetShopSupplier(orderItem.Shop); - //if (!rst.Contains("wx7809625286c28f2f") && !rst.Contains("百川日用")) - //{ - // rst = new WxApiBLL().SetShopSupplier(orderItem.Shop, "wx7809625286c28f2f", "4431685489938137094"); - // if (!rst.Contains("\"errcode\":0")) - // { - // BaseMsgWindow.ShowAnimateMessage("绑定同步单发货失败", "Error", 5); - // return; - // } - //} - - string supplierId = "", supplierName = ""; - try - { - // 查询直拍单是否绑定了同步单代发(放到同步单发货前处理) - var apiSearchDropship = new WxApiBLL().WxApiDropshipSearch(orderItem.Shop, orderItem.order_id, 100); - if (!apiSearchDropship.Contains("\"errcode\":0")) - throw new Exception("查询代发失败!" + BaseRegex.GetStringJson(ref apiSearchDropship, "msg")); - - var dsOrderId = JsonHelper.JObjectParse(apiSearchDropship)["ds_order_id_list"].FirstOrDefault().ParseToString(); - if (!string.IsNullOrEmpty(dsOrderId)) - { - var apiSearchDropshipDetail = new WxApiBLL().WxApiDropshipSearchDetail(orderItem.Shop, dsOrderId); - if (!apiSearchDropshipDetail.Contains("\"errcode\":0")) - throw new Exception("查询代发失详情败!" + BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "msg")); - - supplierId = BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "supplier_appid"); - supplierName = BaseRegex.GetStringJson(ref apiSearchDropshipDetail, "supplier_name"); - if (!string.IsNullOrEmpty(supplierId) && !supplierId.Contains("wx7809625286c28f2f") && !supplierName.Contains("百川日用")) - { - var apiCancelDropship = await new WxApiBLL().WxApiDropshipCancel(orderItem.Shop, orderItem.ItemOrder, dsOrderId); - if (!apiCancelDropship.Contains("\"errcode\":0")) - throw new Exception("取消其他代发失败!请确认商品未加入其他代发!" + BaseRegex.GetStringJsonByRegs(ref apiCancelDropship, apiCancelDropship, "errmsg")); - dsOrderId = ""; - supplierId = ""; - supplierName = ""; - } - } - - if (!supplierId.Contains("wx7809625286c28f2f") && !supplierName.Contains("百川日用")) - { - // 设置同步单供货商代发 - var apiAddDropship = new WxApiBLL().WxApiDropshipAssign(orderItem.Shop, orderItem.order_id, orderItem.product_id, orderItem.sku_id, orderItem.sku_cnt.ParseToInt(), "wx7809625286c28f2f"); - if (!apiAddDropship.Contains("\"errcode\":0")) - throw new Exception("设置同步单代发失败!请确商品已加入同步单代发!" + BaseRegex.GetStringJson(ref apiAddDropship, "msg")); - } - } - catch (Exception ex) - { - BaseMsgWindow.ShowError(ex.Message); - return; - } - } - else - { - // 查询订单是否在代发货中,如果代发需要取消代发 - var apiSearchDropship = new WxApiBLL().WxApiDropshipSearch(orderItem.Shop, orderItem.order_id, 100); - if (!apiSearchDropship.Contains("\"errcode\":0")) - { - BaseMsgWindow.ShowError("代发查询失败," + BaseRegex.GetStringJsonByRegs(ref apiSearchDropship, apiSearchDropship, "errmsg")); - return; - } - if (apiSearchDropship.Contains("ds_order_id_list") && !apiSearchDropship.Contains("\"ds_order_id_list\":[]")) - { - var dsOrderId = JsonHelper.JObjectParse(apiSearchDropship)["ds_order_id_list"].FirstOrDefault().ParseToString(); - var apiCancelDropship = await new WxApiBLL().WxApiDropshipCancel(orderItem.Shop, orderItem.ItemOrder, dsOrderId); - - if (!apiCancelDropship.Contains("\"errcode\":0")) - { - BaseMsgWindow.ShowError("取消代发失败!请确认商品未加入代发!" + BaseRegex.GetStringJsonByRegs(ref apiSearchDropship, apiSearchDropship, "errmsg")); - return; - } - } - } + // Api检测代发状态 + //if (GlobalConfig.BuyConfig.IsSyncDirectBuyOrderWaybill == true) + //{ + // // 设置同步物流单代发 + // //var rst = new WxApiBLL().GetShopSupplier(orderItem.Shop); + // //if (!rst.Contains("wx7809625286c28f2f") && !rst.Contains("百川日用")) + // //{ + // // rst = new WxApiBLL().SetShopSupplier(orderItem.Shop, "wx7809625286c28f2f", "4431685489938137094"); + // // if (!rst.Contains("\"errcode\":0")) + // // { + // // BaseMsgWindow.ShowAnimateMessage("绑定同步单发货失败", "Error", 5); + // // return; + // // } + // //} + // try + // { + // // 查询直拍单是否绑定了同步单代发(放到同步单发货前处理) + // await SetSendOrderSupplier(orderItem, "wx7809625286c28f2f", "百川日用"); + // } + // catch (Exception ex) + // { + // BaseMsgWindow.ShowError(ex.Message); + // return; + // } + //} + //else + //{ + // // 查询订单是否在代发货中,如果代发需要取消代发 + // try + // { + // // 查询直拍单是否绑定了同步单代发(放到同步单发货前处理) + // await SetSendOrderSupplier(orderItem, "", ""); + // } + // catch (Exception ex) + // { + // BaseMsgWindow.ShowError(ex.Message); + // return; + // } + //} // 检测买手号是否掉线 if (GlobalConfig.CurrentPddBuyer.status == "在线") @@ -1379,7 +1387,7 @@ namespace _29WxOrderWpf.Ctrls.OrderCtrls // 打开拍单窗口 - Dispatcher.Invoke(new Action(() => + Dispatcher.Invoke(new Action(async () => { btnBuyOrder.Cursor = Cursors.Hand; @@ -1410,6 +1418,49 @@ namespace _29WxOrderWpf.Ctrls.OrderCtrls buyOrderForm.pnlMap.Visible = false; } buyOrderForm.ShowDialog(); + + if (buyOrderForm.IsBuySuccess) + { + if (GlobalConfig.BuyConfig.IsSyncDirectBuyOrderWaybill == true) + { + // 设置同步物流单代发 + //var rst = new WxApiBLL().GetShopSupplier(orderItem.Shop); + //if (!rst.Contains("wx7809625286c28f2f") && !rst.Contains("百川日用")) + //{ + // rst = new WxApiBLL().SetShopSupplier(orderItem.Shop, "wx7809625286c28f2f", "4431685489938137094"); + // if (!rst.Contains("\"errcode\":0")) + // { + // BaseMsgWindow.ShowAnimateMessage("绑定同步单发货失败", "Error", 5); + // return; + // } + //} + + try + { + // 查询直拍单是否绑定了同步单代发(放到同步单发货前处理) + await SetSendOrderSupplier(orderItem, "wx7809625286c28f2f", "百川日用"); + } + catch (Exception ex) + { + BaseMsgWindow.ShowError(ex.Message); + return; + } + } + else + { + // 查询订单是否在代发货中,如果代发需要取消代发 + try + { + // 查询直拍单是否绑定了同步单代发(放到同步单发货前处理) + await SetSendOrderSupplier(orderItem, "", ""); + } + catch (Exception ex) + { + BaseMsgWindow.ShowError(ex.Message); + return; + } + } + } })); }); } diff --git a/29WxOrderWpf/MainWindow.xaml.cs b/29WxOrderWpf/MainWindow.xaml.cs index 5b8f0db..34a14b9 100644 --- a/29WxOrderWpf/MainWindow.xaml.cs +++ b/29WxOrderWpf/MainWindow.xaml.cs @@ -362,14 +362,22 @@ namespace _29WxOrderWpf foreach (var shop in shops) { var rst = new WxApiBLL().GetShopSupplier(shop); - if (rst.Contains("wx7809625286c28f2f") || rst.Contains("百川日用")) - continue; - - rst = new WxApiBLL().SetShopSupplier(shop, "wx7809625286c28f2f", "4431685489938137094"); - if (!rst.Contains("\"errcode\":0")) + try { - //return; + var jArr = JsonHelper.JObjectParse(rst)["list"] as JArray; + // appid "wx7809625286c28f2f" name "百川日用"; + if (jArr.Any(aa => aa["appid"].ParseToString() == "wx7809625286c28f2f" && aa["status"].ParseToInt() == 1)) + //if (rst.Contains("wx7809625286c28f2f") || rst.Contains("百川日用")) + continue; + + rst = new WxApiBLL().SetShopSupplier(shop, "wx7809625286c28f2f", "4431685489938137094"); + if (!rst.Contains("\"errcode\":0")) + { + //return; + } } + catch + { } } } #endregion diff --git a/Work/_29Tools/Forms/PddMobileBuyOrderForm.cs b/Work/_29Tools/Forms/PddMobileBuyOrderForm.cs index f6acb17..e555986 100644 --- a/Work/_29Tools/Forms/PddMobileBuyOrderForm.cs +++ b/Work/_29Tools/Forms/PddMobileBuyOrderForm.cs @@ -53,6 +53,7 @@ namespace TemuKJD.ToolForms public bool IsClose { get; set; } = false; public bool IsAutoBuy { get; set; } = false; + public bool IsBuySuccess { get; set; } = false; public bool IsFormLoad { get; set; } = false; public bool ShowBuyMask { get; set; } = false; public string BuyErrMsg { get; set; } = ""; @@ -1569,6 +1570,7 @@ namespace TemuKJD.ToolForms #endregion } this.IsClose = true; + this.IsBuySuccess = true; this.Close(); }