Skip to content

Commit

Permalink
增加应付接口
Browse files Browse the repository at this point in the history
  • Loading branch information
herojhc committed Aug 1, 2020
1 parent c4144ba commit 5666653
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 0 deletions.
124 changes: 124 additions & 0 deletions src/XinXiHua/SDK/Services/PayableService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php
/**
* Created by PhpStorm.
* User: JHC
* Date: 2020-08-01
* Time: 17:31
*/

namespace XinXiHua\SDK\Services;


use XinXiHua\SDK\Exceptions\ApiException;

class PayableService extends BaseService
{
/**
* @param int $page
* @param int $limit
* @param array $criteria
* @param array $include
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function paginate($page = 1, $limit = 20, $criteria = [], $include = ['customer', 'category'], $corpId = null)
{
$response = $this->getIsvCorpClient($corpId)->get('/payables', array_merge([
'page' => $page,
'limit' => $limit,
'include' => implode(',', $include)
], $criteria));
if ($response->isResponseSuccess()) {
return $response->getResponseData();
}
throw new ApiException($response->getResponseMessage());
}

/**
* @param $id
* @param array $include
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function show($id, $include = ['customer', 'category'], $corpId = null)
{
$response = $this->getIsvCorpClient($corpId)->get('/payables/' . $id, [
'include' => implode(',', $include)
]);
if ($response->isResponseSuccess()) {
return $response->getResponseData()['data'];
}

throw new ApiException($response->getResponseMessage());
}

/**
* @param $data
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function store($data, $corpId = null)
{

$response = $this->getIsvCorpClient($corpId)->post('/payables', $data);
if ($response->isResponseSuccess()) {
return $response->getResponseData()['data']['id'];
}
throw new ApiException($response->getResponseMessage());

}

/**
* @param $data
* @param $id
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function update($data, $id, $corpId = null)
{

$response = $this->getIsvCorpClient($corpId)->patch('/payables/' . $id, $data);
if ($response->isResponseSuccess()) {
return $response->getResponseData()['data']['id'];
}
throw new ApiException($response->getResponseMessage());
}

/**
* @param $id
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function destroy($id, $corpId = null)
{

$response = $this->getIsvCorpClient($corpId)->delete('/payables/' . $id);
if ($response->isResponseSuccess()) {
return $id;
}
throw new ApiException($response->getResponseMessage());
}

/**
* @param array $ids
* @param null $corpId
* @return bool
* @throws ApiException
*/
public function batchDestroy(array $ids, $corpId = null)
{
$response = $this->getIsvCorpClient($corpId)->post('/payables/batch', [
'delete' => $ids
]);
if ($response->isResponseSuccess()) {
return true;
}

throw new ApiException($response->getResponseMessage());
}
}
62 changes: 62 additions & 0 deletions src/XinXiHua/SDK/Services/PaymentService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Created by PhpStorm.
* User: JHC
* Date: 2020-08-01
* Time: 17:31
*/

namespace XinXiHua\SDK\Services;


use XinXiHua\SDK\Exceptions\ApiException;

class PaymentService extends BaseService
{
/**
* @param $data
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function store($data, $corpId = null)
{
$response = $this->getIsvCorpClient($corpId)->post('/payments', $data);
if ($response->isResponseSuccess()) {
return $response->getResponseData()['data']['id'];
}
throw new ApiException($response->getResponseMessage());

}

/**
* @param $id
* @param array $data
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function pay($id, $data = [], $corpId = null)
{
$response = $this->getIsvCorpClient($corpId)->post('/payments/' . $id . '/pay', $data);
if ($response->isResponseSuccess()) {
return $response->getResponseData();
}
throw new ApiException($response->getResponseMessage());
}

/**
* @param $id
* @param null $corpId
* @return mixed
* @throws ApiException
*/
public function destroy($id, $corpId = null)
{
$response = $this->getIsvCorpClient($corpId)->delete('/payments/' . $id);
if ($response->isResponseSuccess()) {
return $id;
}
throw new ApiException($response->getResponseMessage());
}
}

0 comments on commit 5666653

Please sign in to comment.