* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace TuzhiEasyWeChat\Channels\Product; use TuzhiEasyWeChat\Kernel\BaseClient; use TuzhiEasyWeChat\Kernel\Exceptions\InvalidArgumentException; /** * Class Client. * * @author mingyoung */ class StockClient extends BaseClient { /** * 获取库存流水 * 通过该接口可以获取视频号小店的商品库存流水 * @return \Psr\Http\Message\ResponseInterface|\TuzhiEasyWeChat\Kernel\Support\Collection|array|object|string * * @param $product_id string(uint64) 是 内部商品ID * @param $sku_id string(uint64) 是 内部sku_id * @param $stock_type number 是 库存类型,参考StockType枚举值 0 自营库存;1 达人库存 * @param $finder_id string 否 达人的视频号finder_id,若StockType=1则必填 * @param $begin_time number 是 时间范围开始时间戳,秒级 * @param $end_time number 是 时间范围结束时间戳,秒级 * @param $op_type_list array[number] 否 库存事件类型,参考StockFlowOpType枚举值,填空获取全部 * @param $page_size number 是 每页数量 * @param $next_key string 否 由上次请求返回,记录翻页的上下文。传入时会从上次返回的结果往后翻一页,不传默认获取第一页数据。 * @throws \TuzhiEasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function getflow($product_id,$sku_id,$stock_type,$finder_id,$begin_time,$end_time,$op_type_list,$page_size,$next_key) { $params = [ 'product_id' => $product_id, 'sku_id' => $sku_id, 'stock_type' => $stock_type, 'finder_id' => $finder_id, 'begin_time' => $begin_time, 'end_time' => $end_time, 'op_type_list' => $op_type_list, 'page_size' => $page_size, 'next_key' => $next_key ]; if($next_key){ $params['next_key'] = $next_key; } if($finder_id){ $params['finder_id'] = $finder_id; } return $this->httpPostJson('channels/ec/product/stock/getflow', $params); } /** * 批量获取库存信息 * @return \Psr\Http\Message\ResponseInterface|\TuzhiEasyWeChat\Kernel\Support\Collection|array|object|string * * @param $product_id[] string(uint64) array 是 商品ID列表,上限为50 * @throws \TuzhiEasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function batchget($product_id) { $params = [ 'product_id' => $product_id ]; return $this->httpPostJson('channels/ec/product/stock/batchget', $params); } /** * 快速更新库存 * 可通过该接口快速更新视频号小店商品的库存 * 仅对商品草稿状态为非审核中(edit_status != 2 )的商品适用,本地生活商品不受此规则约束 * @return \Psr\Http\Message\ResponseInterface|\TuzhiEasyWeChat\Kernel\Support\Collection|array|object|string * @param $product_id string(uint64) 是 内部商品ID * @param $sku_id string(uint64) 是 内部sku_id * @param $diff_type number 是 修改类型。1: 增加;2:减少;3:设置。建议使用1或2,不建议使用3,因为使用3在高并发场景可能会出现预期外表现 * @param $num number 是 增加、减少或者设置的库存值。 * @throws \TuzhiEasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function updateStock($product_id,$sku_id,$diff_type,$num) { $params = [ 'product_id' => $product_id, 'sku_id' => $sku_id, 'diff_type' => intval($diff_type), 'num' => intval($num) ]; return $this->httpPostJson('channels/ec/product/stock/update', $params); } /** * 获取库存 * 通过该接口可以获取视频号小店的商品库存信息 * @return \Psr\Http\Message\ResponseInterface|\TuzhiEasyWeChat\Kernel\Support\Collection|array|object|string * @param $product_id string(uint64) 是 内部商品ID * @param $sku_id string(uint64) 是 内部sku_id * @throws \TuzhiEasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function getStock($product_id,$sku_id) { $params = [ 'product_id' => $product_id, 'sku_id' => $sku_id ]; return $this->httpPostJson('channels/ec/product/stock/get', $params); } }