1. 新增 API Rate Limiting (每分鐘 60 次) 2. 實作 ProductServiceInterface 與 findOrCreateWarehouseByName 解決跨模組耦合問題 3. 強化 OrderSync API 驗證 (price 欄位限制最小 0、payment_method 加上允許白名單) 4. 實作 OrderSync API 冪等性處理,重複訂單直接回傳現有資訊 5. 修正 ProductSync API 同步邏輯,每次同步皆會更新產品分類與單位 6. 完善 integration API 對接手冊內容與 UI 排版
49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Integration\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Modules\Inventory\Contracts\ProductServiceInterface;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ProductSyncController extends Controller
|
|
{
|
|
protected $productService;
|
|
|
|
public function __construct(ProductServiceInterface $productService)
|
|
{
|
|
$this->productService = $productService;
|
|
}
|
|
|
|
public function upsert(Request $request)
|
|
{
|
|
$request->validate([
|
|
'external_pos_id' => 'required|string',
|
|
'name' => 'required|string',
|
|
'price' => 'nullable|numeric|min:0',
|
|
'barcode' => 'nullable|string',
|
|
'category' => 'nullable|string',
|
|
'unit' => 'nullable|string',
|
|
'updated_at' => 'nullable|date',
|
|
]);
|
|
|
|
try {
|
|
$product = $this->productService->upsertFromPos($request->all());
|
|
|
|
return response()->json([
|
|
'message' => 'Product synced successfully',
|
|
'data' => [
|
|
'id' => $product->id,
|
|
'external_pos_id' => $product->external_pos_id,
|
|
]
|
|
]);
|
|
} catch (\Exception $e) {
|
|
Log::error('Product Sync Failed', ['error' => $e->getMessage(), 'payload' => $request->all()]);
|
|
return response()->json([
|
|
'message' => 'Sync failed: ' . $e->getMessage(),
|
|
], 500);
|
|
}
|
|
}
|
|
}
|