Skip to content

Commit

Permalink
refactor with new gongmall sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolechen committed Jul 6, 2023
1 parent 1a73970 commit f0d56df
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 76 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"email": "[email protected]"
}],
"require": {
"php": "^7.2",
"php": "^7.1|^8.0",
"hanson/foundation-sdk": "3.0.*|^4.0.3|^5.0|dev-master",
"ext-json": "*",
"ext-openssl": "*"
Expand Down
62 changes: 49 additions & 13 deletions src/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,82 @@ public function getContractUrl(array $params): string
}

/**
* 查询电签结果(废弃).
* 通过合同模板id查询电签结果.
*
* @see https://opendoc.gongmall.com/dian-qian-he-tong/cha-xun-dian-qian-jie-guo.html
* @see https://opendoc.gongmall.com/merchant/dian-qian-he-tong/dian-qian-jie-guo-cha-xun-merchant.html
*
* @param array $params
*
* @return array
* @throws \JsonException
*
* @deprecated 官方标记为已废弃,使用 getContractStatusV2 替代
* @return array
*/
public function getContractStatus(array $params): array
{
return $this->request('/api/employee/getContractStatus', $params);
return $this->request('/api/merchant/employee/getContractStatus', $params);
}

/**
* 通过合同id查询电签结果.
*
* @see https://opendoc.gongmall.com/merchant/dian-qian-he-tong/get-contract-status-merchant.html
*
* @param array $params
*
* @throws \JsonException
*
* @return array
*/
public function getContractStatusByContractId(array $params): array
{
return $this->request('/api/merchant/employee/getContractStatusByContractId', $params);
}

/**
* 查询电签结果.
* 员工添加银行卡账号.
*
* @see https://opendoc.gongmall.com/dian-qian-he-tong/cha-xun-dian-qian-jie-guo-v2.html
* @see https://opendoc.gongmall.com/merchant/dian-qian-he-tong/add-employee-bank-account.html
*
* @param array $params
*
* @throws \JsonException
*
* @return array
*/
public function getContractStatusV2(array $params): array
public function addBankAccount(array $params): array
{
return $this->request('/api/employee/getContractStatusV2', $params);
return $this->request('/api/merchant/employee/addBankAccount', $params);
}

/**
* 修改员工银行卡
* 员工解除签署.
*
* @see https://opendoc.gongmall.com/shi-shi-ti-xian/xiu-gai-yin-hang-ka.html
* @see https://opendoc.gongmall.com/merchant/dian-qian-he-tong/delete-employee-merchant.html
*
* @param array $params
*
* @throws \JsonException
*
* @return array
*/
public function deleteContract(array $params): array
{
return $this->request('/api/merchant/employee/deleteContract', $params);
}

/**
* 更新员工默认手机号或者账号.
*
* @see https://opendoc.gongmall.com/merchant/dian-qian-he-tong/gen-xin-account-merchant.html
*
* @param array $params
*
* @throws \JsonException
*
* @return array
*/
public function syncBankAccount(array $params): array
public function updateEmployee(array $params): array
{
return $this->request('/api/employee/v2/syncBankAccount', $params);
return $this->request('/api/merchant/employee/updateEmployee', $params);
}
}
6 changes: 3 additions & 3 deletions src/Gongmall.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* Class Gongmall.
*
* @property Employee $employee
* @property Withdraw $withdraw
* @property Company $company
* @property Merchant $merchant
* @property Push $push
* @property Api $api
*/
class Gongmall extends Foundation
{
Expand All @@ -34,7 +34,7 @@ class Gongmall extends Foundation
*
* @return array
*/
public function request(string $uri, $params = []): array
public function request(string $uri, array $params = []): array
{
return $this->api->request($uri, $params);
}
Expand Down
8 changes: 2 additions & 6 deletions src/GongmallServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ public function register(Container $pimple): void
return new Employee($pimple);
};

$pimple['withdraw'] = function ($pimple) {
return new Withdraw($pimple);
};

$pimple['company'] = function ($pimple) {
return new Company($pimple);
$pimple['merchant'] = function ($pimple) {
return new Merchant($pimple);
};

$pimple['push'] = function ($pimple) {
Expand Down
10 changes: 6 additions & 4 deletions src/Company.php → src/Merchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@

namespace Bolechen\Gongmall;

class Company extends Api
class Merchant extends Api
{
/**
* 查询企业当前余额.
*
* @see https://opendoc.gongmall.com/shi-shi-ti-xian/cha-xun-qi-ye-yu-e.html
* @see https://opendoc.gongmall.com/merchant/merchant-account/cha-xun-qi-ye-yu-e-merchant.html
*
* @throws \JsonException
*
* @return array
*/
public function getBalance(): array
public function queryBalance(): array
{
return $this->request('/api/company/getBalance');
return $this->request('/api/merchant/queryBalance');
}
}
28 changes: 0 additions & 28 deletions src/Withdraw.php

This file was deleted.

48 changes: 27 additions & 21 deletions tests/GongmallApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@

/**
* @internal
*
* @coversNothing
*/
class GongmallApiTest extends TestCase
{
public $gongmall;
public $data = [];

/**
* @throws \Exception
*/
protected function setUp(): void
{
parent::setUp();
Expand All @@ -41,6 +45,8 @@ protected function setUp(): void

/**
* Employee Tests.
*
* @throws \JsonException
*/
public function testEmployee(): void
{
Expand All @@ -56,42 +62,42 @@ public function testEmployee(): void
$result = $this->gongmall->employee->getContractStatus($data2);
self::assertArrayHasKey('success', $result);

$result = $this->gongmall->employee->getContractStatusV2($data2);
$result = $this->gongmall->employee->getContractStatusByContractId($data2);
self::assertArrayHasKey('success', $result);

// 修改员工银行卡
$data3 = $data2;
$data3['oldBankName'] = '工商银行';
$data3['newBankName'] = '农业银行';
$data3['oldBankAccount'] = '6212253202006079587';
$data3['newBankAccount'] = '6212253202006079587';
$result = $this->gongmall->employee->syncBankAccount($data3);
$data3['bankAccountNo'] = '6212253202006079587';
$result = $this->gongmall->employee->addBankAccount($data3);

self::assertArrayHasKey('success', $result);
self::assertArrayHasKey('errorCode', $result);
}

/**
* Withdraw Tests.
*/
public function testWithdraw(): void
{
$data = $this->data;
$data['bankAccount'] = '6212253202006079587';
$data['amount'] = 123.45;
$data['requestId'] = time();
$data['dateTime'] = date('YmdHis');
// 员工解除签署
$data4['identity'] = $data['idNumber'];
$result = $this->gongmall->employee->deleteContract($data4);

self::assertArrayHasKey('success', $result);
self::assertArrayHasKey('errorCode', $result);

// 更新员工默认手机号或者账号
$data5['name'] = '新姓名';
$data5['mobile'] = '1388888888';
$data5['identity'] = $data['idNumber'];
$result = $this->gongmall->employee->updateEmployee($data5);

$result = $this->gongmall->withdraw->getTaxInfo($data);
self::assertArrayHasKey('success', $result);
self::assertArrayHasKey('errorCode', $result);
}

/**
* Company Tests.
* Merchant Tests.
*
* @throws \JsonException
*/
public function testCompany(): void
public function testMerchant(): void
{
$result = $this->gongmall->company->getBalance();
$result = $this->gongmall->merchant->queryBalance();
self::assertArrayHasKey('success', $result);
}

Expand Down

0 comments on commit f0d56df

Please sign in to comment.