[STYLE] 調整 IoT API 回應格式與程式碼風格
1. 移除 B005, B012, B014, B017 回應中的 message 欄位,以相容機台端的解析邏輯。 2. 統一 MachineController 內的型別轉換格式與程式碼縮排。 3. 同步更新 api-docs.php 文件範例,移除多餘的 message 欄位。
This commit is contained in:
parent
0e6f5b703c
commit
69e825aeb3
@ -180,7 +180,6 @@ class MachineController extends Controller
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'code' => 200,
|
||||
'message' => 'OK',
|
||||
'data' => $slots->map(function ($slot) {
|
||||
return [
|
||||
'tid' => $slot->slot_no,
|
||||
@ -307,7 +306,6 @@ class MachineController extends Controller
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'code' => 200,
|
||||
'message' => 'OK',
|
||||
'data' => $advertisements->values()
|
||||
]);
|
||||
}
|
||||
@ -366,10 +364,10 @@ class MachineController extends Controller
|
||||
|
||||
$mappedSlots = array_map(function ($item) {
|
||||
return [
|
||||
'slot_no' => isset($item['tid']) ? (string)$item['tid'] : null,
|
||||
'slot_no' => isset($item['tid']) ? (string) $item['tid'] : null,
|
||||
'product_id' => $item['t060v00'] ?? null,
|
||||
'stock' => isset($item['num']) ? (int)$item['num'] : 0,
|
||||
'type' => isset($item['type']) ? (int)$item['type'] : null,
|
||||
'stock' => isset($item['num']) ? (int) $item['num'] : 0,
|
||||
'type' => isset($item['type']) ? (int) $item['type'] : null,
|
||||
];
|
||||
}, $legacyData);
|
||||
|
||||
@ -423,7 +421,6 @@ class MachineController extends Controller
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'code' => 200,
|
||||
'message' => 'OK',
|
||||
'data' => $products
|
||||
]);
|
||||
}
|
||||
@ -487,7 +484,6 @@ class MachineController extends Controller
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'code' => 200,
|
||||
'message' => 'OK',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
@ -518,12 +514,15 @@ class MachineController extends Controller
|
||||
$pickupCode = PickupCode::where('machine_id', $machine->id)
|
||||
->where('code', $code)
|
||||
->where('status', 'active')
|
||||
->where(function($q) { $q->whereNull('expires_at')->orWhere('expires_at', '>', now()); })
|
||||
->where(function ($q) {
|
||||
$q->whereNull('expires_at')->orWhere('expires_at', '>', now());
|
||||
})
|
||||
->first();
|
||||
|
||||
if (!$pickupCode) {
|
||||
$fails = Cache::increment("pickup_fails:{$machine->id}");
|
||||
if ($fails === 1) Cache::put("pickup_fails:{$machine->id}", 1, 600);
|
||||
if ($fails === 1)
|
||||
Cache::put("pickup_fails:{$machine->id}", 1, 600);
|
||||
if ($fails >= 5) {
|
||||
Cache::put($lockoutKey, true, 60);
|
||||
Cache::forget("pickup_fails:{$machine->id}");
|
||||
@ -579,18 +578,22 @@ class MachineController extends Controller
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), ['code' => 'required|string|size:8']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'code' => 400], 400);
|
||||
if ($validator->fails())
|
||||
return response()->json(['success' => false, 'code' => 400], 400);
|
||||
|
||||
$code = $request->input('code');
|
||||
$passCode = PassCode::where('machine_id', $machine->id)
|
||||
->where('code', $code)
|
||||
->where('status', 'active')
|
||||
->where(function($q) { $q->whereNull('expires_at')->orWhere('expires_at', '>', now()); })
|
||||
->where(function ($q) {
|
||||
$q->whereNull('expires_at')->orWhere('expires_at', '>', now());
|
||||
})
|
||||
->first();
|
||||
|
||||
if (!$passCode) {
|
||||
$fails = Cache::increment("passcode_fails:{$machine->id}");
|
||||
if ($fails >= 5) Cache::put($lockoutKey, true, 60);
|
||||
if ($fails >= 5)
|
||||
Cache::put($lockoutKey, true, 60);
|
||||
return response()->json(['success' => false, 'code' => 404], 404);
|
||||
}
|
||||
|
||||
|
||||
@ -164,7 +164,6 @@ return [
|
||||
'response' => [
|
||||
'success' => true,
|
||||
'code' => 200,
|
||||
'message' => 'OK',
|
||||
'data' => [
|
||||
[
|
||||
't070v01' => '測試機台廣告',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user