[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([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'OK',
|
|
||||||
'data' => $slots->map(function ($slot) {
|
'data' => $slots->map(function ($slot) {
|
||||||
return [
|
return [
|
||||||
'tid' => $slot->slot_no,
|
'tid' => $slot->slot_no,
|
||||||
@ -307,7 +306,6 @@ class MachineController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'OK',
|
|
||||||
'data' => $advertisements->values()
|
'data' => $advertisements->values()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -366,10 +364,10 @@ class MachineController extends Controller
|
|||||||
|
|
||||||
$mappedSlots = array_map(function ($item) {
|
$mappedSlots = array_map(function ($item) {
|
||||||
return [
|
return [
|
||||||
'slot_no' => isset($item['tid']) ? (string)$item['tid'] : null,
|
'slot_no' => isset($item['tid']) ? (string) $item['tid'] : null,
|
||||||
'product_id' => $item['t060v00'] ?? null,
|
'product_id' => $item['t060v00'] ?? null,
|
||||||
'stock' => isset($item['num']) ? (int)$item['num'] : 0,
|
'stock' => isset($item['num']) ? (int) $item['num'] : 0,
|
||||||
'type' => isset($item['type']) ? (int)$item['type'] : null,
|
'type' => isset($item['type']) ? (int) $item['type'] : null,
|
||||||
];
|
];
|
||||||
}, $legacyData);
|
}, $legacyData);
|
||||||
|
|
||||||
@ -423,7 +421,6 @@ class MachineController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'OK',
|
|
||||||
'data' => $products
|
'data' => $products
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -487,7 +484,6 @@ class MachineController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'OK',
|
|
||||||
'data' => $data
|
'data' => $data
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -518,19 +514,22 @@ class MachineController extends Controller
|
|||||||
$pickupCode = PickupCode::where('machine_id', $machine->id)
|
$pickupCode = PickupCode::where('machine_id', $machine->id)
|
||||||
->where('code', $code)
|
->where('code', $code)
|
||||||
->where('status', 'active')
|
->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();
|
->first();
|
||||||
|
|
||||||
if (!$pickupCode) {
|
if (!$pickupCode) {
|
||||||
$fails = Cache::increment("pickup_fails:{$machine->id}");
|
$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) {
|
if ($fails >= 5) {
|
||||||
Cache::put($lockoutKey, true, 60);
|
Cache::put($lockoutKey, true, 60);
|
||||||
Cache::forget("pickup_fails:{$machine->id}");
|
Cache::forget("pickup_fails:{$machine->id}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessStateLog::dispatch($machine->id, $machine->company_id, "[PickupCode] Verification failed: :code", 'info', ['code' => $code]);
|
ProcessStateLog::dispatch($machine->id, $machine->company_id, "[PickupCode] Verification failed: :code", 'info', ['code' => $code]);
|
||||||
|
|
||||||
return response()->json(['success' => false, 'message' => 'Invalid code', 'code' => 404, 'remaining_attempts' => 5 - $fails], 404);
|
return response()->json(['success' => false, 'message' => 'Invalid code', 'code' => 404, 'remaining_attempts' => 5 - $fails], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,7 +543,7 @@ class MachineController extends Controller
|
|||||||
'action' => 'verify_success',
|
'action' => 'verify_success',
|
||||||
'remark' => "log.pickup.verify_success",
|
'remark' => "log.pickup.verify_success",
|
||||||
'raw_data' => [
|
'raw_data' => [
|
||||||
'machine_sn' => $machine->serial_no,
|
'machine_sn' => $machine->serial_no,
|
||||||
'code' => $pickupCode->code,
|
'code' => $pickupCode->code,
|
||||||
'slot' => $pickupCode->slot_no
|
'slot' => $pickupCode->slot_no
|
||||||
]
|
]
|
||||||
@ -573,24 +572,28 @@ class MachineController extends Controller
|
|||||||
{
|
{
|
||||||
$machine = $request->get('machine');
|
$machine = $request->get('machine');
|
||||||
$lockoutKey = "passcode_lockout:{$machine->id}";
|
$lockoutKey = "passcode_lockout:{$machine->id}";
|
||||||
|
|
||||||
if (Cache::has($lockoutKey)) {
|
if (Cache::has($lockoutKey)) {
|
||||||
return response()->json(['success' => false, 'message' => 'Locked', 'code' => 429], 429);
|
return response()->json(['success' => false, 'message' => 'Locked', 'code' => 429], 429);
|
||||||
}
|
}
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), ['code' => 'required|string|size:8']);
|
$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');
|
$code = $request->input('code');
|
||||||
$passCode = PassCode::where('machine_id', $machine->id)
|
$passCode = PassCode::where('machine_id', $machine->id)
|
||||||
->where('code', $code)
|
->where('code', $code)
|
||||||
->where('status', 'active')
|
->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();
|
->first();
|
||||||
|
|
||||||
if (!$passCode) {
|
if (!$passCode) {
|
||||||
$fails = Cache::increment("passcode_fails:{$machine->id}");
|
$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);
|
return response()->json(['success' => false, 'code' => 404], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +625,7 @@ class MachineController extends Controller
|
|||||||
public function verifyStaffCard(Request $request)
|
public function verifyStaffCard(Request $request)
|
||||||
{
|
{
|
||||||
$machine = $request->get('machine');
|
$machine = $request->get('machine');
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'code' => 'required|string', // 卡片 UID
|
'code' => 'required|string', // 卡片 UID
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -164,7 +164,6 @@ return [
|
|||||||
'response' => [
|
'response' => [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'code' => 200,
|
'code' => 200,
|
||||||
'message' => 'OK',
|
|
||||||
'data' => [
|
'data' => [
|
||||||
[
|
[
|
||||||
't070v01' => '測試機台廣告',
|
't070v01' => '測試機台廣告',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user