Commit faafecce authored by 王源's avatar 王源 🎧

Merge branch 'feature/exception' into rpc/shopify

parents 993c55ea b0e265fd
<?php
declare(strict_types=1);
namespace Meibuyu\Micro\Amqp\Producer;
use Exception;
use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage;
use Meibuyu\Micro\Exceptions\HttpResponseException;
use Meibuyu\Micro\Model\Auth;
/**
* @Producer(exchange="micro", routingKey="exception-log")
*/
class ExceptionLogProducer extends ProducerMessage
{
public function __construct($data)
{
try {
$data['operator'] = Auth::user()['name'];
} catch (HttpResponseException $e) {
put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
// 排除依赖包文件和运行缓存文件
if (strpos($data['file'], '/vendor/') === false && strpos($data['file'], '/runtime/') === false) {
try {
exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output);
if (!empty($output[0]) && is_string($output[0])) {
preg_match('/(?<=\()[^ ]+/', $output[0], $matches);
if (!empty($matches[0])) {
$data['coder'] = $matches[0];
}
}
} catch (Exception $e) {
put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
}
$this->payload = $data;
}
}
......@@ -4,16 +4,27 @@ declare(strict_types=1);
namespace Meibuyu\Micro\Exceptions\Handler;
use Exception;
use Hyperf\Amqp\Producer;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\Logger\LoggerFactory;
use Meibuyu\Micro\Amqp\Producer\ExceptionLogProducer;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Throwable;
class AppExceptionHandler extends ExceptionHandler
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var StdoutLoggerInterface
*/
......@@ -24,20 +35,48 @@ class AppExceptionHandler extends ExceptionHandler
*/
protected $logger;
public function __construct(StdoutLoggerInterface $stdoutLogger, LoggerFactory $loggerFactory)
/**
* @var ConfigInterface
*/
protected $config;
public function __construct(ContainerInterface $container)
{
$this->stdoutLogger = $stdoutLogger;
$this->logger = $loggerFactory->get('Uncaught Exception');
$this->container = $container;
$this->stdoutLogger = $container->get(StdoutLoggerInterface::class);
$this->logger = $container->get(LoggerFactory::class)->get('Uncaught Exception');
$this->config = $container->get(ConfigInterface::class);
}
public function handle(Throwable $throwable, ResponseInterface $response)
{
// 捕获所有未捕获的异常
$this->stopPropagation();
$msg = sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile());
$message = $throwable->getMessage();
$line = $throwable->getLine();
$file = $throwable->getFile();
$trace = $throwable->getTraceAsString();
$code = $throwable->getCode();
$data = [
'server' => $this->config->get('app_name'),
'file' => $file,
'line' => $line,
'message' => $message,
'trace' => $trace,
'code' => $code,
'created_at' => now(),
];
try {
$exceptionLogProducer = new ExceptionLogProducer($data);
$producer = $this->container->get(Producer::class);
$producer->produce($exceptionLogProducer);
} catch (Exception $e) {
put_log('异常日志失败; ' . $e->getMessage(), 'ExceptionLogProducer.log');
}
$msg = sprintf('%s[%s] in %s', $message, $line, $file);
$this->stdoutLogger->error($msg);
$this->logger->error($msg);
$this->stdoutLogger->error($throwable->getTraceAsString());
$this->stdoutLogger->error($trace);
return $response->withStatus(500)->withBody(new SwooleStream($msg));
}
......
......@@ -16,4 +16,11 @@ interface OperationServiceInterface
* @return mixed
*/
public function getBusinessSaleOtherDatum(array $conditions);
/**
* 获取销售报表其他数据
* @param array $conditions 必传条件 site_id team_id start_time end_time
* @return mixed
*/
public function getBusinessSaleOtherDatumRmb(array $conditions);
}
\ No newline at end of file
......@@ -93,6 +93,14 @@ interface SubOrderServiceInterface
*/
public function purchaseError($orderId,$errorCode):array ;
/**
* 1688采购取消
* @param $orderNo
* @param $editData
* @return bool
*/
public function purchaseCancel($orderNo,$editData = []):bool;
/**
* 1688采购 修改oa子订单
* @param $editData
......
......@@ -12,4 +12,18 @@ interface PurchaseDoneServiceInterface
* @return mixed
*/
public function archivePurchase($orderIds);
/**
*通过子订单编号通知取消
* @param array $orderIds 子订单编号 ['3333444','12222']
* @return mixed
*/
public function noticeToCancel($orderIds);
/**
* 传输产品规格
* @param $data ['order_id'=>'子订单编号','order_standard'=>'产品规格']
* @return mixed
*/
public function productStandard($data);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment