feat: [商品管理] 優化商品匯入邏輯,支援 13 碼條碼自動生成、Upsert 更新機制與 Excel 說明工作表
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 1m7s

This commit is contained in:
2026-02-06 09:26:50 +08:00
parent e1aa452b3c
commit 906b094c18
7 changed files with 187 additions and 44 deletions

View File

@@ -197,6 +197,10 @@ class ProductController extends Controller
$validated['code'] = $this->generateRandomCode();
}
if (empty($validated['barcode'])) {
$validated['barcode'] = $this->generateRandomBarcode();
}
$product = Product::create($validated);
return redirect()->route('products.index')->with('success', '商品已建立');
@@ -260,6 +264,10 @@ class ProductController extends Controller
$validated['code'] = $this->generateRandomCode();
}
if (empty($validated['barcode'])) {
$validated['barcode'] = $this->generateRandomBarcode();
}
$product->update($validated);
if ($request->input('from') === 'show') {
@@ -328,4 +336,21 @@ class ProductController extends Controller
return $code;
}
/**
* 生成隨機 13 碼條碼 (純數字)
*/
private function generateRandomBarcode(): string
{
$barcode = '';
do {
$barcode = '';
for ($i = 0; $i < 13; $i++) {
$barcode .= rand(0, 9);
}
} while (Product::where('barcode', $barcode)->exists());
return $barcode;
}
}