rabb
This commit is contained in:
@@ -7,6 +7,7 @@ use app\common\model\OrderInfo;
|
||||
use app\common\model\RabbitMqConfig;
|
||||
use ba\Random;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use support\think\Db;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -35,11 +36,13 @@ class RabbOrderPrint extends Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
|
||||
$host = RabbitMqConfig::$host;
|
||||
$port = RabbitMqConfig::$port;
|
||||
$user = RabbitMqConfig::$user;
|
||||
$password = RabbitMqConfig::$password;
|
||||
$queue = RabbitMqConfig::$queue_t . '-order.print.queue';
|
||||
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
@@ -58,10 +61,10 @@ class RabbOrderPrint extends Command
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg){
|
||||
$callback = function ($msg) use ($queue){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::write('收到消息--->' . $data . '--->' . $date_time . "\n");
|
||||
Log::info('收到消息--->' . $data . '--->' . $date_time . "\n");
|
||||
// 如果是数字。则打印订单
|
||||
$is_log = false;
|
||||
$curl_error = '';
|
||||
@@ -76,7 +79,7 @@ class RabbOrderPrint extends Command
|
||||
$order_id = $data;
|
||||
}
|
||||
print_r($order_id . "\r\n");
|
||||
$order = OrderInfo::where(['id' => $order_id])->find();
|
||||
$order = Db::table('tb_order_info')->where(['id' => $order_id])->find();
|
||||
if($order) {
|
||||
$rand = 'cashier_order' . Random::build();
|
||||
$send_id = 'cashier_'. $order['shop_id'];
|
||||
@@ -105,14 +108,14 @@ class RabbOrderPrint extends Command
|
||||
$curl_error = 'Curl error: ' . curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
Log::write('内部通讯结果(订单打印)--->' . $output . '通讯ID--->cashier_' .$order['shop_id']. '---' . date('Y-m-d H:i:s') . "\n");
|
||||
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) {
|
||||
MqLog::create([
|
||||
'queue' => '',
|
||||
Db::table('tb_mq_log')->insert([
|
||||
'queue' => $queue,
|
||||
'msg' => $data,
|
||||
'type' => 'orderPrint',
|
||||
'plat' => 'Cashier',
|
||||
|
||||
Reference in New Issue
Block a user