using KonSoft.Admin.Enums; using KonSoft.Admin.ValueObjects; using System; using Volo.Abp; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.Identity; namespace KonSoft.Admin.Entities; public class Order : FullAuditedAggregateRoot { private Order() { } public Order(Guid customerId, Guid serviceCategoryId, DateTime serviceTime, decimal amount, AddressInfo address, string? remark = null) { CustomerId = customerId; ServiceCategoryId = serviceCategoryId; ServiceTime = serviceTime; Amount = amount; Address = address; Remark = remark; Status = OrderStatus.Created; } /// /// 用户ID /// public Guid CustomerId { get; private set; } public virtual IdentityUser Customer { get; private set; } /// /// 家政人员ID /// public Guid? HouseholdWorkerId { get; private set; } public IdentityUser? HouseholdWorker { get; private set; } /// /// 服务项目ID /// public Guid ServiceCategoryId { get; private set; } /// /// 服务预约时间 /// public DateTime ServiceTime { get; private set; } /// /// 订单状态 /// public OrderStatus Status { get; private set; } /// /// 应付金额 /// public decimal Amount { get; private set; } /// /// 实付金额 /// public decimal PaidAmount { get; private set; } /// /// 支付方式 /// public string PaymentMethod { get; private set; } /// /// 地址 /// public AddressInfo Address { get; private set; } /// /// 备注 /// public string? Remark { get; private set; } /// /// 取消原因 /// 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.Created) { throw new BusinessException("订单无法分配师傅"); } HouseholdWorkerId = workerId; Status = OrderStatus.Assigned; } public void RejectOrder(Guid workerId) { if (Status != OrderStatus.Created) { throw new BusinessException("订单无法分配师傅"); } if (HouseholdWorkerId != workerId) { throw new BusinessException("订单不属于你,无法退单"); } Status = OrderStatus.Created; } public void PayServiceCallFee() { if (Status != OrderStatus.Assigned) { throw new BusinessException("订单无法支付上门费"); } Status = OrderStatus.ServiceCallPaymentComplete; } public void Pay() { if (Status != OrderStatus.ServiceCompleted) { throw new BusinessException("订单服务未完成无法支付"); } Status = OrderStatus.PaymentPending; } public void StartService() { if (Status != OrderStatus.ServiceCallPaymentComplete) { throw new BusinessException("订单未支付上门费无法开始"); } Status = OrderStatus.ServiceStarted; } public void CompleteService() { if (Status != OrderStatus.ServiceStarted) { throw new BusinessException("订单未开始,无法完成"); } Status = OrderStatus.ServiceCompleted; } public void Cancel(string reason) { // 若已完成或退款中则不可取消 if (Status == OrderStatus.ServiceCompleted || Status == OrderStatus.Cancelled || Status == OrderStatus.Refunded) { throw new BusinessException("订单无法被取消"); } CancelReason = reason; Status = OrderStatus.Cancelled; } }