Merge branch 'main' of github.com:jtt-fan/29WxOrder

This commit is contained in:
wule committed 2026-08-26 07:32:39 +08:00
commit d4f96b0880
3 files changed
+148 -28

No files matched your search

@@ -289,7 +289,21 @@
VerticalContentAlignment="Center"
Text="{Binding TaxNo}" />
</wpf:TitleContent>
<CheckBox Content="显示订单窗口" IsChecked="{Binding IsOrderListDialogOpen}" />
<wpf:TitleContent
Title="最大金额:"
VerticalContentAlignment="Center"
Placement="Left"
TitleVerticalAlignment="Center">
<wpf:NumberBox
Width="80"
Maximum="999999"
Minimum="0"
Value="{Binding MaxAmount}" />
</wpf:TitleContent>
<CheckBox
VerticalContentAlignment="Center"
Content="显示订单窗口"
IsChecked="{Binding IsOrderListDialogOpen}" />
</wpf:SpacingStackPanel>
</Border>
<!-- 订单列表(已移除分页与订单分组) -->
@@ -310,7 +324,7 @@
<!-- 表头 -->
<Border
Grid.Row="0"
Padding="20,14"
Padding="20,10"
Background="{StaticResource RowBgBrush}"
BorderBrush="{StaticResource SplitLineBrush}"
BorderThickness="0,0,0,1">
@@ -322,7 +336,7 @@
<ColumnDefinition Width="80" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1.2*" />
<ColumnDefinition Width="1.5*" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Column="0"
@@ -341,10 +355,23 @@
Content="反选"
Style="{StaticResource LinkButtonStyle}" />-->
</StackPanel>
<TextBlock
Grid.Column="1"
Style="{StaticResource HeaderCellTextStyle}"
Text="商品信息" />
<WrapPanel Grid.Column="1">
<TextBlock Style="{StaticResource HeaderCellTextStyle}" Text="商品信息" />
<TextBlock Margin="10,0,0,0" Style="{StaticResource HeaderCellTextStyle}">
<TextBlock.Text>
<MultiBinding StringFormat="({0}/{1})">
<Binding Path="SelectedCount" />
<Binding Path="Orders.Count" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock
Margin="10,0,0,0"
FontSize="14"
FontWeight="Black"
Foreground="{StaticResource SuccessBrush}"
Text="{Binding AmountTotal, StringFormat='已开 {0} 金额'}" />
</WrapPanel>
<TextBlock
Grid.Column="3"
Style="{StaticResource HeaderCellTextStyle}"
@@ -353,10 +380,19 @@
Grid.Column="4"
Style="{StaticResource HeaderCellTextStyle}"
Text="实付金额" />
<TextBlock
Grid.Column="5"
Style="{StaticResource HeaderCellTextStyle}"
Text="发票" />
<WrapPanel Grid.Column="5">
<TextBlock
Margin="0,0,20,0"
Style="{StaticResource HeaderCellTextStyle}"
Text="发票" />
<TextBlock Foreground="{StaticResource SuccessBrush}" Text="{Binding InvoicedAmountTotal, StringFormat='已开:¥{0:N2}'}" />
<TextBlock
Margin="5,0"
Foreground="LightGray"
Text="/" />
<TextBlock Foreground="{StaticResource AmountBrush}" Text="{Binding UninvoicedAmountTotal, StringFormat='未开:¥{0:N2}'}" />
</WrapPanel>
<TextBlock
Grid.Column="6"
Style="{StaticResource HeaderCellTextStyle}"
@@ -435,7 +471,7 @@
<ColumnDefinition Width="80" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1.2*" />
<ColumnDefinition Width="1.5*" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<!-- 勾选 -->
@@ -443,7 +479,8 @@
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsChecked="{Binding IsSelected}" />
IsChecked="{Binding IsSelected}"
IsEnabled="{Binding IsSelected}" />
<!-- 商品 -->
<Grid Grid.Column="1" VerticalAlignment="Center">
@@ -71,7 +71,7 @@ public class PddBrowserOrderInvoiceViewModel : BindableBaseEx
public int Quantity => order_Goods?.Sum(a => a.goods_number.Value) ?? 0;
/// <summary> 发票状态文案:已开票 / 待开票 </summary>
public string InvoiceStatusText => IsInvoiced ? "已开票" : "待开票";
public string InvoiceStatusText => IsInvoiced ? "已提交申请" : "待开票";
public DateTime OrderTime
@@ -10,6 +10,7 @@ using AllBase.Util;
using CefSharp;
using CefSharp.Handler;
using CefSharp.Wpf;
using MAX.Core.Helpers;
using NaiBa.Util.Extension;
using Newtonsoft.Json;
using System;
@@ -50,15 +51,23 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
private string _taxNo = "";
private CancellationTokenSource _cancellationTokenSource; public PDDInvoiceViewModel()
{
Orders = new ObservableCollection<PddBrowserOrderInvoiceViewModel>();
Orders.CollectionChanged += Orders_CollectionChanged;
BuyerLoginList = GlobalConfig.PDDBuyerLoginList;
//Orders = new ObservableCollection<PDDInvoiceOrderModel>(_allOrders);
//_ = InitSampleData();
InitBrowser();
if (EnvironmentHelper.IsTest)
{
InvoiceTitle = "嵩县雷神商贸有限责任公司";
TaxNo = "91410325MADQERT68E";
MaxAmount = 99;
_ = InitSampleData();
}
}
partial void InitBrowser();
@@ -164,7 +173,38 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
get => _taxNo;
set => SetProperty(ref _taxNo, value, nameof(TaxNo));
}
/// <summary>
/// 开始开票总金额
/// </summary>
public decimal AmountTotal
{
get => GetValue<decimal>();
set => SetValue(value);
}
/// <summary>
/// 最大开票金额
/// </summary>
public decimal MaxAmount
{
get => GetValue<decimal>();
set => SetValue(value);
}
/// <summary>
/// 已开票金额
/// </summary>
public decimal InvoicedAmountTotal
{
get => GetValue<decimal>();
set => SetValue(value);
}
/// <summary>
/// 未开票金额
/// </summary>
public decimal UninvoicedAmountTotal
{
get => GetValue<decimal>();
set => SetValue(value);
}
public ICommand SearchCommand => new DelegateCommand(Search);
public ICommand ResetCommand => new DelegateCommand(ResetSearch);
@@ -219,7 +259,11 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
#region 勾选 / 全选 / 反选
public int SelectedCount
{
get => GetValue<int>();
set => SetValue(value);
}
private bool? _isSelectAll;
private bool _isUpdatingSelectAll;
@@ -235,7 +279,13 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
if (_isUpdatingSelectAll) return;
if (value == true)
{
foreach (var order in Orders) order.IsSelected = true;
foreach (var order in Orders)
{
if (order.IsInvoiced == false)
{
order.IsSelected = true;
}
}
}
else if (value == false)
{
@@ -267,6 +317,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
}
int selected = Orders.Count(o => o.IsSelected);
IsSelectAll = selected == 0 ? false : selected == Orders.Count ? true : (bool?)null;
SelectedCount = selected;
}
finally
{
@@ -310,9 +361,13 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
BaseMsgWindow.ShowError("请先勾选需要开票的订单");
return;
}
if (MaxAmount <= 0)
{
BaseMsgWindow.ShowError("请填写开票总金额");
return;
}
var confirm = BaseMsgWindow.ShowConfirm(
$"已勾选 {targets.Count} 个待开票订单,确定开始批量开票吗?\n请确认发票抬头与税号无误。",
$"已勾选 {targets.Count} 个待开票订单,确定开始批量开票吗?\n请确认发票抬头与税号无误。\n开票总金额:{MaxAmount}",
"批量开票");
if (confirm.DialogResult != true) return;
@@ -325,6 +380,7 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
private async Task BatchInvoiceAsync(List<PddBrowserOrderInvoiceViewModel> targets)
{
IsBatchInvoicing = true;
AmountTotal = 0;
int success = 0, fail = 0;
try
{
@@ -334,26 +390,43 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
for (int i = 0; i < targets.Count; i++)
{
if (AmountTotal >= MaxAmount)
{
return;
}
var order = targets[i];
BottomMsg = $"正在批量开票:{i}/{targets.Count},当前订单:{order.order_sn}";
ProgressValue = i;
bool ok = false;
if (EnvironmentHelper.IsTest)
{
ok = true;
await Task.Delay(1000);
}
else
{
_currentInvoiceTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
BrowserDetail.Load($"https://mobile.yangkeduo.com/transac_return_compensation.html?_t_timestamp=transac_modify_invoice&order_sn={order.order_sn}");
_currentInvoiceTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
BrowserDetail.Load($"https://mobile.yangkeduo.com/transac_return_compensation.html?_t_timestamp=transac_modify_invoice&order_sn={order.order_sn}");
// 等待页面脚本执行完成(最长 60 秒)
var done = await Task.WhenAny(_currentInvoiceTcs.Task, Task.Delay(TimeSpan.FromSeconds(60)));
bool ok = done == _currentInvoiceTcs.Task && _currentInvoiceTcs.Task.Result;
// 等待页面脚本执行完成(最长 60 秒)
var done = await Task.WhenAny(_currentInvoiceTcs.Task, Task.Delay(TimeSpan.FromSeconds(60)));
ok = done == _currentInvoiceTcs.Task && _currentInvoiceTcs.Task.Result;
}
if (ok)
{
order.IsInvoiced = true;
order.IsSelected = false;
success++;
AmountTotal += order.order_amount / 100m;
}
else
{
fail++;
}
ProgressValue = success + fail;
BottomMsg = $"正在批量开票:{i}/{targets.Count},当前订单:{order.order_sn}。总金额:{AmountTotal.ToString("N2")}";
StatisticsInvoiceAmount();
await Task.Delay(1000);
}
}
catch (Exception ex)
@@ -366,11 +439,19 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
_currentInvoiceTcs = null;
ProgressMaximum = targets.Count;
ProgressValue = targets.Count;
BottomMsg = $"批量开票完成:成功 {success} 个,失败 {fail} 个";
BottomMsg = $"批量开票完成:成功 {success} 个,失败 {fail} 个。总金额:{AmountTotal.ToString("N2")}";
IsBatchInvoicing = false;
BaseMsgWindow.ShowInfo(BottomMsg);
}
}
/// <summary>
/// 统计发票金额
/// </summary>
private void StatisticsInvoiceAmount()
{
InvoicedAmountTotal = Orders.Where(a => a.IsInvoiced).Sum(a => a.order_amount) / 100m;
UninvoicedAmountTotal = Orders.Where(a => a.IsInvoiced == false).Sum(a => a.order_amount) / 100m;
}
#endregion
@@ -489,6 +570,8 @@ public partial class PDDInvoiceViewModel : BindableBaseEx
Orders.Add(item);
}
}
StatisticsInvoiceAmount();
}
#endregion