using Fake.Application; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Oms.Application.Dtos.Orders; using Oms.Application.Shared; namespace Oms.Application.Services.Orders; public partial class OrderService { private OrderFileManager OrderFileManager => LazyServiceProvider.GetRequiredService(); /// /// 查询订单附件(按类型分组)。客户登录仅返回系统面单。 /// [HttpGet("/order/files")] public async Task GetOrderFilesAsync([FromQuery] int orderId) { await GetOrderOrThrowAsync(orderId); var customerView = OmsSessionHelper.IsCustomerLogin(CurrentUser); return await OrderFileManager.GetGroupedAsync(orderId, customerView); } /// /// 上传订单附件。客户账号禁止上传。 /// [HttpPost("/order/files/upload")] [Consumes("multipart/form-data")] public async Task> UploadOrderFilesAsync( [FromForm] int orderId, [FromForm] string fileType, [FromForm] List files) { await GetOrderOrThrowAsync(orderId); var collection = new FormFileCollection(); foreach (var file in files ?? []) { collection.Add(file); } return await OrderFileManager.UploadAsync( orderId, fileType, collection, CurrentUser.GetId(), OmsSessionHelper.IsCustomerLogin(CurrentUser)); } /// /// 删除订单附件。客户账号禁止删除。 /// [HttpPost("/order/files/delete")] public async Task DeleteOrderFileAsync([FromBody] OrderFileDeleteInput input) { if (input == null || input.Id <= 0) { throw new BusinessException("附件 Id 无效"); } var entity = await LazyServiceProvider .GetRequiredService() .FirstOrDefaultAsync(x => x.Id == input.Id) ?? throw new BusinessException("附件不存在"); await GetOrderOrThrowAsync(entity.OrderId); await OrderFileManager.DeleteAsync( input.Id, OmsSessionHelper.IsCustomerLogin(CurrentUser)); } }