Loading src/Amqp/Producer/ExceptionLogProducer.php +27 −14 Original line number Original line Diff line number Diff line Loading @@ -23,24 +23,37 @@ class ExceptionLogProducer extends ProducerMessage } catch (HttpResponseException $e) { } catch (HttpResponseException $e) { put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); } } // 排除依赖包文件和运行缓存文件 // 获取trace中真实文件和行数 put_log("file: {$data['file']}", 'ExceptionLogProducerEcho.log'); if (!empty($data['trace'])) { if (strpos($data['file'], '/vendor/') === false && strpos($data['file'], '/runtime/') === false) { preg_match('/(\/var\/www\/html\/.+?\/app\/.+?\.php)(?=\()/', $data['trace'], $matchFiles); if (!empty($matchFiles[0])) { $data['file'] = $matchFiles[0]; $file = str_replace('/', '\/', $matchFiles[0]); $file = str_replace('.', '\.', $file); $pattern = '/(?<=' . $file . '\()[0-9]+(?=\))/'; preg_match($pattern, $data['trace'], $matchLines); if (!empty($matchLines[0])) { $data['line'] = $matchLines[0]; } } } if (!empty($data['file'])) { // 只对项目app文件夹下的错误获取编码人 preg_match('/(\/var\/www\/html\/.+?\/app\/)/', $data['file'], $matchPaths); if (!empty($matchPaths[0])) { try { try { put_log("git: git blame -L {$data['line']},{$data['line']} {$data['file']}", 'ExceptionLogProducerEcho.log'); exec("cd {$matchPaths[0]} && git blame -L {$data['line']},{$data['line']} {$data['file']}", $output); exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output); put_log("output: $output", 'ExceptionLogProducerEcho.log'); if (!empty($output[0]) && is_string($output[0])) { if (!empty($output[0]) && is_string($output[0])) { preg_match('/(?<=\()[^ ]+/', $output[0], $matches); preg_match('/(?<=\()[^ ]+/', $output[0], $matchCoders); put_log("matches: $matches", 'ExceptionLogProducerEcho.log'); if (!empty($matchCoders[0])) { if (!empty($matches[0])) { $data['coder'] = $matchCoders[0]; $data['coder'] = $matches[0]; } } } } } catch (Exception $e) { } catch (Exception $e) { put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); } } } } } $this->payload = $data; $this->payload = $data; } } Loading src/Service/Interfaces/File/FileServiceInterface.php 0 → 100644 +15 −0 Original line number Original line Diff line number Diff line <?php namespace Meibuyu\Micro\Service\Interfaces\File; interface FileServiceInterface { /** * @param string $type 类型编码 0001 * @param integer $number 生成条形码数量 100 * @return mixed */ public function generateBarCode($type, $number); } No newline at end of file src/Service/Interfaces/Product/ShopifyServiceInterface.php +9 −0 Original line number Original line Diff line number Diff line Loading @@ -86,4 +86,13 @@ interface ShopifyServiceInterface */ */ public function updateFulfillmentTracking($fulfillmentId, $params, $shopifySiteId); public function updateFulfillmentTracking($fulfillmentId, $params, $shopifySiteId); /** * 通过id数组获取shopify的location数据 * @param $ids * @param string[] $columns * @return array 默认keyBy('id') * @author zero */ public function getLocationsByIds($ids, $columns = ['*']); } } src/Service/Interfaces/Purchase/PurchaseDoneServiceInterface.php +8 −0 Original line number Original line Diff line number Diff line Loading @@ -26,4 +26,12 @@ interface PurchaseDoneServiceInterface * @return mixed * @return mixed */ */ public function productStandard($data); public function productStandard($data); /** * 通过子订单编号查询状态 * @param array $orderIds 子订单编号 ['3333444','12222'] * @return mixed */ public function getOrderStatus($orderIds); } } No newline at end of file src/Shopify/lib/AbstractShopify.php +24 −48 Original line number Original line Diff line number Diff line Loading @@ -9,7 +9,8 @@ namespace Meibuyu\Micro\Shopify\lib; namespace Meibuyu\Micro\Shopify\lib; use Exception; use Exception; use Meibuyu\Micro\Shopify\Tools\HttpRequestJson; use Meibuyu\Micro\Shopify\tools\CurlHttpRequestJson; use Meibuyu\Micro\Shopify\tools\HttpRequestJson; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface; abstract class AbstractShopify abstract class AbstractShopify Loading Loading @@ -45,7 +46,7 @@ abstract class AbstractShopify private $config; private $config; /** /** * @var HttpRequestJson * @var HttpRequestJson|CurlHttpRequestJson */ */ private $httpRequestJson; private $httpRequestJson; Loading @@ -62,7 +63,7 @@ abstract class AbstractShopify $this->id = $id; $this->id = $id; $this->pluralizeKey = $this->pluralizeKey ?: $this->resourceKey . 's'; $this->pluralizeKey = $this->pluralizeKey ?: $this->resourceKey . 's'; $this->resourceUrl = ($parentResourceUrl ? "$parentResourceUrl/" : $config['api_url']) . $this->pluralizeKey . ($this->id ? "/{$this->id}" : ''); $this->resourceUrl = ($parentResourceUrl ? "$parentResourceUrl/" : $config['api_url']) . $this->pluralizeKey . ($this->id ? "/{$this->id}" : ''); $this->httpRequestJson = make(HttpRequestJson::class); $this->httpRequestJson = make(CurlHttpRequestJson::class); if (isset($config['api_password'])) { if (isset($config['api_password'])) { $this->httpHeaders['X-Shopify-Access-Token'] = $config['api_password']; $this->httpHeaders['X-Shopify-Access-Token'] = $config['api_password']; } elseif (!isset($config['api_password'])) { } elseif (!isset($config['api_password'])) { Loading Loading @@ -158,20 +159,20 @@ abstract class AbstractShopify return $resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); return $resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); } } // /** /** // * 获取数量 * 获取数量 // * @param array $urlParams * @param array $urlParams // * @return mixed * @return mixed // * @throws Exception * @throws Exception // */ */ // public function count($urlParams = []) public function count($urlParams = []) // { { // if (!$this->countEnabled) { if (!$this->countEnabled) { // throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); // } } // $url = $this->generateUrl($urlParams, null, 'count'); $url = $this->generateUrl($urlParams, null, 'count'); // return $this->get([], $url, 'count'); return $this->get([], $url, 'count'); // } } /** /** * @param array $urlParams * @param array $urlParams Loading Loading @@ -282,15 +283,14 @@ abstract class AbstractShopify /** /** * 处理响应 * 处理响应 * @param ResponseInterface $response * @param array $response * @param null $dataKey * @param null $dataKey * @return mixed * @return mixed * @throws Exception * @throws Exception */ */ public function processResponse($response, $dataKey = null) public function processResponse($response, $dataKey = null) { { $code = $response->getStatusCode(); [$code, , $content] = $response; $content = $response->getBody()->getContents(); $content = json_decode($content, true); $content = json_decode($content, true); if (isset($content['errors'])) { if (isset($content['errors'])) { throw new Exception($this->castString($content['errors']), $code); throw new Exception($this->castString($content['errors']), $code); Loading @@ -302,28 +302,6 @@ abstract class AbstractShopify } } } } /** * 处理响应 * @param array $response * @param null $dataKey * @return mixed * @throws Exception */ public function processResponseOld($response, $dataKey = null) { [$code, $header, $body] = $response; $content = json_decode($body, true); if (isset($content['errors'])) { throw new Exception($this->castString($content['errors']), $code); } if ($dataKey && isset($content[$dataKey])) { return $content[$dataKey]; } else { return $content; } } /** /** * 处理响应 * 处理响应 * @param ResponseInterface $response * @param ResponseInterface $response Loading @@ -333,9 +311,7 @@ abstract class AbstractShopify */ */ public function processPageResponse($response, $dataKey = null) public function processPageResponse($response, $dataKey = null) { { $code = $response->getStatusCode(); [$code, $headers, $content] = $response; $headers = $response->getHeaders(); $content = $response->getBody()->getContents(); $content = json_decode($content, true); $content = json_decode($content, true); $link = $this->getLink($headers); $link = $this->getLink($headers); if (isset($content['errors'])) { if (isset($content['errors'])) { Loading @@ -351,11 +327,11 @@ abstract class AbstractShopify public function getLink($header, $type = 'next') public function getLink($header, $type = 'next') { { if (!empty($header['X-Shopify-API-Version'][0]) && $header['X-Shopify-API-Version'][0] < '2019-07') { if (!empty($header['x-shopify-api-version'][0]) && $header['x-shopify-api-version'][0] < '2019-07') { return null; return null; } } if (!empty($header['Link'][0])) { if (!empty($header['link'][0])) { $headerLinks = $header['Link'][0]; $headerLinks = $header['link'][0]; if (stristr($headerLinks, '; rel="' . $type . '"') > -1) { if (stristr($headerLinks, '; rel="' . $type . '"') > -1) { $headerLinks = explode(',', $headerLinks); $headerLinks = explode(',', $headerLinks); foreach ($headerLinks as $headerLink) { foreach ($headerLinks as $headerLink) { Loading Loading
src/Amqp/Producer/ExceptionLogProducer.php +27 −14 Original line number Original line Diff line number Diff line Loading @@ -23,24 +23,37 @@ class ExceptionLogProducer extends ProducerMessage } catch (HttpResponseException $e) { } catch (HttpResponseException $e) { put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('获取操作人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); } } // 排除依赖包文件和运行缓存文件 // 获取trace中真实文件和行数 put_log("file: {$data['file']}", 'ExceptionLogProducerEcho.log'); if (!empty($data['trace'])) { if (strpos($data['file'], '/vendor/') === false && strpos($data['file'], '/runtime/') === false) { preg_match('/(\/var\/www\/html\/.+?\/app\/.+?\.php)(?=\()/', $data['trace'], $matchFiles); if (!empty($matchFiles[0])) { $data['file'] = $matchFiles[0]; $file = str_replace('/', '\/', $matchFiles[0]); $file = str_replace('.', '\.', $file); $pattern = '/(?<=' . $file . '\()[0-9]+(?=\))/'; preg_match($pattern, $data['trace'], $matchLines); if (!empty($matchLines[0])) { $data['line'] = $matchLines[0]; } } } if (!empty($data['file'])) { // 只对项目app文件夹下的错误获取编码人 preg_match('/(\/var\/www\/html\/.+?\/app\/)/', $data['file'], $matchPaths); if (!empty($matchPaths[0])) { try { try { put_log("git: git blame -L {$data['line']},{$data['line']} {$data['file']}", 'ExceptionLogProducerEcho.log'); exec("cd {$matchPaths[0]} && git blame -L {$data['line']},{$data['line']} {$data['file']}", $output); exec("git blame -L {$data['line']},{$data['line']} {$data['file']}", $output); put_log("output: $output", 'ExceptionLogProducerEcho.log'); if (!empty($output[0]) && is_string($output[0])) { if (!empty($output[0]) && is_string($output[0])) { preg_match('/(?<=\()[^ ]+/', $output[0], $matches); preg_match('/(?<=\()[^ ]+/', $output[0], $matchCoders); put_log("matches: $matches", 'ExceptionLogProducerEcho.log'); if (!empty($matchCoders[0])) { if (!empty($matches[0])) { $data['coder'] = $matchCoders[0]; $data['coder'] = $matches[0]; } } } } } catch (Exception $e) { } catch (Exception $e) { put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); put_log('获取编码人失败; ' . $e->getMessage(), 'ExceptionLogProducer.log'); } } } } } $this->payload = $data; $this->payload = $data; } } Loading
src/Service/Interfaces/File/FileServiceInterface.php 0 → 100644 +15 −0 Original line number Original line Diff line number Diff line <?php namespace Meibuyu\Micro\Service\Interfaces\File; interface FileServiceInterface { /** * @param string $type 类型编码 0001 * @param integer $number 生成条形码数量 100 * @return mixed */ public function generateBarCode($type, $number); } No newline at end of file
src/Service/Interfaces/Product/ShopifyServiceInterface.php +9 −0 Original line number Original line Diff line number Diff line Loading @@ -86,4 +86,13 @@ interface ShopifyServiceInterface */ */ public function updateFulfillmentTracking($fulfillmentId, $params, $shopifySiteId); public function updateFulfillmentTracking($fulfillmentId, $params, $shopifySiteId); /** * 通过id数组获取shopify的location数据 * @param $ids * @param string[] $columns * @return array 默认keyBy('id') * @author zero */ public function getLocationsByIds($ids, $columns = ['*']); } }
src/Service/Interfaces/Purchase/PurchaseDoneServiceInterface.php +8 −0 Original line number Original line Diff line number Diff line Loading @@ -26,4 +26,12 @@ interface PurchaseDoneServiceInterface * @return mixed * @return mixed */ */ public function productStandard($data); public function productStandard($data); /** * 通过子订单编号查询状态 * @param array $orderIds 子订单编号 ['3333444','12222'] * @return mixed */ public function getOrderStatus($orderIds); } } No newline at end of file
src/Shopify/lib/AbstractShopify.php +24 −48 Original line number Original line Diff line number Diff line Loading @@ -9,7 +9,8 @@ namespace Meibuyu\Micro\Shopify\lib; namespace Meibuyu\Micro\Shopify\lib; use Exception; use Exception; use Meibuyu\Micro\Shopify\Tools\HttpRequestJson; use Meibuyu\Micro\Shopify\tools\CurlHttpRequestJson; use Meibuyu\Micro\Shopify\tools\HttpRequestJson; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface; abstract class AbstractShopify abstract class AbstractShopify Loading Loading @@ -45,7 +46,7 @@ abstract class AbstractShopify private $config; private $config; /** /** * @var HttpRequestJson * @var HttpRequestJson|CurlHttpRequestJson */ */ private $httpRequestJson; private $httpRequestJson; Loading @@ -62,7 +63,7 @@ abstract class AbstractShopify $this->id = $id; $this->id = $id; $this->pluralizeKey = $this->pluralizeKey ?: $this->resourceKey . 's'; $this->pluralizeKey = $this->pluralizeKey ?: $this->resourceKey . 's'; $this->resourceUrl = ($parentResourceUrl ? "$parentResourceUrl/" : $config['api_url']) . $this->pluralizeKey . ($this->id ? "/{$this->id}" : ''); $this->resourceUrl = ($parentResourceUrl ? "$parentResourceUrl/" : $config['api_url']) . $this->pluralizeKey . ($this->id ? "/{$this->id}" : ''); $this->httpRequestJson = make(HttpRequestJson::class); $this->httpRequestJson = make(CurlHttpRequestJson::class); if (isset($config['api_password'])) { if (isset($config['api_password'])) { $this->httpHeaders['X-Shopify-Access-Token'] = $config['api_password']; $this->httpHeaders['X-Shopify-Access-Token'] = $config['api_password']; } elseif (!isset($config['api_password'])) { } elseif (!isset($config['api_password'])) { Loading Loading @@ -158,20 +159,20 @@ abstract class AbstractShopify return $resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); return $resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); } } // /** /** // * 获取数量 * 获取数量 // * @param array $urlParams * @param array $urlParams // * @return mixed * @return mixed // * @throws Exception * @throws Exception // */ */ // public function count($urlParams = []) public function count($urlParams = []) // { { // if (!$this->countEnabled) { if (!$this->countEnabled) { // throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); // } } // $url = $this->generateUrl($urlParams, null, 'count'); $url = $this->generateUrl($urlParams, null, 'count'); // return $this->get([], $url, 'count'); return $this->get([], $url, 'count'); // } } /** /** * @param array $urlParams * @param array $urlParams Loading Loading @@ -282,15 +283,14 @@ abstract class AbstractShopify /** /** * 处理响应 * 处理响应 * @param ResponseInterface $response * @param array $response * @param null $dataKey * @param null $dataKey * @return mixed * @return mixed * @throws Exception * @throws Exception */ */ public function processResponse($response, $dataKey = null) public function processResponse($response, $dataKey = null) { { $code = $response->getStatusCode(); [$code, , $content] = $response; $content = $response->getBody()->getContents(); $content = json_decode($content, true); $content = json_decode($content, true); if (isset($content['errors'])) { if (isset($content['errors'])) { throw new Exception($this->castString($content['errors']), $code); throw new Exception($this->castString($content['errors']), $code); Loading @@ -302,28 +302,6 @@ abstract class AbstractShopify } } } } /** * 处理响应 * @param array $response * @param null $dataKey * @return mixed * @throws Exception */ public function processResponseOld($response, $dataKey = null) { [$code, $header, $body] = $response; $content = json_decode($body, true); if (isset($content['errors'])) { throw new Exception($this->castString($content['errors']), $code); } if ($dataKey && isset($content[$dataKey])) { return $content[$dataKey]; } else { return $content; } } /** /** * 处理响应 * 处理响应 * @param ResponseInterface $response * @param ResponseInterface $response Loading @@ -333,9 +311,7 @@ abstract class AbstractShopify */ */ public function processPageResponse($response, $dataKey = null) public function processPageResponse($response, $dataKey = null) { { $code = $response->getStatusCode(); [$code, $headers, $content] = $response; $headers = $response->getHeaders(); $content = $response->getBody()->getContents(); $content = json_decode($content, true); $content = json_decode($content, true); $link = $this->getLink($headers); $link = $this->getLink($headers); if (isset($content['errors'])) { if (isset($content['errors'])) { Loading @@ -351,11 +327,11 @@ abstract class AbstractShopify public function getLink($header, $type = 'next') public function getLink($header, $type = 'next') { { if (!empty($header['X-Shopify-API-Version'][0]) && $header['X-Shopify-API-Version'][0] < '2019-07') { if (!empty($header['x-shopify-api-version'][0]) && $header['x-shopify-api-version'][0] < '2019-07') { return null; return null; } } if (!empty($header['Link'][0])) { if (!empty($header['link'][0])) { $headerLinks = $header['Link'][0]; $headerLinks = $header['link'][0]; if (stristr($headerLinks, '; rel="' . $type . '"') > -1) { if (stristr($headerLinks, '; rel="' . $type . '"') > -1) { $headerLinks = explode(',', $headerLinks); $headerLinks = explode(',', $headerLinks); foreach ($headerLinks as $headerLink) { foreach ($headerLinks as $headerLink) { Loading