Files
KonSoft.Clean/modules/admin/src/KonSoft.Admin.Application/ApplicationServices/OrderAppService.cs
kon1z 28954870f6 feat 移除订单编号字段并优化订单创建逻辑
- 移除了 `Order` 实体中的 `OrderSN` 字段及相关逻辑。
- 修改 `Order` 构造函数,简化参数,新增默认状态字段。
- 更新 `AddressInfo` 属性访问修饰符为 `private set`。
- 调整 `OrderAppService` 的订单创建逻辑,适配新构造函数。
- 更新数据库迁移路径,新增迁移文件 `20251017042956_V1.0.0`。
- 新增 `AppOrder`、`AppProduct`、`AppServiceCategory` 表。
- 在 `AbpUsers` 表中新增字段以支持用户扩展。
- 更新实体配置,统一命名约定,支持扩展映射。
- 添加 `AdminDataSeedContributor` 类,预留数据种子逻辑。
2025-10-17 13:24:27 +08:00

167 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using KonSoft.Admin.Dtos;
using KonSoft.Admin.Entities;
using KonSoft.Admin.IApplicationServices;
using KonSoft.Admin.IRepositories;
using KonSoft.Admin.ValueObjects;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace KonSoft.Admin.ApplicationServices;
public class OrderAppService(IOrderRepository orderRepository) : ApplicationService, IOrderAppService
{
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>
/// 取消订单
/// </summary>
/// <param name="orderId"></param>
/// <param name="reason"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task CancelAsync(Guid orderId, string reason)
{
var order = await _orderRepository.GetAsync(o => o.Id == orderId);
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>
/// 创建订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<OrderDto> CreateAsync(CreateOrderDto input)
{
// 生成订单号 TODO
var orderSN = "SN001";
var address = ObjectMapper.Map<AddressDto, AddressInfo>(input.Address);
var order = new Order(input.CustomerId, input.ServiceCategoryId, input.ServiceTime,
input.Amount, address, input.Remark);
await _orderRepository.InsertAsync(order);
return ObjectMapper.Map<Order, OrderDto>(order);
}
/// <summary>
/// 根据订单ID删除订单
/// </summary>
/// <param name="id">订单ID</param>
public async Task DeleteAsync(params Guid[] ids)
{
// 根据ID删除订单
await _orderRepository.DeleteAsync(x => ids.Contains(x.Id));
}
/// <summary>
/// 修改订单信息
/// </summary>
/// <param name="input">订单DTO对象</param>
/// s
public async Task EditAsync(OrderDto input)
{
// 根据ID查询订单如果不存在则抛出异常【修改前端必然看到了,数据若查不到提示自定义异常信息】
var order = await _orderRepository.FindAsync(o => o.Id == input.Id) ??
throw new BusinessException("订单找不到").WithData("Id", input.Id);
// 将输入的DTO字段映射到订单实体
ObjectMapper.Map(input, order);
// 更新订单
await _orderRepository.UpdateAsync(order);
}
/// <summary>
/// 支付
/// </summary>
/// <param name="orderId"></param>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task<OrderDto> PayAsync(Guid orderId, PayOrderDto input)
{
throw new NotImplementedException();
}
/// <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获取单个订单
/// </summary>
public async Task<OrderDto> GetAsync(Guid id)
{
// 根据ID从数据库查询订单
var order = await _orderRepository.GetAsync(o => o.Id == id);
// 转换为OrderDto返回
return ObjectMapper.Map<Order, OrderDto>(order);
}
/// <summary>
/// 获取所有订单列表
/// </summary>
public async Task<PagedResultDto<OrderDto>> GetListAsync(PagedResultRequestDto input)
{
// 查询所有订单
var orders = await _orderRepository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, "Id");
var totalCount = await _orderRepository.CountAsync();
var orderDtos = ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
return new PagedResultDto<OrderDto>(totalCount, orderDtos);
}
}