refactor: 重構 VendorProduct API 與新增進貨單重複檢查前端邏輯
All checks were successful
ERP-Deploy-Production / deploy-production (push) Successful in 1m9s
ERP-Deploy-Demo / deploy-demo (push) Successful in 1m10s

1. 將 VendorProductController 中的 Eloquent 關聯操作改為透過 ProcurementService 使用 DB 操作,解除跨模組 Model 直接依賴。
2. ProcurementService 加入 vendor product 的資料存取方法。
3. 進貨單建立前端 (GoodsReceipt/Create.tsx) 新增重複進貨檢查與警告對話框邏輯。
This commit is contained in:
2026-02-25 11:11:28 +08:00
parent e406ecd63d
commit ad91b08dbc
11 changed files with 689 additions and 23 deletions

View File

@@ -99,4 +99,52 @@ class ProcurementService implements ProcurementServiceInterface
{
return \App\Modules\Procurement\Models\Vendor::whereIn('id', $ids)->get(['id', 'name', 'code']);
}
public function attachProductToVendor(int $vendorId, int $productId, ?float $lastPrice): void
{
\Illuminate\Support\Facades\DB::table('product_vendor')->insert([
'vendor_id' => $vendorId,
'product_id' => $productId,
'last_price' => $lastPrice,
'created_at' => now(),
'updated_at' => now(),
]);
}
public function updateVendorProductPrice(int $vendorId, int $productId, ?float $lastPrice): void
{
\Illuminate\Support\Facades\DB::table('product_vendor')
->where('vendor_id', $vendorId)
->where('product_id', $productId)
->update([
'last_price' => $lastPrice,
'updated_at' => now(),
]);
}
public function checkVendorHasProduct(int $vendorId, int $productId): bool
{
return \Illuminate\Support\Facades\DB::table('product_vendor')
->where('vendor_id', $vendorId)
->where('product_id', $productId)
->exists();
}
public function getVendorProductPrice(int $vendorId, int $productId): ?float
{
$pivot = \Illuminate\Support\Facades\DB::table('product_vendor')
->where('vendor_id', $vendorId)
->where('product_id', $productId)
->first();
return $pivot ? (float) $pivot->last_price : null;
}
public function detachProductFromVendor(int $vendorId, int $productId): void
{
\Illuminate\Support\Facades\DB::table('product_vendor')
->where('vendor_id', $vendorId)
->where('product_id', $productId)
->delete();
}
}