feat: 客户余额人工调整写入账户流水
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s

新增 /customer/adjust-balance;更新接口忽略直接改余额,避免无痕调整。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-11 17:34:45 +08:00
parent f453661e46
commit 8a4a0787cd
6 changed files with 91 additions and 5 deletions

View File

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
namespace Oms.Application.Dtos.Customers;
/// <summary>
/// 人工调整客户账户余额入参。
/// </summary>
public class AdjustCustomerBalanceInput
{
/// <summary>
/// 客户主键。
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// 调整差额:正数入账、负数扣减,不能为 0。
/// </summary>
[Required]
public decimal Amount { get; set; }
/// <summary>
/// 调整原因(必填,写入流水备注)。
/// </summary>
[Required]
[StringLength(512, MinimumLength = 2)]
public string Remark { get; set; } = string.Empty;
}

View File

@ -52,7 +52,7 @@ public class UpdateCustomerInput
public string? WechatNickname { get; set; }
/// <summary>
/// 账户余额;不传则保留原值。
/// 账户余额(已废弃:更新接口忽略此字段,请走 /customer/adjust-balance 留痕)。
/// </summary>
[Range(typeof(decimal), "0", "999999999999")]
public decimal? Balance { get; set; }

View File

@ -141,6 +141,11 @@ public class CustomerAccountFlowService : ApplicationService
CustomerAccountFlowBizTypes.Recharge => "充值入账",
CustomerAccountFlowBizTypes.OrderPay => "订单支付",
CustomerAccountFlowBizTypes.PickupPay => "揽收支付",
CustomerAccountFlowBizTypes.ReferralCommission => "推荐佣金",
CustomerAccountFlowBizTypes.CommissionToBalance => "佣金转入余额",
CustomerAccountFlowBizTypes.CommissionWithdraw => "佣金提现",
CustomerAccountFlowBizTypes.MarketingAdjust => "营销调整",
CustomerAccountFlowBizTypes.ManualAdjust => "人工调整",
_ => bizType
};
}

View File

@ -56,6 +56,9 @@ public class CustomerService : ApplicationService
private CustomerServiceAdvisorResolver ServiceAdvisorResolver =>
LazyServiceProvider.GetRequiredService<CustomerServiceAdvisorResolver>();
private CustomerBalanceMutator BalanceMutator =>
LazyServiceProvider.GetRequiredService<CustomerBalanceMutator>();
/// <summary>
/// 查询客户列表。
/// </summary>
@ -377,10 +380,7 @@ public class CustomerService : ApplicationService
entity.WechatNickname = NormalizeOptionalText(input.WechatNickname);
}
if (input.Balance.HasValue)
{
entity.Balance = input.Balance.Value;
}
// 余额禁止在更新接口直接改写,避免无流水留痕;请使用 AdjustBalanceAsync
if (input.TotalQuota.HasValue)
{
@ -435,6 +435,27 @@ public class CustomerService : ApplicationService
await CustomerRepository.UpdateAsync(entity);
}
/// <summary>
/// 人工调整客户账户余额并写入账户流水。
/// </summary>
/// <param name="input">客户 Id、调整差额(可正可负)、必填原因。</param>
[HttpPost("/customer/adjust-balance")]
public async Task AdjustBalanceAsync(AdjustCustomerBalanceInput input)
{
if (input.Amount == 0)
{
throw new BusinessException("调整金额不能为 0");
}
if (string.IsNullOrWhiteSpace(input.Remark) || input.Remark.Trim().Length < 2)
{
throw new BusinessException("请填写调整原因");
}
var entity = await GetCustomerOrThrowAsync(input.Id);
await BalanceMutator.AdjustManualAsync(entity, input.Amount, input.Remark.Trim());
}
/// <summary>
/// 删除客户。
/// </summary>

View File

@ -138,6 +138,35 @@ public class CustomerBalanceMutator : IScopedDependency
cancellationToken);
}
/// <summary>
/// 运营人工调整余额(正数入账、负数扣减),写入账户流水。
/// </summary>
public Task AdjustManualAsync(
Customer customer,
decimal amount,
string remark,
CancellationToken cancellationToken = default)
{
if (amount == 0)
{
throw new BusinessException("调整金额不能为 0");
}
if (string.IsNullOrWhiteSpace(remark))
{
throw new BusinessException("调整原因不能为空");
}
return ApplyAsync(
customer,
amount,
CustomerAccountFlowBizTypes.ManualAdjust,
null,
null,
remark.Trim(),
cancellationToken);
}
private async Task ApplyAsync(
Customer customer,
decimal signedAmount,

View File

@ -18,4 +18,7 @@ public static class CustomerAccountFlowBizTypes
public const string CommissionWithdraw = "commissionWithdraw";
public const string MarketingAdjust = "marketingAdjust";
/// <summary>运营人工调整账户余额。</summary>
public const string ManualAdjust = "manualAdjust";
}