188 lines
4.3 KiB
C#
188 lines
4.3 KiB
C#
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<Guid>
|
|
{
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用户ID
|
|
/// </summary>
|
|
public Guid CustomerId { get; private set; }
|
|
public virtual IdentityUser Customer { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 家政人员ID
|
|
/// </summary>
|
|
public Guid? HouseholdWorkerId { get; private set; }
|
|
public IdentityUser? HouseholdWorker { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 服务项目ID
|
|
/// </summary>
|
|
public Guid ServiceCategoryId { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 服务预约时间
|
|
/// </summary>
|
|
public DateTime ServiceTime { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 订单状态
|
|
/// </summary>
|
|
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.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;
|
|
}
|
|
} |