From 3e0b0bea6f494630c2012ff2457f0737d86f3515 Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Fri, 20 Mar 2020 11:42:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=B8=A4=E4=B8=AA=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/GwallWms.php | 37 +++++++++++++++++++++++++++++++------ src/XinyiWms.php | 11 +++++++++-- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/GwallWms.php b/src/GwallWms.php index 0da1832..8f494d9 100644 --- a/src/GwallWms.php +++ b/src/GwallWms.php @@ -131,7 +131,12 @@ class GwallWms extends BaseWms implements WmsInterface ]; $result = $this->request($service, $postData); - return $result; + if (!$result['success']) { + return $result; + } + $data = $result['response'][0]; + $formatData = $this->formatGoodsStockInfo($data); + return array_merge($result, ['response' => $formatData]); } /** @@ -145,12 +150,12 @@ class GwallWms extends BaseWms implements WmsInterface $data = []; foreach ($params as $item) { $result = $this->goodsStockInfoSingle($item['wms_code']); - if (!$result['isSuccess']) { + if (!$result['success']) { continue; } - array_push($data, $result['body']); + array_push($data, $result['response']); } - return $data; + return ['success' => true, 'response' => $data]; } /** @@ -354,8 +359,15 @@ class GwallWms extends BaseWms implements WmsInterface 'encrypt' => $encrypt, 'content' => $base64Content, ]; - $response = $this->post($query); - return \GuzzleHttp\json_decode($response, true); + $result = $this->post($query); + $result = \GuzzleHttp\json_decode($result, true); + + $isSuccess = (empty($result) || !$result['isSuccess']) ? false : true; + $response = [ + 'success' => $isSuccess, + 'response' => $isSuccess ? $result['body'] : $result, + ]; + return $response; } public function base64Content($content, $encrypt = 0) @@ -372,4 +384,17 @@ class GwallWms extends BaseWms implements WmsInterface { return strtoupper(md5($content . $this->config['session_key'])); } + + public function formatGoodsStockInfo($params) + { + $params = array_map(function ($item) { + return array_merge($item, [ + 'itemCode' => $item['sku'], + 'itemId' => $item['sku'], + 'quantity' => $item['uqty'], + 'lockQuantity' => $item['qty'] - $item['uqty'], + ]); + }, $params); + return $params; + } } diff --git a/src/XinyiWms.php b/src/XinyiWms.php index fbd070c..74e146c 100644 --- a/src/XinyiWms.php +++ b/src/XinyiWms.php @@ -150,7 +150,9 @@ class XinyiWms extends BaseWms implements WmsInterface } $result = $this->xmlPost($method, $postData); - return $result; + return $result['success'] + ? array_merge($result, ['response' => $result['response']['items']['item']]) + : $result; } /** @@ -474,6 +476,11 @@ class XinyiWms extends BaseWms implements WmsInterface $res = $this->createSign($method, $body); $result = $this->post($body, $res); - return $result; + $isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true; + $response = [ + 'success' => $isSuccess, + 'response' => $isSuccess ? $result['response'] : $result, + ]; + return $response; } } \ No newline at end of file