chore 优化代码
This commit is contained in:
@ -1,157 +1,171 @@
|
||||
using KonSoft.Admin.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using KonSoft.Admin.Enums;
|
||||
using Volo.Abp.Domain.Entities.Auditing;
|
||||
using Volo.Abp.Identity;
|
||||
|
||||
namespace KonSoft.Admin.Entities
|
||||
namespace KonSoft.Admin.Entities;
|
||||
|
||||
public class Order : FullAuditedAggregateRoot<Guid>
|
||||
{
|
||||
public class Order : FullAuditedAggregateRoot<Guid>
|
||||
protected Order()
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单编号
|
||||
/// </summary>
|
||||
public string OrderSN { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public Guid CustomerId { get; private set; }
|
||||
/// <summary>
|
||||
/// 家政人员ID
|
||||
/// </summary>
|
||||
public Guid? WorkerId { get; private set; }
|
||||
|
||||
///// <summary>
|
||||
///// 用户ID
|
||||
///// </summary>
|
||||
//public virtual IdentityUser Customer { get; private set; }
|
||||
///// <summary>
|
||||
///// 家政人员ID
|
||||
///// </summary>
|
||||
//public virtual IdentityUser? Worker { get; private set; }
|
||||
/// <summary>
|
||||
/// 服务项目ID
|
||||
/// </summary>
|
||||
public Guid ServiceCategoryId { get; private set; }
|
||||
|
||||
public virtual ServiceCategory ServiceCategory { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务预约时间
|
||||
/// </summary>
|
||||
public DateTime ServiceTime { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应付金额
|
||||
/// </summary>
|
||||
public decimal Amount { get; private set; }
|
||||
/// <summary>
|
||||
/// 实付金额
|
||||
/// </summary>
|
||||
public decimal PaidAmount { get; private set; }
|
||||
/// <summary>
|
||||
/// 支付方式
|
||||
/// </summary>
|
||||
public string PaymentMethod { get; private set; }
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public AddressInfo Address { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? Remark { get; private set; }
|
||||
/// <summary>
|
||||
/// 取消原因
|
||||
/// </summary>
|
||||
public string? CancelReason { get; private set; }
|
||||
|
||||
protected Order() { }
|
||||
|
||||
|
||||
public Order(Guid id, string orderSN, Guid customerId, Guid serviceCategoryId, DateTime serviceTime, decimal amount, AddressInfo address, string remark = null)
|
||||
: base(id)
|
||||
{
|
||||
OrderSN = orderSN;
|
||||
CustomerId = customerId;
|
||||
ServiceCategoryId = serviceCategoryId;
|
||||
ServiceTime = serviceTime;
|
||||
Amount = amount;
|
||||
Address = address;
|
||||
Remark = remark;
|
||||
Status = OrderStatus.PendingPayment;
|
||||
}
|
||||
|
||||
|
||||
public void MarkPaid(decimal paidAmount, string method)
|
||||
{
|
||||
if (Status != OrderStatus.PendingPayment)
|
||||
throw new InvalidOperationException("订单不在待付款状态");
|
||||
|
||||
|
||||
PaidAmount = paidAmount;
|
||||
PaymentMethod = method;
|
||||
Status = OrderStatus.PaidWaitingAssign;
|
||||
}
|
||||
|
||||
|
||||
public void AssignWorker(Guid workerId)
|
||||
{
|
||||
if (Status != OrderStatus.PaidWaitingAssign)
|
||||
throw new InvalidOperationException("订单无法分配师傅");
|
||||
|
||||
|
||||
WorkerId = workerId;
|
||||
Status = OrderStatus.AssignedWaitingService;
|
||||
}
|
||||
|
||||
|
||||
public void StartService()
|
||||
{
|
||||
if (Status != OrderStatus.AssignedWaitingService)
|
||||
throw new InvalidOperationException("订单无法开始");
|
||||
|
||||
|
||||
Status = OrderStatus.InService;
|
||||
}
|
||||
|
||||
|
||||
public void CompleteService()
|
||||
{
|
||||
if (Status != OrderStatus.InService)
|
||||
throw new InvalidOperationException("订单未开始服务,无法完成");
|
||||
|
||||
|
||||
Status = OrderStatus.WaitingConfirm;
|
||||
}
|
||||
|
||||
|
||||
public void ConfirmCompletion()
|
||||
{
|
||||
if (Status != OrderStatus.WaitingConfirm)
|
||||
throw new InvalidOperationException("订单无法确认");
|
||||
|
||||
|
||||
Status = OrderStatus.Completed;
|
||||
}
|
||||
|
||||
|
||||
public void Cancel(string reason)
|
||||
{
|
||||
// 若已完成或退款中则不可取消
|
||||
if (Status == OrderStatus.Completed || Status == OrderStatus.Refunding || Status == OrderStatus.Refunded)
|
||||
throw new InvalidOperationException("订单无法被取消");
|
||||
|
||||
|
||||
CancelReason = reason;
|
||||
Status = OrderStatus.Canceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Order(Guid id, string orderSN, Guid customerId, Guid serviceCategoryId, DateTime serviceTime, decimal amount,
|
||||
AddressInfo address, string remark = null)
|
||||
: base(id)
|
||||
{
|
||||
OrderSN = orderSN;
|
||||
CustomerId = customerId;
|
||||
ServiceCategoryId = serviceCategoryId;
|
||||
ServiceTime = serviceTime;
|
||||
Amount = amount;
|
||||
Address = address;
|
||||
Remark = remark;
|
||||
Status = OrderStatus.PendingPayment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订单编号
|
||||
/// </summary>
|
||||
public string OrderSN { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public Guid CustomerId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 家政人员ID
|
||||
/// </summary>
|
||||
public Guid? WorkerId { get; private set; }
|
||||
|
||||
///// <summary>
|
||||
///// 用户ID
|
||||
///// </summary>
|
||||
//public virtual IdentityUser Customer { get; private set; }
|
||||
///// <summary>
|
||||
///// 家政人员ID
|
||||
///// </summary>
|
||||
//public virtual IdentityUser? Worker { get; private set; }
|
||||
/// <summary>
|
||||
/// 服务项目ID
|
||||
/// </summary>
|
||||
public Guid ServiceCategoryId { get; private set; }
|
||||
|
||||
public virtual ServiceCategory ServiceCategory { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务预约时间
|
||||
/// </summary>
|
||||
public DateTime ServiceTime { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应付金额
|
||||
/// </summary>
|
||||
public decimal Amount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 实付金额
|
||||
/// </summary>
|
||||
public decimal PaidAmount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付方式
|
||||
/// </summary>
|
||||
public string PaymentMethod { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public AddressInfo Address { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? Remark { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 取消原因
|
||||
/// </summary>
|
||||
public string? CancelReason { get; private set; }
|
||||
|
||||
|
||||
public void MarkPaid(decimal paidAmount, string method)
|
||||
{
|
||||
if (Status != OrderStatus.PendingPayment)
|
||||
{
|
||||
throw new InvalidOperationException("订单不在待付款状态");
|
||||
}
|
||||
|
||||
|
||||
PaidAmount = paidAmount;
|
||||
PaymentMethod = method;
|
||||
Status = OrderStatus.PaidWaitingAssign;
|
||||
}
|
||||
|
||||
|
||||
public void AssignWorker(Guid workerId)
|
||||
{
|
||||
if (Status != OrderStatus.PaidWaitingAssign)
|
||||
{
|
||||
throw new InvalidOperationException("订单无法分配师傅");
|
||||
}
|
||||
|
||||
|
||||
WorkerId = workerId;
|
||||
Status = OrderStatus.AssignedWaitingService;
|
||||
}
|
||||
|
||||
|
||||
public void StartService()
|
||||
{
|
||||
if (Status != OrderStatus.AssignedWaitingService)
|
||||
{
|
||||
throw new InvalidOperationException("订单无法开始");
|
||||
}
|
||||
|
||||
|
||||
Status = OrderStatus.InService;
|
||||
}
|
||||
|
||||
|
||||
public void CompleteService()
|
||||
{
|
||||
if (Status != OrderStatus.InService)
|
||||
{
|
||||
throw new InvalidOperationException("订单未开始服务,无法完成");
|
||||
}
|
||||
|
||||
|
||||
Status = OrderStatus.WaitingConfirm;
|
||||
}
|
||||
|
||||
|
||||
public void ConfirmCompletion()
|
||||
{
|
||||
if (Status != OrderStatus.WaitingConfirm)
|
||||
{
|
||||
throw new InvalidOperationException("订单无法确认");
|
||||
}
|
||||
|
||||
|
||||
Status = OrderStatus.Completed;
|
||||
}
|
||||
|
||||
|
||||
public void Cancel(string reason)
|
||||
{
|
||||
// 若已完成或退款中则不可取消
|
||||
if (Status == OrderStatus.Completed || Status == OrderStatus.Refunding || Status == OrderStatus.Refunded)
|
||||
{
|
||||
throw new InvalidOperationException("订单无法被取消");
|
||||
}
|
||||
|
||||
|
||||
CancelReason = reason;
|
||||
Status = OrderStatus.Canceled;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user