Loading src/Service/Interfaces/BaseInfoServiceInterface.php +26 −0 Original line number Diff line number Diff line Loading @@ -162,4 +162,30 @@ interface BaseInfoServiceInterface */ public function getReviewUsers($teamId, $authId); /** * 通过id数组获取部门数组 * @param array $idList 默认去重 * @param array $relations 关联关系,默认空 ['users', 'leader'] * @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark'] * @return array 默认keyBY('id') */ public function getDepartmentListByIdList(array $idList, array $relations = [], array $columns = ['*']): array; /** * 获取单个部门数据 * @param int $id * @param array $relations 关联关系,默认空 ['users', 'leader'] * @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark'] * @return array|null */ public function getDepartmentById($id, array $relations = [], array $columns = ['*']); /** * 获取所有部门数据 * @param array $relations 关联关系,默认空 ['users', 'leader'] * @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark'] * @return array 默认已keyBy('id') */ public function departments(array $relations = [], array $columns = ['*']): array; } src/Shopify/ShopifyApp.php +8 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ use Meibuyu\Micro\Shopify\lib\Collect; use Meibuyu\Micro\Shopify\lib\Collection; use Meibuyu\Micro\Shopify\lib\CustomCollection; use Meibuyu\Micro\Shopify\lib\Metafield; use Meibuyu\Micro\Shopify\lib\Product; use Meibuyu\Micro\Shopify\lib\ProductVariant; use Meibuyu\Micro\Shopify\lib\SmartCollection; use Meibuyu\Micro\Shopify\lib\Webhook; Loading @@ -27,12 +29,16 @@ use Meibuyu\Micro\Shopify\lib\Webhook; * @property-read CustomCollection $CustomCollection * @property-read SmartCollection $SmartCollection * @property-read Metafield $Metafield * @property-read Product $Product * @property-read ProductVariant $ProductVariant * * @method Webhook Webhook(integer $id = null) * @method Collection Collection(integer $id = null) * @method CustomCollection CustomCollection(integer $id = null) * @method SmartCollection SmartCollection(integer $id = null) * @method Metafield Metafield(integer $id = null) * @method Product Product(integer $id = null) * @method ProductVariant ProductVariant(integer $id = null) * */ class ShopifyApp Loading @@ -45,6 +51,8 @@ class ShopifyApp 'CustomCollection', 'SmartCollection', 'Metafield', 'Product', 'ProductVariant', ]; protected $childResources = array( Loading src/Shopify/lib/AbstractShopify.php +115 −19 Original line number Diff line number Diff line Loading @@ -153,6 +153,95 @@ abstract class AbstractShopify return $resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); } // /** // * @param array $urlParams // * @param null $url // * @param null $dataKey // * @return mixed // * @throws Exception // */ // public function get($urlParams = [], $url = null, $dataKey = null) // { // if (!$url) $url = $this->generateUrl($urlParams); // $response = HttpRequestJson::get($url, $this->httpHeaders); // if (!$dataKey) $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey; // return $this->processResponse($response, $dataKey); // } // // /** // * 根据id获取一条数据 // * @param $id // * @param array $urlParams // * @return mixed // * @throws Exception // */ // public function show($id, $urlParams = []) // { // $url = $this->generateUrl($urlParams, $id); // $response = HttpRequestJson::get($url, $this->httpHeaders); // return $this->processResponse($response, $this->resourceKey); // } // // /** // * 获取数量 // * @param array $urlParams // * @return mixed // * @throws Exception // */ // public function count($urlParams = []) // { // if (!$this->countEnabled) { // throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); // } // $url = $this->generateUrl($urlParams, null, 'count'); // return $this->get([], $url, 'count'); // } // // /** // * @param $dataArray // * @param null $url // * @param bool $wrapData // * @return mixed // * @throws Exception // */ // public function post($dataArray, $url = null, $wrapData = true) // { // if (!$url) $url = $this->generateUrl(); // if ($wrapData && !empty($dataArray)) $dataArray = $this->wrapData($dataArray); // $response = HttpRequestJson::post($url, $dataArray, $this->httpHeaders); // return $this->processResponse($response, $this->resourceKey); // } // // /** // * @param int|string $id // * @param $dataArray // * @param null $url // * @param bool $wrapData // * @return mixed // * @throws Exception // */ // public function put($id, $dataArray, $url = null, $wrapData = true) // { // if (!$url) $url = $this->generateUrl([], $id); // if ($wrapData && !empty($dataArray)) $dataArray = $this->wrapData($dataArray); // $response = HttpRequestJson::put($url, $dataArray, $this->httpHeaders); // return $this->processResponse($response, $this->resourceKey); // } // // /** // * @param int|string $id // * @param array $urlParams // * @param null $url // * @return mixed // * @throws Exception // */ // public function delete($id = null, $urlParams = [], $url = null) // { // if (!$url) $url = $this->generateUrl($urlParams, $id); // $response = HttpRequestJson::delete($url, $this->httpHeaders); // return $this->processResponse($response); // } /** * @param array $urlParams * @param null $url Loading Loading @@ -182,21 +271,6 @@ abstract class AbstractShopify return $this->processResponse($response, $this->resourceKey); } /** * 获取数量 * @param array $urlParams * @return mixed * @throws Exception */ public function count($urlParams = []) { if (!$this->countEnabled) { throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); } $url = $this->generateUrl($urlParams, null, 'count'); return $this->get([], $url, 'count'); } /** * @param $dataArray * @param null $url Loading Loading @@ -268,14 +342,36 @@ abstract class AbstractShopify * @return mixed * @throws Exception */ // public function processResponse($response, $dataKey = null) // { // $httpCode = $response->getStatusCode(); // $content = $response->getBody()->getContents(); // $content = json_decode($content, true); // // if (isset($content['errors'])) { // throw new Exception($this->castString($content['errors']), $httpCode); // } // if ($dataKey && isset($content[$dataKey])) { // return $content[$dataKey]; // } else { // return $content; // } // } /** * 处理响应 * @param array $response * @param null $dataKey * @return mixed * @throws Exception */ public function processResponse($response, $dataKey = null) { $httpCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); $content = json_decode($content, true); [$code, $header, $body] = $response; $content = json_decode($body, true); if (isset($content['errors'])) { throw new Exception($this->castString($content['errors']), $httpCode); throw new Exception($this->castString($content['errors']), $code); } if ($dataKey && isset($content[$dataKey])) { return $content[$dataKey]; Loading src/Shopify/lib/Product.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: Zero * Date: 2020/9/2 * Time: 16:50 */ namespace Meibuyu\Micro\Shopify\lib; /** * Class Product * @package Meibuyu\Micro\Shopify\lib * * @property-read ProductImage $Image * @property-read ProductVariant $Variant * @property-read Metafield $Metafield * * @method ProductImage Image(integer $id = null) * @method ProductVariant Variant(integer $id = null) * @method Metafield Metafield(integer $id = null) */ class Product extends AbstractShopify { protected $resourceKey = 'product'; protected $childResource = [ 'ProductImage' => 'Image', 'ProductVariant' => 'Variant', 'Metafield', ]; } src/Shopify/lib/ProductImage.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: Zero * Date: 2020/9/2 * Time: 16:50 */ namespace Meibuyu\Micro\Shopify\lib; class ProductImage extends AbstractShopify { protected $resourceKey = 'image'; } Loading
src/Service/Interfaces/BaseInfoServiceInterface.php +26 −0 Original line number Diff line number Diff line Loading @@ -162,4 +162,30 @@ interface BaseInfoServiceInterface */ public function getReviewUsers($teamId, $authId); /** * 通过id数组获取部门数组 * @param array $idList 默认去重 * @param array $relations 关联关系,默认空 ['users', 'leader'] * @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark'] * @return array 默认keyBY('id') */ public function getDepartmentListByIdList(array $idList, array $relations = [], array $columns = ['*']): array; /** * 获取单个部门数据 * @param int $id * @param array $relations 关联关系,默认空 ['users', 'leader'] * @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark'] * @return array|null */ public function getDepartmentById($id, array $relations = [], array $columns = ['*']); /** * 获取所有部门数据 * @param array $relations 关联关系,默认空 ['users', 'leader'] * @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark'] * @return array 默认已keyBy('id') */ public function departments(array $relations = [], array $columns = ['*']): array; }
src/Shopify/ShopifyApp.php +8 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ use Meibuyu\Micro\Shopify\lib\Collect; use Meibuyu\Micro\Shopify\lib\Collection; use Meibuyu\Micro\Shopify\lib\CustomCollection; use Meibuyu\Micro\Shopify\lib\Metafield; use Meibuyu\Micro\Shopify\lib\Product; use Meibuyu\Micro\Shopify\lib\ProductVariant; use Meibuyu\Micro\Shopify\lib\SmartCollection; use Meibuyu\Micro\Shopify\lib\Webhook; Loading @@ -27,12 +29,16 @@ use Meibuyu\Micro\Shopify\lib\Webhook; * @property-read CustomCollection $CustomCollection * @property-read SmartCollection $SmartCollection * @property-read Metafield $Metafield * @property-read Product $Product * @property-read ProductVariant $ProductVariant * * @method Webhook Webhook(integer $id = null) * @method Collection Collection(integer $id = null) * @method CustomCollection CustomCollection(integer $id = null) * @method SmartCollection SmartCollection(integer $id = null) * @method Metafield Metafield(integer $id = null) * @method Product Product(integer $id = null) * @method ProductVariant ProductVariant(integer $id = null) * */ class ShopifyApp Loading @@ -45,6 +51,8 @@ class ShopifyApp 'CustomCollection', 'SmartCollection', 'Metafield', 'Product', 'ProductVariant', ]; protected $childResources = array( Loading
src/Shopify/lib/AbstractShopify.php +115 −19 Original line number Diff line number Diff line Loading @@ -153,6 +153,95 @@ abstract class AbstractShopify return $resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''); } // /** // * @param array $urlParams // * @param null $url // * @param null $dataKey // * @return mixed // * @throws Exception // */ // public function get($urlParams = [], $url = null, $dataKey = null) // { // if (!$url) $url = $this->generateUrl($urlParams); // $response = HttpRequestJson::get($url, $this->httpHeaders); // if (!$dataKey) $dataKey = $this->id ? $this->resourceKey : $this->pluralizeKey; // return $this->processResponse($response, $dataKey); // } // // /** // * 根据id获取一条数据 // * @param $id // * @param array $urlParams // * @return mixed // * @throws Exception // */ // public function show($id, $urlParams = []) // { // $url = $this->generateUrl($urlParams, $id); // $response = HttpRequestJson::get($url, $this->httpHeaders); // return $this->processResponse($response, $this->resourceKey); // } // // /** // * 获取数量 // * @param array $urlParams // * @return mixed // * @throws Exception // */ // public function count($urlParams = []) // { // if (!$this->countEnabled) { // throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); // } // $url = $this->generateUrl($urlParams, null, 'count'); // return $this->get([], $url, 'count'); // } // // /** // * @param $dataArray // * @param null $url // * @param bool $wrapData // * @return mixed // * @throws Exception // */ // public function post($dataArray, $url = null, $wrapData = true) // { // if (!$url) $url = $this->generateUrl(); // if ($wrapData && !empty($dataArray)) $dataArray = $this->wrapData($dataArray); // $response = HttpRequestJson::post($url, $dataArray, $this->httpHeaders); // return $this->processResponse($response, $this->resourceKey); // } // // /** // * @param int|string $id // * @param $dataArray // * @param null $url // * @param bool $wrapData // * @return mixed // * @throws Exception // */ // public function put($id, $dataArray, $url = null, $wrapData = true) // { // if (!$url) $url = $this->generateUrl([], $id); // if ($wrapData && !empty($dataArray)) $dataArray = $this->wrapData($dataArray); // $response = HttpRequestJson::put($url, $dataArray, $this->httpHeaders); // return $this->processResponse($response, $this->resourceKey); // } // // /** // * @param int|string $id // * @param array $urlParams // * @param null $url // * @return mixed // * @throws Exception // */ // public function delete($id = null, $urlParams = [], $url = null) // { // if (!$url) $url = $this->generateUrl($urlParams, $id); // $response = HttpRequestJson::delete($url, $this->httpHeaders); // return $this->processResponse($response); // } /** * @param array $urlParams * @param null $url Loading Loading @@ -182,21 +271,6 @@ abstract class AbstractShopify return $this->processResponse($response, $this->resourceKey); } /** * 获取数量 * @param array $urlParams * @return mixed * @throws Exception */ public function count($urlParams = []) { if (!$this->countEnabled) { throw new Exception("当前类{$this->getResourceName()}不支持count()方法"); } $url = $this->generateUrl($urlParams, null, 'count'); return $this->get([], $url, 'count'); } /** * @param $dataArray * @param null $url Loading Loading @@ -268,14 +342,36 @@ abstract class AbstractShopify * @return mixed * @throws Exception */ // public function processResponse($response, $dataKey = null) // { // $httpCode = $response->getStatusCode(); // $content = $response->getBody()->getContents(); // $content = json_decode($content, true); // // if (isset($content['errors'])) { // throw new Exception($this->castString($content['errors']), $httpCode); // } // if ($dataKey && isset($content[$dataKey])) { // return $content[$dataKey]; // } else { // return $content; // } // } /** * 处理响应 * @param array $response * @param null $dataKey * @return mixed * @throws Exception */ public function processResponse($response, $dataKey = null) { $httpCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); $content = json_decode($content, true); [$code, $header, $body] = $response; $content = json_decode($body, true); if (isset($content['errors'])) { throw new Exception($this->castString($content['errors']), $httpCode); throw new Exception($this->castString($content['errors']), $code); } if ($dataKey && isset($content[$dataKey])) { return $content[$dataKey]; Loading
src/Shopify/lib/Product.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: Zero * Date: 2020/9/2 * Time: 16:50 */ namespace Meibuyu\Micro\Shopify\lib; /** * Class Product * @package Meibuyu\Micro\Shopify\lib * * @property-read ProductImage $Image * @property-read ProductVariant $Variant * @property-read Metafield $Metafield * * @method ProductImage Image(integer $id = null) * @method ProductVariant Variant(integer $id = null) * @method Metafield Metafield(integer $id = null) */ class Product extends AbstractShopify { protected $resourceKey = 'product'; protected $childResource = [ 'ProductImage' => 'Image', 'ProductVariant' => 'Variant', 'Metafield', ]; }
src/Shopify/lib/ProductImage.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: Zero * Date: 2020/9/2 * Time: 16:50 */ namespace Meibuyu\Micro\Shopify\lib; class ProductImage extends AbstractShopify { protected $resourceKey = 'image'; }