Commit 30f735a0 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/issue_coin' into 'master'

Feature/issue coin See merge request !203
parents f837e880 70bb9c95
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\psources\CoinPlatform;
class IssueChainController extends BaseController
{
/**
* 可发行链列表
* @return array
*/
public function actionIndex()
{
$data = null;
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if (empty($platform_id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (1 == $platform_id) {
$chain_model = CoinPlatform::find()->all();
} else {
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->all();
}
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
$val->issue_charge = (float)sprintf("%0.3f", $val->issue_charge);
$val->charge_unit = isset($val->gas->coin_name) ? $val->gas->coin_name : '';
unset($val->download_url);
unset($val->introduce);
unset($val->create_time);
unset($val->update_time);
}
$msg = 'ok';
$code = 0;
$data = is_array($chain_model) ? $chain_model : [$chain_model];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 人工审核状态
* @return array
*/
public function actionManualReviewStatus()
{
$status = 0;
$manual_review = Yii::$app->redis->get('issue_chain_manual_review');
if (false == $manual_review || 'open' == $manual_review) {
$status = 1;
}
return ['code' => 0, 'data' => $status];
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -4,6 +4,7 @@ namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinIssueTransfer;
use common\models\psources\CoinPlatform;
use common\service\chain33\Chain33Service;
use Yii;
......@@ -16,7 +17,7 @@ class WalletController extends BaseController
$code = 0;
$msg = 'success';
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($platform_id)){
if (empty($platform_id)) {
$msg = '参数不能为空';
$code = -1;
$data = null;
......@@ -24,7 +25,7 @@ class WalletController extends BaseController
}
$data = CoinPlatform::find()->select("name, download_url, introduce")->where(['id' => $platform_id])->asArray()->one();
if(empty($data)){
if (empty($data)) {
$msg = '数据不存在';
$data = null;
$code = -1;
......@@ -39,16 +40,16 @@ class WalletController extends BaseController
public function actionGameTradeUpdate()
{
$coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2 ,'msg' => '0'])->limit(30)->all();
foreach ($coinAirDropTrade as $val){
$coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2, 'msg' => '0'])->limit(30)->all();
foreach ($coinAirDropTrade as $val) {
$fee = 100000;
$amount = 1 * 1e8;
$execer = 'coins';
$note = '';
$service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){
$createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer);
if (0 != $createRawTransaction['code']) {
continue;
}
......@@ -57,13 +58,13 @@ class WalletController extends BaseController
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
if (0 != $signRawTx['code']) {
continue;
}
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str);
if(0 != $result['code']){
if (0 != $result['code']) {
continue;
}
$currentModel = CoinAirDropTrade::findOne($val->id);
......@@ -77,23 +78,59 @@ class WalletController extends BaseController
public function actionGetBalance()
{
$coinAirDropTrade = CoinAirDropTrade::find()->where(['balance' => 0])->limit(60)->all();
$address = [];
foreach ($coinAirDropTrade as $val){
$address[] = $val->coins_address;
$code = 0;
$msg = 'success';
$platform_id = Yii::$app->request->get('platform_id', '');
$token = Yii::$app->request->get('address', '');
if (empty($platform_id) || empty($token)) {
$msg = '参数不能为空';
$code = -1;
$data = null;
goto doEnd;
}
$service = new Chain33Service();
$node = Yii::$app->params['chain_parallel']['primary'];
$service = new Chain33Service($node);
$address[] = $token;
$execer = 'coins';
$result = $service->getBalance($address, $execer);
if(0 == $result['code']){
$result_balance = $result['result'];
foreach ($result_balance as $val){
$coinAirDropTrade = CoinAirDropTrade::find()->where(['coins_address' => $val['addr']])->one();
if(empty($coinAirDropTrade)) continue;
$coinAirDropTrade->balance = $val['balance'];
$coinAirDropTrade->save();
}
$result = $service->getBalance($address, $execer);
if (0 !== $result['code']) {
$msg = $result['msg'];
$code = -1;
$data = null;
goto doEnd;
}
return ['code' => 1, 'msg' => 'ok'];
$data = $result['result'];
doEnd :
return ['code' => $code, 'data' => $data, 'msg' => $msg];
}
public function actionTransfer()
{
$code = -1;
$request = Yii::$app->request;
$post = $request->post();
if (!$request->isPost) {
$msg = '请求错误!';
goto doEnd;
}
$txhex = isset($post['txhex']) ? $post['txhex'] : '';
$issue_coin_id = isset($post['issue_coin_id']) ? $post['issue_coin_id'] : 0;
if (false == $txhex || false == $issue_coin_id) {
$msg = '参数错误!';
goto doEnd;
}
$model = new CoinIssueTransfer();
$data['txhex'] = $txhex;
$data['issue_coin_id'] = (int)$issue_coin_id;
$model->load($data, '');
$model->save();
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
}
\ No newline at end of file
<?php
namespace backend\assets\coinSupportedCoin;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-supported-coin';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
namespace backend\controllers;
use common\models\psources\CoinSupportedCoin;
use Yii;
class CoinSupportedCoinController extends BaseController
{
public function actionList()
{
$platform_id = Yii::$app->request->get('id');
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$id = $request->get('id', '');
$where = [];
if ($id) {
$where[] = ['platform_id' => $id];
}
$data = CoinSupportedCoin::getList($page, $limit, $where);
$data['code'] = 0;
Yii::$app->response->format = 'json';
return $data;
}
return $this->render('index', ['platform_id' => $platform_id]);
}
public function actionAdd()
{
$this->layout = false;
$model = new CoinSupportedCoin();
$model->setScenario(CoinSupportedCoin::SCENARIOS_CREATE);
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$data = Yii::$app->request->post();
if ($model->load($data, '') && $model->save()) {
return ['code' => 0, 'msg' => 'succeed'];
}
$error = $model->errors;
if ($error) {
return ['code' => -1, 'msg' => current($model->firstErrors)];
}
}
$platform_id = Yii::$app->request->get('platform_id');
return $this->render('add', ['model' => $model, 'platform_id' => $platform_id]);
}
public function actionDelete()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', 0);
if ($id) {
$model = CoinSupportedCoin::findOne(['id' => $id]);
if ($model) {
try {
$model->delete();
return ['code' => 0, 'msg' => 'succeed'];
} catch (\Throwable $t) {
return ['code' => $t->getCode(), 'msg' => $t->getMessage()];
}
}
}
return ['code' => -1, 'msg' => '删除失败'];
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ namespace backend\controllers;
use backend\models\coin\CoinPlatformForm;
use common\models\psources\CoinPlatform;
use common\models\psources\CoinPlatformWithHold;
use Yii;
......@@ -39,6 +40,7 @@ class WalletController extends BaseController
{
$model = new CoinPlatformForm();
$model->scenario = 'add';
$platform_withhold = CoinPlatformWithHold::find()->select('id, platform')->orderBy('platform')->asArray()->all();
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
if ($model->load($data, '') && $model->validate()) {
......@@ -60,7 +62,8 @@ class WalletController extends BaseController
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('add', ['model' => $model]);
return $this->render('add', ['model' => $model, 'platform_withhold' => $platform_withhold]);
}
public function actionEdit()
......@@ -90,9 +93,10 @@ class WalletController extends BaseController
} elseif (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id', null);
if ($id) {
$platform_withhold = CoinPlatformWithHold::find()->select('id, platform')->orderBy('platform')->asArray()->all();
$coin = CoinPlatform::findOne(['id' => $id]);
$this->layout = false;
return $this->render('edit', ['model' => $coin]);
return $this->render('edit', ['model' => $coin, 'platform_withhold' => $platform_withhold]);
}
}
}
......
......@@ -14,6 +14,7 @@ class CoinPlatformForm extends Model
{
public $id;
public $name;
public $chain_id;
public $download_url;
public $introduce;
......@@ -27,6 +28,7 @@ class CoinPlatformForm extends Model
return [
[['name'], 'required', 'on' => 'add'],
[['id', 'name'], 'required', 'on' => 'update'],
[['chain_id', 'download_url', 'introduce'], 'safe']
];
}
......@@ -34,6 +36,7 @@ class CoinPlatformForm extends Model
{
return [
'id' => 'ID',
'chain_id' => '所属链',
'name' => '名称',
'download_url' => '下载链接',
'introduce' => '介绍'
......@@ -46,10 +49,16 @@ class CoinPlatformForm extends Model
'add' => [
'id',
'name',
'chain_id',
'download_url',
'introduce'
],
'update' => [
'id',
'name',
'chain_id',
'download_url',
'introduce'
],
];
}
......
<div style="padding: 5px 20px;">
<br>
<form id="addData">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="input-group my-group">
<span class="input-group-addon">币种名称</span>
<input name="coin_name" type="text" class="form-control" lay-verify="required">
</div>
<input class="layui-input" name="platform_id" type="hidden" value="<?= $platform_id ?>"
lay-verify="required">
</form>
</div>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use backend\assets\coinSupportedCoin\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>货币列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<button class="layui-btn layui-btn-sm" lay-event="add" id="add">单笔添加</button>
</div>
</div>
<input id="platform_id" type="hidden" value="<?= $platform_id ?>">
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="operationTpl">
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
</script>
......@@ -23,6 +23,18 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">所属链</label>
<div class="layui-input-block">
<select name="chain_id">
<?php foreach ($platform_withhold as $val): ?>
<option value="<?= $val['id'] ?>" <?php if ($model->chain_id == $val['id']) {
echo "selected";
} ?>><?= $val['platform'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label>
<div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
......@@ -40,3 +52,6 @@
</form>
</div>
</div>
<script>
layui.form.render();
</script>
......@@ -24,6 +24,18 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">所属链</label>
<div class="layui-input-block">
<select name="chain_id">
<?php foreach ($platform_withhold as $val): ?>
<option value="<?= $val['id'] ?>" <?php if ($model->chain_id == $val['id']) {
echo "selected";
} ?>><?= $val['platform'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label>
<div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
......
......@@ -42,10 +42,7 @@ IndexAsset::register($this);
</div>
<script type="text/html" id="operationTpl">
<a lay-event="edit">
<button class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i></button>
</a>
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/coin-supported-coin/list?id={{d.id}}" >支持发行货币种类</a>
</script>
/**
* @author rlgyzhcn@qq.com
*/
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
form.render();
var platform_id = $("#platform_id").val();
var tableIns = table.render({
elem: "#table1",
url: '/admin/coin-supported-coin/list?id=' + platform_id,
limit: 10,
page: 1,
loading: true,
cols: [[
{field: 'id', title: 'ID'},
{field: 'coin_name', title: '货币对'},
{field: 'create_time', title: '创建时间'},
{field: 'id', title: '操作', templet: '#operationTpl'}
]],
});
form.on('submit(form1)', function (data) {
table.reload("table1", {
where: data.field,
page: {curr: 1},
});
return false;
});
//监听单元格事件
table.on('tool(table1)', function (obj) {
var data = obj.data;
if (obj.event == 'delete') {
layer.confirm('真的要删除' + data.coin_name + '吗?', {icon: 3, title: '删除'}, function (index) {
layer.close(index);
//向服务端发送删除指令
$.get('/admin/coin-supported-coin/delete?id=' + obj.data.id, function (data, status) {
if (data.code == 0) {
obj.del(); //删除对应行(tr)的DOM结构
}
layer.msg(data.msg);
});
});
}
});
$('#add').click(function () {
//打开弹窗
$.get('/admin/coin-supported-coin/add?platform_id=' + platform_id, {}, function (str) {
var index = layer.open({
type: 1,
title: '添加数据',
id: 'add-one',
skin: 'layui-layer-lan',
area: ['320px', 'auto'],
content: str,
btn: ['确认', '取消'],
btn1: function () {
$.post('/admin/coin-supported-coin/add', $("#addData").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
}
});
}
});
layui.form.render();
});
return false;
});
\ No newline at end of file
......@@ -26,14 +26,14 @@ class LoginStatusAuthInterceptor extends ActionFilter
$token_string = Yii::$app->request->headers->get('Token');
if(false == $token_string){
$msg = 'platform auth error';
$code = '40004';
$code = '40001';
goto doEnd;
}
$model = new Admin();
$user = $model->loginByAccessToken($token_string,'');
if(false == $user){
$msg = 'user auth error';
$code = '40004';
$code = '40002';
goto doEnd;
}
$user_id = $user->uid;
......
<?php
namespace common\components;
use yii\base\Component;
class ErrorMessage extends Component
{
/**
* 预定义错误信息
*/
public static $errors = [
'ErrTokenNameLen' => "token名字太长",
'ErrTokenSymbolLen' => " token符号太长",
'ErrTokenTotalOverflow' => ' token 总数过大, 或是负的',
'ErrTokenSymbolUpper' => ' token symbol 需要全是大写字母',
'ErrTokenIntroLen' => ' Token介绍太长',
'ErrTokenExist' => ' Token Symbol 已经存在',
'ErrTokenNotPrecreated' => ' Token 还没有预创建',
'ErrTokenCreatedApprover' => 'Token Approver 没有权限',
'ErrTokenRevoker' => ' Token Revoker 错误 (需要创建者自己撤销)',
'ErrTokenCanotRevoked' => 'Token 不能撤销',
'ErrTokenOwner' => 'Token Owner 错误',
'ErrTokenHavePrecreated' => 'Token已经被预创建',
'ErrTokenBlacklist' => 'Token 在黑名单里',
'ErrTokenNotExist' => 'Token 不存在',
'ErrTokenSymbolExistAlready' => 'Token Symbol 已经存在'
];
/**
* 获取错误信息
*/
public static function getMessage($msg)
{
$message = isset(self::$errors[$msg]) ? self::$errors[$msg] : '未知错误';
return $message;
}
}
\ No newline at end of file
<?php
namespace common\models;
use Yii;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper;
class Tools
{
/**
* 获取随机验证码
* @return string
*/
public static function getRandomNumber($count = 6, $type = 'mixed')
{
$chars = '1234567890abcdefghijklmnopqrstuvwxyz';
switch($type) {
case 'number':
$startIndex = 0;
$endIndex = 9;
break;
case 'letter':
$startIndex = 10;
$endIndex = 35;
break;
default :
$startIndex = 0;
$endIndex = 35;
break;
}
$randomNumber = '';
for($i = 0; $i<$count; $i++) {
$randomNumber .= substr($chars, rand($startIndex, $endIndex), 1);
}
return $randomNumber;
}
/**
* 获取文件全路径
* @param type $filename
* @param type $type
* @return string
*/
public static function getFileUrl($fileName)
{
return $fileName? Url::to('@resDomain' . $fileName): '';
}
/**
* 判断当前日期是否是可用日期
* @param type $startData
* @param type $endData
*/
public static function isAvailableDate($start, $end)
{
$current = date('Y-m-d');
$start = $start?date('Y-m-d', strtotime($start)):$current;
$end = $end?date('Y-m-d', strtotime($end)):$current;
if($start <= $current && $end >= $current) {
return true;
} else {
return false;
}
}
/**
* 添加get查询数据
* @param type $values
*/
public static function addQueryParams($values)
{
Yii::$app->request->setQueryParams(\yii\helpers\ArrayHelper::merge(Yii::$app->request->get(), $values));
}
/**
* 获取post数据, 可附加额外数据
* @param array $values 附加数据,必须是数组形式
* @param string $formName 指定数据附加到特定键
*/
public static function getPost(array $values, $formName = null)
{
if(Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
if($formName !== null) {
$data[$formName] = ArrayHelper::merge($data[$formName], $values);
} else {
$data = ArrayHelper::merge($data, $values);
}
return $data;
} else {
return;
}
}
/**
* 获取到下个给定时间点还有多长时间,单位 秒
* @param mixed $time 可以是一个时间字符串,也可以是时间字符串数组
* 格式为 h:m:s
* @return $duration 返回值为到下个时间点还有多长时间,以秒为单位
*/
public static function getDuration($time)
{
if(!is_array($time)) {
$time = (array)$time;
}
$seconds = [];
foreach($time as $value) {
$timeArray = explode(':', $value);
if(3 != count($timeArray)) {
return false;
}
list($hour, $minute, $second) = $timeArray;
if((int)$hour < 0 || (int)$hour > 23 || (int)$minute < 0 || (int)$minute > 59 || (int)$second < 0 || (int)$second > 59) {
return false;
}
$seconds[] = $hour * 3600 + $minute * 60 + $second;
}
sort($seconds);
$currentTimeSecond = idate('H') * 3600 + idate('i') * 60 + idate('s');
foreach($seconds as $second) {
if(($second - $currentTimeSecond) > 0) {
return $second - $currentTimeSecond;
}
}
return $seconds[0] + (24 * 3600 - $currentTimeSecond);
}
/**
* 保留小数位数,向下取数
* @param float $number //数字
* @param int $precision //精度
* 例如, roundDown(1.20058, 4) return 1.2005
*/
public static function roundDown($number, $precision)
{
$pow = pow(10, (int)$precision);
return floor($number*$pow)/$pow;
}
/**
* 获取一条错误信息
* @param type $errors
* @return type
*/
public static function getFirstError($errors,$defaultError = null)
{
if(count($errors) > 0){
foreach($errors as $error) {
return $error[0];
}
}
$defaultError = '请求数据有误';
return $defaultError;
}
/**
* 格式化数字
* @param int $num
* @return string
*/
public static function formatNumber($num)
{
return ($num/100000000 > 1) ? sprintf('%.2f', $num/100000000).'亿' : (($num/10000 > 1) ? sprintf('%.2f', $num/10000).'万' : sprintf('%.2f', $num));
}
/**
* 获取配置参数
* @param string $moduleId 模块ID
* @param mixed $keys
* @param mixed $default 默认值
*/
public static function getModuleParams($moduleId, $keys, $default = null)
{
if(is_string($keys) && isset(Yii::$app->params[$moduleId][$keys])) {
return Yii::$app->params[$moduleId][$keys];
} elseif(is_array($keys) && isset(Yii::$app->params[$moduleId])) {
$params = Yii::$app->params[$moduleId];
foreach($keys as $key) {
if(isset($params[$key])) {
$params = $params[$key];
} else {
return $default;
}
}
return $params;
}
return $default;
}
/**
* 获取上传文件目录
* @param string $moduleId 模块ID
* @param array $moduleSubDir 模块子目录
*/
public static function getUploadDir($moduleId, $moduleSubdir = null)
{
$uploadDir = '/' . $moduleId;
if(is_array($moduleSubdir)) {
foreach($moduleSubdir as $dirName) {
$uploadDir .= '/' . $dirName;
}
}
return $uploadDir;
}
/**
* 复制文件夹及子目录文件
* @param string $source
* @param string $destination
*/
public static function xCopy($source, $destination)
{
if(!is_dir($source)) {
return;
}
FileHelper::createDirectory($destination, 0755, true);
$handle = opendir($source);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
$path = $source . DIRECTORY_SEPARATOR . $file;
if (is_dir($path)) {
static::xCopy($path, $destination . DIRECTORY_SEPARATOR . $file);
} else {
copy($path, $destination . DIRECTORY_SEPARATOR . $file);
}
}
closedir($handle);
}
/**
* 压缩文件或文件夹
* @param string $source 文件夹或文件路径
*/
public static function folderToZip($source, &$zipArchive, $exclusiveLength)
{
if (is_dir($source) || is_file($source)) {
$handle = opendir($source);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
$path = $source . DIRECTORY_SEPARATOR . $file;
$localPath = substr($path, $exclusiveLength);
if (is_file($path)) {
$zipArchive->addFile($path, $localPath);
} elseif (is_dir($path)) {
$zipArchive->addEmptyDir($localPath);
static::folderToZip($path, $zipArchive, $exclusiveLength);
}
}
closedir($handle);
}
}
/**
* 压缩文件夹
* @param string $source
*/
public static function zipDir($source)
{
$pathinfo = pathinfo($source);
$basename = $pathinfo['basename'];
$dirname = $pathinfo['dirname'];
$zipArchive = new \ZipArchive();
$zipArchive->open($dirname . DIRECTORY_SEPARATOR . $basename . '.zip', \ZipArchive::CREATE);
$exclusiveLength = strlen($dirname) + 1;
static::folderToZip($source, $zipArchive, $exclusiveLength);
$zipArchive->close();
}
public static function unZip($source)
{
$pathinfo = pathinfo($source);
$dirname = $pathinfo['dirname'];
$zipArchive = new \ZipArchive();
$resource = $zipArchive->open($source);
if ($resource === true) {
$zipArchive->extractTo($dirname);
$zipArchive->close();
}
}
/**
* 生成全球唯一标识uuid
* @param string $source
*/
public function uuid(){
if (function_exists('com_create_guid')) {
return com_create_guid();
} else {
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
class CoinIssueChainRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_PRE_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_chain_record}}';
}
public function rules()
{
return [
[['pre_create_tx', 'pre_send_transaction', 'pre_query_transaction', 'finish_tx', 'finish_send_transaction', 'finish_query_transaction', 'issue_coin_id'], 'required'],
[['issue_coin_id'], 'integer'],
[['finish_tx'], 'safe']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_PRE_CREATE => ['pre_create_tx', 'pre_send_transaction', 'pre_query_transaction', 'finish_tx', 'finish_send_transaction', 'finish_query_transaction', 'issue_coin_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getCoin()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id']);
}
public function getAdvance()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id'])->where(['status' => CoinIssueCoin::STATUS_ADVANCE]);
}
public function getConfirm()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id'])->where(['>', 'status', CoinIssueCoin::STATUS_CONFIRM]);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class CoinIssueCoin extends CommonActiveRecord
{
const UN_PAY = 0;
const ALLOW_PAY = 1;
const SUCCESS_PAY = 2;
const STATUS_ADVANCE = 0; //预发行,待确认
const STATUS_PEDDING = 1; //预发行成功,待用户确认
const STATUS_CANCEL = 2; //用户点击撤消后的状态
const STATUS_CANCEL_SUCCESS = 3; //撤消成功
const STATUS_CANCEL_FAILED = 4; //撤消失败
const STATUS_CONFIRM = 5; //用户点击确认后的状态
const STATUS_ALLOW = 6; //开启人工审核,管理员后台点击通过后的状态 (未开启人工审核,跳过该状态)
const STATUS_REFUSE = 7; //开启人工审核,管理员后台点击拒绝后的状态 (未开启人工审核,跳过该状态)
const STATUS_SUCCESS = 8; //发行成功
const STATUS_FAILED = 9; //(预)发行失败
const TYPE_NO = 0; //不是增发
const TYPE_YES = 1; //是增发
const ISSUE_TOKEN = 'issue_token';
const REVOKE_TOKEN = 'revoke_token';
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
const SCENARIOS_CANCEL = 'cancel';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_coin}}';
}
public function rules()
{
return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'], 'required'],
[['total', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id'], 'integer'],
['introduction', 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [1, 6]],
['name', 'string', 'length' => [1, 20]],
#['status', 'in', 'range' => [1, 2, 0]],
['name', 'verfiyName'],
['symbol', 'verfiySymbol'],
['total', 'verfiyAmount']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'],
self:: SCENARIOS_UPDATE => ['status'],
self:: SCENARIOS_CANCEL => ['status'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function verfiyName($attribute, $params)
{
//增发
if (CoinIssueCoin::TYPE_YES == $this->type) {
$model = CoinIssueCoin::find()->where(['name' => $this->name, 'owner' => $this->owner, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if (false == $model) {
$this->addError($attribute, '该Token币种尚未发行');
return false;
}
if (0 == $model->category) {
$this->addError($attribute, '该Token币种不可增发');
return false;
}
}
//非增发
if (CoinIssueCoin::TYPE_NO == $this->type) {
$model = CoinIssueCoin::find()->where(['name' => $this->name, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if ($model) {
$this->addError($attribute, 'Token名称已存在');
return false;
}
}
}
public function verfiySymbol($attribute, $params)
{
if (!preg_match('/^[A-Z]+$/', $this->symbol)) {
$this->addError($attribute, 'Token简称必须大写');
return false;
}
if (CoinIssueCoin::TYPE_YES == $this->type) {
$model = CoinIssueCoin::find()->where(['symbol' => $this->symbol, 'owner' => $this->owner, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if (false == $model) {
$this->addError($attribute, '该Token币种尚未发行');
return false;
}
if (0 == $model->category) {
$this->addError($attribute, '该Token币种不可增发');
return false;
}
}
if (CoinIssueCoin::TYPE_NO == $this->type) {
$model = CoinIssueCoin::find()->where(['symbol' => $this->symbol, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if ($model) {
$this->addError($attribute, 'Token名称已存在');
return false;
}
}
}
public function verfiyAmount($attribute, $params)
{
if (CoinIssueCoin::TYPE_YES == $this->type) {
if ($this->$attribute > 10) {
$this->addError($attribute, '增发发行量不能超过10亿');
return false;
}
}
$issue_record = CoinIssueCoin::find()->where(['platform_id' => $this->platform_id, 'symbol' => $this->symbol, 'status' => CoinIssueCoin::STATUS_SUCCESS])->sum('total');
$issue_record = empty($issue_record) ? 0 : $issue_record;
if ($issue_record + $this->$attribute > 20) {
$this->addError($attribute, '最大发行量20亿,目前已发行' . $issue_record . '亿');
return false;
}
}
public function attributeLabels()
{
return [
'name' => 'Token全称',
'symbol' => 'Token简称',
'total' => '发行数量',
'owner' => '接收地址',
'introduction' => 'Token简介',
'category' => '是否增发',
'chain_id' => '平行链名称',
'msg' => '失败原因',
'status' => '状态',
'charge_unit_id' => '手续费',
];
}
public function attributes()
{
return array_merge(parent::attributes(), ['issue_charge', 'charge_unit', 'url', 'chain_name']);
}
/**
* 获取状态数组
* @return array
*/
public static function getAgentStatus()
{
return [
self::STATUS_SUCCESS => '发行成功',
self::STATUS_FAIL => '发行失败',
];
}
public function getChain()
{
return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']);
}
public function getPlatform()
{
return $this->hasOne(CoinPlatform::className(), ['id' => 'platform_id']);
}
public function getGas()
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
public function getTransfer()
{
return $this->hasOne(CoinIssueChainRecord::className(), ['issue_coin_id' => 'id']);
}
public function getRevoke()
{
return $this->hasOne(CoinIssueRevokeRecord::className(), ['issue_coin_id' => 'id']);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
class CoinIssueRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_record}}';
}
public function rules()
{
return [
[['platform_id', 'total'], 'required'],
[['total', 'platform_id'], 'integer'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['platform_id', 'total'],
self:: SCENARIOS_UPDATE => ['platform_id', 'total'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
class CoinIssueRevokeRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coins_issue_revoke_record}}';
}
public function rules()
{
return [
[['revoke_tx', 'revoke_send_transaction', 'issue_coin_id'], 'required'],
[['issue_coin_id'], 'integer'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['revoke_tx', 'revoke_send_transaction', 'issue_coin_id', 'revoke_query_transaction'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getCoin()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id']);
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ namespace common\models\psources;
class CoinPlatform extends BaseActiveRecord
{
public static function tableName()
{
return '{{%coin_platform}}';
......@@ -18,8 +19,8 @@ class CoinPlatform extends BaseActiveRecord
/**
* 获取钱包信息列表
*
* @param int $page
* @param int $limit
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
......@@ -30,7 +31,7 @@ class CoinPlatform extends BaseActiveRecord
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
return ['count' => $count, 'data' => $data];
}
......@@ -73,4 +74,19 @@ class CoinPlatform extends BaseActiveRecord
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
public function attributes()
{
return array_merge(parent::attributes(), ['chain_name', 'charge_unit']);
}
public function getChain()
{
return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']);
}
public function getGas()
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
}
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class CoinSupportedCoin extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_supported_coin}}';
}
public function rules()
{
return [
[['platform_id', 'coin_name'], 'required'],
[['platform_id'], 'integer'],
['coin_name', 'string', 'length' => [1, 50]],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['platform_id', 'coin_name'],
self:: SCENARIOS_UPDATE => ['platform_id', 'coin_name'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'platform_id' => '所属钱包',
'coin_name' => '币种名称',
];
}
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
return ['count' => $count, 'data' => $data];
}
public function addOne($params)
{
$params = array_filter($params, function ($value) {
if (null == $value) {
return false;
}
return true;
});
$this->setAttributes($params, false);
try {
return (bool)$this->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use yii\web\Linkable;
use yii\web\Link;
class CommonActiveRecord extends ActiveRecord
{
public $cacheKeyStorage = []; //缓存key寄存器
public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
$data = [];
$cachePrefix = __CLASS__;
$cache = Yii::$app->cache;
foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
if (strpos($field, '.')) {
$fieldChunks = explode('.', $field);
$primaryKey = is_array($this->primaryKey) ? implode('-', $this->primaryKey) : $this->primaryKey;
$uniqueRelationCacheKey = "{$cachePrefix}_{$primaryKey}_{$fieldChunks[0]}";
$this->addCacheKeyToStorage($uniqueRelationCacheKey);
$relation = $cache->get($uniqueRelationCacheKey);
if (!$relation) {
$relation = $this->{$fieldChunks[0]};
$cache->set($uniqueRelationCacheKey, $relation);
}
if (is_array($relation)) {
foreach ($relation as $relatedField => $relatedObject) {
if (!is_object($relatedObject)) {
continue;
}
$data[$fieldChunks[0]][$relatedField][$fieldChunks[1]] = $this->getRelationField($relatedObject, $fieldChunks[1]);
}
} else {
if (!is_object($relation)) {
continue;
}
$data[$fieldChunks[0]][$fieldChunks[1]] = $this->getRelationField($relation, $fieldChunks[1]);
}
} else {
$data[$field] = is_string($definition) ? $this->$definition : call_user_func($definition, $this, $field);
}
}
$this->deleteStorageCaches();
if ($this instanceof Linkable) {
$data['_links'] = Link::serialize($this->getLinks());
}
return $recursive ? ArrayHelper::toArray($data) : $data;
}
/**
* This method also will check relations which are declared in [[extraFields()]]
* to determine which related fields can be returned.
* @inheritdoc
*/
protected function resolveFields(array $fields, array $expand)
{
$result = [];
foreach ($this->fields() as $field => $definition) {
if (is_integer($field)) {
$field = $definition;
}
if (empty($fields) || in_array($field, $fields, true)) {
$result[$field] = $definition;
}
}
if (empty($expand)) {
return $result;
}
$extraFieldsKeys = array_keys($this->extraFields());
foreach($expand as $expandedAttribute) {
if(in_array(explode('.',$expandedAttribute)[0], $this->extraFields())) {
$result[$expandedAttribute] = $expandedAttribute;
}else if(in_array($expandedAttribute, $extraFieldsKeys)) {
$result[$expandedAttribute] = $this->extraFields()[$expandedAttribute];
}
}
return $result;
}
/**
* Additional method to check the related model has specified field
*/
private function getRelationField($relatedRecord, $field)
{
if (!$relatedRecord->hasAttribute($field) && !$relatedRecord->isRelationPopulated($field)) {
throw new \yii\web\ServerErrorHttpException(sprintf(
"Related record '%s' does not have attribute '%s'",
get_class($relatedRecord), $field)
);
}
if($relatedRecord->hasAttribute($field)) {
return ArrayHelper::toArray($relatedRecord)[$field];
} else {
return $relatedRecord->{$field};
}
}
public static function quoteDbName($dbname)
{
return '`' . $dbname . '`';
}
/**
* 添加cache key到寄存器
* @param type $cacheKey
*/
public function addCacheKeyToStorage($cacheKey)
{
if(!in_array($cacheKey, $this->cacheKeyStorage)) {
$this->cacheKeyStorage[] = $cacheKey;
}
}
/**
* 删除寄存器里所有的cache
*/
public function deleteStorageCaches()
{
foreach($this->cacheKeyStorage as $cacheKey) {
Yii::$app->cache->delete($cacheKey);
}
}
}
\ No newline at end of file
......@@ -246,6 +246,16 @@ class Chain33Service
return $this->send($params, 'Chain33.QueryTransaction');
}
public function query()
{
$params = [
"execer" => 'manage',
"funcName" => "GetConfigItem",
"payload" => ['data' => 'token-finisher']
];
return $this->send($params, 'Chain33.Query');
}
public function getBalance($address, $execer)
{
$params = [
......@@ -298,6 +308,29 @@ class Chain33Service
return $this->send($params, 'Chain33.SignRawTx');
}
public function createRawTokenPreCreateTx($params)
{
return $this->send($params, 'token.CreateRawTokenPreCreateTx');
}
public function createRawTokenFinishTx($symbol, $owner)
{
$params = [
'symbol' => $symbol,
'owner' => $owner
];
return $this->send($params, 'token.CreateRawTokenFinishTx');
}
public function createRawTokenRevokeTx($symbol, $owner)
{
$params = [
'symbol' => $symbol,
'owner' => $owner
];
return $this->send($params, 'token.CreateRawTokenRevokeTx');
}
public function getBlock2MainInfo($start, $end)
{
$params = [
......
......@@ -207,36 +207,5 @@ class CrossChainController extends Controller
$this->queryTransaction($node_params, $result['result']['tx']['next']);
}
return $result;
// if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// }
//
// if (isset($result['result']['receipt']['ty']) && 2 == $result['result']['receipt']['ty']){
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// }
//
// return $result;
// if (isset($result['result']['receipt']) && is_array($result['result']['receipt']['logs'])){
// foreach ($result['result']['receipt']['logs'] as $log) {
// if (isset($log['tyName']) && 'logerr' == strtolower($log['tyName'])){
// return $result;
// }
// }
// }
// static $result = [];
// $service = new Chain33Service($node_params);
// $result = $service->QueryTransaction($send_result);
// echo json_encode($result) . PHP_EOL;
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// return $result;
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -22,6 +22,8 @@ class TickerController extends Controller
$ticker_builder->TickerSort();
});
}
echo date('Y-m-d H:i:s') .'排序更新成功' . PHP_EOL;
return 0;
}
public function actionHot()
......
<?php
namespace wallet\controllers;
use common\models\psources\CoinPlatform;
use common\models\psources\CoinSupportedCoin;
use Yii;
use wallet\base\BaseController;
class IssueChainController extends BaseController
{
/**
* 可发行链列表
* @return array
*/
public function actionIndex()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (1 == $platform_id) {
$chain_model = CoinPlatform::find()->all();
} else {
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->all();
}
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
unset($val->download_url);
unset($val->introduce);
unset($val->create_time);
unset($val->update_time);
unset($val->chain_id);
}
$msg = 'ok';
$code = 0;
$data = $chain_model;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 发行链信息
* @return array
*/
public function actionChainInfo()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (empty($platform_id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (1 == $platform_id) {
$chain_model = CoinPlatform::find()->select('id, chain_id')->all();
} else {
$chain_model = CoinPlatform::find()->select('id, chain_id')->where(['id' => $platform_id])->all();
}
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
$coin_supported_coin = CoinSupportedCoin::find()->select('id, coin_name')->where(['platform_id' => $val->id])->asArray()->all();
$val->charge_unit = $coin_supported_coin;
}
$msg = 'ok';
$code = 0;
$data = is_array($chain_model) ? $chain_model : [$chain_model];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 设置手续费
* @param integer issue_charge
* @param integer charge_unit_id
* @param integer platform_id
* @return array
*/
public function actionSetCharge()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$result = Yii::$app->request->post();
$issue_charge = isset($result['issue_charge']) ? $result['issue_charge'] : '';
$charge_unit_id = isset($result['charge_unit_id']) ? strtoupper($result['charge_unit_id']) : '';
$id = isset($result['platform_id']) ? (int)$result['platform_id'] : 0;
if (false == $issue_charge || false == $charge_unit_id) {
$msg = '提交数据有误';
$code = -1;
goto doEnd;
}
if (1 == $platform_id) {
$platform_id = $id;
}
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->one();
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
$chain_model->issue_charge = $issue_charge;
$chain_model->charge_unit_id = $charge_unit_id;
if (false == $chain_model->save()) {
$msg = '手续费设置失败';
$code = -1;
goto doEnd;
}
$msg = 'ok';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg];
}
/**
* 人工审核开启/关闭
* @param string manual_review
* @return array
*/
public function actionManageReview()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (1 != $platform_id) {
$msg = '当前账户无权限操作';
$code = -1;
goto doEnd;
}
$manual_review = \Yii::$app->request->post('manual_review', '');
if (!in_array($manual_review, ['open', 'close'])) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
Yii::$app->redis->set('issue_chain_manual_review', $manual_review);
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use common\models\psources\CoinIssueChainRecord;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\CoinIssueCoin;
class IssueCoinController extends BaseController
{
/**
* 申请列表
* @param integer page
* @param integer size
* @param integer status
* @param string owner
* @param integer chain_id
* @return array
*/
public function actionApplyList()
{
$platform_id = Yii::$app->request->getPlatformId();
$page = \Yii::$app->request->get('page', 1);
$size = \Yii::$app->request->get('size', 10);
$status = \Yii::$app->request->get('status', -1);
$owner = \Yii::$app->request->get('owner', '');
$chain_id = \Yii::$app->request->get('chain_id', '');
if (1 == $platform_id) {
$query = CoinIssueCoin::find()
->select('id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time')
->where(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]])
->orderBy('create_time desc');
} else {
$query = CoinIssueCoin::find()
->select('id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time')
->where(['platform_id' => $platform_id])
->andWhere(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]])
->orderBy('create_time desc');
}
if ($status > -1) {
$query->andWhere(['status' => $status]);
}
if (false != $owner) {
$query->andWhere(['owner' => $owner]);
}
if (false != $chain_id) {
$query->andWhere(['chain_id' => $chain_id]);
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
foreach ($models as &$val) {
$platform = isset($val->chain->platform) ? $val->chain->platform : '';
$val->chain_name = $platform;
$val->charge_unit = isset($val->gas->coin_name) ? $val->gas->coin_name : '';
$val->url = Yii::$app->redis->hget('platform_brower_info', $platform);
$val->total = (int)$val->total * 1e8;
}
$data = [
'list' => $models,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => (int)$page,
]
];
$msg = 'ok';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 申请详情
* @param integer id
* @return array
*/
public function actionApplyDetail()
{
$id = Yii::$app->request->get('id', '');
$data = null;
if (empty($id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
$data = CoinIssueCoin::find()->where(['id' => $id])->one();
$platform = isset($data->chain->platform) ? $data->chain->platform : '';
$data->total = (int)$data->total * 1e8;
$data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0');
$data->charge_unit = isset($data->gas->coin_name) ? $data->gas->coin_name : '';
$data->url = Yii::$app->redis->hget('platform_brower_info', $platform);
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 申请操作管理
* @param integer id
* @param integer status
* @param string msg
* @return array
*/
public function actionVerify()
{
$id = Yii::$app->request->post('id', '');
$status = Yii::$app->request->post('status', '');
$msg = Yii::$app->request->post('msg', '');
if (false == $id || false == $status) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (!in_array($status, [CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE])) {
$msg = '状态值错误';
$code = -1;
goto doEnd;
}
$model = CoinIssueCoin::findOne($id);
if (false == $model) {
$msg = '不存在的记录';
$code = -1;
goto doEnd;
}
$data = [
'status' => $status,
#'msg' => $msg
];
$model->setScenario(CoinIssueCoin::SCENARIOS_UPDATE);
$model->load($data, '');
if (!$model->save()) {
$msg = current($model->firstErrors);
$code = -1;
goto doEnd;
}
$record = CoinIssueChainRecord::find()->where(['issue_coin_id' => $id])->one();
$record->finish_tx = 'failed';
$record->finish_send_transaction = 'failed';
$record->finish_query_transaction = $msg;
$record->save();
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
}
\ No newline at end of file
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