All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m2s
- 修正 Alpine.js 作用域問題,恢復效期編輯彈窗功能 - 整合機台日誌與效期管理至主列表頁 (Index) - 優化大螢幕貨道格線佈局,解決日期折行問題 - 縮小彈窗字體與內距,調整為極簡奢華風 UI - 新增貨道效期與批號欄位之 Migration 與模型關聯 - 補齊中、英、日三語系翻譯檔
143 lines
3.9 KiB
PHP
143 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\App;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Machine\Machine;
|
|
use App\Jobs\Machine\ProcessHeartbeat;
|
|
use App\Jobs\Machine\ProcessTimerStatus;
|
|
use App\Jobs\Machine\ProcessCoinInventory;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class MachineController extends Controller
|
|
{
|
|
/**
|
|
* B010: Machine Heartbeat & Status Update (Asynchronous)
|
|
*/
|
|
public function heartbeat(Request $request)
|
|
{
|
|
$machine = $request->get('machine');
|
|
$data = $request->all();
|
|
|
|
// 異步處理狀態更新
|
|
ProcessHeartbeat::dispatch($machine->serial_no, $data);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'code' => 200,
|
|
'message' => 'OK',
|
|
'status' => '49' // 某些硬體可能需要的成功碼
|
|
], 202); // 202 Accepted
|
|
}
|
|
|
|
/**
|
|
* B018: Record Machine Restock/Setup Report (Asynchronous)
|
|
*/
|
|
public function recordRestock(Request $request)
|
|
{
|
|
$machine = $request->get('machine');
|
|
$data = $request->all();
|
|
$data['serial_no'] = $machine->serial_no;
|
|
|
|
\App\Jobs\Machine\ProcessRestockReport::dispatch($data);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'code' => 200,
|
|
'message' => 'Restock report accepted',
|
|
'status' => '49'
|
|
], 202);
|
|
}
|
|
|
|
/**
|
|
* B017: Get Slot Info & Stock (Synchronous)
|
|
*/
|
|
public function getSlots(Request $request)
|
|
{
|
|
$machine = $request->get('machine');
|
|
$slots = $machine->slots()->with('product')->get();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'code' => 200,
|
|
'data' => $slots->map(function ($slot) {
|
|
return [
|
|
'slot_no' => $slot->slot_no,
|
|
'product_id' => $slot->product_id,
|
|
'stock' => $slot->stock,
|
|
'capacity' => $slot->capacity,
|
|
'price' => $slot->price,
|
|
'status' => $slot->status,
|
|
];
|
|
})
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* B710: Sync Timer status (Asynchronous)
|
|
*/
|
|
public function syncTimer(Request $request)
|
|
{
|
|
$machine = $request->get('machine');
|
|
$data = $request->all();
|
|
|
|
ProcessTimerStatus::dispatch($machine->serial_no, $data);
|
|
|
|
return response()->json(['success' => true], 202);
|
|
}
|
|
|
|
/**
|
|
* B220: Sync Coin Inventory (Asynchronous)
|
|
*/
|
|
public function syncCoinInventory(Request $request)
|
|
{
|
|
$machine = $request->get('machine');
|
|
$data = $request->all();
|
|
|
|
ProcessCoinInventory::dispatch($machine->serial_no, $data);
|
|
|
|
return response()->json(['success' => true], 202);
|
|
}
|
|
|
|
/**
|
|
* B650: Verify Member Code/Barcode (Synchronous)
|
|
*/
|
|
public function verifyMember(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'code' => 'required|string',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return response()->json(['success' => false, 'message' => 'Invalid code'], 400);
|
|
}
|
|
|
|
$code = $request->input('code');
|
|
|
|
// 搜尋會員 (barcode 或特定驗證碼)
|
|
$member = \App\Models\Member\Member::where('barcode', $code)
|
|
->orWhere('id', $code) // 暫時支援 ID
|
|
->first();
|
|
|
|
if (!$member) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'code' => 404,
|
|
'message' => 'Member not found'
|
|
], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'code' => 200,
|
|
'data' => [
|
|
'member_id' => $member->id,
|
|
'name' => $member->name,
|
|
'points' => $member->points,
|
|
'wallet_balance' => $member->wallet_balance ?? 0,
|
|
]
|
|
]);
|
|
}
|
|
}
|