Commit 60f0b8c2 authored by shajiaiming's avatar shajiaiming

fix

parent 37ee074c
...@@ -50,14 +50,6 @@ class IssueCoinController extends BaseController ...@@ -50,14 +50,6 @@ class IssueCoinController extends BaseController
goto doEnd; goto doEnd;
} }
$pre_create_tx = isset($result['pre_create_tx']) ? $result['pre_create_tx'] : '';
$pre_send_transaction = isset($result['pre_send_transaction']) ? $result['pre_send_transaction'] : '';
if (false == $pre_create_tx || false == $pre_send_transaction) {
$msg = '预签名错误';
$code = -1;
goto doEnd;
}
$result = [ $result = [
'name' => isset($result['name']) ? $result['name'] : '', 'name' => isset($result['name']) ? $result['name'] : '',
'symbol' => isset($result['symbol']) ? strtoupper($result['symbol']) : '', 'symbol' => isset($result['symbol']) ? strtoupper($result['symbol']) : '',
...@@ -80,20 +72,6 @@ class IssueCoinController extends BaseController ...@@ -80,20 +72,6 @@ class IssueCoinController extends BaseController
$code = 0; $code = 0;
$data = $model->getPrimaryKey(); $data = $model->getPrimaryKey();
$params = [
'pre_create_tx' => $pre_create_tx,
'pre_send_transaction' => $pre_send_transaction,
'pre_query_transaction' => 'standby',
'finish_tx' => 'standby',
'finish_send_transaction' => 'standby',
'finish_query_transaction' => 'standby',
'issue_coin_id' => $data,
];
$transfer_model = new CoinIssueChainRecord();
$transfer_model->setScenario(CoinIssueChainRecord::SCENARIOS_PRE_CREATE);
$transfer_model->load($params,'');
$transfer_model->save();
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
} }
...@@ -175,14 +153,69 @@ class IssueCoinController extends BaseController ...@@ -175,14 +153,69 @@ class IssueCoinController extends BaseController
} }
/** /**
* 撤消申请 * 申请撤消/确认
* @param integer id
* @param string pre_create_tx
* @param string pre_send_transaction
* @return array
*/
public function actionSendTransfer()
{
$params = Yii::$app->request->post();
$id = isset($params['id']) ? (int)$params['id'] : 0;
$pre_create_tx = isset($params['pre_create_tx']) ? $params['pre_create_tx'] : '';
$pre_send_transaction = isset($params['pre_send_transaction']) ? $params['pre_send_transaction'] : '';
if (false == $id || false == $pre_create_tx || false == $pre_send_transaction) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
$model = CoinIssueChainRecord::find()->where(['issue_coin_id' => $id])->one();
if (true == $model) {
$msg = '交易记录已存在';
$code = -1;
goto doEnd;
}
$params = [
'pre_create_tx' => $pre_create_tx,
'pre_send_transaction' => $pre_send_transaction,
'pre_query_transaction' => 'standby',
'finish_tx' => 'standby',
'finish_send_transaction' => 'standby',
'finish_query_transaction' => 'standby',
'issue_coin_id' => $id,
];
$transfer_model = new CoinIssueChainRecord();
$transfer_model->setScenario(CoinIssueChainRecord::SCENARIOS_PRE_CREATE);
$transfer_model->load($params, '');
if (!$transfer_model->save()) {
$msg = current($transfer_model->firstErrors);
$code = -1;
goto doEnd;
}
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
/**
* 申请撤消/确认
* @param integer id * @param integer id
* @param integer status
* @return array * @return array
*/ */
public function actionVerify() public function actionVerify()
{ {
$id = Yii::$app->request->post('id', ''); $params = Yii::$app->request->post();
if (false == $id) { $id = isset($params['id']) ? (int)$params['id'] : 0;
$status = isset($params['status']) ? (int)$params['status'] : 0;
if (false == $id || false == $status) {
$msg = '缺少必要的参数'; $msg = '缺少必要的参数';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
...@@ -195,6 +228,13 @@ class IssueCoinController extends BaseController ...@@ -195,6 +228,13 @@ class IssueCoinController extends BaseController
goto doEnd; goto doEnd;
} }
$record_model = CoinIssueChainRecord::find()->where(['issue_coin_id' => $id])->one();
if (false == $record_model) {
$msg = '交易记录不存在';
$code = -1;
goto doEnd;
}
if ($model->status > CoinIssueCoin::UN_AUDIT) { if ($model->status > CoinIssueCoin::UN_AUDIT) {
$msg = '不允许取消的发行'; $msg = '不允许取消的发行';
$code = -1; $code = -1;
...@@ -202,7 +242,7 @@ class IssueCoinController extends BaseController ...@@ -202,7 +242,7 @@ class IssueCoinController extends BaseController
} }
$data = [ $data = [
'status' => CoinIssueCoin::CANCEL_ISSUE, 'status' => $status,
]; ];
$model->setScenario(CoinIssueCoin::SCENARIOS_CANCEL); $model->setScenario(CoinIssueCoin::SCENARIOS_CANCEL);
$model->load($data, ''); $model->load($data, '');
...@@ -212,10 +252,117 @@ class IssueCoinController extends BaseController ...@@ -212,10 +252,117 @@ class IssueCoinController extends BaseController
goto doEnd; goto doEnd;
} }
if ($status == CoinIssueCoin::ALLOWED_ISSUE) {
$record_model->pre_query_transaction = 'success';
$record_model->update();
}
$code = 0; $code = 0;
$msg = 'success'; $msg = 'success';
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg]; return ['code' => $code, 'msg' => $msg];
} }
/**
* 手续费划转
* @return
*/
public function actionPayCharge()
{
$issue_coin_model = CoinIssueCoin::find()
->select('id')->where(['charge_pay' => CoinIssueCoin::ALLOW_PAY])->asArray()->all();
if (false == $issue_coin_model) {
echo date('Y-m-d H:i:s') . '暂无手续费划转任务' . PHP_EOL;
return 0;
}
$issue_transfer = CoinIssueTransfer::find()
->where(['unissue' => 1])
->andWhere(['in', 'issue_coin_id', ArrayHelper::getColumn($issue_coin_model, 'id')])
->asArray()
->all();
if (false == $issue_transfer) {
echo date('Y-m-d H:i:s') . '暂无手续费划转任务' . PHP_EOL;
return 0;
}
$node = Yii::$app->params['chain_nodes']['STO'];
$service = new Chain33Service($node);
foreach ($issue_transfer as $val) {
$result = $service->sendTransaction($val['txhex']);
if (0 == $result['code']) {
$send_result = $result['result'];
$currentModel = CoinIssueTransfer::findOne($val['id']);
$currentModel->send_result = $send_result;
$currentModel->msg = 0;
$currentModel->save();
} else {
$currentModel = CoinIssueTransfer::findOne($val['id']);
$currentModel->msg = $result['msg'];
$currentModel->save();
}
}
echo date('Y-m-d H:i:s') . '手续费划转任务完成' . PHP_EOL;
return 0;
}
/**
* 手续费划转状态确认
* @return
*/
public function actionPayChargeStatus()
{
$unissue = -1;
$model = CoinIssueTransfer::find()->where(['<>', 'send_result', '0'])->andWhere(['msg' => '0'])->asArray()->all();
if (empty($model)) {
echo date('Y-m-d H:i:s') . '暂无需要确认的手续费划转状态' . PHP_EOL;
return 0;
}
$node = \Yii::$app->params['chain_parallel']['primary'];
$service = new Chain33Service($node);
foreach ($model as $val) {
$send_result = $val['send_result'];
$result = $service->QueryTransaction($send_result);
if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
$query_result = 'success';
$msg = 'success';
goto doEnd;
} else if (isset($result['result']['receipt']['ty']) && 2 == $result['result']['receipt']['ty']) {
$query_result = 'success';
$msg = 'success';
goto doEnd;
} else {
if (isset($result['result']['receipt']['logs'])) {
foreach ($result['result']['receipt']['logs'] as $log) {
if (isset($log['tyName']) && 'LogErr' == $log['tyName']) {
$msg = $log['tyName'];
break;
}
}
} else {
$msg = $result['msg'];
}
$query_result = $result['code'];
goto doEnd;
}
doEnd :
if ('success' == $msg) {
$unissue = 0;
$coin_issue_coin = CoinIssueCoin::find()->where(['id' => $val['issue_coin_id']])->one();
$coin_issue_coin->charge_pay = CoinIssueCoin::SUCCESS_PAY;
$coin_issue_coin->save();
}
$currentModel = CoinIssueTransfer::findOne($val['id']);
$currentModel->query_result = $query_result;
if ($unissue > -1) {
$currentModel->unissue = $unissue;
}
$currentModel->msg = $msg;
$currentModel->save();
}
}
} }
\ No newline at end of file
...@@ -35,4 +35,9 @@ class CoinIssueChainRecord extends CommonActiveRecord ...@@ -35,4 +35,9 @@ class CoinIssueChainRecord extends CommonActiveRecord
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
} }
public function getCoin()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id']);
}
} }
\ No newline at end of file
...@@ -20,6 +20,7 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -20,6 +20,7 @@ class CoinIssueCoin extends CommonActiveRecord
const SUCCESS_ISSUE = 3; const SUCCESS_ISSUE = 3;
const FAIL_ISSUE = 4; const FAIL_ISSUE = 4;
const CANCEL_ISSUE = 5; const CANCEL_ISSUE = 5;
const ALLOWED_ISSUE = 6;
//定义场景 //定义场景
const SCENARIOS_CREATE = 'create'; const SCENARIOS_CREATE = 'create';
...@@ -146,6 +147,6 @@ class CoinIssueCoin extends CommonActiveRecord ...@@ -146,6 +147,6 @@ class CoinIssueCoin extends CommonActiveRecord
public function getTransfer() public function getTransfer()
{ {
return $this->hasOne(CoinIssueChainTransfer::className(), ['issue_coin_id' => 'id']); return $this->hasOne(CoinIssueChainRecord::className(), ['issue_coin_id' => 'id']);
} }
} }
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinIssueTransfer extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_transfer}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
public function rules()
{
return [
[['txhex', 'issue_coin_id'], 'required'],
[['send_result', 'query_result', 'msg'], 'safe']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['txhex', 'issue_coin_id', 'send_result', 'query_result', 'msg'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment