PHP code example of goodcatch / guanyierp

1. Go to this page and download the library: Download goodcatch/guanyierp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goodcatch / guanyierp example snippets



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'
    ]);




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