lqmac 8 months ago
parent d684bd41b3
commit 6445a12864
  1. 95
      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商品详情 // wmc商品详情
$params = $this->request->param(); $params = $this->request->param();
$goods = GoodsModel::where('goods_id', $params['goods_id'])->find(); if (!$params['list'] || !$params['province'] || !$params['city'] || !$params['district']) {
if (!$goods) { return $this->renderError('参数错误!');
return $this->renderError('商品不存在');
} }
$return = [];
$res = "无货"; foreach ($params['list'] as $value) {
switch ($goods->channel) { $res = "无货";
case 'sn': $goods = GoodsModel::where('goods_id', $value['goods_id'])->find();
$city = Region::where('name',$params['city'])->where('level',2)->find(); switch ($goods->channel) {
$district = Region::where('name',$params['district'])->where('level',3)->find(); case 'sn':
$suning = new \app\common\service\Suning(); $city = Region::where('name',$params['city'])->where('level',2)->find();
$goods->num = $param['num'] ?? 1; $district = Region::where('name',$params['district'])->where('level',3)->find();
$ret = $suning->shoppingCartPrice([$goods->toArray()], $city->sn_code, $district->sn_code); // var_dump($city);
if ($ret && $ret[0]['state'] == 1) { // var_dump($district);
$res = "有货"; $suning = new \app\common\service\Suning();
} $goods->num = $param['num'] ?? 1;
break; $data = $suning->shoppingCartPrice([$goods->toArray()], $city->sn_code, $district->sn_code);
case 'jd': $data['goods_name'] = $goods['goods_name'];
$province = Region::where('name',$params['province'])->where('level',1)->find(); $data['goods_id'] = $goods['goods_id'];
$city = Region::where('name',$params['city'])->where('level',2)->find(); break;
$district = Region::where('name',$params['district'])->where('level',3)->find(); case 'jd':
$jd = new \app\common\service\Jd(); $province = Region::where('name',$params['province'])->where('level',1)->find();
$goods->num = $params['num'] ?? 1; $city = Region::where('name',$params['city'])->where('level',2)->find();
$ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $params['num'] ?? 1); $district = Region::where('name',$params['district'])->where('level',3)->find();
$res = $ret['stockResp']['desc']; $jd = new \app\common\service\Jd();
if (strpos($res, "无货") == true) { $arr = [];
$res = "无货";
} elseif (strpos($res, "有货") == true) { $ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $value['num'] ?? 1);
$res = "有货"; if ($ret) {
} $res = $ret['stockResp']['desc'];
// echo "<pre>"; if (strpos($res, "无货") !== false) {
// print_r($ret); $res = "无货";
// exit; } elseif (strpos($res, "有货") == false) {
$res = "有货";
break; }
default: }
if ($goods->stock_total > ($params['num'] ?? 1)) { $data = [
$res = "有货"; 'state'=> $res,
} 'goods_name'=> $goods['goods_name'],
break; 'goods_id'=> $goods['goods_id'],
];
break;
default:
if ($goods->stock_total > ($value['num'] ?? 1)) {
$res = "有货";
}
$data = [
'state'=> $res,
'goods_name'=> $goods['goods_name'],
'goods_id'=> $goods['goods_id'],
];
break;
}
$return[] = $data;
} }
return $this->renderSuccess(['stock' => $res]);
return $this->renderSuccess($return);
} }
public function browseLog(): Json public function browseLog(): Json
{ {

@ -50,6 +50,9 @@ class Jd extends BaseService {
curl_close($curl); curl_close($curl);
$res = json_decode($response, true); $res = json_decode($response, true);
// echo "<pre>";
// print_r($res);
// exit();
if ($res && isset($res['success']) && $res['success'] == 1) { if ($res && isset($res['success']) && $res['success'] == 1) {
return $res['result']; 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/FulladdressGetRequest.php');
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ListpagepriceQueryRequest.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'); 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); $resp = $this->_client->execute($req);
$data = json_decode($resp, true); $data = json_decode($resp, true);
if (isset($data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']) && $data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']) { 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 []; return [];
} }

@ -33,7 +33,9 @@ class Goods extends Controller
{ {
// 获取列表记录 // 获取列表记录
$model = new GoodsModel; $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')); return $this->renderSuccess(compact('list'));
} }

@ -75,7 +75,7 @@ class Store extends Controller
*/ */
public function platformList(): Json 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 = []; $platformList = [];
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$platformList[$value['code']] = $value['name']; $platformList[$value['code']] = $value['name'];

Loading…
Cancel
Save