订单软删除

This commit is contained in:
liu
2026-08-12 09:42:48 +08:00
parent fa4bf6fe61
commit ce1f36b5b4
10 changed files with 127 additions and 6 deletions
@@ -12,6 +12,7 @@ use App\Models\UserModel;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Modules\AnnoRoute\Attribute\DeleteRoute;
use Modules\AnnoRoute\Attribute\GetRoute;
use Modules\AnnoRoute\Attribute\PutRoute;
use Modules\AnnoRoute\Attribute\RequestAttribute;
@@ -400,6 +401,27 @@ class StoreOrderController extends BaseController
return $this->success(['success' => $orders->count()]);
}
/**
* 删除订单(软删除):仅已取消订单允许删除;删除后后台列表/详情、小程序端均不可见
*/
#[DeleteRoute(route: '/{id}', authorize: 'delete', where: ['id' => '[0-9]+'])]
public function delete(int $id): JsonResponse
{
$order = StoreOrderModel::find($id);
if (empty($order)) {
throw new RepositoryException('订单不存在');
}
if ($order->status !== StoreOrderModel::STATUS_CANCELLED) {
throw new RepositoryException(
'订单当前状态为「' . (self::STATUS_NAMES[$order->status] ?? $order->status) . '」,仅已取消订单可删除'
);
}
$order->delete();
return $this->success();
}
/**
* 状态流转合法路径(与迁移状态定义一致):
* 待接单→已接单/已取消;采购中→配送中/已完成;配送中→已完成