lqmac 8 months ago
parent d684bd41b3
commit 6445a12864
  1. 51
      app/api/controller/Goods.php
  2. 3
      app/common/service/Jd.php
  3. 14
      app/common/service/Suning.php
  4. 4
      app/store/controller/Goods.php
  5. 2
      app/store/controller/Store.php

@ -77,48 +77,63 @@ class Goods extends Controller
{
// wmc商品详情
$params = $this->request->param();
$goods = GoodsModel::where('goods_id', $params['goods_id'])->find();
if (!$goods) {
return $this->renderError('商品不存在');
if (!$params['list'] || !$params['province'] || !$params['city'] || !$params['district']) {
return $this->renderError('参数错误!');
}
$return = [];
foreach ($params['list'] as $value) {
$res = "无货";
$goods = GoodsModel::where('goods_id', $value['goods_id'])->find();
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();
// var_dump($city);
// var_dump($district);
$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 = "有货";
}
$data = $suning->shoppingCartPrice([$goods->toArray()], $city->sn_code, $district->sn_code);
$data['goods_name'] = $goods['goods_name'];
$data['goods_id'] = $goods['goods_id'];
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);
$arr = [];
$ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $value['num'] ?? 1);
if ($ret) {
$res = $ret['stockResp']['desc'];
if (strpos($res, "无货") == true) {
if (strpos($res, "无货") !== false) {
$res = "无货";
} elseif (strpos($res, "有货") == true) {
} elseif (strpos($res, "有货") == false) {
$res = "有货";
}
// echo "<pre>";
// print_r($ret);
// exit;
}
$data = [
'state'=> $res,
'goods_name'=> $goods['goods_name'],
'goods_id'=> $goods['goods_id'],
];
break;
default:
if ($goods->stock_total > ($params['num'] ?? 1)) {
if ($goods->stock_total > ($value['num'] ?? 1)) {
$res = "有货";
}
$data = [
'state'=> $res,
'goods_name'=> $goods['goods_name'],
'goods_id'=> $goods['goods_id'],
];
break;
}
return $this->renderSuccess(['stock' => $res]);
$return[] = $data;
}
return $this->renderSuccess($return);
}
public function browseLog(): Json
{

@ -50,6 +50,9 @@ class Jd extends BaseService {
curl_close($curl);
$res = json_decode($response, true);
// echo "<pre>";
// print_r($res);
// exit();
if ($res && isset($res['success']) && $res['success'] == 1) {
return $res['result'];
}

@ -15,7 +15,7 @@ require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/Passpartproduc
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};
/**
* 苏宁服务
*/
@ -212,7 +212,17 @@ class Suning extends BaseService {
$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'];
$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 [];
}

@ -33,7 +33,9 @@ class Goods extends Controller
{
// 获取列表记录
$model = new GoodsModel;
$list= $model->getList($this->request->param(), (int)$this->request->param('pageSize', 15));
$params = $this->request->param();
$params['channel'] = 'zy';
$list= $model->getList($params, (int)$this->request->param('pageSize', 15));
return $this->renderSuccess(compact('list'));
}

@ -75,7 +75,7 @@ class Store extends Controller
*/
public function platformList(): Json
{
$list = Channel::where('status', 1)->whereIn('code',['jd','sn','zy'])->select();
$list = Channel::where('status', 1)->whereIn('code',['zy'])->select();
$platformList = [];
foreach ($list as $key => $value) {
$platformList[$value['code']] = $value['name'];

Loading…
Cancel
Save