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

Merge branch 'feature/exception' into rpc/shopify

parents 993c55ea b0e265fd
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
"hyperf/service-governance": "~1.1.0", "hyperf/service-governance": "~1.1.0",
"fzaninotto/faker": "^1.9", "fzaninotto/faker": "^1.9",
"phpoffice/phpspreadsheet": "^1.8", "phpoffice/phpspreadsheet": "^1.8",
"dimsav/unix-zipper": "1.*" "dimsav/unix-zipper": "1.*",
"hyperf/amqp": "~1.1.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
<?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); ...@@ -4,16 +4,27 @@ declare(strict_types=1);
namespace Meibuyu\Micro\Exceptions\Handler; namespace Meibuyu\Micro\Exceptions\Handler;
use Exception;
use Hyperf\Amqp\Producer;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream; use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\Logger\LoggerFactory; use Hyperf\Logger\LoggerFactory;
use Meibuyu\Micro\Amqp\Producer\ExceptionLogProducer;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Throwable; use Throwable;
class AppExceptionHandler extends ExceptionHandler class AppExceptionHandler extends ExceptionHandler
{ {
/**
* @var ContainerInterface
*/
protected $container;
/** /**
* @var StdoutLoggerInterface * @var StdoutLoggerInterface
*/ */
...@@ -24,20 +35,48 @@ class AppExceptionHandler extends ExceptionHandler ...@@ -24,20 +35,48 @@ class AppExceptionHandler extends ExceptionHandler
*/ */
protected $logger; protected $logger;
public function __construct(StdoutLoggerInterface $stdoutLogger, LoggerFactory $loggerFactory) /**
* @var ConfigInterface
*/
protected $config;
public function __construct(ContainerInterface $container)
{ {
$this->stdoutLogger = $stdoutLogger; $this->container = $container;
$this->logger = $loggerFactory->get('Uncaught Exception'); $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) public function handle(Throwable $throwable, ResponseInterface $response)
{ {
// 捕获所有未捕获的异常 // 捕获所有未捕获的异常
$this->stopPropagation(); $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->stdoutLogger->error($msg);
$this->logger->error($msg); $this->logger->error($msg);
$this->stdoutLogger->error($throwable->getTraceAsString()); $this->stdoutLogger->error($trace);
return $response->withStatus(500)->withBody(new SwooleStream($msg)); return $response->withStatus(500)->withBody(new SwooleStream($msg));
} }
......
...@@ -16,4 +16,11 @@ interface OperationServiceInterface ...@@ -16,4 +16,11 @@ interface OperationServiceInterface
* @return mixed * @return mixed
*/ */
public function getBusinessSaleOtherDatum(array $conditions); 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 ...@@ -93,6 +93,14 @@ interface SubOrderServiceInterface
*/ */
public function purchaseError($orderId,$errorCode):array ; public function purchaseError($orderId,$errorCode):array ;
/**
* 1688采购取消
* @param $orderNo
* @param $editData
* @return bool
*/
public function purchaseCancel($orderNo,$editData = []):bool;
/** /**
* 1688采购 修改oa子订单 * 1688采购 修改oa子订单
* @param $editData * @param $editData
......
...@@ -12,4 +12,18 @@ interface PurchaseDoneServiceInterface ...@@ -12,4 +12,18 @@ interface PurchaseDoneServiceInterface
* @return mixed * @return mixed
*/ */
public function archivePurchase($orderIds); 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