24 lines
1.2 KiB
C#
24 lines
1.2 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
namespace Store.Users.Contracts.Dtos;
|
|
|
|
/// <summary>资金请求;DTO 检查输入,服务区分积分/余额操作并校验权限。</summary>
|
|
public sealed class UserFundsRequest : IValidatableObject
|
|
{
|
|
[Required(ErrorMessage = "目标账户不能为空"), StringLength(20)] public string UserName { get; set; } = "";
|
|
[Required(ErrorMessage = "请求号不能为空"), StringLength(64)] public string RequestId { get; set; } = "";
|
|
[Range(typeof(decimal), "0.01", "1000000")]
|
|
public decimal Amount { get; set; }
|
|
/// <summary>积分支持充值、转移;余额支持充值、消费。</summary>
|
|
[Required(ErrorMessage = "操作类型不能为空"), StringLength(20)] public string Operation { get; set; } = "";
|
|
[StringLength(255)]
|
|
public string? Remark { get; set; }
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
if (decimal.Round(Amount, 2) != Amount)
|
|
yield return new ValidationResult("金额最多保留两位小数", [nameof(Amount)]);
|
|
}
|
|
}
|
|
|
|
public sealed record UserFundsResponse(string UserName, decimal Value, string RequestId);
|