25 changed files with 1180 additions and 4 deletions
@ -0,0 +1,58 @@ |
|||||
|
using BBWYB.Common.Http; |
||||
|
using BBWYB.Common.Models; |
||||
|
using Newtonsoft.Json; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Net.Http; |
||||
|
|
||||
|
namespace U.APIServices |
||||
|
{ |
||||
|
public class BaseApiService |
||||
|
{ |
||||
|
private RestApiService restApiService; |
||||
|
|
||||
|
protected GlobalContext globalContext; |
||||
|
|
||||
|
public BaseApiService(RestApiService restApiService, GlobalContext globalContext) |
||||
|
{ |
||||
|
this.restApiService = restApiService; |
||||
|
this.globalContext = globalContext; |
||||
|
} |
||||
|
|
||||
|
protected ApiResponse<T> SendRequest<T>(string apiHost, |
||||
|
string apiPath, |
||||
|
object param, |
||||
|
IDictionary<string, string> headers, |
||||
|
HttpMethod httpMethod, |
||||
|
string contentType = RestApiService.ContentType_Json, |
||||
|
ParamPosition paramPosition = ParamPosition.Body, |
||||
|
bool enableRandomTimeStamp = false) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
if (headers == null) |
||||
|
headers = new Dictionary<string, string>(); |
||||
|
if (!headers.ContainsKey("ClientCode")) |
||||
|
headers.Add("ClientCode", "U"); |
||||
|
if (!headers.ContainsKey("ClientVersion")) |
||||
|
headers.Add("ClientVersion", "10000"); |
||||
|
if (!headers.ContainsKey("Authorization") && !string.IsNullOrEmpty(globalContext.UserToken)) |
||||
|
headers.Add("Authorization", $"Bearer {globalContext.UserToken}"); |
||||
|
if (!headers.ContainsKey("qy")) |
||||
|
headers.Add("qy", "qy"); |
||||
|
|
||||
|
var result = restApiService.SendRequest(apiHost, apiPath, param, headers, httpMethod, contentType, paramPosition, enableRandomTimeStamp); |
||||
|
if (result.StatusCode != System.Net.HttpStatusCode.OK && |
||||
|
result.Content.Contains("\"Success\"") && |
||||
|
result.Content.Contains("\"Msg\"") && |
||||
|
result.Content.Contains("\"Data\"")) |
||||
|
throw new BusinessException($"{result.StatusCode} {result.Content}") { Code = (int)result.StatusCode }; |
||||
|
return JsonConvert.DeserializeObject<ApiResponse<T>>(result.Content); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
return ApiResponse<T>.Error((ex is BusinessException) ? (ex as BusinessException).Code : 0, ex.Message); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,108 @@ |
|||||
|
using BBWYB.Common.Http; |
||||
|
using BBWYB.Common.Models; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
using U.Models; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Net.Http; |
||||
|
|
||||
|
namespace U.APIServices |
||||
|
{ |
||||
|
public class MdsApiService : BaseApiService, IDenpendency |
||||
|
{ |
||||
|
public MdsApiService(RestApiService restApiService, GlobalContext globalContext) : base(restApiService, globalContext) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public ApiResponse<MDSUserResponse> GetUserInfo(string userToken) |
||||
|
{ |
||||
|
return SendRequest<MDSUserResponse>(globalContext.MDSApiHost, |
||||
|
"/TaskList/User/GetUserInfo", |
||||
|
null, |
||||
|
new Dictionary<string, string>() |
||||
|
{ |
||||
|
{ "Authorization", $"Bearer {userToken}" } |
||||
|
}, HttpMethod.Get); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
//public ApiResponse<IList<ShopResponse>> GetShopsByUserTeam(long userId)
|
||||
|
//{
|
||||
|
// return SendRequest<IList<ShopResponse>>(globalContext.MDSApiHost, "TaskList/Shop/GetShopsByUserTeam", $"userId={userId}", null, System.Net.Http.HttpMethod.Get);
|
||||
|
//}
|
||||
|
|
||||
|
public ApiResponse<IList<Department>> GetShopDetailList() |
||||
|
{ |
||||
|
var response = new ApiResponse<IList<Department>>(); |
||||
|
var response2 = SendRequest<JArray>(globalContext.MDSApiHost, "TaskList/UserDepartment/GetShopDetailList", null, null, HttpMethod.Get); |
||||
|
if (!response.Success) |
||||
|
{ |
||||
|
response.Code = response2.Code; |
||||
|
response.Msg = response2.Msg; |
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
response.Data = new List<Department>(); |
||||
|
foreach (var jDepartment in response2.Data) |
||||
|
{ |
||||
|
var jayShops = jDepartment.Value<JArray>("ShopList"); |
||||
|
if (jayShops == null || !jayShops.HasValues) |
||||
|
continue; //排除空店部门
|
||||
|
var d = new Department() |
||||
|
{ |
||||
|
Id = jDepartment.Value<string>("Id"), |
||||
|
Name = jDepartment.Value<string>("DepartmentName") |
||||
|
}; |
||||
|
response.Data.Add(d); |
||||
|
foreach (var jShop in jayShops) |
||||
|
{ |
||||
|
if (jShop.Value<long?>("ShopId") == null || string.IsNullOrEmpty(jShop.Value<string>("AppToken"))) |
||||
|
continue; //排除未授权
|
||||
|
try |
||||
|
{ |
||||
|
var shop = new Shop() |
||||
|
{ |
||||
|
ShopId = jShop.Value<long>("ShopId"), |
||||
|
AppKey = jShop.Value<string>("AppKey"), |
||||
|
AppSecret = jShop.Value<string>("AppSecret"), |
||||
|
AppToken = jShop.Value<string>("AppToken"), |
||||
|
ManagePwd = jShop.Value<string>("ManagePwd"), |
||||
|
Platform = (Platform)jShop.Value<int>("PlatformId"), |
||||
|
PlatformCommissionRatio = jShop.Value<decimal?>("PlatformCommissionRatio") ?? 0.05M, |
||||
|
ShopName = jShop.Value<string>("ShopName"), |
||||
|
VenderType = jShop.Value<string>("ShopType"), |
||||
|
TeamId = jShop.Value<string>("TeamId") |
||||
|
}; |
||||
|
d.ShopList.Add(shop); |
||||
|
//var jayAccounts = jShop.Value<JArray>("AccountList");
|
||||
|
//if (jayAccounts == null || !jayAccounts.HasValues)
|
||||
|
// continue;
|
||||
|
//shop.PurchaseAccountList = new List<PurchaseAccount>();
|
||||
|
//foreach (var jPurchaseAccount in jayAccounts)
|
||||
|
//{
|
||||
|
// shop.PurchaseAccountList.Add(new PurchaseAccount()
|
||||
|
// {
|
||||
|
// Id = jPurchaseAccount.Value<long>("Id"),
|
||||
|
// AccountName = jPurchaseAccount.Value<string>("AccountName"),
|
||||
|
// AppKey = jPurchaseAccount.Value<string>("AppKey"),
|
||||
|
// AppSecret = jPurchaseAccount.Value<string>("AppSecret"),
|
||||
|
// AppToken = jPurchaseAccount.Value<string>("AppToken"),
|
||||
|
// ShopId = shop.ShopId
|
||||
|
// //PurchasePlatformId = jPurchaseAccount.Value<long>()
|
||||
|
// });
|
||||
|
//}
|
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Console.WriteLine(jShop.ToString()); |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
using BBWYB.Common.Models; |
||||
|
using U.Models; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Net.Http; |
||||
|
using BBWYB.Common.Http; |
||||
|
|
||||
|
namespace U.APIServices |
||||
|
{ |
||||
|
public class ShopService : BaseApiService, IDenpendency |
||||
|
{ |
||||
|
public ShopService(RestApiService restApiService, GlobalContext globalContext) : base(restApiService, globalContext) { } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取部门及下属店铺
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public ApiResponse<IList<DepartmentResponse>> GetDepartmentList() |
||||
|
{ |
||||
|
return SendRequest<IList<DepartmentResponse>>(globalContext.BBYWApiHost, "api/vender/GetDeparmentList", null, |
||||
|
new Dictionary<string, string>() |
||||
|
{ |
||||
|
{ "bbwyTempKey", "21jfhayu27q" } |
||||
|
}, HttpMethod.Get); |
||||
|
} |
||||
|
|
||||
|
public ApiResponse<IList<ShopResponse>> GetShopListByIds(IList<string> shopIds) |
||||
|
{ |
||||
|
return SendRequest<IList<ShopResponse>>(globalContext.BBYWApiHost, "api/vender/GetShopListByShopIds", new |
||||
|
{ |
||||
|
shopIds |
||||
|
}, new Dictionary<string, string>() |
||||
|
{ |
||||
|
{ "bbwyTempKey", "21jfhayu27q" } |
||||
|
}, HttpMethod.Post); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
<Application x:Class="U.App" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:local="clr-namespace:U" |
||||
|
StartupUri="MainWindow.xaml"> |
||||
|
<Application.Resources> |
||||
|
|
||||
|
</Application.Resources> |
||||
|
</Application> |
@ -0,0 +1,87 @@ |
|||||
|
using BBWYB.Common.Extensions; |
||||
|
using BBWYB.Common.Http; |
||||
|
using BBWYB.Common.Models; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using System; |
||||
|
using System.Diagnostics; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Reflection; |
||||
|
using System.Windows; |
||||
|
using U.Models; |
||||
|
using Utils; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Interaction logic for App.xaml
|
||||
|
/// </summary>
|
||||
|
public partial class App : Application |
||||
|
{ |
||||
|
public IServiceProvider ServiceProvider { get; private set; } |
||||
|
public IConfiguration Configuration { get; private set; } |
||||
|
|
||||
|
protected override void OnStartup(StartupEventArgs e) |
||||
|
{ |
||||
|
var pjzsExeList = Process.GetProcessesByName("PJZS"); |
||||
|
if (pjzsExeList != null && pjzsExeList.Count() > 1) |
||||
|
{ |
||||
|
Environment.Exit(Environment.ExitCode); |
||||
|
} |
||||
|
|
||||
|
var gl = new GlobalContext(); |
||||
|
string userToken = string.Empty; |
||||
|
#if DEBUG
|
||||
|
//齐越山鸡
|
||||
|
userToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNTM1MzMwMzI4ODkyMTQ5NzYwIiwidGVhbUlkIjoiMTUxNjk3NDI1MDU0MjUwMTg4OCIsInNvblRlYW1JZHMiOiIxNDM2Mjg4NTAwMjM1MjQzNTIwIiwiZXhwIjoxNjk0NjY5NjkxfQ.cSwro-7bGwOu92YejH9JhMenTai7Mvf99i2paQCmxIw"; |
||||
|
#else
|
||||
|
|
||||
|
var tokenResult = ReadMMF(); |
||||
|
if (tokenResult.isOk) |
||||
|
userToken = tokenResult.content; |
||||
|
else |
||||
|
{ |
||||
|
MessageBox.Show($"读取内存数据失败\r\n{tokenResult.content}", "提示"); |
||||
|
Environment.Exit(0); |
||||
|
} |
||||
|
#endif
|
||||
|
gl.UserToken = userToken; |
||||
|
|
||||
|
|
||||
|
|
||||
|
//var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
|
//var builder = new ConfigurationBuilder().SetBasePath(applicationPath).AddJsonFile("appSettings.json", false, true);
|
||||
|
//Configuration = builder.Build();
|
||||
|
|
||||
|
//gl.BBYWApiHost = Configuration.GetSection("BBWYApiHost").Value;
|
||||
|
//gl.MDSApiHost = Configuration.GetSection("MDSApiHost").Value;
|
||||
|
//IServiceCollection serviceCollection = new ServiceCollection();
|
||||
|
//serviceCollection.AddHttpClient();
|
||||
|
|
||||
|
//serviceCollection.AddSingleton<RestApiService>();
|
||||
|
//serviceCollection.AddSingleton(gl);
|
||||
|
//serviceCollection.BatchRegisterServices(new Assembly[] { Assembly.Load("PJZS") }, typeof(IDenpendency));
|
||||
|
//serviceCollection.AddMapper(new MappingProfile());
|
||||
|
//ServiceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
base.OnStartup(e); |
||||
|
} |
||||
|
|
||||
|
public (bool isOk, string content) ReadMMF() |
||||
|
{ |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
var token = MemoryHelper.GetMemoryToken(); |
||||
|
if (string.IsNullOrEmpty(token)) |
||||
|
return (false, "token为空"); |
||||
|
else |
||||
|
return (true, token); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
return (false, ex.Message); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
using System.Windows; |
||||
|
|
||||
|
[assembly: ThemeInfo( |
||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
|
//(used if a resource is not found in the page,
|
||||
|
// or application resource dictionaries)
|
||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
|
//(used if a resource is not found in the page,
|
||||
|
// app, or any theme specific resource dictionaries)
|
||||
|
)] |
@ -0,0 +1,26 @@ |
|||||
|
using Newtonsoft.Json; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
[ClassInterface(ClassInterfaceType.AutoDual)] |
||||
|
[ComVisible(true)] |
||||
|
public class GlobalContext |
||||
|
{ |
||||
|
public User User { get; set; } |
||||
|
|
||||
|
public string UserToken { get; set; } |
||||
|
|
||||
|
|
||||
|
#region APIHost
|
||||
|
public string BBYWApiHost { get; set; } |
||||
|
|
||||
|
public string MDSApiHost { get; set; } |
||||
|
#endregion
|
||||
|
|
||||
|
public string GetUserString() |
||||
|
{ |
||||
|
return JsonConvert.SerializeObject(User); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
<b:BWindow x:Class="U.MainWindow" |
||||
|
xmlns:b="clr-namespace:SJ.Controls;assembly=SJ.Controls" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
xmlns:local="clr-namespace:U" |
||||
|
mc:Ignorable="d" |
||||
|
Title="U" Height="560" Width="700" |
||||
|
RightButtonGroupMargin="0,5,5,0"> |
||||
|
<Grid x:Name="grid"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="30"/> |
||||
|
<RowDefinition/> |
||||
|
</Grid.RowDefinitions> |
||||
|
|
||||
|
<Border BorderThickness="0,0,0,1" BorderBrush="#D7D7D7" Background="#8080FF"> |
||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0" |
||||
|
TextBlock.Foreground="White"> |
||||
|
<TextBlock Text="商品条形码生成"/> |
||||
|
<TextBlock Text="v10000" Margin="5,0,0,0"/> |
||||
|
<TextBlock x:Name="txtUserName" Margin="5,0,0,0"/> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
</Grid> |
||||
|
</b:BWindow> |
@ -0,0 +1,216 @@ |
|||||
|
using BBWYB.Common.Extensions; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Web.WebView2.Core; |
||||
|
using SJ.Controls; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Windows; |
||||
|
using System.Windows.Controls; |
||||
|
using U.APIServices; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Interaction logic for MainWindow.xaml
|
||||
|
/// </summary>
|
||||
|
public partial class MainWindow : BWindow |
||||
|
{ |
||||
|
private GlobalContext globalContext; |
||||
|
private WebView2Manager w2m; |
||||
|
private bool isNavigated; |
||||
|
|
||||
|
|
||||
|
private IList<string> managerDepartment; |
||||
|
private MdsApiService mdsApiService; |
||||
|
private ShopService shopService; |
||||
|
public MainWindow() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
this.managerDepartment = new List<string>() { "董事办", "财务部", "技术部", "总经办" }; |
||||
|
this.Loaded += MainWindow_Loaded; |
||||
|
this.Closed += MainWindow_Closed; |
||||
|
} |
||||
|
|
||||
|
private void MainWindow_Closed(object sender, EventArgs e) |
||||
|
{ |
||||
|
Environment.Exit(Environment.ExitCode); |
||||
|
} |
||||
|
|
||||
|
private bool CheckWebview2Runtime() |
||||
|
{ |
||||
|
bool isInstall = false; |
||||
|
try |
||||
|
{ |
||||
|
isInstall = !string.IsNullOrEmpty(CoreWebView2Environment.GetAvailableBrowserVersionString()); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Console.WriteLine(ex.Message); |
||||
|
} |
||||
|
return isInstall; |
||||
|
} |
||||
|
|
||||
|
private void MainWindow_Loaded(object sender, System.Windows.RoutedEventArgs e) |
||||
|
{ |
||||
|
if (!CheckWebview2Runtime()) |
||||
|
{ |
||||
|
MessageBox.Show("缺少webview2 runtime,请下载安装之后再运行评价助手"); |
||||
|
//下载webview2 runtime
|
||||
|
//Task.Factory.StartNew(DownloadWebview2Runtime);
|
||||
|
var webview2RuntimeUrl = "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/238fc310-c6c1-4a3e-a806-4a7c3c17b377/MicrosoftEdgeWebView2RuntimeInstallerX64.exe"; |
||||
|
try |
||||
|
{ |
||||
|
System.Diagnostics.Process.Start("explorer.exe", webview2RuntimeUrl); |
||||
|
Thread.Sleep(1000); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Clipboard.SetText(webview2RuntimeUrl); |
||||
|
MessageBox.Show($"{ex.Message}\r\n调用浏览器失败,网页链接已复制到剪切板,请手动打开浏览器访问", "提示"); |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
Environment.Exit(Environment.ExitCode); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//var sp = (App.Current as App).ServiceProvider;
|
||||
|
//using (var s = sp.CreateScope())
|
||||
|
//{
|
||||
|
// w2m = s.ServiceProvider.GetRequiredService<WebView2Manager>();
|
||||
|
// //globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>();
|
||||
|
// //mdsApiService = s.ServiceProvider.GetRequiredService<MdsApiService>();
|
||||
|
// //shopService = s.ServiceProvider.GetRequiredService<ShopService>();
|
||||
|
//}
|
||||
|
|
||||
|
w2m = new WebView2Manager(); |
||||
|
|
||||
|
//Login();
|
||||
|
//txtUserName.Text = globalContext.User.Name;
|
||||
|
var url = "http://upc.qiyue666.com/barcode/"; |
||||
|
w2m.CoreWebView2InitializationCompleted = (e) => |
||||
|
{ |
||||
|
//w2m.wb2.CoreWebView2.AddHostObjectToScript("uContext", this.globalContext);
|
||||
|
isNavigated = true; |
||||
|
w2m.wb2.CoreWebView2.Navigate(url); |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
w2m.Init(); |
||||
|
w2m.wb2.SetValue(Grid.RowProperty, 1); |
||||
|
w2m.wb2.Margin = new Thickness(1, 0, 1, 0); |
||||
|
grid.Children.Add(w2m.wb2); |
||||
|
|
||||
|
|
||||
|
|
||||
|
if (w2m.IsInitializationCompleted && !isNavigated) |
||||
|
{ |
||||
|
w2m.wb2.CoreWebView2.Navigate(url); |
||||
|
//w2m.wb2.CoreWebView2.NavigateToString(content);
|
||||
|
isNavigated = true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void Login() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
var mdsUserResponse = mdsApiService.GetUserInfo(globalContext.UserToken); |
||||
|
if (!mdsUserResponse.Success) |
||||
|
throw new Exception($"获取磨刀石用户信息失败 {mdsUserResponse.Msg}"); |
||||
|
|
||||
|
globalContext.User = mdsUserResponse.Data.Map<User>(); |
||||
|
globalContext.User.Token = globalContext.UserToken; |
||||
|
globalContext.User.SonDepartmentNames = string.Empty; |
||||
|
if (mdsUserResponse.Data.SonDepartmentList != null && mdsUserResponse.Data.SonDepartmentList.Count > 0) |
||||
|
globalContext.User.SonDepartmentNames = string.Join(',', mdsUserResponse.Data.SonDepartmentList.Select(sd => sd.DepartmentName)); |
||||
|
|
||||
|
IList<Department> departmentList = null; |
||||
|
if (globalContext.User.TeamName == "刷单组" || |
||||
|
managerDepartment.Contains(globalContext.User.TeamName) || |
||||
|
managerDepartment.Any(m => globalContext.User.SonDepartmentNames.Contains(m))) |
||||
|
{ |
||||
|
var response = shopService.GetDepartmentList(); |
||||
|
if (!response.Success) |
||||
|
throw new Exception(response.Msg); |
||||
|
departmentList = response.Data.Map<List<Department>>(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
var response = mdsApiService.GetShopDetailList(); |
||||
|
if (!response.Success) |
||||
|
throw new Exception(response.Msg); |
||||
|
departmentList = response.Data; |
||||
|
if (departmentList.Count == 0) |
||||
|
throw new Exception("缺少有效的部门数据"); |
||||
|
|
||||
|
var shopIds = new List<string>(); |
||||
|
foreach (var d in departmentList) |
||||
|
{ |
||||
|
if (d.ShopList != null && d.ShopList.Count > 0) |
||||
|
{ |
||||
|
foreach (var s in d.ShopList) |
||||
|
shopIds.Add(s.ShopId.ToString()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
var shopList2Res = shopService.GetShopListByIds(shopIds); |
||||
|
if (shopList2Res.Success && shopList2Res.Data != null && shopList2Res.Data.Count() > 0) |
||||
|
{ |
||||
|
foreach (var d in departmentList) |
||||
|
{ |
||||
|
foreach (var shop in d.ShopList) |
||||
|
{ |
||||
|
var s2 = shopList2Res.Data.FirstOrDefault(s => s.ShopId == shop.ShopId); |
||||
|
if (s2 != null) |
||||
|
{ |
||||
|
shop.DingDingKey = s2.DingDingKey; |
||||
|
shop.DingDingWebHook = s2.DingDingWebHook; |
||||
|
shop.SkuSafeTurnoverDays = s2.SkuSafeTurnoverDays; |
||||
|
shop.SiNanPolicyLevel = s2.SiNanPolicyLevel; |
||||
|
shop.SiNanDingDingKey = s2.SiNanDingDingKey; |
||||
|
shop.SiNanDingDingWebHook = s2.SiNanDingDingWebHook; |
||||
|
shop.AppKey2 = s2.AppKey2; |
||||
|
shop.AppSecret2 = s2.AppSecret2; |
||||
|
shop.AppToken2 = s2.AppToken2; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
for (var i = 0; i < departmentList.Count(); i++) |
||||
|
{ |
||||
|
var d = departmentList[i]; |
||||
|
for (var j = 0; j < d.ShopList.Count(); j++) |
||||
|
{ |
||||
|
var shop = d.ShopList[j]; |
||||
|
if (string.IsNullOrEmpty(shop.AppToken2)) |
||||
|
{ |
||||
|
d.ShopList.RemoveAt(j); |
||||
|
j--; |
||||
|
} |
||||
|
} |
||||
|
if (d.ShopList == null || d.ShopList.Count() == 0) |
||||
|
{ |
||||
|
departmentList.RemoveAt(i); |
||||
|
i--; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
globalContext.User.DepartmentList = departmentList; |
||||
|
|
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
App.Current.Dispatcher.Invoke(() => |
||||
|
{ |
||||
|
MessageBox.Show(ex.Message, "登录失败"); |
||||
|
}); |
||||
|
Environment.Exit(Environment.ExitCode); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,49 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.IO.Pipes; |
||||
|
|
||||
|
namespace Utils |
||||
|
{ |
||||
|
public class MemoryHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 获取token
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public static string GetMemoryToken() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
string pipeId = Environment.GetCommandLineArgs()[1]; |
||||
|
//创建输入类型匿名管道
|
||||
|
using (PipeStream pipeClient = new AnonymousPipeClientStream(PipeDirection.In, pipeId)) |
||||
|
{ |
||||
|
using (StreamReader sr = new StreamReader(pipeClient)) |
||||
|
{ |
||||
|
string temp; |
||||
|
|
||||
|
do |
||||
|
{ |
||||
|
temp = sr.ReadLine(); |
||||
|
} |
||||
|
while (!temp.StartsWith("SYNC")); |
||||
|
|
||||
|
|
||||
|
while ((temp = sr.ReadLine()) != null) |
||||
|
{ |
||||
|
return temp; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return string.Empty; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
return string.Empty; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
namespace U.Models |
||||
|
{ |
||||
|
public class PurchaseAccountResponse |
||||
|
{ |
||||
|
public long Id { get; set; } |
||||
|
|
||||
|
public string AccountName { get; set; } |
||||
|
|
||||
|
public long ShopId { get; set; } |
||||
|
|
||||
|
public Platform PurchasePlatformId { get; set; } |
||||
|
|
||||
|
public string AppKey { get; set; } |
||||
|
|
||||
|
public string AppSecret { get; set; } |
||||
|
|
||||
|
public string AppToken { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,86 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace U.Models |
||||
|
{ |
||||
|
public class ShopResponse |
||||
|
{ |
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
public Platform PlatformId { get; set; } |
||||
|
|
||||
|
public long? ShopId { get; set; } |
||||
|
|
||||
|
public string ShopName { get; set; } |
||||
|
|
||||
|
public string ShopType { get; set; } |
||||
|
|
||||
|
public string AppKey { get; set; } |
||||
|
|
||||
|
public string AppSecret { get; set; } |
||||
|
|
||||
|
public string AppToken { get; set; } |
||||
|
|
||||
|
public string AppKey2 { get; set; } |
||||
|
|
||||
|
public string AppSecret2 { get; set; } |
||||
|
|
||||
|
public string AppToken2 { get; set; } |
||||
|
|
||||
|
//public IList<PurchaseAccountResponse> PurchaseList { get; set; }
|
||||
|
|
||||
|
public string ManagePwd { get; set; } |
||||
|
|
||||
|
public decimal? PlatformCommissionRatio { get; set; } |
||||
|
|
||||
|
public string TeamId { get; set; } |
||||
|
|
||||
|
public string TeamName { get; set; } |
||||
|
|
||||
|
public string DingDingWebHook { get; set; } |
||||
|
|
||||
|
public string DingDingKey { get; set; } |
||||
|
|
||||
|
public int SkuSafeTurnoverDays { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南策略等级
|
||||
|
/// </summary>
|
||||
|
public int SiNanPolicyLevel { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
public string SiNanDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南钉钉密钥
|
||||
|
/// </summary>
|
||||
|
public string SiNanDingDingKey { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// U钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
public string UDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// U钉钉密钥
|
||||
|
/// </summary>
|
||||
|
public string UDingDingKey { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class DepartmentResponse |
||||
|
{ |
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public IList<ShopResponse> ShopList { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class DepartmentResponse2 |
||||
|
{ |
||||
|
public string DepartmentId { get; set; } |
||||
|
|
||||
|
public string DepartmentName { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace U.Models |
||||
|
{ |
||||
|
public class MDSUserResponse |
||||
|
{ |
||||
|
public long Id { get; set; } |
||||
|
public string DepartmentName { get; set; } |
||||
|
public string DepartmentId { get; set; } |
||||
|
|
||||
|
public string UserName { get; set; } |
||||
|
|
||||
|
public string UserNick { get; set; } |
||||
|
|
||||
|
public IList<DepartmentResponse2> SonDepartmentList { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace U.Models |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 电商平台
|
||||
|
/// </summary>
|
||||
|
public enum Platform |
||||
|
{ |
||||
|
淘宝 = 0, |
||||
|
京东 = 1, |
||||
|
阿里巴巴 = 2, |
||||
|
拼多多 = 3, |
||||
|
微信 = 4 |
||||
|
} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
using AutoMapper; |
||||
|
|
||||
|
namespace U.Models |
||||
|
{ |
||||
|
public class MappingProfile : Profile |
||||
|
{ |
||||
|
public MappingProfile() |
||||
|
{ |
||||
|
CreateMap<MDSUserResponse, User>().ForMember(t => t.TeamId, opt => opt.MapFrom(f => f.DepartmentId)) |
||||
|
.ForMember(t => t.TeamName, opt => opt.MapFrom(f => f.DepartmentName)) |
||||
|
.ForMember(t => t.Name, opt => opt.MapFrom(f => f.UserName)); |
||||
|
|
||||
|
CreateMap<ShopResponse, Shop>().ForMember(t => t.VenderType, opt => opt.MapFrom(f => f.ShopType)) |
||||
|
.ForMember(t => t.Platform, opt => opt.MapFrom(f => f.PlatformId)); |
||||
|
//.ForMember(t => t.PurchaseAccountList, opt => opt.MapFrom(f => f.PurchaseList));
|
||||
|
|
||||
|
CreateMap<PurchaseAccountResponse, PurchaseAccount>(); |
||||
|
CreateMap<DepartmentResponse, Department>(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
using System.ComponentModel; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
public class NotifyObject : INotifyPropertyChanged |
||||
|
{ |
||||
|
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
protected void OnPropertyChanged([CallerMemberName]string propertyName = "") |
||||
|
{ |
||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
||||
|
} |
||||
|
|
||||
|
protected bool Set<T>(ref T oldValue, T newValue, [CallerMemberName]string propertyName = "") |
||||
|
{ |
||||
|
if (Equals(oldValue, newValue)) |
||||
|
return false; |
||||
|
oldValue = newValue; |
||||
|
OnPropertyChanged(propertyName); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
public class Department : NotifyObject |
||||
|
{ |
||||
|
private bool isSelected; |
||||
|
|
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public IList<Shop> ShopList { get; set; } |
||||
|
public bool IsSelected |
||||
|
{ |
||||
|
get => isSelected; |
||||
|
set |
||||
|
{ |
||||
|
if (Set(ref isSelected, value)) |
||||
|
OnIsSelectedChanged?.Invoke(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Department() |
||||
|
{ |
||||
|
ShopList = new List<Shop>(); |
||||
|
} |
||||
|
|
||||
|
public Action OnIsSelectedChanged { get; set; } |
||||
|
|
||||
|
public override string ToString() |
||||
|
{ |
||||
|
return this.Name; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
using U.Models; |
||||
|
using System; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
public class PurchaseAccount : NotifyObject,ICloneable |
||||
|
{ |
||||
|
private string accountName; |
||||
|
private Platform purchasePlatformId; |
||||
|
private string appKey; |
||||
|
private string appSecret; |
||||
|
private string appToken; |
||||
|
|
||||
|
public long Id { get; set; } |
||||
|
|
||||
|
public long ShopId { get; set; } |
||||
|
public string AccountName { get => accountName; set { Set(ref accountName, value); } } |
||||
|
public Platform PurchasePlatformId { get => purchasePlatformId; set { Set(ref purchasePlatformId, value); } } |
||||
|
public string AppKey { get => appKey; set { Set(ref appKey, value); } } |
||||
|
public string AppSecret { get => appSecret; set { Set(ref appSecret, value); } } |
||||
|
public string AppToken { get => appToken; set { Set(ref appToken, value); } } |
||||
|
|
||||
|
public object Clone() |
||||
|
{ |
||||
|
return this.MemberwiseClone(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,89 @@ |
|||||
|
using U.Models; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
public class Shop : NotifyObject |
||||
|
{ |
||||
|
private bool isSelected; |
||||
|
private string shopName; |
||||
|
|
||||
|
public bool IsSelected { get => isSelected; set { Set(ref isSelected, value); } } |
||||
|
/// <summary>
|
||||
|
/// 店铺Id
|
||||
|
/// </summary>
|
||||
|
public long ShopId { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 商家类型
|
||||
|
/// </summary>
|
||||
|
public string VenderType { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺平台
|
||||
|
/// </summary>
|
||||
|
public Platform Platform { get; set; } |
||||
|
|
||||
|
public string AppKey { get; set; } |
||||
|
|
||||
|
public string AppSecret { get; set; } |
||||
|
|
||||
|
public string AppToken { get; set; } |
||||
|
|
||||
|
public string AppKey2 { get; set; } |
||||
|
|
||||
|
public string AppSecret2 { get; set; } |
||||
|
|
||||
|
public string AppToken2 { get; set; } |
||||
|
|
||||
|
public string ShopName { get => shopName; set { Set(ref shopName, value); } } |
||||
|
|
||||
|
//public IList<PurchaseAccount> PurchaseAccountList { get; set; }
|
||||
|
|
||||
|
public string ManagePwd { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 店铺扣点
|
||||
|
/// </summary>
|
||||
|
public decimal? PlatformCommissionRatio { get; set; } |
||||
|
|
||||
|
public string TeamId { get; set; } |
||||
|
|
||||
|
public string TeamName { get; set; } |
||||
|
|
||||
|
public string DingDingWebHook { get; set; } |
||||
|
|
||||
|
public string DingDingKey { get; set; } |
||||
|
|
||||
|
public int SkuSafeTurnoverDays { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南策略等级
|
||||
|
/// </summary>
|
||||
|
public int SiNanPolicyLevel { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
public string SiNanDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南钉钉密钥
|
||||
|
/// </summary>
|
||||
|
public string SiNanDingDingKey { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// U钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
public string UDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// U钉钉密钥
|
||||
|
/// </summary>
|
||||
|
public string UDingDingKey { get; set; } |
||||
|
|
||||
|
public override string ToString() |
||||
|
{ |
||||
|
return ShopName; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
public class User : NotifyObject |
||||
|
{ |
||||
|
//private string name;
|
||||
|
|
||||
|
private Shop shop; |
||||
|
|
||||
|
public long Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string TeamId { get; set; } |
||||
|
|
||||
|
public string TeamName { get; set; } |
||||
|
|
||||
|
public string SonDepartmentNames { get; set; } |
||||
|
|
||||
|
public Shop Shop { get => shop; set { Set(ref shop, value); } } |
||||
|
|
||||
|
public IList<Department> DepartmentList { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺列表 (暂时只有刷单组才需要)
|
||||
|
/// </summary>
|
||||
|
public IList<Shop> ShopList { get; set; } |
||||
|
|
||||
|
public string Token { get; set; } |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<OutputType>WinExe</OutputType> |
||||
|
<TargetFramework>net6.0-windows</TargetFramework> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<UseWPF>true</UseWPF> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.2-mauipre.1.22102.15" /> |
||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.2-mauipre.1.22054.8" /> |
||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" /> |
||||
|
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1829-prerelease" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\BBWYB.Common\BBWYB.Common.csproj" /> |
||||
|
<ProjectReference Include="..\SJ.Controls\SJ.Controls.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
@ -0,0 +1,69 @@ |
|||||
|
using BBWYB.Common.Models; |
||||
|
using Microsoft.Web.WebView2.Core; |
||||
|
using Microsoft.Web.WebView2.Wpf; |
||||
|
using System; |
||||
|
using io = System.IO; |
||||
|
|
||||
|
namespace U |
||||
|
{ |
||||
|
public class WebView2Manager : IDenpendency |
||||
|
{ |
||||
|
public WebView2 wb2 { get; private set; } |
||||
|
//public WebView2Manager()
|
||||
|
//{
|
||||
|
// Init();
|
||||
|
//}
|
||||
|
public void Init() |
||||
|
{ |
||||
|
if (wb2 == null) |
||||
|
{ |
||||
|
wb2 = new WebView2(); |
||||
|
var wb2Setting = CoreWebView2Environment.CreateAsync(userDataFolder: io.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WebView2UserData")).Result; |
||||
|
wb2.EnsureCoreWebView2Async(wb2Setting); |
||||
|
wb2.CoreWebView2InitializationCompleted += Wb2_CoreWebView2InitializationCompleted; |
||||
|
wb2.NavigationCompleted += Wb2_NavigationCompleted; |
||||
|
wb2.WebMessageReceived += Wb2_WebMessageReceived; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Action<CoreWebView2WebMessageReceivedEventArgs> OnWebMessageReceived; |
||||
|
public Action<CoreWebView2NavigationCompletedEventArgs> OnNavigationCompleted; |
||||
|
public Action<CoreWebView2InitializationCompletedEventArgs> CoreWebView2InitializationCompleted; |
||||
|
public bool IsInitializationCompleted { get ; private set; } |
||||
|
|
||||
|
private void Wb2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e) |
||||
|
{ |
||||
|
OnWebMessageReceived?.Invoke(e); |
||||
|
} |
||||
|
|
||||
|
private void Wb2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e) |
||||
|
{ |
||||
|
OnNavigationCompleted?.Invoke(e); |
||||
|
} |
||||
|
|
||||
|
private void Wb2_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e) |
||||
|
{ |
||||
|
CoreWebView2InitializationCompleted?.Invoke(e); |
||||
|
IsInitializationCompleted = true; |
||||
|
} |
||||
|
|
||||
|
public void Close() |
||||
|
{ |
||||
|
if (wb2 != null && wb2.CoreWebView2 != null) |
||||
|
{ |
||||
|
IsInitializationCompleted = false; |
||||
|
wb2.CoreWebView2InitializationCompleted -= Wb2_CoreWebView2InitializationCompleted; |
||||
|
wb2.NavigationCompleted -= Wb2_NavigationCompleted; |
||||
|
wb2.WebMessageReceived -= Wb2_WebMessageReceived; |
||||
|
var udf = wb2.CoreWebView2.Environment.UserDataFolder; |
||||
|
wb2.Dispose(); |
||||
|
wb2 = null; |
||||
|
try |
||||
|
{ |
||||
|
io.Directory.Delete(udf, true); |
||||
|
} |
||||
|
catch { } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue