feat: 支持可配置充值收款码,并补客户监控下钻筛选
All checks were successful
Build and Deploy / deploy (push) Successful in 5m14s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-07 12:33:53 +08:00
parent 9bbdd73690
commit c4eb12c3ee
7 changed files with 168 additions and 4 deletions

View File

@ -45,6 +45,12 @@ public class CustomerPaginatedInput
/// <summary>按绑定代理 Id 筛选。</summary> /// <summary>按绑定代理 Id 筛选。</summary>
public int? AgentId { get; set; } public int? AgentId { get; set; }
/// <summary>
/// 监控页客户 KPI 下钻口径:total / newToday / online / inactive7d。
/// 与 /monitor/overview 客户统计一致;传入时默认仅 Normal 客户。
/// </summary>
public string? MonitorScope { get; set; }
/// <summary> /// <summary>
/// 排序字段:createTime / updateTime / customerCode / customerName / balance。 /// 排序字段:createTime / updateTime / customerCode / customerName / balance。
/// </summary> /// </summary>

View File

@ -0,0 +1,17 @@
namespace Oms.Application.Dtos.System;
/// <summary>
/// 充值收款码展示输出。
/// </summary>
public class PaymentReceiveQrOutput
{
/// <summary>
/// 支付宝收款码可访问 URL;未配置时为空。
/// </summary>
public string AlipayUrl { get; set; } = string.Empty;
/// <summary>
/// 微信收款码可访问 URL;未配置时为空。
/// </summary>
public string WechatUrl { get; set; } = string.Empty;
}

View File

@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Http;
namespace Oms.Application.Dtos.System;
/// <summary>
/// 上传充值收款码入参(multipart/form-data:channel + file)。
/// </summary>
public class PaymentReceiveQrUploadInput
{
/// <summary>
/// 渠道:alipay / wechat。
/// </summary>
public string Channel { get; set; } = string.Empty;
/// <summary>
/// 收款码图片。
/// </summary>
public IFormFile File { get; set; } = null!;
}

View File

@ -518,6 +518,13 @@ public class CustomerService : ApplicationService
var customerGroupValue = input.CustomerGroup.GetValueOrDefault(); var customerGroupValue = input.CustomerGroup.GetValueOrDefault();
var hasAgentFilter = input.AgentId is > 0; var hasAgentFilter = input.AgentId is > 0;
var agentId = input.AgentId.GetValueOrDefault(); var agentId = input.AgentId.GetValueOrDefault();
var monitorScope = NormalizeMonitorScope(input.MonitorScope);
var hasMonitorScope = !string.IsNullOrEmpty(monitorScope);
// 与 /monitor/overview 客户 KPI 同一时间口径
var today = DateTime.Today;
var tomorrow = today.AddDays(1);
var inactive7dThreshold = today.AddDays(-7);
var onlineSince = DateTime.Now.AddMinutes(-30);
return customer => return customer =>
(string.IsNullOrWhiteSpace(keyword) || (string.IsNullOrWhiteSpace(keyword) ||
@ -526,10 +533,32 @@ public class CustomerService : ApplicationService
(customer.Phone ?? string.Empty).Contains(keyword) || (customer.Phone ?? string.Empty).Contains(keyword) ||
(customer.Email ?? string.Empty).Contains(keyword)) && (customer.Email ?? string.Empty).Contains(keyword)) &&
(!hasStatusFilter || customer.Status == statusValue) && (!hasStatusFilter || customer.Status == statusValue) &&
(!hasMonitorScope || customer.Status == CustomerStatus.Normal) &&
(!hasCustomerGroupFilter || customer.CustomerGroup == customerGroupValue) && (!hasCustomerGroupFilter || customer.CustomerGroup == customerGroupValue) &&
(string.IsNullOrWhiteSpace(salesman) || customer.Salesman == salesman) && (string.IsNullOrWhiteSpace(salesman) || customer.Salesman == salesman) &&
(string.IsNullOrWhiteSpace(customerService) || customer.CustomerService == customerService) && (string.IsNullOrWhiteSpace(customerService) || customer.CustomerService == customerService) &&
(!hasAgentFilter || customer.AgentId == agentId); (!hasAgentFilter || customer.AgentId == agentId) &&
(monitorScope != "newToday" || (customer.CreateTime >= today && customer.CreateTime < tomorrow)) &&
(monitorScope != "online" ||
(customer.LastLoginTime != null && customer.LastLoginTime >= onlineSince)) &&
(monitorScope != "inactive7d" ||
(customer.LastLoginTime == null || customer.LastLoginTime < inactive7dThreshold));
}
/// <summary>
/// 规范化监控下钻口径;非法值视为无筛选。
/// </summary>
private static string? NormalizeMonitorScope(string? scope)
{
var value = (scope ?? string.Empty).Trim().ToLowerInvariant();
return value switch
{
"total" => "total",
"newtoday" => "newToday",
"online" => "online",
"inactive7d" => "inactive7d",
_ => null,
};
} }
private async Task<Dictionary<int, (string Code, string Name)>> ResolveAgentDisplayMapAsync( private async Task<Dictionary<int, (string Code, string Name)>> ResolveAgentDisplayMapAsync(

View File

@ -1,9 +1,11 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using Fake.Application; using Fake.Application;
using Fake.ObjectStorage;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Oms.Application.Dtos.Shared; using Oms.Application.Dtos.Shared;
using Oms.Application.Dtos.System; using Oms.Application.Dtos.System;
using Oms.Application.Shared; using Oms.Application.Shared;
using Oms.Application.Storage;
using Oms.Domain.SystemAggregate.Consts; using Oms.Domain.SystemAggregate.Consts;
using Oms.Domain.SystemAggregate.Entities; using Oms.Domain.SystemAggregate.Entities;
using Oms.Domain.SystemAggregate.Repositories; using Oms.Domain.SystemAggregate.Repositories;
@ -17,10 +19,14 @@ namespace Oms.Application.Services.System;
public class SystemOtherConfigService : ApplicationService public class SystemOtherConfigService : ApplicationService
{ {
private const string SecretMask = "******"; private const string SecretMask = "******";
private const string PaymentQrChannelAlipay = "alipay";
private const string PaymentQrChannelWechat = "wechat";
private ISystemOtherConfigRepository SystemOtherConfigRepository => private ISystemOtherConfigRepository SystemOtherConfigRepository =>
LazyServiceProvider.GetRequiredService<ISystemOtherConfigRepository>(); LazyServiceProvider.GetRequiredService<ISystemOtherConfigRepository>();
private IObjectStorage FileStorage => LazyServiceProvider.GetRequiredService<IObjectStorage>();
/// <summary> /// <summary>
/// 查询系统其他配置列表。 /// 查询系统其他配置列表。
/// </summary> /// </summary>
@ -140,13 +146,92 @@ public class SystemOtherConfigService : ApplicationService
await SystemOtherConfigRepository.DeleteAsync(entity); await SystemOtherConfigRepository.DeleteAsync(entity);
} }
/// <summary>
/// 获取客户充值用支付宝/微信收款码图片地址。未配置时对应 URL 为空(前端可回退本地默认图)。
/// </summary>
[HttpGet("/system/other-config/payment-qr")]
public async Task<PaymentReceiveQrOutput> GetPaymentReceiveQrAsync()
{
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
return new PaymentReceiveQrOutput
{
AlipayUrl = FileStorage.GetPublicUrl(entity?.AppKey),
WechatUrl = FileStorage.GetPublicUrl(entity?.Remark)
};
}
/// <summary>
/// 上传并替换充值收款码图片。Channel=alipay|wechat;返回最新支付宝/微信可访问 URL。
/// </summary>
/// <param name="input">入参:渠道 + 图片文件。</param>
[HttpPost("/system/other-config/payment-qr/upload")]
[Consumes("multipart/form-data")]
public async Task<PaymentReceiveQrOutput> UploadPaymentReceiveQrAsync([FromForm] PaymentReceiveQrUploadInput input)
{
var channel = (input.Channel ?? string.Empty).Trim().ToLowerInvariant();
if (channel is not (PaymentQrChannelAlipay or PaymentQrChannelWechat))
{
throw new BusinessException("渠道仅支持 alipay 或 wechat");
}
var key = await OmsFileUploadHelper.SavePaymentReceiveQrAsync(input.File, FileStorage);
var entity = await EnsurePaymentReceiveQrConfigAsync();
if (channel == PaymentQrChannelAlipay)
{
entity.AppKey = key;
}
else
{
entity.Remark = key;
}
await SystemOtherConfigRepository.UpdateAsync(entity);
return new PaymentReceiveQrOutput
{
AlipayUrl = FileStorage.GetPublicUrl(entity.AppKey),
WechatUrl = FileStorage.GetPublicUrl(entity.Remark)
};
}
private async Task<SystemOtherConfig> EnsurePaymentReceiveQrConfigAsync()
{
var entity = await SystemOtherConfigRepository.GetByConfigCodeAsync(SystemOtherConfigCodes.PaymentReceiveQr);
if (entity != null)
{
return entity;
}
var deleted = await SystemOtherConfigRepository.GetByConfigCodeIncludingDeletedAsync(
SystemOtherConfigCodes.PaymentReceiveQr);
if (deleted != null)
{
deleted.IsDeleted = false;
deleted.ConfigName = "充值收款码";
deleted.Enabled = true;
deleted.TimeoutSeconds = 30;
deleted.BaseUrl = null;
deleted.AppSecret = null;
await SystemOtherConfigRepository.UpdateAsync(deleted);
return deleted;
}
return await SystemOtherConfigRepository.InsertAsync(new SystemOtherConfig
{
ConfigCode = SystemOtherConfigCodes.PaymentReceiveQr,
ConfigName = "充值收款码",
Enabled = true,
TimeoutSeconds = 30
});
}
private static Expression<Func<SystemOtherConfig, bool>> BuildListPredicate(SystemOtherConfigListInput input) private static Expression<Func<SystemOtherConfig, bool>> BuildListPredicate(SystemOtherConfigListInput input)
{ {
var keyword = input.Keyword?.Trim(); var keyword = input.Keyword?.Trim();
return x => return x =>
string.IsNullOrWhiteSpace(keyword) || x.ConfigCode != SystemOtherConfigCodes.PaymentReceiveQr
x.ConfigCode.Contains(keyword) || && (string.IsNullOrWhiteSpace(keyword)
x.ConfigName.Contains(keyword); || x.ConfigCode.Contains(keyword)
|| x.ConfigName.Contains(keyword));
} }
private async Task<SystemOtherConfig> GetConfigOrThrowAsync(int id) private async Task<SystemOtherConfig> GetConfigOrThrowAsync(int id)

View File

@ -26,6 +26,9 @@ public static class OmsFileUploadHelper
public static Task<string> SaveWarehouseParcelImageAsync(IFormFile file, IObjectStorage storage) => public static Task<string> SaveWarehouseParcelImageAsync(IFormFile file, IObjectStorage storage) =>
SaveImageAsync(file, storage, "parcel", "包裹商品图片"); SaveImageAsync(file, storage, "parcel", "包裹商品图片");
public static Task<string> SavePaymentReceiveQrAsync(IFormFile file, IObjectStorage storage) =>
SaveImageAsync(file, storage, "payment-qr", "收款码图片");
private static async Task<string> SaveImageAsync( private static async Task<string> SaveImageAsync(
IFormFile? file, IFormFile? file,
IObjectStorage storage, IObjectStorage storage,

View File

@ -59,4 +59,9 @@ public static class SystemOtherConfigCodes
/// 国内揽收服务商推送件重尺/费用(历史配置;鉴权已改由 itfx 上游应用完成,OMS 不再校验 AppKey)。 /// 国内揽收服务商推送件重尺/费用(历史配置;鉴权已改由 itfx 上游应用完成,OMS 不再校验 AppKey)。
/// </summary> /// </summary>
public const string PickupOpenApi = "pickup_open_api"; public const string PickupOpenApi = "pickup_open_api";
/// <summary>
/// 客户充值收款码(AppKey=支付宝收款码 object key,Remark=微信收款码 object key)。
/// </summary>
public const string PaymentReceiveQr = "payment_receive_qr";
} }