From 3968794197bc3fbccc73eb4a74092c041eece7af Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Wed, 5 Nov 2025 09:24:25 +0800 Subject: [PATCH] client create --- scripts/rabborderprint.php | 52 +++++++++++++++++++++++------------ scripts/rabbproductupdate.php | 40 ++++++++++++++++++++------- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/scripts/rabborderprint.php b/scripts/rabborderprint.php index 62b8340..8d7bf37 100644 --- a/scripts/rabborderprint.php +++ b/scripts/rabborderprint.php @@ -4,16 +4,18 @@ require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../support/bootstrap.php'; use ba\Random; +use extend\workermans\model\Base; use PhpAmqpLib\Connection\AMQPStreamConnection; +use support\Redis; use support\think\Db; use support\Log; +use GatewayClient\Gateway; - $host = config('cons.mq.host'); - $port = config('cons.mq.port'); - $user = config('cons.mq.user'); - $password = config('cons.mq.password'); - $queue = config('cons.mq.queue_t') . '-order.print.queue'; - +$host = config('cons.mq.host'); +$port = config('cons.mq.port'); +$user = config('cons.mq.user'); +$password = config('cons.mq.password'); +$queue = config('cons.mq.queue_t') . '-order.print.queue'; try { // define('AMQP_DEBUG', true); @@ -71,18 +73,34 @@ try { 'data' => $data ]; $snd_data_json = json_encode($snd_data); - // 内部给收银机推送打订单 - $url = 'http://127.0.0.1:8686/?method=sendToUid&account='. $send_id .'¶ms=' . $snd_data_json; // 替换为你的服务地址和端口 - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $output = curl_exec($ch); - if (curl_errno($ch)) { - $is_log = true; - $curl_error = 'Curl error: ' . curl_error($ch); + Gateway::$registerAddress = '127.0.0.1:1238'; + $res = Gateway::sendToUid($send_id, $snd_data_json); + Log::info('订单打印推送结果-->' . $res); + $result = Redis::get($snd_data['send_id']); + if($result) { + $msg_id_arr = json_decode($result, true); + $msg_id_arr_c = count($msg_id_arr); + $msg_id_arr[$msg_id_arr_c] = $snd_data; + $result_n = json_encode($msg_id_arr); + Base::setredis_new($result_n, $snd_data['send_id']); + }else { + $params_arr_n[] = $snd_data; + print_r('数组-------->' . json_encode($params_arr_n)) . "\r\n"; + Base::setredis_new(json_encode($params_arr_n), $snd_data['send_id']); } - curl_close($ch); - Log::info('内部通讯结果(订单打印)--->' . $output . '通讯ID--->cashier_' .$order['shop_id']. '---' . date('Y-m-d H:i:s') . "\n"); +// +// 内部给收银机推送打订单 +// $url = 'http://127.0.0.1:8686/?method=sendToUid&account='. $send_id .'¶ms=' . $snd_data_json; // 替换为你的服务地址和端口 +// $ch = curl_init(); +// curl_setopt($ch, CURLOPT_URL, $url); +// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); +// $output = curl_exec($ch); +// if (curl_errno($ch)) { +// $is_log = true; +// $curl_error = 'Curl error: ' . curl_error($ch); +// } +// curl_close($ch); +// Log::info('内部通讯结果(订单打印)--->' . $output . '通讯ID--->cashier_' .$order['shop_id']. '---' . date('Y-m-d H:i:s') . "\n"); }else { $curl_error = 'order Data is empty'; $is_log = true; diff --git a/scripts/rabbproductupdate.php b/scripts/rabbproductupdate.php index 3c45620..1e58752 100644 --- a/scripts/rabbproductupdate.php +++ b/scripts/rabbproductupdate.php @@ -7,6 +7,8 @@ use ba\Random; use PhpAmqpLib\Connection\AMQPStreamConnection; use support\think\Db; use support\Log; +use GatewayClient\Gateway; +use support\Redis; try { // define('AMQP_DEBUG', true); @@ -55,17 +57,35 @@ use support\Log; 'data' => $data ]; $snd_data_json = json_encode($snd_data); - $url = 'http://127.0.0.1:8686/?method=' . $method . '&account='. $send_id .'¶ms=' . $snd_data_json; // 替换为你的服务地址和端口 - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $output = curl_exec($ch); - if (curl_errno($ch)) { - $is_log = true; - $curl_error = 'Curl error: ' . curl_error($ch); + Gateway::$registerAddress = '127.0.0.1:1238'; + $res = Gateway::sendToGroup($send_id, $snd_data_json); + Log::info('商品更新推送结果-->' . $res); + $result = Redis::get($snd_data['send_id']); + if($result) { + $msg_id_arr = json_decode($result, true); + $msg_id_arr_c = count($msg_id_arr); + $msg_id_arr[$msg_id_arr_c] = $snd_data; + $result_n = json_encode($msg_id_arr); + \extend\workermans\model\Base::setredis_new($result_n, $snd_data['send_id']); + }else { + $params_arr_n[] = $snd_data; + print_r('数组-------->' . json_encode($params_arr_n)) . "\r\n"; + \extend\workermans\model\Base::setredis_new(json_encode($params_arr_n), $snd_data['send_id']); } - curl_close($ch); - Log::info('内部通讯结果(商品更新)--->' . $output . '通讯ID--->shop_id-->' .$send_id. '---' . date('Y-m-d H:i:s') . "\n"); + + + +// $url = 'http://127.0.0.1:8686/?method=' . $method . '&account='. $send_id .'¶ms=' . $snd_data_json; // 替换为你的服务地址和端口 +// $ch = curl_init(); +// curl_setopt($ch, CURLOPT_URL, $url); +// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); +// $output = curl_exec($ch); +// if (curl_errno($ch)) { +// $is_log = true; +// $curl_error = 'Curl error: ' . curl_error($ch); +// } +// curl_close($ch); +// Log::info('内部通讯结果(商品更新)--->' . $output . '通讯ID--->shop_id-->' .$send_id. '---' . date('Y-m-d H:i:s') . "\n"); if($is_log) { Db::table('tb_mq_log')->insert([ 'queue' => $queue,