修复一些错误
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\ProductPriceModel;
|
||||
use App\Models\StoreOrderItemModel;
|
||||
use App\Models\StoreOrderModel;
|
||||
use App\Services\BillNumberService;
|
||||
use App\Services\ItemImageResolver;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -161,7 +162,7 @@ class OrderController extends BaseMiniController
|
||||
'total_amount', 'status', 'remark', 'purchase_id', 'bill_id', 'created_at',
|
||||
])
|
||||
->with(['items' => static fn ($itemsQuery) => $itemsQuery
|
||||
->select(['id', 'order_id', 'product_name', 'quantity', 'unit'])
|
||||
->select(['id', 'order_id', 'product_name', 'product_spec', 'quantity', 'unit', 'image_ids'])
|
||||
->orderBy('id')]);
|
||||
if (isset($params['status'])) {
|
||||
$query->where('status', (int) $params['status']);
|
||||
@@ -177,6 +178,28 @@ class OrderController extends BaseMiniController
|
||||
->orderBy('id', 'desc')
|
||||
->paginate((int) ($params['pageSize'] ?? 10));
|
||||
|
||||
// 商品预览(每单前 3 条明细):首图跨订单一次性批量解析
|
||||
$previewMap = [];
|
||||
$flatItems = [];
|
||||
foreach ($paginator->getCollection() as $order) {
|
||||
foreach ($order->items as $item) {
|
||||
$flatItems[] = [
|
||||
'order_id' => $order->id,
|
||||
'product_name' => $item->product_name,
|
||||
'product_spec' => $item->product_spec,
|
||||
'quantity' => $item->quantity,
|
||||
'unit' => $item->unit,
|
||||
'image_ids' => (array) $item->image_ids,
|
||||
];
|
||||
}
|
||||
}
|
||||
app(ItemImageResolver::class)->resolve($flatItems);
|
||||
foreach ($flatItems as $flatItem) {
|
||||
$orderId = $flatItem['order_id'];
|
||||
unset($flatItem['order_id']);
|
||||
$previewMap[$orderId][] = $flatItem;
|
||||
}
|
||||
|
||||
$paginator->getCollection()->transform(
|
||||
static fn (StoreOrderModel $order): array => [
|
||||
'id' => $order->id,
|
||||
@@ -193,12 +216,7 @@ class OrderController extends BaseMiniController
|
||||
'bill_id' => $order->bill_id,
|
||||
'created_at' => $order->created_at?->toDateTimeString(),
|
||||
'item_count' => $order->items->count(),
|
||||
'items' => $order->items->take(3)
|
||||
->map(static fn (StoreOrderItemModel $item): array => [
|
||||
'product_name' => $item->product_name,
|
||||
'quantity' => $item->quantity,
|
||||
'unit' => $item->unit,
|
||||
])->values()->all(),
|
||||
'items' => $previewMap[$order->id] ?? [],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user