From 15cf21e512a6a9dea2871cfa6344d14f90ff61ae Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Tue, 28 Oct 2025 14:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restart_services.sh | 14 +++-- scripts/applyamstemp.php | 63 +++++++++++++++++++++ scripts/birthdaygiftsms.php | 49 ++++++++++++++++ scripts/rabborderprint.php | 102 ++++++++++++++++++++++++++++++++++ scripts/rabbproductupdate.php | 90 ++++++++++++++++++++++++++++++ sd.php | 48 ---------------- stop_webman_commands.php | 8 +-- 7 files changed, 318 insertions(+), 56 deletions(-) create mode 100644 scripts/applyamstemp.php create mode 100644 scripts/birthdaygiftsms.php create mode 100644 scripts/rabborderprint.php create mode 100644 scripts/rabbproductupdate.php delete mode 100644 sd.php diff --git a/restart_services.sh b/restart_services.sh index efe9852..5e11c99 100644 --- a/restart_services.sh +++ b/restart_services.sh @@ -18,17 +18,23 @@ php start.php stop echo "启动 webman 服务(后台模式)..." php start.php start -d + +cd /rh/p_ysk/scripts || { + echo "错误:无法切换到目录 /rh/p_ysk/scripts" + exit 1 +} + # 启动各类 webman 进程(后台运行) echo "启动 applysmstemp 进程..." -nohup php webman applysmstemp & +nohup php applysmstemp.php & echo "启动 birthdaygiftsms 进程..." -nohup php webman birthdaygiftsms & +nohup php birthdaygiftsms.php & echo "启动 rabborderprint 进程..." -nohup php webman rabborderprint & +nohup php rabborderprint.php & echo "启动 rabbproductupdate 进程..." -nohup php webman rabbproductupdate & +nohup php rabbproductupdate.php & echo "所有命令执行完成" diff --git a/scripts/applyamstemp.php b/scripts/applyamstemp.php new file mode 100644 index 0000000..af936a0 --- /dev/null +++ b/scripts/applyamstemp.php @@ -0,0 +1,63 @@ +channel(); + $rabbit_channel->queue_declare($queue, false, true, false, false, false, [ +// 'x-message-ttl' => ['I', 180000] + ]); + + $callback = function ($msg) use ($queue){ + $data = $msg->body; + Log::info('MQ收到消息[申请新短信模版/营销短信发送/微信模版消息]--->' . $data . "\n"); + $arr = explode(',', $data); + if(isset($arr[2])) { + $type = $arr[2]; + if($type == 'applySmsTemp') { + // 发给队列 短信模版审核 + $a = Redis::send('apply.sms.temp', $data); + Log::info('消息队列投递结果----》' . $a); + }elseif ($type == 'sendMarkSms') { + // 发给队列 营销短信发送 + Redis::send('send.mark.sms', $data); + }elseif ($type == 'sendWechatTemp') { + // 发给队列 发送微信模版消息 + Redis::send('send.wechat.temp', $data); + } + }else { + Log::info('MQ收到消息[申请新短信模版/营销短信发送/微信模版消息]格式错误'); + } + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); + }; + $rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback); + while ($rabbit_channel->is_consuming()) { + $rabbit_channel->wait(); + } + $rabbit_channel->close(); + $connection->close(); diff --git a/scripts/birthdaygiftsms.php b/scripts/birthdaygiftsms.php new file mode 100644 index 0000000..f77546d --- /dev/null +++ b/scripts/birthdaygiftsms.php @@ -0,0 +1,49 @@ +channel(); + $rabbit_channel->queue_declare($queue, false, true, false, false, false, [ +// 'x-message-ttl' => ['I', 180000] + ]); + + $callback = function ($msg) use ($queue){ + $date_time = date('Y-m-d H:i:s'); + $data = $msg->body; + Log::info('MQ收到消息[生日有礼]--->' . $data . '--->' . $date_time . "\n"); + // 发给队列 + Redis::send('birthday.gift.sms', $data); + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); + }; + $rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback); + while ($rabbit_channel->is_consuming()) { + $rabbit_channel->wait(); + } + $rabbit_channel->close(); + $connection->close(); diff --git a/scripts/rabborderprint.php b/scripts/rabborderprint.php new file mode 100644 index 0000000..ac68122 --- /dev/null +++ b/scripts/rabborderprint.php @@ -0,0 +1,102 @@ +channel(); + $rabbit_channel->queue_declare($queue, false, true, false, false, false, [ + 'x-message-ttl' => ['I', 180000] + ]); + + $callback = function ($msg) use ($queue){ + $date_time = date('Y-m-d H:i:s'); + $data = $msg->body; + Log::info('MQ收到消息[订单打印]--->' . $data . '--->' . $date_time . "\n"); + // 如果是数字。则打印订单 + $is_log = false; + $curl_error = ''; + print_r($data . "\r\n"); + $order_id_t = strpos($data, '_'); + print_r($order_id_t . "嘿嘿\r\n"); + if($order_id_t !== false) { + print_r($order_id_t . "\r\n"); + $order_id = substr($data, 0, $order_id_t); + }else { + print_r( "无下划线\r\n"); + $order_id = $data; + } + print_r($order_id . "\r\n"); + $order = Db::table('tb_order_info')->where(['id' => $order_id])->find(); + if($order) { + $rand = 'cashier_order' . Random::build(); + $send_id = 'cashier_'. $order['shop_id']; + // 收银机打印订单 + $snd_data = [ + 'msg' => '收银机订单打印', + 'type' => 'cashier', + 'operate_type' => 'order_print', + 'data_type' => 'order', + 'status' => 1, + 'method' => 'sendToUid', + 'send_num' => 0, + 'send_id' => $send_id, + 'msg_id' => $rand, + '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); + } + 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; + } + if($is_log) { + Db::table('tb_mq_log')->insert([ + 'queue' => $queue, + 'msg' => $data, + 'type' => 'orderPrint', + 'plat' => 'Cashier', + 'create_time' => date('Y-m-d H:i:s'), + 'fail_time' => date('Y-m-d H:i:s'), + 'err_info' => $curl_error, + ]); + } + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); + }; + $rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback); + while ($rabbit_channel->is_consuming()) { + $rabbit_channel->wait(); + } + $rabbit_channel->close(); + $connection->close(); diff --git a/scripts/rabbproductupdate.php b/scripts/rabbproductupdate.php new file mode 100644 index 0000000..a1e66de --- /dev/null +++ b/scripts/rabbproductupdate.php @@ -0,0 +1,90 @@ +channel(); + $rabbit_channel->queue_declare($queue, false, true, false, false, false, [ +// 'x-message-ttl' => ['I', 180000] + ]); + + $callback = function ($msg) use ($queue){ + $date_time = date('Y-m-d H:i:s'); + $data = $msg->body; + Log::info('MQ收到消息[商品更新]--->' . $data . '--->' . $date_time . "\n"); + // 如果是数字。则打印订单 + $is_log = false; + $curl_error = ''; + if(is_numeric($data)) { + $rand = 'product_update' . Random::build(); + $send_id = 'product_update'. $data; + $method = 'sendToGroup'; + $snd_data = [ + 'msg' => '商品更新', + 'type' => 'product', + 'operate_type' => 'product_update', + 'data_type' => 'product_update', + 'status' => 1, + 'method' => $method, + 'send_num' => 0, + 'send_id' => $send_id, + 'msg_id' => $rand, + '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); + } + 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, + 'msg' => $data, + 'type' => 'product_update', + 'plat' => 'product', + 'create_time' => date('Y-m-d H:i:s'), + 'fail_time' => date('Y-m-d H:i:s'), + 'err_info' => $curl_error, + ]); + } + } + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); + }; + $rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback); + while ($rabbit_channel->is_consuming()) { + $rabbit_channel->wait(); + } + $rabbit_channel->close(); + $connection->close(); diff --git a/sd.php b/sd.php deleted file mode 100644 index b2260b1..0000000 --- a/sd.php +++ /dev/null @@ -1,48 +0,0 @@ -eventLoop = \Workerman\Events\Swoole::class; - -$worker->onWorkerStart = function() { - // Create RabbitMQ Client - $client = Client::factory([ - 'host' => '127.0.0.1', - 'port' => 5672, - 'user' => 'guest', - 'password' => 'guest', - 'vhost' => '/', - 'heartbeat' => 60, - 'heartbeat_callback' => function () { - echo " [-] coroutine-consumer-heartbeat\n"; - }, - 'interval' => [100, 300] - ])->connect(); - $channel = $client->channel(); - $channel->queueDeclare('hello-coroutine'); - // Consumer - $channel->consume(function (Message $message, Channel $channel, \Bunny\AbstractClient $client) { - echo " [>] Received ", $message->content, "\n"; - }, - 'hello-coroutine', - '', - false, - true - ); - $client->run(); - echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; - // Producer - \Workerman\Timer::add($interval = 5 , function () use ($channel) { - $channel->publish($message = 'Hello World By Self Timer. ' . time(), [], '', 'hello-coroutine'); - echo " [<] Sent $message\n"; - }); - echo " [!] Producer timer created, interval: $interval s.\n"; -}; -Worker::runAll(); \ No newline at end of file diff --git a/stop_webman_commands.php b/stop_webman_commands.php index f70f765..d05e8ec 100644 --- a/stop_webman_commands.php +++ b/stop_webman_commands.php @@ -6,10 +6,10 @@ // 定义需要终止的进程关键词(与启动命令对应) $processKeywords = [ - 'webman applysmstemp', - 'webman birthdaygiftsms', - 'webman rabborderprint', - 'webman rabbproductupdate' + 'applysmstemp.php', + 'birthdaygiftsms.php', + 'rabborderprint.php', + 'rabbproductupdate.php' ]; echo "开始终止 Webman 进程...\n";