_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 "
"; // 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 ""; // 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 ""; // 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 ""; // 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 ""; 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 ""; // 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'=> (isset($value['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 ""; // 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 []; } /** * 下单 * [createOrder description] * @param [type] $order [description] * @param [type] $order_address [description] * @param [type] $orderGoods [description] * @param array $invoice [description] * @return [type] [description] */ public function createOrder($order, $order_address, $orderGoods, $invoice = []){ $req = new \OrderAddRequest(); $req -> setChannelcode($this->_channel_code); $req -> setTradeNo($order['order_no']); //收货地址 $req -> setReceiverName($order_address['name']); //$req -> setTelephone("010-84728989"); $req -> setMobile($order_address['phone']); $req -> setProvinceId($order_address['province_id']); $req -> setCityId($order_address['city_id']); $req -> setCountyId($order_address['region_id']); //$req -> setTownId("03"); $req -> setAddress($order_address['detail']); $req -> setHopeArrivalTime("2019-11-06-3"); //订单金额 $req -> setPayment("支付方式:01-在线支付-易付宝; 02-企业汇款支付; 03-代扣支付;04-代扣分步支付"); $req -> setAmount($order['total_price']); $req -> setServFee(0); $req -> setRemark("备注(不多于80个汉字)"); //是否开票 $req -> setInvoiceState("是否开发票:1=开;0=不开"); $req -> setInvoiceType("发票类型:1-增值税专票;;2-电子发票 ,(invoiceState是否开票=1时必填)"); $req -> setInvoiceTitle("发票抬头(发票类型为2电子发票时必传)"); //订单商品sku $skus = []; foreach ($orderGoods as $item) { $sku = new \Sku(); $sku-> setNum($item['total_num']); $sku-> setSkuId($item['goods_no']); $sku-> setSupplierCode($item['supplier_code']); $sku-> setUnitPrice($item['goods_price']); $skus[] = $sku; } $req -> setSku(array($sku)); //开票信息 // $specialVatTicket= new \SpecialVatTicket(); // $specialVatTicket-> setConsigneeAddress("收票件人地址(发票类型为1增值税专票必传)"); // $specialVatTicket-> setConsigneeMobileNum("收票件人电话(发票类型为1增值税专票必传)"); // $specialVatTicket-> setConsigneeName("收票件人姓名(发票类型为1增值税专票必传)"); // $specialVatTicket-> setRegAccount("23235254664336"); // $specialVatTicket-> setRegAdd("江苏省南京市雨花区软件大道舜天集团"); // $specialVatTicket-> setRegBank("453453434534354"); // $specialVatTicket-> setRegTel("18767890345"); // $specialVatTicket-> setTaxNo("纳税人识别号:数字或字母,字段长度为15、18、20位 "); // $req -> setSpecialVatTicket($specialVatTicket); //api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 $req -> setCheckParam('true'); $client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); $resp = $this->_client->execute($req); $data = json_decode($resp, true); print_r("返回响应报文:".$resp); if (isset($data['sn_responseContent']['sn_body']['addOrder']) && $data['sn_responseContent']['sn_body']['addOrder']) { return $data['sn_responseContent']['sn_body']['addOrder']; } return []; } /** * 获取订单状态 * [getOrderStatus description] * @param [type] $order_no [description] * @return [type] [description] */ public function getOrderStatus($order_no){ $req = new \OrderstatusGetRequest(); $req -> setOrderId($order_no); //api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 $req -> setCheckParam('true'); $client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); $resp = $this->_client->execute($req); $data = json_decode($resp, true); print_r("返回响应报文:".$resp); if (isset($data['sn_request']['sn_body']['getOrderstatus']) && $data['sn_request']['sn_body']['getOrderstatus']) { return $data['sn_request']['sn_body']['getOrderstatus']; } return []; } }