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