1. 優化「出貨紀錄」介面,重新排列欄位優先級並移除冗餘的機台流水號。 2. 統一出貨紀錄中的商品與貨道樣式,與取貨碼模組視覺語言同步。 3. 修正出貨紀錄搜尋邏輯,支援商品名稱與貨道編號模糊搜尋。 4. 修正「訂單詳情」側滑面板中的金額顯示(修正 price/subtotal 映射)。 5. 補強訂單詳情的出貨狀態 (dispense_status) 標籤顯示邏輯。 6. 將出貨紀錄中的「數量」表頭修正為「金額」,確保與 MQTT 協議回傳資料語意一致。 7. 更新多語系檔,新增搜尋欄位 placeholder 與相關 UI 標籤翻譯。 8. 新增發票資料表 machine_time 欄位遷移檔,以完整記錄機台開立時間。
83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Machine;
|
|
|
|
use App\Models\Machine\Machine;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ProcessTransaction implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected $serialNo;
|
|
protected $payload;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct(string $serialNo, array $payload)
|
|
{
|
|
$this->serialNo = $serialNo;
|
|
$this->payload = $payload;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(\App\Services\Transaction\TransactionService $transactionService, \App\Services\Machine\MqttService $mqttService): void
|
|
{
|
|
$machine = Machine::withoutGlobalScopes()->where('serial_no', $this->serialNo)->first();
|
|
|
|
if (!$machine) {
|
|
Log::warning("MQTT Transaction: Machine not found", ['serial_no' => $this->serialNo]);
|
|
return;
|
|
}
|
|
|
|
$flowId = $this->payload['flow_id'] ?? 'N/A';
|
|
|
|
try {
|
|
// 將 serial_no 放入 payload 供 Service 使用
|
|
$data = $this->payload;
|
|
$data['serial_no'] = $this->serialNo;
|
|
|
|
$transactionService->processTransaction($data);
|
|
|
|
ProcessStateLog::dispatch(
|
|
$machine->id,
|
|
$machine->company_id,
|
|
"Transaction processed: :id",
|
|
'info',
|
|
array_merge($this->payload, ['id' => $flowId]),
|
|
'transaction'
|
|
);
|
|
|
|
// 發送成功回饋 (ACK)
|
|
$mqttService->pushCommand($this->serialNo, 'transaction_ack', [
|
|
'flow_id' => $flowId,
|
|
'status' => 'success',
|
|
'message' => 'Processed successfully'
|
|
], (string) $flowId);
|
|
|
|
} catch (\Exception $e) {
|
|
Log::error("Failed to process MQTT transaction for machine {$this->serialNo}: " . $e->getMessage(), [
|
|
'payload' => $this->payload,
|
|
'exception' => $e
|
|
]);
|
|
|
|
// 發送失敗回饋 (ACK)
|
|
$mqttService->pushCommand($this->serialNo, 'transaction_ack', [
|
|
'flow_id' => $flowId,
|
|
'status' => 'error',
|
|
'message' => $e->getMessage()
|
|
], (string) $flowId);
|
|
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|