upd: 修改订单与家政人员接口
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
using KonSoft.Admin.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
|
||||
namespace KonSoft.Admin.Dtos
|
||||
{
|
||||
public class OrderPagedResultRequestDto : PagedResultRequestDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单状态
|
||||
/// </summary>
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Created;
|
||||
|
||||
/// <summary>
|
||||
/// 服务时间
|
||||
/// </summary>
|
||||
public DateTime? ServiceTime { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KonSoft.Admin.Dtos
|
||||
{
|
||||
public class WorkerRegisterDto
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
using KonSoft.Admin.Dtos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Application.Services;
|
||||
|
||||
namespace KonSoft.Admin.IApplicationServices;
|
||||
|
||||
public interface IHouseholdWorkerAppService : IApplicationService
|
||||
{
|
||||
/// <summary>
|
||||
/// 家政人员注册
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task RegisterAsync(WorkerRegisterDto input);
|
||||
|
||||
/// <summary>
|
||||
/// 家政人员接单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
Task AcceptOrderAsync(Guid orderId);
|
||||
|
||||
/// <summary>
|
||||
/// 家政人员退单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
Task RejectOrderAsync(Guid orderId);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 已到达(开始服务)
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
Task StartServiceAsync(Guid orderId);
|
||||
|
||||
/// <summary>
|
||||
/// 完成服务
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
Task CompleteServiceAsync(Guid orderId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前分配给家政人员的订单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<OrderDto>> GetAssignedOrdersAsync(OrderPagedResultRequestDto requestDto);
|
||||
|
||||
/// <summary>
|
||||
/// 获取待接单订单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<OrderDto>> GetCreatedOrdersAsync(OrderPagedResultRequestDto requestDto);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -15,14 +15,37 @@ public interface IOrderAppService : IApplicationService
|
||||
/// <returns></returns>
|
||||
Task<OrderDto> CreateAsync(CreateOrderDto input);
|
||||
|
||||
Task<OrderDto> PayAsync(Guid orderId, PayOrderDto input);
|
||||
Task AssignAsync(Guid orderId, Guid workerId);
|
||||
Task StartServiceAsync(Guid orderId);
|
||||
Task CompleteServiceAsync(Guid orderId);
|
||||
Task ConfirmAsync(Guid orderId);
|
||||
/// <summary>
|
||||
/// 支付上门费
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task PayServiceCallFeeAsync(Guid orderId, PayOrderDto input);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 支付
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task PayAsync(Guid orderId, PayOrderDto input);
|
||||
|
||||
/// <summary>
|
||||
/// 取消订单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="reason"></param>
|
||||
/// <returns></returns>
|
||||
Task CancelAsync(Guid orderId, string reason);
|
||||
Task DeleteAsync(params Guid[] ids);
|
||||
/// <summary>
|
||||
/// 修改订单
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task EditAsync(OrderDto input);
|
||||
Task<OrderDto> GetAsync(Guid id);
|
||||
Task<PagedResultDto<OrderDto>> GetListAsync(PagedResultRequestDto input);
|
||||
Task<PagedResultDto<OrderDto>> GetListAsync(OrderPagedResultRequestDto input);
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
using Volo.Abp.Application.Services;
|
||||
|
||||
namespace KonSoft.Admin.IApplicationServices;
|
||||
|
||||
public interface IWorkerAppService : IApplicationService
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,126 @@
|
||||
using KonSoft.Admin.Dtos;
|
||||
using KonSoft.Admin.Entities;
|
||||
using KonSoft.Admin.IApplicationServices;
|
||||
using KonSoft.Admin.IRepositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.ObjectMapping;
|
||||
|
||||
namespace KonSoft.Admin.ApplicationServices
|
||||
{
|
||||
public class HouseholdWorkerAppService : ApplicationService, IHouseholdWorkerAppService
|
||||
{
|
||||
public IOrderRepository _orderRepository { get; set; }
|
||||
|
||||
public HouseholdWorkerAppService(IOrderRepository orderRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 家政人员接单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task AcceptOrderAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null) throw new BusinessException("未找到订单");
|
||||
|
||||
order.AssignWorker(CurrentUser.Id!.Value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取已接单任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<List<OrderDto>> GetAssignedOrdersAsync(OrderPagedResultRequestDto requestDto)
|
||||
{
|
||||
//TODO 默认根据角色筛选对应订单,整合到一个接口中
|
||||
var query = await _orderRepository.GetQueryableAsync();
|
||||
var orders = query.Where(o => o.HouseholdWorkerId == CurrentUser.Id)
|
||||
.PageBy(requestDto).ToList(); ;
|
||||
|
||||
return ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取待接单任务
|
||||
/// </summary>
|
||||
/// <param name="requestDto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<OrderDto>> GetCreatedOrdersAsync(OrderPagedResultRequestDto requestDto)
|
||||
{
|
||||
//TODO 默认根据角色筛选对应订单,整合到一个接口中
|
||||
var query = await _orderRepository.GetQueryableAsync();
|
||||
var orders = query.Where(o => o.Status == Enums.OrderStatus.Created)
|
||||
.PageBy(requestDto).ToList(); ;
|
||||
|
||||
return ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 家政人员注册
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task RegisterAsync(WorkerRegisterDto input)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// 退单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exasception cref="NotImplementedException"></exception>
|
||||
public async Task RejectOrderAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null) throw new BusinessException("未找到订单");
|
||||
|
||||
order.RejectOrder(CurrentUser.Id!.Value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 开始服务
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task StartServiceAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null) throw new BusinessException("未找到订单");
|
||||
|
||||
order.StartService();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 服务完成
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task CompleteServiceAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null) throw new BusinessException("未找到订单");
|
||||
|
||||
order.CompleteService();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,18 +18,6 @@ public class OrderAppService(IOrderRepository orderRepository) : ApplicationServ
|
||||
{
|
||||
private readonly IOrderRepository _orderRepository = orderRepository;
|
||||
|
||||
/// <summary>
|
||||
/// 分配师傅
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="workerId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task AssignAsync(Guid orderId, Guid workerId)
|
||||
{
|
||||
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
|
||||
order.AssignWorker(workerId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消订单
|
||||
@ -44,29 +32,6 @@ public class OrderAppService(IOrderRepository orderRepository) : ApplicationServ
|
||||
order.Cancel(reason);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 完成订单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task CompleteServiceAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
|
||||
order.CompleteService();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确认订单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task ConfirmAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
|
||||
order.ConfirmCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建订单
|
||||
@ -97,10 +62,9 @@ public class OrderAppService(IOrderRepository orderRepository) : ApplicationServ
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改订单信息
|
||||
/// 修改订单信息
|
||||
/// </summary>
|
||||
/// <param name="input">订单DTO对象</param>
|
||||
/// s
|
||||
public async Task EditAsync(OrderDto input)
|
||||
{
|
||||
// 根据ID查询订单,如果不存在则抛出异常【修改前端必然看到了,数据若查不到提示自定义异常信息】
|
||||
@ -111,35 +75,37 @@ public class OrderAppService(IOrderRepository orderRepository) : ApplicationServ
|
||||
ObjectMapper.Map(input, order);
|
||||
|
||||
// 更新订单
|
||||
await _orderRepository.UpdateAsync(order);
|
||||
//await _orderRepository.UpdateAsync(order);
|
||||
}
|
||||
|
||||
public async Task PayServiceCallFeeAsync(Guid orderId, PayOrderDto input)
|
||||
{
|
||||
var order = await _orderRepository.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null) throw new BusinessException("未找到订单");
|
||||
|
||||
order.PayServiceCallFee();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 支付
|
||||
/// 支付
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task<OrderDto> PayAsync(Guid orderId, PayOrderDto input)
|
||||
public async Task PayAsync(Guid orderId, PayOrderDto input)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var order = await _orderRepository.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
if (order == null) throw new BusinessException("未找到订单");
|
||||
|
||||
order.Pay();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始订单
|
||||
/// </summary>
|
||||
/// <param name="orderId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task StartServiceAsync(Guid orderId)
|
||||
{
|
||||
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
|
||||
order.StartService();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据订单ID获取单个订单
|
||||
/// 根据订单ID获取单个订单
|
||||
/// </summary>
|
||||
public async Task<OrderDto> GetAsync(Guid id)
|
||||
{
|
||||
@ -151,12 +117,13 @@ public class OrderAppService(IOrderRepository orderRepository) : ApplicationServ
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有订单列表
|
||||
/// 获取订单列表
|
||||
/// </summary>
|
||||
public async Task<PagedResultDto<OrderDto>> GetListAsync(PagedResultRequestDto input)
|
||||
public async Task<PagedResultDto<OrderDto>> GetListAsync(OrderPagedResultRequestDto input)
|
||||
{
|
||||
// 查询所有订单
|
||||
var orders = await _orderRepository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, "Id");
|
||||
//TODO 默认根据角色筛选对应订单,整合到一个接口中
|
||||
var query = await _orderRepository.GetQueryableAsync();
|
||||
var orders = query.PageBy(input).OrderBy(o => o.Id).ToList();
|
||||
|
||||
var totalCount = await _orderRepository.CountAsync();
|
||||
|
||||
@ -164,4 +131,8 @@ public class OrderAppService(IOrderRepository orderRepository) : ApplicationServ
|
||||
|
||||
return new PagedResultDto<OrderDto>(totalCount, orderDtos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -2,13 +2,13 @@
|
||||
|
||||
public enum OrderStatus
|
||||
{
|
||||
PendingPayment, // 待支付
|
||||
PaidWaitingAssign, // 已支付待派单
|
||||
AssignedWaitingService, // 已派单待服务
|
||||
InService, // 服务中
|
||||
WaitingConfirm, // 待用户确认
|
||||
Completed, // 已完成
|
||||
Canceled, // 已取消
|
||||
Refunding, // 退款中
|
||||
Refunded // 已退款
|
||||
Created = 1, //用户创建订单
|
||||
Assigned, //家政人员已接单
|
||||
ServiceCallPaymentComplete, //上门费支付完成
|
||||
ServiceStarted, //服务开始
|
||||
ServiceCompleted, //服务已完成
|
||||
PaymentPending, //用户支付订单
|
||||
PaymentComplete, //用户支付完成
|
||||
Cancelled, //订单取消
|
||||
Refunded, //订单退款
|
||||
}
|
||||
@ -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