修改统计功能 使用新API接口
This commit is contained in:
1 parent
03f71a5d64
commit
8431a8f6b0
6 files changed
+1117
-708
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using _29WxOrderWpf.Commands;
|
||||
using _29WxOrderWpf.Commands;
|
||||
using _29WxOrderWpf.Common;
|
||||
using _29WxOrderWpf.Ctrls.Statistics.Models;
|
||||
using _29WxOrderWpf.Ctrls.Statistics.Services;
|
||||
@@ -12,6 +12,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Work.BaseForms;
|
||||
|
||||
namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
|
||||
{
|
||||
@@ -31,6 +32,9 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
|
||||
private ObservableCollection<ShopOption> _selectedShops;
|
||||
private string _selectedPlatform;
|
||||
|
||||
/// <summary>上一次真正生效(并据此计算过日期)的时间范围选项,避免同一个选项被重复应用</summary>
|
||||
private TimeRangeOption _appliedTimeRange;
|
||||
|
||||
public ShopRevenueStatisticsViewModel()
|
||||
: this(new ShopRevenueStatisticsService())
|
||||
{
|
||||
@@ -70,7 +74,16 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
|
||||
set
|
||||
{
|
||||
this.SetValue(x => x.SelectedTimeRange, value);
|
||||
ApplyTimeRange();
|
||||
|
||||
// 只有用户真正切换到“另一个”时间范围选项时才重新计算起止日期。
|
||||
// 页签切换时下拉框会把同一个选项(甚至先 null 再回写)重放一遍,
|
||||
// 若照样重算,就会把用户手工调过的日期覆盖掉。
|
||||
if (value != null && !ReferenceEquals(_appliedTimeRange, value))
|
||||
{
|
||||
_appliedTimeRange = value;
|
||||
ApplyTimeRange();
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(IsCustomDateRange));
|
||||
}
|
||||
}
|
||||
@@ -235,57 +248,66 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>根据选中店铺生成查询店铺 key 列表:未选/全选/选中“全部店铺”时返回空列表(表示全部店铺)</summary>
|
||||
private List<string> BuildSelectedShopKeys()
|
||||
/// <summary>
|
||||
/// 根据选中店铺生成查询用 ERP 店铺ID 列表(接口 ShopIds 使用 ShopLoginInfo.ErpShopId):
|
||||
/// 未选/全选/选中“全部店铺”时返回空列表(表示全部店铺)。
|
||||
/// </summary>
|
||||
private List<string> BuildSelectedShopIds()
|
||||
{
|
||||
var selected = SelectedShops;
|
||||
if (selected == null || selected.Count == 0)
|
||||
return new List<string>();
|
||||
|
||||
var keys = selected.Select(s => s == null ? string.Empty : s.AppKey).ToList();
|
||||
if (keys.Any(string.IsNullOrEmpty))
|
||||
var ids = selected.Select(s => s == null ? string.Empty : s.ErpShopId).ToList();
|
||||
if (ids.Any(string.IsNullOrEmpty))
|
||||
return new List<string>();
|
||||
|
||||
if (selected.Count >= ShopOptions.Count)
|
||||
return new List<string>();
|
||||
|
||||
return keys;
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>执行查询,刷新页面所有统计数据</summary>
|
||||
private async Task LoadAsync()
|
||||
/// <summary>组装查询参数(起止日期已保证先后顺序)</summary>
|
||||
private ShopRevenueStatisticsQuery BuildQuery()
|
||||
{
|
||||
if (StartDate > EndDate)
|
||||
if (StartDate == EndDate)
|
||||
{
|
||||
EndDate = EndDate.AddDays(1).AddSeconds(-1);
|
||||
}
|
||||
else if (StartDate > EndDate)
|
||||
{
|
||||
var temp = StartDate;
|
||||
StartDate = EndDate;
|
||||
EndDate = temp;
|
||||
}
|
||||
|
||||
|
||||
return new ShopRevenueStatisticsQuery
|
||||
{
|
||||
StartDate = StartDate,
|
||||
EndDate = EndDate,
|
||||
ShopIds = BuildSelectedShopIds(),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>执行查询,刷新页面所有统计数据</summary>
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
try
|
||||
{
|
||||
var query = new ShopRevenueStatisticsQuery
|
||||
{
|
||||
StartDate = StartDate,
|
||||
EndDate = EndDate,
|
||||
ShopKeys = BuildSelectedShopKeys(),
|
||||
};
|
||||
var result = await _service.QueryAsync(BuildQuery());
|
||||
|
||||
Summary = await _service.GetSummaryAsync(query);
|
||||
|
||||
var trend = await _service.GetSalesTrendAsync(query);
|
||||
TrendData = new ObservableCollection<RevenueTrendPoint>(trend);
|
||||
|
||||
var proportion = await _service.GetShopSalesProportionAsync(query);
|
||||
ShopProportionData = new ObservableCollection<ShopSalesProportionItem>(proportion);
|
||||
|
||||
var table = await _service.GetShopStatisticsAsync(query);
|
||||
ShopStatistics = new ObservableCollection<ShopStatisticsItem>(table);
|
||||
Summary = result.Summary;
|
||||
TrendData = new ObservableCollection<RevenueTrendPoint>(result.Trend ?? new List<RevenueTrendPoint>());
|
||||
ShopProportionData = new ObservableCollection<ShopSalesProportionItem>(result.ShopProportions ?? new List<ShopSalesProportionItem>());
|
||||
ShopStatistics = new ObservableCollection<ShopStatisticsItem>(result.ShopStatistics ?? new List<ShopStatisticsItem>());
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 查询异常:保留上一次数据,可在此接入日志/错误提示
|
||||
// 查询异常:保留上一次数据,并弹框提示
|
||||
BaseMsgForm.ShowError("查询失败:" + ex.Message, "提示");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -309,35 +331,53 @@ namespace _29WxOrderWpf.Ctrls.Statistics.ViewModels
|
||||
|
||||
private async Task ShowOrderList(string type)
|
||||
{
|
||||
var query = new ShopRevenueStatisticsQuery
|
||||
var detailType = ParseDetailType(type);
|
||||
List<ShopOrderDetailResponse> showList;
|
||||
// 明细接口数据量大、耗时长,期间显示页面统一的加载遮罩,避免点了没反应
|
||||
IsLoading = true;
|
||||
try
|
||||
{
|
||||
StartDate = StartDate,
|
||||
EndDate = EndDate,
|
||||
ShopKeys = BuildSelectedShopKeys(),
|
||||
};
|
||||
var rows = await _service.QueryRowsAsync(query);
|
||||
List<ShopRevenueStatisticsRow> showList = new List<ShopRevenueStatisticsRow>();
|
||||
switch (type)
|
||||
{
|
||||
case "ValidOrderCount":
|
||||
showList = RevenueStatisticsAggregator.GetValidOrder(rows);
|
||||
break; //有效订单
|
||||
case "RefundOrderCount":
|
||||
showList = RevenueStatisticsAggregator.GetRefundOrder(rows);
|
||||
break;//退款订单
|
||||
case "BuyerRefundRemainingAmount":
|
||||
showList = RevenueStatisticsAggregator.GetBuyerRefundRemainingOrder(rows);
|
||||
break;//待退回采购金额
|
||||
default:
|
||||
break;
|
||||
showList = await _service.QueryOrderRowsAsync(BuildQuery(), detailType)
|
||||
?? new List<ShopOrderDetailResponse>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError("订单明细查询失败:" + ex.Message, "提示");
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
if (showList.Count == 0)
|
||||
{
|
||||
BaseMsgForm.ShowInfo("未查询到符合条件的订单明细。", "提示");
|
||||
return;
|
||||
}
|
||||
|
||||
new DialogWindow(GetWindow())
|
||||
{
|
||||
Title="订单列表",
|
||||
Title = "订单列表",
|
||||
Content = new ShowOrderDialogView(showList),
|
||||
DataContext = rows
|
||||
DataContext = showList
|
||||
}.Show();
|
||||
}
|
||||
|
||||
/// <summary>卡片“明细”按钮参数 → 订单明细类型(对应接口参数 OrderType)</summary>
|
||||
private static ShopOrderDetailType ParseDetailType(string type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "RefundOrderCount":
|
||||
return ShopOrderDetailType.Refund; //退款订单
|
||||
case "BuyerRefundRemainingAmount":
|
||||
return ShopOrderDetailType.BuyerUnrefunded; //买手未退回金额的订单
|
||||
default:
|
||||
return ShopOrderDetailType.Valid; //有效订单
|
||||
}
|
||||
}
|
||||
|
||||
public Func<Window> GetWindow;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user