|
|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Components\AsyncResponse;
|
|
|
+use App\Log;
|
|
|
use App\Services\DeliveryService;
|
|
|
use App\Services\PrintService;
|
|
|
use App\Terminal;
|
|
|
@@ -21,28 +22,32 @@ class PrintController extends Controller
|
|
|
|
|
|
public function getPrintDataApi(Request $request): array
|
|
|
{
|
|
|
- if(!$request->has('printStr')) return ['success'=> false , 'message' => '为空'];
|
|
|
+ if (!$request->has('printStr')) return ['success' => false, 'message' => '为空'];
|
|
|
$results = app(DeliveryService::class)->getDelivery($request['printStr']);
|
|
|
$ip = $request->getClientIp();
|
|
|
- $terminal = Terminal::query()->where('ip',$ip)->with('printers')->first();
|
|
|
+ $terminal = Terminal::query()->with('printers')->where('ip', $ip)->first();
|
|
|
if (!$terminal) return ['success' => false, 'messages' => '当前终端没有注册'];
|
|
|
$printers = [];
|
|
|
foreach ($terminal->printers as $printer) {
|
|
|
- $printer_type = $printer['print_type'];
|
|
|
- if (!array_key_exists($printer_type,$printers)) $printers[$printer_type] = [];
|
|
|
+ $printer_type = $printer['print_type'];
|
|
|
+ if (!array_key_exists($printer_type, $printers)) $printers[$printer_type] = [];
|
|
|
$printers[$printer_type][] = $printer['printer_name'];
|
|
|
}
|
|
|
- foreach ($results as $key=>$result) {
|
|
|
- $results[$key]['printerName'] = $printers[$result['component_type']][0] ?? '';
|
|
|
+ foreach ($results as $key => $result) {
|
|
|
+ $component_type = $result['component_type'];
|
|
|
+ $type = TerminalPrinter::$PrintType[$component_type];
|
|
|
+ $results[$key]['printer_name'] = $printers[$type][0] ?? '';
|
|
|
}
|
|
|
- return ['success' => true,'data' => $results];
|
|
|
+ return ['success' => true, 'data' => $results];
|
|
|
}
|
|
|
|
|
|
- public function uploadPrintDataApi(Request $request,DeliveryService $service): array
|
|
|
+ public function uploadPrintDataApi(Request $request, DeliveryService $service): array
|
|
|
{
|
|
|
- return $service->customProcessing($request['printData']);
|
|
|
- }
|
|
|
-
|
|
|
+ if (is_string($request['printData']))
|
|
|
+ $request['printData'] = json_decode($request['printData']);
|
|
|
|
|
|
+ $item = $service->customProcessing($request['printData']);
|
|
|
+ return ['success' => true, 'data' => $item];
|
|
|
+ }
|
|
|
|
|
|
}
|