request->isGet) { $this->code = -1; $this->msg = '请求方式错误!'; goto doEnd; } $params = Yii::$app->request->get(); $wallet_address = isset($params['wallet_address']) ? $params['wallet_address'] : ''; if (false == $wallet_address) { $this->code = -1; $this->msg = '参数错误'; goto doEnd; } $page = Yii::$app->request->get('page', 1); $size = Yii::$app->request->get('size', 10); $query = WalletChain::find() ->select('id, token, platform, create_time, status') ->where(['wallet_address' => $wallet_address]) ->orderBy('id'); $model = $query->offset(($page - 1) * $size)->orderBy('create_time desc')->limit($size)->asArray()->all(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]); $this->data = [ 'list' => $model, 'page' => [ 'pageCount' => $pages->pageCount, 'pageSize' => $size, 'currentPage' => $page, ] ]; doEnd : return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; } /** * h5发行链 * @param string platform * @param string address * @param string private_key * @param string fee * @param string token * @param string host * @param string port * @param string wallet_address * @param string hash * @return array */ public function actionChain() { $request = Yii::$app->request; if (!$request->isPost) { $this->code = -1; $this->msg = '请求方式错误!'; goto doEnd; } $post = $request->post(); $model = new WalletChain(); $model->setScenario(WalletChain::SCENARIOS_CREATE); $params = [ 'platform' => isset($post['platform']) ? $post['platform'] : '', 'address' => isset($post['address']) ? $post['address'] : '', 'private_key' => isset($post['private_key']) ? $post['private_key'] : '', 'token' => isset($post['token']) ? strtoupper($post['token']) : '', 'host' => isset($post['host']) ? $post['host'] : '', 'port' => isset($post['port']) ? $post['port'] : '', 'wallet_address' => isset($post['wallet_address']) ? $post['wallet_address'] : '', 'status' => WalletChain::STATUS_NO, 'origin' => WalletChain::ORIGIN_MANAGE, 'fee' => isset($post['fee']) ? $post['fee'] : '', 'hash' => isset($post['hash']) ? $post['hash'] : '' ]; if ($model->load($params, '') && !$model->save()) { $this->msg = $model->errors; $this->code = -1; goto doEnd; } $id = Yii::$app->p_sources->getLastInsertID(); // $params = [ // 'platform' => 'BZCHAIN', // 'host' => '112.74.59.221', // 'port' => 1235, // ]; $node_params = Yii::$app->params['para']; $service = new Chain33Service($node_params); $result = $service->addPara($params['platform'], $params['host'] . ':' . $params['port']); if (0 != $result['code']) { $this->code = $result['code']; $this->msg = $result['msg']; goto doEnd; } $chain_update = WalletChain::find()->where(['id' => $id])->one(); $chain_update->setScenario(WalletChain::SCENARIOS_UPDATE); $chain_update->status = WalletChain::STATUS_YES; $chain_update->save(); doEnd : return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; } /** * h5发行链 * @param string wallet_address * @return array */ public function actionDetail() { if (!Yii::$app->request->isGet) { $this->code = -1; $this->msg = '请求方式错误!'; goto doEnd; } $params = Yii::$app->request->get(); $id = isset($params['id']) ? $params['id'] : ''; if (false == $id) { $this->code = -1; $this->msg = '参数错误'; goto doEnd; } $model = WalletChain::find()->select('platform, token, address, private_key, fee, host, port, hash, status')->where(['id' => (int)$id])->asArray()->one(); if (empty($model)) { goto doEnd; } $model['fee'] = $model['fee'] . $model['token']; $model['charge'] = '10BTY'; $this->data = $model; goto doEnd; doEnd : return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; } }