upd: 修改订单与家政人员接口
This commit is contained in:
		@ -1,7 +1,9 @@
 | 
			
		||||
using System;
 | 
			
		||||
using KonSoft.Admin.Enums;
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
@ -21,18 +23,20 @@ public class Order : FullAuditedAggregateRoot<Guid>
 | 
			
		||||
        Amount = amount;
 | 
			
		||||
        Address = address;
 | 
			
		||||
        Remark = remark;
 | 
			
		||||
        Status = OrderStatus.PendingPayment;
 | 
			
		||||
        Status = OrderStatus.Created;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///     用户ID
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public Guid CustomerId { get; private set; }
 | 
			
		||||
    public virtual IdentityUser Customer { get; private set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///     家政人员ID
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public Guid? WorkerId { get; private set; }
 | 
			
		||||
    public Guid? HouseholdWorkerId { get; private set; }
 | 
			
		||||
    public IdentityUser? HouseholdWorker { get; private set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///     服务项目ID
 | 
			
		||||
@ -80,79 +84,105 @@ public class Order : FullAuditedAggregateRoot<Guid>
 | 
			
		||||
    public string? CancelReason { get; private set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void MarkPaid(decimal paidAmount, string method)
 | 
			
		||||
    {
 | 
			
		||||
        if (Status != OrderStatus.PendingPayment)
 | 
			
		||||
        {
 | 
			
		||||
            throw new InvalidOperationException("订单不在待付款状态");
 | 
			
		||||
        }
 | 
			
		||||
    //public void MarkPaid(decimal paidAmount, string method)
 | 
			
		||||
    //{
 | 
			
		||||
    //    if (Status != OrderStatus.PendingPayment)
 | 
			
		||||
    //    {
 | 
			
		||||
    //        throw new InvalidOperationException("订单不在待付款状态");
 | 
			
		||||
    //    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        PaidAmount = paidAmount;
 | 
			
		||||
        PaymentMethod = method;
 | 
			
		||||
        Status = OrderStatus.PaidWaitingAssign;
 | 
			
		||||
    }
 | 
			
		||||
    //    PaidAmount = paidAmount;
 | 
			
		||||
    //    PaymentMethod = method;
 | 
			
		||||
    //    Status = OrderStatus.PaidWaitingAssign;
 | 
			
		||||
    //}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void AssignWorker(Guid workerId)
 | 
			
		||||
    {
 | 
			
		||||
        if (Status != OrderStatus.PaidWaitingAssign)
 | 
			
		||||
        if (Status != OrderStatus.Created)
 | 
			
		||||
        {
 | 
			
		||||
            throw new InvalidOperationException("订单无法分配师傅");
 | 
			
		||||
            throw new BusinessException("订单无法分配师傅");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        WorkerId = workerId;
 | 
			
		||||
        Status = OrderStatus.AssignedWaitingService;
 | 
			
		||||
        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.AssignedWaitingService)
 | 
			
		||||
        if (Status != OrderStatus.ServiceCallPaymentComplete)
 | 
			
		||||
        {
 | 
			
		||||
            throw new InvalidOperationException("订单无法开始");
 | 
			
		||||
            throw new BusinessException("订单未支付上门费无法开始");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Status = OrderStatus.InService;
 | 
			
		||||
        Status = OrderStatus.ServiceStarted;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public void CompleteService()
 | 
			
		||||
    {
 | 
			
		||||
        if (Status != OrderStatus.InService)
 | 
			
		||||
        if (Status != OrderStatus.ServiceStarted)
 | 
			
		||||
        {
 | 
			
		||||
            throw new InvalidOperationException("订单未开始服务,无法完成");
 | 
			
		||||
            throw new BusinessException("订单未开始,无法完成");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Status = OrderStatus.WaitingConfirm;
 | 
			
		||||
        Status = OrderStatus.ServiceCompleted;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
        if (Status == OrderStatus.ServiceCompleted || Status == OrderStatus.Cancelled || Status == OrderStatus.Refunded)
 | 
			
		||||
        {
 | 
			
		||||
            throw new InvalidOperationException("订单无法被取消");
 | 
			
		||||
            throw new BusinessException("订单无法被取消");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        CancelReason = reason;
 | 
			
		||||
        Status = OrderStatus.Canceled;
 | 
			
		||||
        Status = OrderStatus.Cancelled;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user