From dacacb352c582e29ccca9f148b3c90b7001ab693 Mon Sep 17 00:00:00 2001 From: wule Date: Tue, 11 Aug 2026 22:15:32 +0800 Subject: [PATCH] =?UTF-8?q?api=E8=B0=83=E7=94=A8=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E4=BB=A3=E5=8F=91=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderCtrls/OrderListRowItemCtrl.xaml.cs | 67 +++++++++----- 29WxOrderWpf/StartUp.cs | 18 ++-- AllBase/BaseClass.cs | 2 +- AllBase/Helper/GlobalConfig.cs | 9 +- AllBase/Model/DBModel/ShopLoginInfo.cs | 17 +++- Work/29WxOrderWork.csproj | 1 + Work/_29Tools/BLL/WxApiBLL.cs | 91 +++++++++++++++++++ 7 files changed, 167 insertions(+), 38 deletions(-) create mode 100644 Work/_29Tools/BLL/WxApiBLL.cs diff --git a/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs b/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs index f4e2d69..6569704 100644 --- a/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs +++ b/29WxOrderWpf/Ctrls/OrderCtrls/OrderListRowItemCtrl.xaml.cs @@ -508,30 +508,49 @@ namespace _29WxOrderWpf.Ctrls.OrderCtrls return; } - // 检测是否加入代发 - if (orderItem.Shop?.LoginStatus == "登录成功" && orderItem.BuyGoodsBtnTxt == "云仓拍单" && !isAbnormalOrder) - { - var is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierOrderList(orderItem.Shop, orderItem.order_id); - if (!is29SupplierRst.Contains("\"code\":0")) - is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierOrderList(orderItem.Shop, orderItem.order_id); - if (is29SupplierRst.Contains("\"code\":0") && is29SupplierRst.Contains("\"supplierName\":\"29供货商\"")) // "supplierName":"29供货商" - { - orderItem.Shop.Is29Supplier = true; - } - else - { - ShopBLL.CheckShopLogin(orderItem.Shop); - if (orderItem.Shop?.LoginStatus == "登录成功") - { - Dispatcher.Invoke(new Action(() => - { - BaseMsgWindow.ShowError("店铺后台未查询到该代发单,请确认店铺在线且商品加入代发"); - btnBuyOrder.Cursor = Cursors.Hand; - })); - return; - } - } - } + // Api检测是否加入代发 + if (orderItem.BuyGoodsBtnTxt == "云仓拍单" && !isAbnormalOrder) + { + var apiSearchDropship = new WxApiBLL().WxApiDropshipSearch(orderItem.Shop, orderItem.order_id, 100); + if (apiSearchDropship.Contains("\"ds_order_id_list\":[]")) + { + var apiAddDropship = new WxApiBLL().WxApiDropshipAssign(orderItem.Shop, orderItem.order_id, orderItem.product_id, orderItem.sku_id, orderItem.sku_cnt.ParseToInt()); + } + apiSearchDropship = new WxApiBLL().WxApiDropshipSearch(orderItem.Shop, orderItem.order_id, 100); + if (apiSearchDropship.Contains("\"ds_order_id_list\":[]")) + BaseMsgWindow.ShowError("店铺后台未查询到该代发单,请确商品已加入29供货商代发"); + } + + // 模拟检测是否加入代发 + //if (orderItem.Shop?.LoginStatus == "登录成功" && orderItem.BuyGoodsBtnTxt == "云仓拍单" && !isAbnormalOrder) + //{ + // var is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierOrderList(orderItem.Shop, orderItem.order_id); + // if (!is29SupplierRst.Contains("\"code\":0")) + // is29SupplierRst = WxOrderSupplierBLL.GetWxSupplierOrderList(orderItem.Shop, orderItem.order_id); + // if (!is29SupplierRst.Contains("\"code\":0")) + // { + // ShopBLL.CheckShopLogin(orderItem.Shop); + // if (orderItem.Shop?.LoginStatus != "登录成功") + // { + // Dispatcher.Invoke(new Action(() => + // { + // BaseMsgWindow.ShowAnimateMessage("店铺掉线", "Error", 5); + // btnBuyOrder.Cursor = Cursors.Hand; + // })); + // return; + // } + // } + // if (!is29SupplierRst.Contains("\"supplierName\":\"29供货商\"")) // "supplierName":"29供货商" + // { + // Dispatcher.Invoke(new Action(() => + // { + // BaseMsgWindow.ShowError("店铺后台未查询到该代发单,请确认店铺在线且商品加入代发"); + // btnBuyOrder.Cursor = Cursors.Hand; + // })); + // return; + // } + // orderItem.Shop.Is29Supplier = true; + //} // 掉线提示重登 if (orderItem.Shop?.LoginStatus != "登录成功") diff --git a/29WxOrderWpf/StartUp.cs b/29WxOrderWpf/StartUp.cs index df03ce8..79a4116 100644 --- a/29WxOrderWpf/StartUp.cs +++ b/29WxOrderWpf/StartUp.cs @@ -2,6 +2,8 @@ using AllBase.DouYinModel.Param.ConfigManage; using AllBase.Helper; using AllBase.Model.Config; +using AllBase.Model.DBModel; +using NaiBa.Util; using NaiBa.Util.Helper; using System; using System.Collections.Generic; @@ -14,12 +16,16 @@ namespace _29WxOrderWpf { public class StartUp { - public static void Init() - { - GlobalConfig.BuyConfig = ConfigHelper.LoadConfig("buy_config_260708"); - if (GlobalConfig.BuyConfig == null) - GlobalConfig.BuyConfig = new BuyConfig(); - } + public static void Init() + { + GlobalConfig.BuyConfig = ConfigHelper.LoadConfig("buy_config_260708"); + if (GlobalConfig.BuyConfig == null) + GlobalConfig.BuyConfig = new BuyConfig(); + + GlobalConfig.lstWXShopTokenInfo = ConfigHelper.LoadConfig>("wx_shop_token_list"); + if (GlobalConfig.lstWXShopTokenInfo == null) + GlobalConfig.lstWXShopTokenInfo = new ConcurrentList(); + } public static void SaveBuyConfig() { diff --git a/AllBase/BaseClass.cs b/AllBase/BaseClass.cs index c350dad..9eb58c9 100644 --- a/AllBase/BaseClass.cs +++ b/AllBase/BaseClass.cs @@ -32,7 +32,7 @@ namespace AllBase /// 版本ID /// - public static int VersionCount = 223; + public static int VersionCount = 225; public static string ServerUrl { get; set; } = "http://1.13.195.131:9000"; public static string DebugUrl { get; set; } = "http://localhost:9000"; diff --git a/AllBase/Helper/GlobalConfig.cs b/AllBase/Helper/GlobalConfig.cs index fd0680c..88153e9 100644 --- a/AllBase/Helper/GlobalConfig.cs +++ b/AllBase/Helper/GlobalConfig.cs @@ -27,10 +27,11 @@ namespace AllBase.Helper /// 店铺列表 /// public static ObservableCollectionThreadSafe ShopLoginList { get; set; } = new ObservableCollectionThreadSafe(); - /// - /// 拼多多买手列表 - /// - public static ObservableCollectionThreadSafe PDDBuyerLoginList { get; set; } = new ObservableCollectionThreadSafe(); + public static ConcurrentList lstWXShopTokenInfo = new ConcurrentList(); + /// + /// 拼多多买手列表 + /// + public static ObservableCollectionThreadSafe PDDBuyerLoginList { get; set; } = new ObservableCollectionThreadSafe(); /// /// 当前拼多多买手 /// diff --git a/AllBase/Model/DBModel/ShopLoginInfo.cs b/AllBase/Model/DBModel/ShopLoginInfo.cs index b6fc56b..c8d18d9 100644 --- a/AllBase/Model/DBModel/ShopLoginInfo.cs +++ b/AllBase/Model/DBModel/ShopLoginInfo.cs @@ -1,4 +1,5 @@ -using AllBase.Model.MvvmBaseClasses; +using AllBase.Helper; +using AllBase.Model.MvvmBaseClasses; using System; using System.Collections.Generic; using System.ComponentModel; @@ -91,9 +92,8 @@ namespace AllBase.Model.DBModel public bool is_point_shop_expire { get; set; } public int expire_time { get; set; } - public string openid { get; set; } - } + } public class ShopCompany { @@ -115,4 +115,15 @@ namespace AllBase.Model.DBModel /// public string openid { get; set; } } + + public class WXShopTokenInfo + { + public string shopId { get; set; } // "1960967267443618234", + public string shopName { get; set; } // "夜笙供应链", + public int? type { get; set; } // 500, + public int? markupRate { get; set; } // 10, + public string accessToken { get; set; } // "100_cw6r7-hhGaLKG7ndv558eO_3z3-5PokAG8d0Y1vc3Rczd3FuIqkefdaqVj5CNtkCYtMbTYvhnwJ7-JkBVQVe9nE0KK5SBI8AlfA7E0_sTtqcwMqKAXoCj1X4h3sjZIMX84dboC-PfzlI0wh0ADHeAHDSVZ" + public DateTime mdyTime { get; set; } = DateTime.MinValue; + public bool isExpire { get { return mdyTime.AddMinutes(60) < DateTime.Now; } } + } } diff --git a/Work/29WxOrderWork.csproj b/Work/29WxOrderWork.csproj index 36efe79..078c638 100644 --- a/Work/29WxOrderWork.csproj +++ b/Work/29WxOrderWork.csproj @@ -267,6 +267,7 @@ + diff --git a/Work/_29Tools/BLL/WxApiBLL.cs b/Work/_29Tools/BLL/WxApiBLL.cs new file mode 100644 index 0000000..e340841 --- /dev/null +++ b/Work/_29Tools/BLL/WxApiBLL.cs @@ -0,0 +1,91 @@ +using AllBase; +using AllBase.Helper; +using AllBase.Model.DBModel; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace Work._29Tools.BLL +{ + public class WxApiBLL + { + private WXShopTokenInfo UpdateShopWxToken(ShopLoginInfo shop) + { + var url = BaseClass.Build29WxObjString("shop/e57_get_wx_shop_token"); + var data = UserLogin.GetSignaturex(); + data += "&shop_id=" + shop.ShopId; + var html = GetHtml.PostUtf8(url, data); + // 获取失败 + if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":0")) + { + return new WXShopTokenInfo() { shopId = shop.ShopId, accessToken = "", mdyTime = DateTime.Now }; + } + else + { + var token = new WXShopTokenInfo() + { + shopId = shop.ShopId, + accessToken = BaseRegex.GetStringJson(ref html, "accessToken"), + mdyTime = DateTime.Now, + }; + return token; + } + } + + public WXShopTokenInfo GetWxToken(ShopLoginInfo shop) + { + WXShopTokenInfo token = GlobalConfig.lstWXShopTokenInfo.FirstOrDefault(t => t.shopId == shop.ShopId); + if (token == null) + token = new WXShopTokenInfo(); + if (token.isExpire || string.IsNullOrEmpty(token.accessToken)) + { + token = new WxApiBLL().UpdateShopWxToken(shop); + + if (!string.IsNullOrEmpty(token.accessToken)) + { + GlobalConfig.lstWXShopTokenInfo.RemoveAll(t => t.shopId == shop.ShopId); + GlobalConfig.lstWXShopTokenInfo.Add(token); + NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_shop_token_list", GlobalConfig.lstWXShopTokenInfo); + } + } + return token; + } + + public string WxApiDropshipSearch(ShopLoginInfo shop, string orderId, int status) + { + StringBuilder sb = new StringBuilder(); + sb.Append(UserLogin.GetSignaturex()); + sb.Append("&token=").Append(GetWxToken(shop).accessToken); + sb.Append("&order_id=").Append(orderId); + sb.Append("&status=").Append(status); + + var url = BaseClass.Build29WxObjString("product/wx_api_dropship_search"); + var data = sb.ToString(); + var html = GetHtml.PostUtf8(url, data); + if (string.IsNullOrEmpty(html) || !html.Contains("\"errcode\":0")) + html = GetHtml.PostUtf8(url, data); + return html; + } + + + public string WxApiDropshipAssign(ShopLoginInfo shop, string orderId, string spuId, string skuId, int cnt) + { + StringBuilder sb = new StringBuilder(); + sb.Append(UserLogin.GetSignaturex()); + sb.Append("&token=").Append(GetWxToken(shop).accessToken); + sb.Append("&order_id=").Append(orderId); + sb.Append("&dropship_product_list=").Append("[{\"spu_id\":\"" + spuId + "\",\"sku_id\":\"" + skuId + "\",\"product_cnt\":" + cnt + "}]"); + + var url = BaseClass.Build29WxObjString("product/wx_api_dropship_assign"); + var data = sb.ToString(); + var html = GetHtml.PostUtf8(url, data); + if (string.IsNullOrEmpty(html) || !html.Contains("\"errcode\":0")) + html = GetHtml.PostUtf8(url, data); + return html; + } + } +}