|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
namespace app\wss;
|
|
|
+use app\model\saas\SaasOrderDetail;
|
|
|
use Workerman\Connection\TcpConnection;
|
|
|
|
|
|
class PrintWss
|
|
|
@@ -17,6 +18,43 @@ class PrintWss
|
|
|
|
|
|
public function onMessage(TcpConnection $connection, $data)
|
|
|
{
|
|
|
+ if (empty($data)) $connection->send(['type' => 'empty','data' => []]);
|
|
|
+ $param = json_decode($data,true);
|
|
|
+ if ($param['type'] == 'get_data') {
|
|
|
+ $printer = explode("-",$param['printer']);
|
|
|
+ $printJob = (new SaasOrderDetail)->where("shop_id",$printer[1])->where("print_id",$printer[0])->where("status",1)->findOrEmpty();
|
|
|
+ if (!$printJob->isEmpty()) {
|
|
|
+ $range = Null;
|
|
|
+ if ($printJob['end_page'] > $printJob['start_page']) {
|
|
|
+ $range = $printJob['start_page']."-".$printJob['end_page'];
|
|
|
+ }
|
|
|
+ if ($printJob['end_page'] == $printJob['start_page']) {
|
|
|
+ $range = (int) $printJob['end_page'];
|
|
|
+ }
|
|
|
+ $color_mode = ($printJob['color']==1?'color':'monochrome');
|
|
|
+ $duplex = "simplex";
|
|
|
+ if ($printJob['paper_size'] == 'A4' && $printJob['duplex'] == 2) {
|
|
|
+ $duplex = 'duplexshort'; // duplexlong
|
|
|
+ }
|
|
|
+ if ($printJob['paper_size'] == 'A3' && $printJob['duplex'] == 2) {
|
|
|
+ $duplex = 'duplexlong'; // duplexshort
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ "type" => "print",
|
|
|
+ "data" => [
|
|
|
+ "jobId" => $printJob['id'],
|
|
|
+ "action" => 'create',
|
|
|
+ "remoteUrl" => "https://".sConf("storage.cos_http_domain")."/".$printJob['path'],
|
|
|
+ "customFileName" => $printJob['order_sn'],
|
|
|
+ "exe" => ['-print-to',$printJob['print_name'],'-print-settings',"{$range},{$printJob['number']}x,{$color_mode},$duplex,paper={$printJob['paper_size']}",'-silent'],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $printJob->status = 2;
|
|
|
+ $printJob->save();
|
|
|
+ } else {
|
|
|
+ $data = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
$connection->send($data);
|
|
|
}
|
|
|
|