alan/dcache-helper

There is no license information available for the latest version (v1.0.1) of this package.

dcache-helper

v1.0.1 2020-01-07 13:11 UTC

This package is auto-updated.

Last update: 2024-11-08 00:11:38 UTC


README

  1. 安装

    composer require alan/alan/dcache-helper

  2. 使用

use alan\dcache_helper\CoroutineHelper;
use alan\dcache_helper\DCacheHelperFace;

require "../vendor/autoload.php";

$cnf = [
    'dcache_invoice_locator' => 'xxxxxxxxxxxxxxxxxxx',
    'tars_dacache_proxy' => "DCache.centerProxyServer.ProxyObj",
    'modules' => [
        'order'                     => 'center2order',
        'orderItem'                 => 'center2orderItem',
        'invoice'                   => 'center2invoice',
        'invoiceItem'               => 'center2invoiceItem',
        'merchantInvoice'           => 'center2relMerchantInvoice',
        'invoiceDeliver'            => 'center2invoiceDeliver',
        'relBusinessOrderInvoice'   => 'center2relBussinessOrderInvoice',
        'relBusinessUserInvoice'    => 'center2relBussinessUserInvoice',
        'taxInvoice'                => 'center2relTaxInvoice',
        'userInvoice'               => 'center2relUserInvoice',
    ],
];

$order_sn = '6550307913561455313';
$type = 1;

if ($type == 0) {
    $start = microtime(true);
    $config = new \alan\dcache_helper\Config($cnf['dcache_invoice_locator'], 2, $cnf['modules'], $cnf['tars_dacache_proxy']);
    $face = DCacheHelperFace::instance($config);
    $helper = $face->getHelper();
    $result = $merchantInvoice = $face->withHelper($helper)->order()->get($order_sn);
    $merchantInvoice = $face->withHelper($helper)->orderItem()->get($order_sn);
    print_r($result);
    print_r($merchantInvoice);
    $cost = microtime(true) - $start;
    echo "all cost {$cost} \n";
} else {
    go(function () use ($cnf, $order_sn){
        $config = new \alan\dcache_helper\Config($cnf['dcache_invoice_locator'], 3, $cnf['modules'], $cnf['tars_dacache_proxy']);
        $face = DCacheHelperFace::instance($config);
        $helper = $face->getHelper();
        $start = microtime(true);
        $coroutine = new CoroutineHelper();
        $coroutine->add(function() use ($face, $helper, $order_sn){
            $merchantInvoice = $face->withHelper($helper)->order()->get($order_sn);
            return [1, $merchantInvoice];
        });

        $coroutine->add(function() use ($face, $helper, $order_sn){
            $merchantInvoice = $face->withHelper($helper)->orderItem()->get($order_sn);
            return [2, $merchantInvoice];
        });
        $result = $coroutine->run();
        print_r($result);
    });
}