diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index bb5095f4..738d5f25 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.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('参数错误!'); } - - $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 "
";
-                // print_r($ret);
-                // exit;
-               
-                break;
-            default:
-                if ($goods->stock_total > ($params['num'] ?? 1)) {
-                    $res = "有货";
-                }
-                break;
+        $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;
+                    $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();
+                    $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, "无货") !== false) {
+                            $res = "无货";
+                        } elseif (strpos($res, "有货") == false) {
+                            $res = "有货";
+                        }
+                    }
+                    $data = [
+                        'state'=> $res,
+                        'goods_name'=> $goods['goods_name'],
+                        '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
     {
diff --git a/app/common/service/Jd.php b/app/common/service/Jd.php
index 45d27c9c..c64e2de3 100644
--- a/app/common/service/Jd.php
+++ b/app/common/service/Jd.php
@@ -50,6 +50,9 @@ class Jd extends BaseService {
 
         curl_close($curl);
         $res = json_decode($response, true);
+        // echo "
";
+        // print_r($res);
+        // exit();
         if ($res && isset($res['success']) && $res['success'] == 1) {
             return $res['result'];
         }
diff --git a/app/common/service/Suning.php b/app/common/service/Suning.php
index e6515cc5..00f6bb40 100644
--- a/app/common/service/Suning.php
+++ b/app/common/service/Suning.php
@@ -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 [];
     }
diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php
index 7b6ce645..b6e57d4b 100644
--- a/app/store/controller/Goods.php
+++ b/app/store/controller/Goods.php
@@ -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'));
     }
 
diff --git a/app/store/controller/Store.php b/app/store/controller/Store.php
index b10ff9d3..b88c67a3 100644
--- a/app/store/controller/Store.php
+++ b/app/store/controller/Store.php
@@ -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'];