You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
12 KiB
251 lines
12 KiB
<?php
|
|
declare(strict_types=1);
|
|
namespace app\common\service;
|
|
|
|
|
|
require_once(root_path() .'/extend/suning-sdk-php/SuningSdk.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/DefaultSuningClient.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/itemDetailQueryRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/custom/IsvitemlistQueryRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProdpoolQueryRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProdbasicdetailGetRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProddetailGetRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProdimageQueryRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/PasspartproductinfoQueryRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/FulladdressGetRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ListpagepriceQueryRequest.php');
|
|
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ShoppingcartpriceQueryRequest.php');
|
|
use app\api\model\{Goods as GoodsModel, Store as StoreModel};
|
|
/**
|
|
* 苏宁服务
|
|
*/
|
|
class Suning extends BaseService {
|
|
|
|
private $_domain = "https://open.suning.com/api/http/sopRequest";
|
|
private $_app_key = "ea13e4bb325235bfbd39927dbc32cbbd";
|
|
private $_app_secrect = "b4b797916f4cf211e4c043603f3d8139";
|
|
private $_channel_code = 84;
|
|
private $_client = null;
|
|
|
|
|
|
public function __construct($config = array()){
|
|
$this->_domain = $config['domain'] ?? $this->_domain;
|
|
$this->_app_key = $config['app_key'] ?? $this->_app_key;
|
|
$this->_app_secrect = $config['app_secrect'] ?? $this->_app_secrect;
|
|
$this->_channel_code = $config['channel_code'] ?? $this->_channel_code;
|
|
$this->_client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
}
|
|
/**
|
|
* 商品池
|
|
* [goodsPoolQuery description]
|
|
* @param [type] $page [description]
|
|
* @param [type] $limit [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function goodsPoolQuery($page, $limit){
|
|
$req = new \ProdpoolQueryRequest();
|
|
$req -> setChannelCode($this->_channel_code);
|
|
$req -> setPageNo($page);
|
|
$req -> setPageSize($limit);
|
|
//$req -> setStartTime("2024-01-11 01:01:01");
|
|
//$req -> setEndTime("2022-01-11 23:59:59");
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
// echo "<pre>";
|
|
// print_r($data);
|
|
if (isset($data['sn_responseContent']['sn_body']['queryProdpool']) && $data['sn_responseContent']['sn_body']['queryProdpool']) {
|
|
return $data['sn_responseContent']['sn_body']['queryProdpool'];
|
|
}
|
|
return [];
|
|
}
|
|
/**
|
|
* 商品基本信息
|
|
* [goodsPoolQuery description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param [type] $sku_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function goodsBasicInfo($supplier_code, $sku_id){
|
|
$req = new \ProdbasicdetailGetRequest();
|
|
$req -> setSkuId($sku_id);
|
|
$req -> setSupplierCode($supplier_code);
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
// echo "<pre>";
|
|
// print_r($data);
|
|
// exit();
|
|
if (isset($data['sn_responseContent']['sn_body']['getProdbasicdetail']) && $data['sn_responseContent']['sn_body']['getProdbasicdetail']) {
|
|
return $data['sn_responseContent']['sn_body']['getProdbasicdetail'];
|
|
}
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 商品详细信息
|
|
* [goodsPoolQuery description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param [type] $sku_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function goodsDetail($supplier_code, $sku_id){
|
|
$req = new \ProddetailGetRequest();
|
|
$req -> setSkuId($sku_id);
|
|
$req -> setSupplierCode($supplier_code);
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
// echo "<pre>";
|
|
// print_r($data);
|
|
// exit();
|
|
if (isset($data['sn_responseContent']['sn_body']['getProddetail']) && $data['sn_responseContent']['sn_body']['getProddetail']) {
|
|
return $data['sn_responseContent']['sn_body']['getProddetail'];
|
|
}
|
|
return [];
|
|
}
|
|
/**
|
|
* 商品详细信息
|
|
* [goodsPoolQuery description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param [type] $sku_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function goodsImage($supplier_code, $sku_id){
|
|
$req = new \ProdimageQueryRequest();
|
|
$req -> setSkuId($sku_id);
|
|
$req -> setSupplierCode($supplier_code);
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
// echo "<pre>";
|
|
// print_r($data);
|
|
// exit();
|
|
if (isset($data['sn_responseContent']['sn_body']['queryProdimage']) && $data['sn_responseContent']['sn_body']['queryProdimage']) {
|
|
return $data['sn_responseContent']['sn_body']['queryProdimage'];
|
|
}
|
|
return [];
|
|
}
|
|
/**
|
|
* 获取通子码商品信息接口
|
|
* [passpartproductinfo description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param string $spu_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function passpartproductinfo($supplier_code, $spu_id = ""){
|
|
$req = new \PasspartproductinfoQueryRequest();
|
|
$req -> setSpuId($spu_id);
|
|
$req -> setSupplierCode($supplier_code);
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
echo "<pre>";
|
|
print_r($data);
|
|
//exit();
|
|
if (isset($data['sn_responseContent']['sn_body']['queryProdimage']) && $data['sn_responseContent']['sn_body']['queryProdimage']) {
|
|
return $data['sn_responseContent']['sn_body']['queryProdimage'];
|
|
}
|
|
return [];
|
|
}
|
|
/**
|
|
* 列表页城市维度查询价格及库存状态
|
|
* [passpartproductinfo description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param string $spu_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function listPagePrice($skus, $city_code = "025"){
|
|
$req = new \ListpagepriceQueryRequest();
|
|
$req -> setChannelCode($this->_channel_code);
|
|
$req -> setCityCode("025");
|
|
$arr = [];
|
|
foreach ($skus as &$sku) {
|
|
list($channel, $supplier_code, $sku_id) = explode("-", $sku['unicode']);
|
|
$cmmdtyInfoList= new \CmmdtyInfoList();
|
|
$cmmdtyInfoList->setSkuId($sku_id);
|
|
$cmmdtyInfoList->setSupplierCode($supplier_code);
|
|
$arr[] = $cmmdtyInfoList;
|
|
}
|
|
|
|
$req -> setCmmdtyInfoList($arr);
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
// echo "<pre>";
|
|
// print_r($data);
|
|
// exit();
|
|
if (isset($data['sn_responseContent']['sn_body']['queryListpageprice']['data']) && $data['sn_responseContent']['sn_body']['queryListpageprice']['data']) {
|
|
return $data['sn_responseContent']['sn_body']['queryListpageprice']['data'];
|
|
}
|
|
return [];
|
|
}
|
|
/**
|
|
* 确定到省市区纬度且有明确购买数量的场景查询价格及库存状态
|
|
* [passpartproductinfo description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param string $spu_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function shoppingCartPrice($skus, $city_code = "025", $region_code = "01"){
|
|
$req = new \ShoppingcartpriceQueryRequest();
|
|
$req -> setChannelCode($this->_channel_code);
|
|
$req -> setCityCode($city_code);
|
|
$req -> setRegionCode($region_code);
|
|
$arr = [];
|
|
foreach ($skus as &$sku) {
|
|
list($channel, $supplier_code, $sku_id) = explode("-", $sku['unicode']);
|
|
$cmmdtyInfoList= new \CmmdtyInfoList1();
|
|
$cmmdtyInfoList->setSkuId($sku_id);
|
|
$cmmdtyInfoList->setSupplierCode($supplier_code);
|
|
$cmmdtyInfoList->setNum($sku['num'] ?? 1);
|
|
$arr[] = $cmmdtyInfoList;
|
|
}
|
|
|
|
$req ->setCmmdtyInfoList1($arr);
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
if (isset($data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']) && $data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']) {
|
|
$arr = [];
|
|
$data = $data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data'];
|
|
foreach ($data as $key => &$value) {
|
|
//$goods = GoodsModel::where('goods_id', $sku['goods_id'])->find();
|
|
$arr = [
|
|
'state'=> $value['state'] == 1 ? "有货" : "无货",
|
|
//'goods_name'=> $goods['goods_name'],
|
|
//'goods_id'=> $goods['goods_id'],
|
|
];
|
|
}
|
|
return $arr;
|
|
}
|
|
return [];
|
|
}
|
|
/**
|
|
* 全量地址接口
|
|
* [passpartproductinfo description]
|
|
* @param [type] $supplier_code [description]
|
|
* @param string $spu_id [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function fulladdress(){
|
|
$req = new \FulladdressGetRequest();
|
|
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行
|
|
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json');
|
|
$resp = $this->_client->execute($req);
|
|
$data = json_decode($resp, true);
|
|
// echo "<pre>";
|
|
// print_r($data);
|
|
//exit();
|
|
if (isset($data['sn_responseContent']['sn_body']['getFulladdress']['addressList']) && $data['sn_responseContent']['sn_body']['getFulladdress']['addressList']) {
|
|
return $data['sn_responseContent']['sn_body']['getFulladdress']['addressList'];
|
|
}
|
|
return [];
|
|
|
|
}
|
|
}
|
|
|