lqmac 7 months ago
parent 28ebfe0c63
commit 70b8c8c871
  1. 60
      app/api/controller/Goods.php
  2. 10
      app/api/model/Goods.php
  3. 58
      app/common/service/Jd.php
  4. 241
      app/common/service/Suning.php
  5. 6
      extend/suning-sdk-php/request/sngoods/ShoppingcartpriceQueryRequest.php

@ -20,7 +20,7 @@ use app\common\service\qrcode\Goods as GoodsPoster;
use cores\exception\BaseException;
use think\db\exception\DbException;
use think\response\Json;
use app\api\model\Region;
/**
* 商品控制器
* Class Goods
@ -63,7 +63,63 @@ class Goods extends Controller
}
return $this->renderSuccess(['detail' => $goodsInfo]);
}
/**
* 获取商品详情(详细信息)
* @param int $goodsId 商品ID
* @param bool $verifyStatus 是否验证商品状态(上架)
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws BaseException
*/
public function getGoodsStock(): Json
{
// wmc商品详情
$params = $this->request->param();
$goods = GoodsModel::where('goods_id', $params['goods_id'])->find();
if (!$goods) {
return $this->renderError('商品不存在');
}
$res = "无货";
switch ($goods->channel) {
case 'sn':
$city = Region::where('name',$params['city'])->where('level',2)->find();
$district = Region::where('name',$params['district'])->where('level',3)->find();
$suning = new \app\common\service\Suning();
$goods->num = $param['num'] ?? 1;
$ret = $suning->shoppingCartPrice([$goods->toArray()], $city->sn_code, $district->sn_code);
if ($ret && $ret[0]['state'] == 1) {
$res = "有货";
}
break;
case 'jd':
$province = Region::where('name',$params['province'])->where('level',1)->find();
$city = Region::where('name',$params['city'])->where('level',2)->find();
$district = Region::where('name',$params['district'])->where('level',3)->find();
$jd = new \app\common\service\Jd();
$goods->num = $params['num'] ?? 1;
$ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $params['num'] ?? 1);
$res = $ret['stockResp']['desc'];
if (strpos($res, "无货") == true) {
$res = "无货";
} elseif (strpos($res, "有货") == true) {
$res = "有货";
}
// echo "<pre>";
// print_r($ret);
// exit;
break;
default:
if ($goods->stock_total > ($params['num'] ?? 1)) {
$res = "有货";
}
break;
}
return $this->renderSuccess(['stock' => $res]);
}
public function browseLog(): Json
{
$model = new GoodsModel;

@ -542,18 +542,22 @@ class Goods extends GoodsModel
$catService = new \app\store\model\GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
$goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价
$goods['discount'] = 0;
//价格判断
if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$goods['goods_price_min_plus'] = $priceArr['membershipPrice'];
$goods['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$goods['goods_price_min'] = $goods['cost_price_min'];//店长售价,展示为成本价
$goods['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价
} elseif (UserService::isPlusMember()) {
$goods['goods_price_min'] = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$goods['discount'] = bcdiv((string)($membershipPrice*10), (string)$goods['goods_price_min'], 1);
$goods['goods_price_min'] = $membershipPrice;
} elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$goods['discount'] = bcdiv((string)($priceArr['distributionPrice']*10), (string)$goods['goods_price_min'], 1);
//$goods['goods_price_min'] = $membershipPrice;
$goods['goods_price_min'] = $priceArr['distributionPrice'];
}

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace app\common\service;
/**
* 京东服务
*/
class Jd extends BaseService {
/**
* 获取京东商品库存
* [getGoodsStock description]
* @param [type] $provinceId [description]
* @param [type] $cityId [description]
* @param [type] $countyId [description]
* @param [type] $skuId [description]
* @param integer $skuNum [description]
* @return [type] [description]
*/
public function getGoodsStock($provinceId, $cityId, $countyId,$skuId, $skuNum = 1){
$data = [
'provinceId' => $provinceId,
'cityId' => $cityId,
'countyId' => $countyId,
'townId' => 0,
'skuId' => $skuId,
'skuNum' => $skuNum,
];
//echo 'https://vapi.jd.com/index/sku/getAsynDetail?'.http_build_query($data);
//exit();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?'.http_build_query($data),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Host: vapi.jd.com',
'Referer: https://bpro.jd.com/'
),
));
$response = curl_exec($curl);
curl_close($curl);
$res = json_decode($response, true);
if ($res && isset($res['success']) && $res['success'] == 1) {
return $res['result'];
}
return null;
}
}

@ -0,0 +1,241 @@
<?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');
/**
* 苏宁服务
*/
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']) {
return $data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data'];
}
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 [];
}
}

@ -45,11 +45,11 @@ class ShoppingcartpriceQueryRequest extends SuningRequest{
$this->apiParams["cityCode"] = $cityCode;
}
public function getCmmdtyInfoList() {
public function getCmmdtyInfoList1() {
return $this->cmmdtyInfoList;
}
public function setCmmdtyInfoList($cmmdtyInfoList) {
public function setCmmdtyInfoList1($cmmdtyInfoList) {
$this->cmmdtyInfoList = $cmmdtyInfoList;
$arr = array();
foreach ($cmmdtyInfoList as $temp){
@ -88,7 +88,7 @@ class ShoppingcartpriceQueryRequest extends SuningRequest{
}
class CmmdtyInfoList {
class CmmdtyInfoList1 {
private $apiParams = array();

Loading…
Cancel
Save