goodcatch/guanyierp

使 guanyierp API 更易于使用

v1.0.1 2019-10-06 00:45 UTC

This package is auto-updated.

Last update: 2024-09-06 12:19:44 UTC


README

简化 Guanyi ERP API

安装

composer require goodcatch/guanyierp

php artisan vendor:publish --tag guanyi-config

配置

在配置文件 config/guanyi.php 中,检查以下配置

'auth' => [
    'appkey' => env('GUANYI_API_APP_KEY', ''),
    'sessionkey' => env('GUANYI_API_SESSION_KEY', ''),
    'secret' => env('GUANYI_API_SECRET', '')
]

然后向 .env 文件中添加环境键值对

GUANYI_API_APP_KEY=xxxxxxx
GUANYI_API_SESSION_KEY=xxxxxxx
GUANYI_API_SECRET=xxxxxxx
GUANYI_API_TIME_OUT=2

此外,可选的键值 GUANYI_API 默认为 API URL,可以设置在其他 URL 中

GUANYI_API=http://v2.api.guanyierp.com/rest/erp_open

用法

例如

use Goodcatch\Guanyi\Facades\Guanyi;

public function xxx () {

    // get product by product code
    $model = Guanyi::getProducts ('Product Code');

    // get products, $products->data presents all of product list
    $model = Guanyi::getProducts ();
    
    // checkout whether success or not
    if ($products->success)
    {
    
        // go through list models
        foreach ($model->data as $index => $product)
        {
            // get product fields $product->xxx
        }
        
    } else {
    
        dd ($model->errorCodel); // error code
        dd ($model->errorDesc); // error message
        dd ($model->subErrorDesc); // additional error message
        dd ($model->requestMethod); // guanyi ERP method name

    }
}
Route::get('/guanyi/products', function () {

    // get products by code, with page_no=1, and page_size=9999
    $model = Goodcatch\Guanyi\Facades\Guanyi::getProducts ('Product Code', [], 1, 9999);
    
    if ($model->success)
    {
        return $model->data;
    } else {
        
        // error message from guanyi api
        // for example: page_size=9999 is out of given range 1~99
        return $model->errorDesc;
    }
    
});

// got library exceptions
$model = Goodcatch\Guanyi\Facades\Guanyi::getProducts ();

if (! $model->success && isset ($model->exception) && is_array ($model->exception))
{
    foreach ($model->exception as $ex)
    {
        // Note: Increace GUANYI_API_TIME_OUT while keep getting exception.
        // string $ex
    }

}

// use criteria, note that get started with 'query' before 'critieria'
Goodcatch\Guanyi\Facades\Guanyi::query ()
    ->criteria ('start_date', '2019-09-24 00:00:00')
    ->criteria ('end_date', '2019-09-25 23:59:59')
    // use httpclient
    ->setHttpClient (new GuzzleHttp\Client ([
        // options
        'timeout' => 2
    ]))
    ->getProducts ([
        // overrite criteria
        'start_date' => '2019-09-25 00:00:00'
    ]);


方法

基本信息

店铺查询(gy.erp.shop.get)

getShops

获取店铺列表

getWarehouses

获取仓库列表

商品管理

商品查询(gy.erp.items.get)

getProducts

获取商品列表

采购管理

采购订单查询(gy.erp.purchase.get)

getPurchases

获取采购订单列表

getPurchasesByWarehouseCode

根据仓库代码获取采购订单列表

getPurchasesBySupplierCode

根据供应商代码获取采购订单列表

订单管理

发货单查询(gy.erp.trade.deliverys.get)

getTradeDeliverys

获取发货单列表

getTradeDeliverysByCode

根据单据编号获取发货单列表

getTradeDeliverysByWarehouse

根据仓库代码获取发货单列表

getTradeDeliverysByShop

根据店铺代码获取发货单列表

getTradeDeliverysByOuter

根据平台单号获取发货单列表

许可协议:[The MIT License (MIT)](https://github.com/allenwakeup/guanyierp/blob/HEAD/LICENSE)