Files
datahub/backend/app/Platform/Tools/Request/ProductRequest.php
T

53 lines
1.3 KiB
PHP

<?php
namespace App\Platform\Tools\Request;
use App\Platform\Tools\HttpClient;
class ProductRequest extends HttpClient
{
const BATCH_SIZE = 50;
public static function find(int $id): array
{
$path = "/api/ext/products/$id";
return static::get($path);
}
public static function findByPlatformSkuId(int $tools_store_id, string $platformSkuId): array | null
{
$path = "/api/ext/products";
$response = static::get($path, ['store' => $tools_store_id, 'platformSkuId' => $platformSkuId]);
if(0 === $response['total'] || '0' === $response['total'] ){
return null;
}
if(1 < $response['total']){
throw new \Exception('参数有误,产品匹配到多个结果!');
}
return $response['data']['0'];
}
public static function add(array $data): array
{
$path = "/api/ext/products";
return static::post($path, [], $data);
}
public static function update(array $data): array
{
$path = "/api/ext/products/batch";
return static::put($path, [], $data);
}
public static function list(array $query) : array
{
$path = "/api/ext/products";
return static::get($path, $query);
}
}