long-blade/softone-sdk

一个简化SoftOne WebServices使用的插件。

dev-main 2022-11-07 13:03 UTC

This package is auto-updated.

Last update: 2024-09-07 18:44:22 UTC


README

一个简化SoftOne WebServices使用的插件。

安装

使用Composer安装

composer require long-blade/softone-sdk

文档

- 初始化

首先,您需要为API客户端设置最小要求凭据。

use SoftOne\Context;

// This can be set on the bootstrap of the application.
Context::initialize(
    'https://excample.com/s1services', // server endpoint
    'username',
    'password',
    '2001' // appid
);

如果您知道所有参数。

use SoftOne\Context;

// This can be set on the bootstrap of the application.
Context::initialize(
    'https://excample.com/s1services', // server endpoint
    'username',
    'password',
    '2001', // appid
     #--- optional ---
    '1000', // company
    '1000', // branch
    '0', // module
    '1', // refId
);

一旦客户端初始化完成,您就可以创建一个服务,并使用它与API进行通信

- 读取

可以使用通过BrowserInfo方法构建简单查询的GET请求从ERP获取数据

use SoftOne\Services\BrowserInfo;

$query = BrowserInfo::find()
       ->forObject('CUSTOMER') // This is like a table name
       ->withList('custom-list-filter') // use a custom erp soft one list filter
       ->where(['CUSTOMER.EMAIL'=> 'customer@company.gr']) // you can add filters like this
       ->limit(1);

现在我们构建了一个查询,我们可以执行一个简单的GET请求。

use SoftOne\Client;

$response = Client::get($foo)

- 设置数据

有两种方法可用于设置数据,insert()update()

将记录的数据插入到业务对象中

use SoftOne\Services\Data;

// Insert a new customer
$request = Data::insert('CUSTOMER',[
            'NAME' => 'TEST Soft One Technologies S.A.',
            'AFM' => '999863881',
            'EMAIL' => 'johng@softone.gr',
            'PHONE01' => '+302109484797',
            'FAX' => '9484094',
            'ADDRESS' => '6 Poseidonos street',
            'ZIP' => '17674',
        ]);

$customer = Client::get($request);

$customer->id // returns the new created customer id

通过KEY修改业务对象中的记录数据

use SoftOne\Services\Data;

// Update a new customer with the id of 47
$request = Data::update('CUSTOMER', '47', [
            'NAME' => 'TEST Soft One Technologies S.A.',
            'AFM' => '999863881',
            'EMAIL' => 'johng@softone.gr',
            'PHONE01' => '+302109484797',
            'FAX' => '9484094',
            'ADDRESS' => '6 Poseidonos street',
            'ZIP' => '17674',
        ]);

$customer = Client::get($request);

$customer->isSuccess() // true if updated

- 响应

响应实现了 SoftOne\Contracts\SoftoneResponseInterface

$response->isSuccess(); // Returns bool

$response->body(); // Returns an array with all the data,
// like so:
$body = [
    'reqID' => 0815969338959806593,
    'totalcount' => 6
    'fields' = [
        [
            'name' => 'CUSTOMER.EMAIL',
            'type' => 'string',
        ],
        // ...
    ],
    'columns' = [
        [
            'dataIndex' => 'CUSTOMER.EMAIL',
            'header' => '',
            'width' => '120',
            'decs' => '-1',
            'hidden' => '',
            'sortable' => '1',
        ],
        // ...
    ],
    'extrainfo' = [
        // ...
    ],
    'rows' = [ // the data according to each col
        [
            'email@excample.com',
            // ...
        ],
        // ...
    ]
];

可以使用 $response->data(['key1', 'key2',....]); 方法过滤响应数组

$response->data(['columns', 'rows']);

//OR access explicitly to response obj
$response->rows
$response->columns

测试

使用Composer运行测试

composer test