采购单优化

This commit is contained in:
liu
2026-08-12 17:10:05 +08:00
parent dadfdc1511
commit ef0d394f4f
8 changed files with 359 additions and 155 deletions
@@ -238,7 +238,8 @@ class PurchaseOrderController extends BaseController
}
/**
* C4 商品行修改:采购成本同步该商品全部订货明细;实际称重按数量比例分摊(尾差修正守恒)
* C4 商品行修改:品名/供应商/包规/单位/成本一键同步该商品全部订货明细;
* 实际称重按数量比例分摊(尾差修正守恒)
*/
#[PutRoute(route: '/{id}/row/{productId}', authorize: 'update', where: ['id' => '[0-9]+', 'productId' => '[0-9]+'])]
public function updateRow(int $id, int $productId, PurchaseRowUpdateRequest $request): JsonResponse
@@ -248,13 +249,25 @@ class PurchaseOrderController extends BaseController
throw new RepositoryException('采购单不存在');
}
$validated = $request->validated();
$costPrice = isset($validated['cost_price']) ? (float) $validated['cost_price'] : null;
$attrs = [];
foreach (['product_name', 'supplier_id', 'product_spec', 'unit', 'cost_price'] as $field) {
if (isset($validated[$field])) {
$attrs[$field] = $validated[$field];
}
}
$weight = isset($validated['weight']) ? (float) $validated['weight'] : null;
if ($costPrice === null && $weight === null) {
throw new RepositoryException('采购成本实际称重至少填写一项');
if ($attrs === [] && $weight === null) {
throw new RepositoryException('品名/供应商/包规/单位/成本/实际称重至少填写一项');
}
$count = app(PurchaseEditService::class)->updateRow($purchase, $productId, $costPrice, $weight);
$count = app(PurchaseEditService::class)->updateRow(
$purchase,
$productId,
$attrs,
$weight,
(bool) ($validated['sync_product'] ?? false),
);
return $this->success(['count' => $count], '已同步 ' . $count . ' 条订货明细');
}