其他订单打印
This commit is contained in:
@@ -43,4 +43,8 @@ nohup php orderDetailUpdate.php &
|
||||
echo "启动 consinfochangequeue 进程..."
|
||||
nohup php consinfochangequeue.php &
|
||||
|
||||
echo "启动 otherprint 进程..."
|
||||
nohup php otherprint.php &
|
||||
|
||||
|
||||
echo "所有命令执行完成"
|
||||
|
||||
113
scripts/otherprint.php
Normal file
113
scripts/otherprint.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
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') . '-other.print.local.queue';
|
||||
|
||||
try {
|
||||
// define('AMQP_DEBUG', true);
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
15
|
||||
);
|
||||
$rabbit_channel = $connection->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 = '';
|
||||
$order_id_t = strpos($data, '_');
|
||||
if($order_id_t !== false) {
|
||||
$order_id = substr($data, 0, $order_id_t);
|
||||
}else {
|
||||
$order_id = $data;
|
||||
}
|
||||
$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' => 'other_print',
|
||||
'data_type' => 'other_print',
|
||||
'status' => 1,
|
||||
'method' => 'sendToUid',
|
||||
'send_num' => 0,
|
||||
'send_id' => $send_id,
|
||||
'msg_id' => $rand,
|
||||
'data' => $data
|
||||
];
|
||||
$snd_data_json = json_encode($snd_data);
|
||||
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;
|
||||
Base::setredis_new(json_encode($params_arr_n), $snd_data['send_id']);
|
||||
}
|
||||
}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()) {
|
||||
Log::info('order.print.queue-MQ准备调用wait');
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
}catch (Exception $exception) {
|
||||
Log::info('order.print.queue-MQ错误' . $exception->getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ $processKeywords = [
|
||||
'rabborderprint.php',
|
||||
'orderDetailUpdate.php',
|
||||
'consinfochangequeue.php',
|
||||
'otherprint.php',
|
||||
'rabbproductupdate.php'
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user