87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Dlhis.Entity.Canteen.Enums;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
|
|
namespace Dlhis.Canteen.Order.Request;
|
|
|
|
public class OrderAddRequest : IValidatableObject
|
|
{
|
|
/// <summary>
|
|
/// 是否离线数据
|
|
/// </summary>
|
|
public bool IsOffline { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 消费机器唯一信息
|
|
/// </summary>
|
|
public string DeviceUniqueNo { get; set; }
|
|
|
|
/// <summary>
|
|
/// 第三方订单号
|
|
/// </summary>
|
|
public string ThirdNo { get; set; }
|
|
|
|
/// <summary>
|
|
/// 档案号/QrCode/学工号
|
|
/// </summary>
|
|
[Required(ErrorMessage = "人员档案号/QrCode/学工号不能为空")]
|
|
public string UserUniqueNo { get; set; }
|
|
|
|
/// <summary>
|
|
/// 来源
|
|
/// </summary>
|
|
[EnumDataType(typeof(BalanceRecordSourceEnumType))]
|
|
public BalanceRecordSourceEnumType Source { get; set; }
|
|
|
|
/// <summary>
|
|
/// 收入/支出
|
|
/// </summary>
|
|
[EnumDataType(typeof(BalanceRecordTypeEnumType))]
|
|
public BalanceRecordTypeEnumType? Type { get; set; } = BalanceRecordTypeEnumType.Out;
|
|
|
|
/// <summary>
|
|
/// 金额
|
|
/// </summary>
|
|
[Range(0.01, double.MaxValue)]
|
|
public decimal Amount { get; set; }
|
|
|
|
/// <summary>
|
|
/// 产生时间
|
|
/// </summary>
|
|
public DateTime? CostDateTime { get; set; }
|
|
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
//处理金额
|
|
Amount = Type == BalanceRecordTypeEnumType.In ? Math.Abs(Amount) : -Math.Abs(Amount);
|
|
|
|
if (Type == BalanceRecordTypeEnumType.Out)
|
|
{
|
|
//处理消费类型
|
|
if ((int)Source >= (int)BalanceRecordSourceEnumType.Wechat)
|
|
{
|
|
yield return new ValidationResult($"不支持来源{Source.GetDescription()}", new[] { nameof(Source) });
|
|
}
|
|
|
|
//在线就以API时间为准
|
|
if (!IsOffline)
|
|
{
|
|
CostDateTime = DateTime.Now;
|
|
}
|
|
|
|
if (DeviceUniqueNo.IsEmpty())
|
|
{
|
|
yield return new ValidationResult("设备唯一号不能为空", new[] { nameof(DeviceUniqueNo) });
|
|
}
|
|
}
|
|
else if (Type == BalanceRecordTypeEnumType.In)
|
|
{
|
|
if ((int)Source < (int)BalanceRecordSourceEnumType.Wechat)
|
|
{
|
|
yield return new ValidationResult($"不支持来源{Source.GetDescription()}", new[] { nameof(Source) });
|
|
}
|
|
}
|
|
}
|
|
}
|