购物车迁入
This commit is contained in:
108
app/command/LogAddZip.php
Normal file
108
app/command/LogAddZip.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ZipArchive;
|
||||
|
||||
|
||||
class LogAddZip extends Command
|
||||
{
|
||||
protected static $defaultName = 'LogAddZip';
|
||||
protected static $defaultDescription = 'LogAddZip';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$dir = 'runtime/worker/';
|
||||
$yesterday = date("Ymd", strtotime("-1 day"));
|
||||
// worker 打包
|
||||
$file = $dir . '/' . $yesterday . '.log';
|
||||
$xt_file = $dir . '/xt_' . $yesterday . '.log';
|
||||
$file_zip = $dir . '/' . $yesterday . '.zip';
|
||||
|
||||
$is_close = false;
|
||||
$xt_is_close = false;
|
||||
if(!file_exists($file_zip)) {
|
||||
$zip = new ZipArchive();
|
||||
if($zip->open($file_zip, ZipArchive::CREATE) === TRUE) {
|
||||
if(file_exists($file)) {
|
||||
if($zip->addFile($file, $yesterday . '.log')) {
|
||||
$is_close = true;
|
||||
print_r($yesterday . '.log' . "\r\n");
|
||||
}
|
||||
}
|
||||
if(file_exists($xt_file)) {
|
||||
if($zip->addFile($xt_file, 'xt_' . $yesterday . '.log')) {
|
||||
$xt_is_close = true;
|
||||
print_r('xt_' . $yesterday . '.log' . "\r\n");
|
||||
}
|
||||
}
|
||||
if ($is_close || $xt_is_close) {
|
||||
if($zip->close()) {
|
||||
if($is_close) {
|
||||
unlink($file);
|
||||
}
|
||||
if($xt_is_close) {
|
||||
unlink($xt_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$dir_l = 'runtime/log/';
|
||||
// 如果今天是1号
|
||||
if(date('d') == '01') {
|
||||
// 找到上个月以及最后一天
|
||||
// 上个月
|
||||
$lastmonth = date('Ym', strtotime('-1 month'));
|
||||
// 最后一天
|
||||
$day = date('t', strtotime('last month'));
|
||||
$dir_log = $dir_l . $lastmonth . '/' . $day . '.log';
|
||||
}else {
|
||||
$day = date("d", strtotime("-1 day"));
|
||||
$lastmonth = date('Ym');
|
||||
$dir_log = $dir_l . $lastmonth . '/' . $day . '.log';
|
||||
}
|
||||
// log 打包
|
||||
$file_log = $dir_log;
|
||||
$file_log_zip = $dir_l . '/' . $lastmonth . '/' . $day . '.zip';
|
||||
|
||||
$is_log_close = false;
|
||||
if(!file_exists($file_log_zip)) {
|
||||
$zip = new ZipArchive();
|
||||
if($zip->open($file_log_zip, ZipArchive::CREATE) === TRUE) {
|
||||
if(file_exists($file_log)) {
|
||||
if($zip->addFile($file_log, $day . '.log')) {
|
||||
$is_log_close = true;
|
||||
print_r($day . '.log' . "\r\n");
|
||||
}
|
||||
}
|
||||
if ($is_log_close) {
|
||||
if($zip->close()) {
|
||||
unlink($file_log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
135
app/command/RabbOrderPrint.php
Normal file
135
app/command/RabbOrderPrint.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\model\MqLog;
|
||||
use app\common\model\OrderInfo;
|
||||
use app\common\model\RabbitMqConfig;
|
||||
use ba\Random;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use support\Log;
|
||||
|
||||
|
||||
class RabbOrderPrint extends Command
|
||||
{
|
||||
protected static $defaultName = 'RabbOrderPrint';
|
||||
protected static $defaultDescription = 'RabbOrderPrint';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
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,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::write('收到消息--->' . $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 = OrderInfo::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::write('内部通讯结果(订单打印)--->' . $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' => '',
|
||||
'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();
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
118
app/command/RabbProductUpdate.php
Normal file
118
app/command/RabbProductUpdate.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\model\MqLog;
|
||||
use app\common\model\RabbitMqConfig;
|
||||
use ba\Random;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use think\facade\Log;
|
||||
|
||||
|
||||
class RabbProductUpdate extends Command
|
||||
{
|
||||
protected static $defaultName = 'RabbProductUpdate';
|
||||
protected static $defaultDescription = 'RabbProductUpdate';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$host = RabbitMqConfig::$host;
|
||||
$port = RabbitMqConfig::$port;
|
||||
$user = RabbitMqConfig::$user;
|
||||
$password = RabbitMqConfig::$password;
|
||||
$queue = RabbitMqConfig::$queue_t . '-product.info.change.queue';
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::write('收到商品更新消息--->' . $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::write('内部通讯结果(商品更新)--->' . $output . '通讯ID--->shop_id-->' .$send_id. '---' . date('Y-m-d H:i:s') . "\n");
|
||||
if($is_log) {
|
||||
MqLog::create([
|
||||
'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();
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
14
app/common/MqLog.php
Normal file
14
app/common/MqLog.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use ba\Random;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 错误日志
|
||||
*/
|
||||
class MqLog extends Model
|
||||
{
|
||||
|
||||
}
|
||||
13
app/common/OrderInfo.php
Normal file
13
app/common/OrderInfo.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 订单
|
||||
*/
|
||||
class OrderInfo extends Model
|
||||
{
|
||||
|
||||
}
|
||||
19
app/common/RabbitMqConfig.php
Normal file
19
app/common/RabbitMqConfig.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use ba\Random;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 错误日志
|
||||
*/
|
||||
class RabbitMqConfig extends Model
|
||||
{
|
||||
public static $host = '121.40.109.122';
|
||||
public static $port = '5672';
|
||||
public static $user = 'chaozg';
|
||||
public static $password = 'chaozg123';
|
||||
|
||||
public static $queue_t = 'prod';
|
||||
}
|
||||
Reference in New Issue
Block a user