diff --git a/src/Oms.Application/Dtos/Customers/AdjustCustomerBalanceInput.cs b/src/Oms.Application/Dtos/Customers/AdjustCustomerBalanceInput.cs new file mode 100644 index 0000000..4186e2c --- /dev/null +++ b/src/Oms.Application/Dtos/Customers/AdjustCustomerBalanceInput.cs @@ -0,0 +1,28 @@ +using System.ComponentModel.DataAnnotations; + +namespace Oms.Application.Dtos.Customers; + +/// +/// 人工调整客户账户余额入参。 +/// +public class AdjustCustomerBalanceInput +{ + /// + /// 客户主键。 + /// + [Required] + public int Id { get; set; } + + /// + /// 调整差额:正数入账、负数扣减,不能为 0。 + /// + [Required] + public decimal Amount { get; set; } + + /// + /// 调整原因(必填,写入流水备注)。 + /// + [Required] + [StringLength(512, MinimumLength = 2)] + public string Remark { get; set; } = string.Empty; +} diff --git a/src/Oms.Application/Dtos/Customers/UpdateCustomerInput.cs b/src/Oms.Application/Dtos/Customers/UpdateCustomerInput.cs index 7e9fc36..b8f901b 100644 --- a/src/Oms.Application/Dtos/Customers/UpdateCustomerInput.cs +++ b/src/Oms.Application/Dtos/Customers/UpdateCustomerInput.cs @@ -52,7 +52,7 @@ public class UpdateCustomerInput public string? WechatNickname { get; set; } /// - /// 账户余额;不传则保留原值。 + /// 账户余额(已废弃:更新接口忽略此字段,请走 /customer/adjust-balance 留痕)。 /// [Range(typeof(decimal), "0", "999999999999")] public decimal? Balance { get; set; } diff --git a/src/Oms.Application/Services/Customers/CustomerAccountFlowService.cs b/src/Oms.Application/Services/Customers/CustomerAccountFlowService.cs index c1124f4..98953bb 100644 --- a/src/Oms.Application/Services/Customers/CustomerAccountFlowService.cs +++ b/src/Oms.Application/Services/Customers/CustomerAccountFlowService.cs @@ -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 }; } diff --git a/src/Oms.Application/Services/Customers/CustomerService.cs b/src/Oms.Application/Services/Customers/CustomerService.cs index 8a29a78..868a176 100644 --- a/src/Oms.Application/Services/Customers/CustomerService.cs +++ b/src/Oms.Application/Services/Customers/CustomerService.cs @@ -56,6 +56,9 @@ public class CustomerService : ApplicationService private CustomerServiceAdvisorResolver ServiceAdvisorResolver => LazyServiceProvider.GetRequiredService(); + private CustomerBalanceMutator BalanceMutator => + LazyServiceProvider.GetRequiredService(); + /// /// 查询客户列表。 /// @@ -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); } + /// + /// 人工调整客户账户余额并写入账户流水。 + /// + /// 客户 Id、调整差额(可正可负)、必填原因。 + [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()); + } + /// /// 删除客户。 /// diff --git a/src/Oms.Application/Shared/CustomerBalanceMutator.cs b/src/Oms.Application/Shared/CustomerBalanceMutator.cs index 4a904ea..4eb0372 100644 --- a/src/Oms.Application/Shared/CustomerBalanceMutator.cs +++ b/src/Oms.Application/Shared/CustomerBalanceMutator.cs @@ -138,6 +138,35 @@ public class CustomerBalanceMutator : IScopedDependency cancellationToken); } + /// + /// 运营人工调整余额(正数入账、负数扣减),写入账户流水。 + /// + 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, diff --git a/src/Oms.Domain/CustomersAggregate/Consts/CustomerAccountFlowBizTypes.cs b/src/Oms.Domain/CustomersAggregate/Consts/CustomerAccountFlowBizTypes.cs index e77fc24..ad03bfb 100644 --- a/src/Oms.Domain/CustomersAggregate/Consts/CustomerAccountFlowBizTypes.cs +++ b/src/Oms.Domain/CustomersAggregate/Consts/CustomerAccountFlowBizTypes.cs @@ -18,4 +18,7 @@ public static class CustomerAccountFlowBizTypes public const string CommissionWithdraw = "commissionWithdraw"; public const string MarketingAdjust = "marketingAdjust"; + + /// 运营人工调整账户余额。 + public const string ManualAdjust = "manualAdjust"; }