<?php
namespace backend\controllers;

use common\libs\swoole\RPCApi;
use common\models\forms\DeclarationLoopForm;
use common\models\User;
use Yii;
use yii\helpers\Json;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;

/**
 * Site controller
 */
class TestController extends Controller
{
    /**
     * @throws \yii\base\Exception
     */
    public function actionRpc(){
        $data = [
            ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec001', 'decPv' => '5000', 'insertUserName' => 'dec001', 'conUserName' => 'tester003', 'recUserName' => 'tester003', 'location' => 1],
            ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec002', 'decPv' => '5000', 'insertUserName' => 'dec002', 'conUserName' => 'tester003', 'recUserName' => 'tester003', 'location' => 2],
            ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec003', 'decPv' => '5000', 'insertUserName' => 'dec003', 'conUserName' => 'tester003', 'recUserName' => 'tester003', 'location' => 3],
            ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec004', 'decPv' => '5000', 'insertUserName' => 'dec004', 'conUserName' => 'dec001', 'recUserName' => 'tester003', 'location' => 1],
            ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec005', 'decPv' => '5000', 'insertUserName' => 'dec005', 'conUserName' => 'dec001', 'recUserName' => 'tester003', 'location' => 2],
            ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec006', 'decPv' => '5000', 'insertUserName' => 'dec006', 'conUserName' => 'dec001', 'recUserName' => 'tester003', 'location' => 3],
        ];
        $condition = [
            'namespace' => '\\'.RPCApi::class.'::api',
            'param' => [
                'class'=> '\\'.DeclarationLoopForm::class,
                'fields'=>[
                    'scenario' => 'canDec',
                    'data' => $data,
                ],
                'action'=>'validate',
                'param'=>[],
            ],
        ];
        $rpcApi = new RPCApi();
        if($result = $rpcApi->request($condition)){
            var_dump($result);
        } else {
            var_dump($rpcApi->getError());
        }
    }
}
