Commit fc15d2de authored by rlgy's avatar rlgy

update

parent 7f2e58c0
<?php <?php
/** /**
* Created By Sublime Text 3 * Created By Sublime Text 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com> * @author rlgyzhcn <rlgyzhcn@qq.com>
*/ */
namespace backend\controllers; namespace backend\controllers;
use common\business\Chain33Business;
use Yii; use Yii;
use backend\models\coin\CoinPublishForm; use backend\models\coin\CoinPublishForm;
use common\models\psources\CoinPublish; use common\models\psources\CoinPublish;
...@@ -17,16 +19,23 @@ class CoinPublishController extends BaseController ...@@ -17,16 +19,23 @@ class CoinPublishController extends BaseController
{ {
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
$get = Yii::$app->request->get(); $get = Yii::$app->request->get();
$page = $get['page'] ?? 1; $page = $get['page'] ?? 1;
$limit = $get['limit'] ?? 10; $limit = $get['limit'] ?? 10;
$auth = Yii::$app->authManager; $auth = Yii::$app->authManager;
$role_self = current($auth->getRolesByUser(Yii::$app->user->id)); $role_self = current($auth->getRolesByUser(Yii::$app->user->id));
$child_roles = $auth->getChildRoles($role_self->name); $child_roles = $auth->getChildRoles($role_self->name);
$userful_roles = array_keys($child_roles); $userful_roles = array_keys($child_roles);
// var_dump($userful_roles);die(); $condition[] = ['in', 'owner', $userful_roles];
$condition[] = ['in', 'owner', $userful_roles]; $data = CoinPublish::getList($page, $limit, $condition);
$data = CoinPublish::getList($page, $limit, $condition); //获取热钱包数量
if ($data['code'] == 0 && !empty($data['data'])) {
$list = &$data['data'];
$amount = Chain33Business::getMulAccountTokenAssets($list);
foreach ($list as $k => &$v) {
$v['amount'] = $amount[$v['id']];
}
}
return $data; return $data;
} }
return $this->render('list'); return $this->render('list');
...@@ -36,21 +45,21 @@ class CoinPublishController extends BaseController ...@@ -36,21 +45,21 @@ class CoinPublishController extends BaseController
{ {
if (Yii::$app->request->isGet) { if (Yii::$app->request->isGet) {
$this->layout = false; $this->layout = false;
$id = Yii::$app->request->get('id', null); $id = Yii::$app->request->get('id', null);
if ($id) { if ($id) {
$model = CoinPublish::findOne($id); $model = CoinPublish::findOne($id);
} else { } else {
$model = new CoinPublishForm(); $model = new CoinPublishForm();
} }
$auth = Yii::$app->authManager; $auth = Yii::$app->authManager;
$role = current($auth->getRolesByUser(Yii::$app->user->id)); $role = current($auth->getRolesByUser(Yii::$app->user->id));
$childRoles = array_keys($auth->getChildRoles($role->name)); $childRoles = array_keys($auth->getChildRoles($role->name));
// $coins = Coin::getAllByPlatformId(Yii::$app->user->identity->platform_id, 0, 999); // $coins = Coin::getAllByPlatformId(Yii::$app->user->identity->platform_id, 0, 999);
return $this->render('form', ['model' => $model, 'roles' => $childRoles]); return $this->render('form', ['model' => $model, 'roles' => $childRoles]);
} elseif (Yii::$app->request->isPost) { } elseif (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
$post = Yii::$app->request->post(); $post = Yii::$app->request->post();
$model = new CoinPublishForm(); $model = new CoinPublishForm();
if (isset($post['id']) && !empty($post['id'])) { if (isset($post['id']) && !empty($post['id'])) {
$model->scenario = CoinPublishForm::SCENARIOS_UPDATE; $model->scenario = CoinPublishForm::SCENARIOS_UPDATE;
} else { } else {
...@@ -65,9 +74,9 @@ class CoinPublishController extends BaseController ...@@ -65,9 +74,9 @@ class CoinPublishController extends BaseController
$CoinPublish->company_name = $model->company_name; $CoinPublish->company_name = $model->company_name;
$CoinPublish->coin_name_zh = $model->coin_name_zh; $CoinPublish->coin_name_zh = $model->coin_name_zh;
$CoinPublish->coin_name_en = $model->coin_name_en; $CoinPublish->coin_name_en = $model->coin_name_en;
$CoinPublish->address = $model->address; $CoinPublish->address = $model->address;
$CoinPublish->owner = $model->owner; $CoinPublish->owner = $model->owner;
$CoinPublish->platform_id = Yii::$app->user->identity->platform_id; $CoinPublish->platform_id = Yii::$app->user->identity->platform_id;
if ($CoinPublish->save(false)) { if ($CoinPublish->save(false)) {
return ['code' => 0, 'msg' => 'succeed', 'data' => '']; return ['code' => 0, 'msg' => 'succeed', 'data' => ''];
} else { } else {
...@@ -82,7 +91,7 @@ class CoinPublishController extends BaseController ...@@ -82,7 +91,7 @@ class CoinPublishController extends BaseController
public function actionDel() public function actionDel()
{ {
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', null); $id = Yii::$app->request->get('id', null);
if ($id) { if ($id) {
$model = CoinPublish::findOne(['id' => $id]); $model = CoinPublish::findOne(['id' => $id]);
if ($model->delete()) { if ($model->delete()) {
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
namespace backend\controllers; namespace backend\controllers;
use Yii;
use backend\jobs\FreezeJob; use backend\jobs\FreezeJob;
use common\models\psources\CoinPublish; use common\models\psources\CoinPublish;
use common\models\psources\CoinPublishRule; use common\models\psources\CoinPublishRule;
use common\models\psources\CoinReleaseMember; use common\models\psources\CoinReleaseMember;
use Yii; use common\business\Chain33Business;
class CoinPublishRuleController extends BaseController class CoinPublishRuleController extends BaseController
{ {
...@@ -78,11 +79,20 @@ class CoinPublishRuleController extends BaseController ...@@ -78,11 +79,20 @@ class CoinPublishRuleController extends BaseController
$data['data'] = $models; $data['data'] = $models;
return $data; return $data;
} }
$coin = CoinPublish::findOne($pid);
$coin = CoinPublish::findOne($pid);
$amount = Chain33Business::getAccountTokenAssets($coin->address, $coin->coin_name_en);
// var_dump($amount);die();
if ($amount['code'] == 0) {
$amount = $amount['amount'];
} else {
$amount = 'error';
}
//获取热钱包数量
return $this->render('list', return $this->render('list',
[ [
'coin_name' => $coin->coin_name_en ?? '', 'coin_name' => $coin->coin_name_en ?? '',
'amount' => 100090000, 'amount' => $amount,
'release_amount' => CoinPublishRule::getReleaseAmountThisMonthById($pid), 'release_amount' => CoinPublishRule::getReleaseAmountThisMonthById($pid),
'address' => $coin->address ?? '', 'address' => $coin->address ?? '',
]); ]);
...@@ -106,12 +116,12 @@ class CoinPublishRuleController extends BaseController ...@@ -106,12 +116,12 @@ class CoinPublishRuleController extends BaseController
// 编号 // 编号
$prefix = date('Ymd', time()); $prefix = date('Ymd', time());
$form_database = CoinPublishRule::find() $form_database = CoinPublishRule::find()
->where(['like', 'sid', $prefix]) ->where(['like', 'sid', $prefix])
->orderBy(['sid' => SORT_DESC]) ->orderBy(['sid' => SORT_DESC])
->asArray() ->asArray()
->One(); ->One();
if ($form_database) { if ($form_database) {
$sid = (int) $form_database['sid'] + 1; $sid = (int)$form_database['sid'] + 1;
} else { } else {
$sid = $prefix . '001'; $sid = $prefix . '001';
} }
...@@ -120,11 +130,11 @@ class CoinPublishRuleController extends BaseController ...@@ -120,11 +130,11 @@ class CoinPublishRuleController extends BaseController
} }
if ($model->load($post) && $model->validate()) { if ($model->load($post) && $model->validate()) {
if (CoinPublishRule::SCENARIOS_ADD == $model->scenario) { if (CoinPublishRule::SCENARIOS_ADD == $model->scenario) {
$model->sid = (string) $sid; $model->sid = (string)$sid;
} }
$model->release_time = date_create_from_format(self::DATE_FORMAT[$model->repeat], $model->release_time = date_create_from_format(self::DATE_FORMAT[$model->repeat],
$model->release_time)->format('Y-m-d H:i:s'); $model->release_time)->format('Y-m-d H:i:s');
$model->pid = $this->getPid(); $model->pid = $this->getPid();
if ($model->save()) { if ($model->save()) {
if ($model->qid) { if ($model->qid) {
//删除原有的任务 //删除原有的任务
...@@ -176,6 +186,7 @@ class CoinPublishRuleController extends BaseController ...@@ -176,6 +186,7 @@ class CoinPublishRuleController extends BaseController
/** /**
* 获取id * 获取id
*
* @return int * @return int
*/ */
private function getPid() private function getPid()
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-18
* Time: 下午2:50
*/
namespace backend\jobs;
use Yii;
use yii\queue\JobInterface;
use yii\queue\Queue;
use yii\base\BaseObject;
use common\models\psources\CoinReleaseCheck;
use common\models\psources\CoinReleaseMember;
use common\models\psources\CoinPublishRule;
use common\models\psources\CoinPublish;
use common\business\Chain33Business;
/**
* Class ExtractTokenJob
* 提币任务
*
* @package backend\jobs
*/
class ExtractTokenJob extends BaseObject implements JobInterface
{
/**
* 提币申请id
*
* @var int $cid
*/
public $cid = 0;
/**
* @param Queue $queue which pushed and is handling the job
* @return integer
*/
public function execute($queue)
{
//获取申请
$apply = CoinReleaseCheck::findOne($this->cid);
if ($apply) {
$assets = CoinReleaseMember::findOne($apply->uid);
if ($assets) {
$release = $assets->release;
if ($release >= $apply->amount) {
//提币
$amount = $apply->amount / 1e8;
//获取提币地址
$from = '';
$coin_publish_rule = CoinPublishRule::findOne($assets->rule_id);
if ($coin_publish_rule) {
$coin_publish = CoinPublish::findOne($coin_publish_rule->pid);
if ($coin_publish) {
$from = $coin_publish->address;
}
}
if (!empty($from)) {
$result = Chain33Business::extractToken($from, $apply->to_address, $amount, '', true,
$apply->coin);
if ($result['code'] == 0) {
$assets->release -= $amount;
$assets->output += $amount;
if ($assets->save()) {
//提币成功
$apply->status = CoinReleaseCheck::STATUS_PADDING;//提币中
if ($apply->save()) {
Yii::info("提币成功: [申请id]: $this->cid", __CLASS__);
}
Yii::warning("提币申请状态修改失败: [申请id]: $this->cid", __CLASS__);
} else {
Yii::warning("减少用户资产失败: [申请id]: $this->cid, [资产]: $amount", __CLASS__);
}
} else {
var_dump($result);
Yii::info("提币失败: {$result['msg']}! [申请id]: $this->cid", __CLASS__);
}
} else {
Yii::info("提币失败: 提币地址不存在! [申请id]: $this->cid", __CLASS__);
}
} else {
Yii::info("提币失败: 用户资产不足! [申请id]: $this->cid", __CLASS__);
}
} else {
Yii::info("提币失败: 用户资产信息不存在! [申请id]: $this->cid", __CLASS__);
}
} else {
Yii::info("提币失败: 提币申请不存在! [申请id]: $this->cid", __CLASS__);
}
return 0;
}
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use backend\assets\coinPublishRule\ListAsset; use backend\assets\coinPublishRule\ListAsset;
ListAsset::register($this); ListAsset::register($this);
?> ?>
...@@ -21,7 +22,7 @@ ListAsset::register($this); ...@@ -21,7 +22,7 @@ ListAsset::register($this);
<tbody> <tbody>
<tr> <tr>
<td><?= $coin_name ?></td> <td><?= $coin_name ?></td>
<td><?= $amount ?></td> <td><?= $amount / 1e8 ?></td>
<td><?= $release_amount ?></td> <td><?= $release_amount ?></td>
<td><?= $address ?></td> <td><?= $address ?></td>
</tr> </tr>
......
var table = layui.table; var table = layui.table;
table.render({ table.render({
elem: "#table1", elem: "#table1",
url: '/admin/coin-publish/list', url: '/admin/coin-publish/list',
limit: 10, limit: 10,
page: 1, page: 1,
loading: true, loading: true,
cols: [[ cols: [[
{field: 'id', title: 'ID'}, {field: 'id', title: 'ID'},
{field: 'company_name', title: '公司名称'}, {field: 'company_name', title: '公司名称'},
{field: 'coin_name_zh', title: '币种中文名'}, {field: 'coin_name_zh', title: '币种中文名'},
{field: 'coin_name_en', title: '币种英文名'}, {field: 'coin_name_en', title: '币种英文名'},
{field: 'address', title: '热钱包地址'}, {field: 'address', title: '热钱包地址'},
{field: 'amount', title: '热钱包数量'}, {
{toolbar: '#toolbar', title: '操作'} field: 'amount', title: '热钱包数量', templet: function (d) {
]], return d.amount / 1e8;
}
},
{toolbar: '#toolbar', title: '操作'}
]],
}); });
table.on('tool(table1)', function(obj){ table.on('tool(table1)', function (obj) {
var event = obj.event; var event = obj.event;
var data = obj.data; var data = obj.data;
if ('update' == event) { if ('update' == event) {
$.get('/admin/coin-publish/add', {id: data.id}, function (str) { $.get('/admin/coin-publish/add', {id: data.id}, function (str) {
var index = layer.open({ var index = layer.open({
type: 1, type: 1,
title: '编辑', title: '编辑',
id: 'add-one', id: 'add-one',
skin: 'layui-layer-lan', skin: 'layui-layer-lan',
area: ['320px', 'auto'], area: ['320px', 'auto'],
content: str, content: str,
btn: ['确认', '取消'], btn: ['确认', '取消'],
btn1: function () { btn1: function () {
var company_name = $('#addData input[name="company_name"]').val(); var company_name = $('#addData input[name="company_name"]').val();
var coin_name_zh = $('#addData input[name="coin_name_zh"]').val(); var coin_name_zh = $('#addData input[name="coin_name_zh"]').val();
var coin_name_en = $('#addData input[name="coin_name_en"]').val(); var coin_name_en = $('#addData input[name="coin_name_en"]').val();
if (company_name !== "" && company_name !== "" && coin_name_en !== "") { if (company_name !== "" && company_name !== "" && coin_name_en !== "") {
$btn = $('.layui-layer-btn0').button('loading'); $.post('/admin/coin-publish/add', $("#addData").serialize(), function (rev) {
$.post('/admin/coin-publish/add', $("#addData").serialize(), function (rev) { layer.msg(rev.msg);
layer.msg(rev.msg); if (rev.code == 0) {
if (rev.code == 0) { layer.close(index);
layer.close(index); table.reload("table1", {});
table.reload("table1", {}); }
} });
}); } else {
$btn.button('reset'); layer.msg("请输入完整!");
} else { }
layer.msg("请输入完整!"); return false;
} }
return false; });
} layui.form.render();
}); });
layui.form.render(); } else if ('del' == event) {
}); layer.confirm('确定删除此币种监控吗?', {title: '删除币种'}, function (index) {
}else if('del' == event){ $.get('/admin/coin-publish/del', {id: data.id}, function (rev) {
layer.confirm('确定删除此币种监控吗?', {title: '删除币种'}, function(index){ if (rev.code == 0) {
$.get('/admin/coin-publish/del', {id: data.id}, function(rev) {
if (rev.code == 0) {
obj.del(); obj.del();
layer.close(index); layer.close(index);
} }
}); });
}); });
} }
}); });
$('#add').click(function () { $('#add').click(function () {
//打开弹窗 //打开弹窗
......
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-18 10:21:53
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace common\business;
use common\service\chain33\Chain33Service;
/**
* chain33 区块链接口
*/
class Chain33Business
{
/**
* 查询地址下的token合约下的token资产
*
* @param string $token
* @param string $address
* @return array
*/
public static function getAccountTokenAssets($address, $token)
{
$service = new Chain33Service();
$result = $service->getAccountTokenAssets($address, $token);
if ($result['code'] == 0) {
$result = $result['result'];
if (isset($result['tokenAssets'])) {
$tokenAssets = $result['tokenAssets'];
$tokenAssets = array_column($tokenAssets, null, 'symbol');
if (isset($tokenAssets[$token])) {
return ['code' => 0, 'amount' => $tokenAssets[$token]['account']['balance']];
}
return ['code' => -1, 'msg' => "$token 不存在"];
}
return ['code' => -1, 'msg' => '资产信息不存在'];
}
return $result;
}
/**
* 批量获取token资产
*
* @param array $list
* @return array
*/
public static function getMulAccountTokenAssets($list)
{
foreach ($list as $k => &$v) {
$temp = self::getAccountTokenAssets($v['address'], $v['coin_name_en']);
if ($temp['code'] == 0) {
$v['amount'] = $temp['amount'];
} else {
$v['amount'] = 0;
}
}
return array_column($list, 'amount', 'id');
}
/**
* 提币接口
*
* @param $from
* @param $to
* @param $amount
* @param string $note
* @param bool $isToken
* @param string $tokenSymbol
* @return array|string
*/
public static function extractToken($from, $to, $amount, $note = "", $isToken = true, $tokenSymbol = "")
{
$service = new Chain33Service();
$result = $service->extractToken($from, $to, $amount, $note, $isToken, $tokenSymbol);
if ($result['code'] == 0) {
return $result['result']['hash'];
}
return ['code' => -1, 'msg' => $result['msg']];
}
/**
* 转账接口
*
* @param $from
* @param $to
* @param $amount
* @param string $note
* @param bool $isToken
* @param string $tokenSymbol
* @return array|string
*/
public static function transToken($from, $to, $amount, $note = "", $isToken = true, $tokenSymbol = "")
{
$service = new Chain33Service();
$result = $service->extractToken($from, $to, $amount, $note, $isToken, $tokenSymbol);
if ($result['code'] == 0) {
return $result['result']['hash'];
}
return ['code' => -1, 'msg' => $result['msg']];
}
}
...@@ -7,4 +7,9 @@ ...@@ -7,4 +7,9 @@
*/ */
return [ return [
]; 'chain33' => [
\ No newline at end of file 'scheme' => 'http',
'host' => '114.55.101.159',
'port' => 8801,
],
];
<?php <?php
$chain_url = "121.196.205.182:45656";
return [ return [
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
'supportEmail' => 'support@example.com', 'supportEmail' => 'support@example.com',
...@@ -47,6 +45,6 @@ return [ ...@@ -47,6 +45,6 @@ return [
'http_proxy' => [ 'http_proxy' => [
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => '8118', 'port' => '8118',
'use' => true 'use' => true
] ]
]; ];
...@@ -14,16 +14,17 @@ use Yii; ...@@ -14,16 +14,17 @@ use Yii;
/** /**
* @property integer $id * @property integer $id
* @property integer $uid * @property integer $uid
* @property string $mobile * @property string $mobile
* @property string $coin * @property string $coin
* @property string $to_address * @property double $amount
* @property string $to_address
* @property integer $check_first_status * @property integer $check_first_status
* @property integer $check_first_uid * @property integer $check_first_uid
* @property integer $check_second_status * @property integer $check_second_status
* @property integer $check_second_uid * @property integer $check_second_uid
* @property integer $status * @property integer $status
* @property srting $create_time * @property string $create_time
* @property srting $update_time * @property string $update_time
*/ */
class CoinReleaseCheck extends BaseActiveRecord class CoinReleaseCheck extends BaseActiveRecord
{ {
...@@ -86,18 +87,46 @@ class CoinReleaseCheck extends BaseActiveRecord ...@@ -86,18 +87,46 @@ class CoinReleaseCheck extends BaseActiveRecord
{ {
return [ return [
self::SCENARIOS_CHECK => ['coin', 'start_time', 'end_time', 'mobile'], self::SCENARIOS_CHECK => ['coin', 'start_time', 'end_time', 'mobile'],
self::SCENARIOS_SEARCH => ['status', 'coin', 'check_first_uid', 'check_second_uid', 'start_time', 'end_time', 'mobile'], self::SCENARIOS_SEARCH => [
'status',
'coin',
'check_first_uid',
'check_second_uid',
'start_time',
'end_time',
'mobile'
],
]; ];
} }
public function rules() public function rules()
{ {
return [ return [
[['id', 'uid', 'check_first_status', 'check_first_uid', 'check_second_status', 'check_second_uid', 'status'], 'integer'], [
[['mobile', 'coin', 'to_address', 'create_time', 'update_time', 'start_time', 'end_time'], 'string', 'max' => 255], [
'id',
'uid',
'check_first_status',
'check_first_uid',
'check_second_status',
'check_second_uid',
'status'
],
'integer'
],
[
['mobile', 'coin', 'to_address', 'create_time', 'update_time', 'start_time', 'end_time'],
'string',
'max' => 255
],
[['end_time'], 'compare', 'compareAttribute' => 'start_time', 'operator' => '>=', 'skipOnEmpty' => true], [['end_time'], 'compare', 'compareAttribute' => 'start_time', 'operator' => '>=', 'skipOnEmpty' => true],
[['coin', 'start_time', 'end_time', 'mobile'], 'default', 'value' => '', 'on' => self::SCENARIOS_CHECK], [['coin', 'start_time', 'end_time', 'mobile'], 'default', 'value' => '', 'on' => self::SCENARIOS_CHECK],
[['status', 'coin', 'check_first_uid', 'check_second_uid', 'start_time', 'end_time', 'mobile'], 'default', 'value' => '', 'on' => self::SCENARIOS_SEARCH], [
['status', 'coin', 'check_first_uid', 'check_second_uid', 'start_time', 'end_time', 'mobile'],
'default',
'value' => '',
'on' => self::SCENARIOS_SEARCH
],
]; ];
} }
} }
...@@ -12,15 +12,17 @@ use Yii; ...@@ -12,15 +12,17 @@ use Yii;
/** /**
* CoinReleaseMember * CoinReleaseMember
* @property int $id *
* @property int $rule_id * @property int $id
* @property int $user_id * @property int $rule_id
* @property int $amount 币种总数 * @property int $user_id
* @property int $release 币种释放总数 * @property int $amount 币种总数
* @property int $freeze 币种冻结总数 * @property int $release 币种释放总数
* @property int $platform_id 平台id * @property int $freeze 币种冻结总数
* @property string $mobile 手机号码 * @property int $output 币种提取总数
* @property string $coin 币种 * @property int $platform_id 平台id
* @property string $mobile 手机号码
* @property string $coin 币种
*/ */
class CoinReleaseMember extends BaseActiveRecord class CoinReleaseMember extends BaseActiveRecord
{ {
...@@ -76,9 +78,10 @@ class CoinReleaseMember extends BaseActiveRecord ...@@ -76,9 +78,10 @@ class CoinReleaseMember extends BaseActiveRecord
/** /**
* 导入数据 * 导入数据
* @param int $datas[0] mobile *
* @param string $datas[1] coin * @param int $datas [0] mobile
* @param int $datas[2] amount * @param string $datas [1] coin
* @param int $datas [2] amount
* @return boolean * @return boolean
*/ */
public static function implode(array $datas) public static function implode(array $datas)
...@@ -88,9 +91,10 @@ class CoinReleaseMember extends BaseActiveRecord ...@@ -88,9 +91,10 @@ class CoinReleaseMember extends BaseActiveRecord
} }
try { try {
$result = self::getDb() $result = self::getDb()
->createCommand() ->createCommand()
->batchInsert(self::tableName(), ['rule_id', 'mobile', 'coin', 'amount', 'release', 'freeze'], $datas) ->batchInsert(self::tableName(), ['rule_id', 'mobile', 'coin', 'amount', 'release', 'freeze'],
->execute(); $datas)
->execute();
return $result; return $result;
} catch (\Exception $e) { } catch (\Exception $e) {
} }
...@@ -100,7 +104,7 @@ class CoinReleaseMember extends BaseActiveRecord ...@@ -100,7 +104,7 @@ class CoinReleaseMember extends BaseActiveRecord
/** /**
* 批量获取锁仓规则下的人数 * 批量获取锁仓规则下的人数
* *
* @param array $ids 规则id * @param array $ids 规则id
* @return array|boolean 返回id为键,数量为值的数组 * @return array|boolean 返回id为键,数量为值的数组
*/ */
public static function getCountByRuleIds($ids) public static function getCountByRuleIds($ids)
...@@ -109,7 +113,7 @@ class CoinReleaseMember extends BaseActiveRecord ...@@ -109,7 +113,7 @@ class CoinReleaseMember extends BaseActiveRecord
$ids = [$ids]; $ids = [$ids];
} }
$query = CoinReleaseMember::find()->select(['rule_id', 'COUNT(id) as count']) $query = CoinReleaseMember::find()->select(['rule_id', 'COUNT(id) as count'])
->groupBy('rule_id')->where(['in', 'rule_id', $ids]); ->groupBy('rule_id')->where(['in', 'rule_id', $ids]);
// return $query->createCommand()->getRawSql(); // return $query->createCommand()->getRawSql();
$datas = $query->asArray()->all(); $datas = $query->asArray()->all();
return array_column($datas, 'count', 'rule_id'); return array_column($datas, 'count', 'rule_id');
......
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-18 10:28:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace common\service\chain33;
use Yii;
use common\helpers\Curl;
/**
* chain33 区块链接口
*/
class Chain33Service
{
public static function urlBuild()
{
$config = Yii::$app->params['chain33'];
$scheme = $config['scheme'] ?? 'http';
$host = $config['host'] ?? '127.0.0.1';
$port = (string)$config['port'] ?? '';
if ($port) {
return $scheme . '://' . $host . ':' . $port;
} else {
return $scheme . '://' . $host;
}
}
public static function jsonRpcBuild($params = [], $method = 'Chain33.Query')
{
$data = [
'jsonrpc' => '2.0',
'id' => 0,
'method' => $method,
'params' => [$params],
];
return json_encode($data);
}
public function send($params = [], $method = 'Chain33.Query')
{
$ch = new Curl();
$jsonrpc = self::jsonRpcBuild($params, $method);
echo $jsonrpc;
$ch->setHeader('Content-Type', 'application/json');
$ch->setRawPostData($jsonrpc);
$result = $ch->post(self::urlBuild(), false);
if (!$result) {
return ['code' => -1, 'msg' => '请求失败'];
}
if (0 == $result['id'] && empty($result['error'])) {
$result['code'] = $result['id'];
unset($result['id']);
return $result;
} else {
return ['code' => -1, 'msg' => $result['error']];
}
}
/**
* 获取地址下的所有token资产
*
* @param string $address
* @param string $symbol
* @return array
*/
public function getAccountTokenAssets($address, $symbol)
{
$params = [
"execer" => "token",
"funcName" => "GetAccountTokenAssets",
"payload" => [
"address" => $address,
"execer" => "token",
],
];
return $this->send($params);
}
/**
* 提币
*
* @param $from
* @param $to
* @param $amount
* @param string $note
* @param bool $isToken
* @param string $tokenSymbol
* @return array
*/
public function extractToken($from, $to, $amount, $note = '', $isToken = true, $tokenSymbol = '')
{
$params = [
"from" => $from,
"to" => $to,
"amount" => -$amount,
"note" => $note,
"isToken" => $isToken ? true : false,
"tokenSymbol" => strtoupper($tokenSymbol)
];
return $this->send($params, 'Chain33.SendToAddress');
}
/**
* token 转账
*
* @param $from
* @param $to
* @param $amount
* @param string $note
* @param bool $isToken
* @param string $tokenSymbol
* @return array
*/
public function transToken($from, $to, $amount, $note = '', $isToken = true, $tokenSymbol = '')
{
$params = [
"from" => $from,
"to" => $to,
"amount" => $amount,
"note" => $note,
"isToken" => $isToken ? true : false,
"tokenSymbol" => strtoupper($tokenSymbol)
];
return $this->send($params, 'Chain33.SendToAddress');
}
}
...@@ -16,16 +16,19 @@ use yii\queue\Queue; ...@@ -16,16 +16,19 @@ use yii\queue\Queue;
use yii\console\Controller; use yii\console\Controller;
use common\models\psources\CoinPublishRule; use common\models\psources\CoinPublishRule;
use common\models\psources\CoinReleaseMember; use common\models\psources\CoinReleaseMember;
use backend\jobs\ExtractTokenJob;
/** /**
* Class ExchangeController * Class ExchangeController
* 调用交易所api更新数据保存到redis * 调用交易所api更新数据保存到redis
*
* @package console\controllers * @package console\controllers
*/ */
class DevController extends Controller class DevController extends Controller
{ {
/** /**
* 解冻币任务 * 解冻币任务
*
* @return [type] [description] * @return [type] [description]
*/ */
public function actionFreeze1() public function actionFreeze1()
...@@ -33,4 +36,10 @@ class DevController extends Controller ...@@ -33,4 +36,10 @@ class DevController extends Controller
$qid = Yii::$app->queue->push(new FreezeJob(['id' => 43])); $qid = Yii::$app->queue->push(new FreezeJob(['id' => 43]));
var_dump($qid); var_dump($qid);
} }
public function actionExtractToken()
{
$id = Yii::$app->queue->push(new ExtractTokenJob(['cid' => 1]));
var_dump($id);
}
} }
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