Commit 65bdbfce authored by shajiaiming's avatar shajiaiming

wallet manage

parent 58c904af
......@@ -11,6 +11,7 @@ namespace api\controllers;
use api\base\BaseController;
use common\base\Exception;
use common\business\BrowerBusiness;
use common\business\Chain33Business;
use common\business\CoinBusiness;
use common\business\ExchangeBusiness;
use common\models\psources\Coin;
......@@ -361,7 +362,13 @@ class CoinController extends BaseController
$platform_with_hold['tokensymbol'] = $platform .'.coins';
$platform_with_hold['fee'] = (float)sprintf("%0.4f", (double)$platform_with_hold['fee']);
}
$platform_with_hold['bty_fee'] = (float)sprintf("%0.4f", (double)Yii::$app->params['bty_fee']);;
$service = new Chain33Business();
$result = $service->getProperFee();
if(0 === $result['code']) {
$platform_with_hold['bty_fee'] = (float)sprintf("%0.4f", $result['result']['properFee'] / 1e8);
} else {
$platform_with_hold['bty_fee'] = (float)sprintf("%0.4f", Yii::$app->params['bty_fee']);
}
return ['code' => 0, 'data' => $platform_with_hold];
} else {
......
<?php
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinPlatform;
use common\service\chain33\Chain33Service;
use Yii;
class WalletController extends BaseController
{
public function actionInfo()
{
$code = 1;
$msg = 'success';
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($platform_id)){
$msg = '参数不能为空';
$code = -1;
$data = null;
goto doEnd;
}
$data = CoinPlatform::find()->select("name, download_url, introduce")->where(['id' => $platform_id])->asArray()->one();
if(empty($data)){
$msg = '数据不存在';
$data = null;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'data' => $data, 'msg' => $msg];
}
public function actionGameTradeUpdate()
{
$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']){
continue;
}
$txHex = $createRawTransaction['result'];
$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2';
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
continue;
}
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str);
if(0 != $result['code']){
continue;
}
$currentModel = CoinAirDropTrade::findOne($val->id);
$currentModel->attach = 2;
$currentModel->balance = 0;
$currentModel->msg = $result['result'];
$currentModel->save();
}
return ['code' => 1, 'msg' => 'ok'];
}
public function actionGetBalance()
{
$coinAirDropTrade = CoinAirDropTrade::find()->where(['balance' => 0])->limit(60)->all();
$address = [];
foreach ($coinAirDropTrade as $val){
$address[] = $val->coins_address;
}
$service = new Chain33Service();
$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();
}
}
return ['code' => 1, 'msg' => 'ok'];
}
}
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @authors rlgy <rlgyzhcn@qq.com>
* @date 2018-09-07 17:41:04
*/
namespace backend\assets\wallet;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/wallet';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
\ No newline at end of file
......@@ -5,14 +5,116 @@
* Date: 2018/12/17
* Time: 10:13
*/
namespace backend\controllers;
use common\models\psources\CoinApplicationCategory;
use backend\models\coin\CoinPlatformForm;
use common\models\psources\CoinPlatform;
use Yii;
class WalletController extends BaseController
{
public function actionList()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('name', '');
$where = [];
if ($name) {
$where[] = ['name' => $name];
}
$data = CoinPlatform::getList($page, $limit, $where);
$data['code'] = 0;
Yii::$app->response->format = 'json';
return $data;
}
return $this->render('index');
}
public function actionAdd()
{
$model = new CoinPlatformForm();
$model->scenario = 'add';
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
if ($model->load($data, '') && $model->validate()) {
$coin = Yii::createObject(CoinPlatform::className());
$result = $coin->addOne($data);
if ($result === true) {
$this->success('添加成功', '/admin/wallet/list');
}
}
//表单验证失败
$errors = $model->errors;
if ($errors) {
foreach ($errors as $key => $item) {
$errors = $item[0];
break;
}
} elseif (isset($result) && $result['code'] != 0) {
$errors = $result['message'];
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('add', ['model' => $model]);
}
public function actionEdit()
{
if (Yii::$app->request->isPost) {
$model = new CoinPlatformForm();
$model->scenario = 'update';
$data = Yii::$app->request->post();
Yii::$app->response->format = 'json';
if ($model->load($data, '') && $model->validate()) {
$coin = Yii::createObject(CoinPlatform::className());
$result = $coin->updateOne($data);
if ($result === true) {
return ['code' => 0, 'msg' => 'succeed'];
}
}
$errors = $model->errors;
if ($errors) {
foreach ($errors as $key => $item) {
$errors = $item[0];
break;
}
} elseif (isset($result) && $result['code'] != 0) {
$errors = $result['message'];
}
return ['code' => 1, 'msg' => $errors];
} elseif (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id', null);
if ($id) {
$coin = CoinPlatform::findOne(['id' => $id]);
$this->layout = false;
return $this->render('edit', ['model' => $coin]);
}
}
}
public function actionDelete()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', 0);
if ($id) {
$model = CoinPlatform::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' => '删除失败'];
}
/**
* @return string
* 设置钱包密码
......@@ -24,23 +126,21 @@ class WalletController extends BaseController
$new_passwd = Yii::$app->request->post('new_passwd');
$confirm_passwd = Yii::$app->request->post('confirm_passwd');
$passwd = Yii::$app->redis->get('wallet_passwd');
if(!$passwd){
Yii::$app->redis->set('wallet_passwd',$new_passwd);
if (!$passwd) {
Yii::$app->redis->set('wallet_passwd', $new_passwd);
$this->success('钱包密码设置成功', Yii::$app->request->getReferrer());
}
if($passwd != $old_passwd){
if ($passwd != $old_passwd) {
$this->error('原始密码错误', Yii::$app->request->getReferrer());
}
if($new_passwd != $confirm_passwd){
if ($new_passwd != $confirm_passwd) {
$this->error('确认密码和设置的密码不一致', Yii::$app->request->getReferrer());
}
Yii::$app->redis->set('wallet_passwd',$new_passwd);
Yii::$app->redis->set('wallet_passwd', $new_passwd);
$this->success('钱包密码设置成功', Yii::$app->request->getReferrer());
}
return $this->render('set-passwd');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午4:05
*/
namespace backend\models\coin;
use yii\base\Model;
class CoinPlatformForm extends Model
{
public $id;
public $name;
public $download_url;
public $introduce;
public function formName()
{
return '';
}
public function rules()
{
return [
[['name'], 'required', 'on' => 'add'],
[['id', 'name'], 'required', 'on' => 'update'],
];
}
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => '名称',
'download_url' => '下载链接',
'introduce' => '介绍'
];
}
public function scenarios()
{
return [
'add' => [
'id',
'name',
],
'update' => [
'id',
'name',
],
];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午3:31
*/
?>
<h4>添加钱包</h4>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md6">
<form class="layui-form" method="post" action="">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="<?= $model->name ?>" lay-verify="required">
</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 ?>">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce"><?= $model->introduce?></textarea>
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn">提交</button>
</div>
</form>
</div>
</div>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午6:23
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form class="layui-form" method="post" action="" id="walletEdit">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="<?= $model->id ?>">
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="<?= $model->name ?>" lay-verify="required">
</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 ?>">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce"><?= $model->introduce?></textarea>
</div>
</div>
</form>
</div>
</div>
<script>
var laydate = layui.laydate;
laydate.render({
elem: "#time1"
});
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/coin/upload',
data: {_csrf: $_csrf},
done: function (res) {
console.log(res.data.src);
$("input[name='icon']").val(res.data.src);
$("#icon1").attr('src', res.data.src);
},
error: function (res) {
}
});
//form render
var form = layui.form;
form.render();
</script>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use backend\assets\wallet\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>钱包列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<a href="/admin/wallet/add">
<button class="layui-btn layui-btn-default" id="add">添加钱包</button>
</a>
</div>
<div class="layui-col-md8">
<form class="layui-form" method="get" action="">
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">钱包名称</label>
<div class="layui-input-inline">
<input class="layui-input" name="name">
</div>
</div>
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="form1">搜索</button>
</div>
</form>
</div>
</div>
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</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>
</script>
/**
* @author rlgyzhcn@qq.com
*/
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
form.render();
var tableIns = table.render({
elem: "#table1",
url: '/admin/wallet/list',
limit: 10,
page: 1,
loading: true,
cols: [[
{field: 'id', title: 'ID'},
{field: 'name', 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.name + '吗?', {icon: 3, title: '删除'}, function (index) {
layer.close(index);
//向服务端发送删除指令
$.get('/admin/wallet/delete?id=' + obj.data.id, function (data, status) {
if (data.code == 0) {
obj.del(); //删除对应行(tr)的DOM结构
}
layer.msg(data.msg);
});
});
} else if (obj.event == 'edit') {
$.get('/admin/wallet/edit', {id: data.id}, function (str) {
var editIndex = layer.open({
type: 1,
title: '编辑: ' + data.name,
area: '625px',
content: str,
btn: ['保存', '取消'],
btn1: function () {
// console.log();
$.post('/admin/wallet/edit', $("#walletEdit").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
table.reload("table1", {
where: data.field,
});
layer.close(editIndex);
}
});
}
});
});
}
});
\ No newline at end of file
......@@ -131,6 +131,12 @@ class Chain33Business
return $service->getBlockHashByHeight($height);
}
public static function getProperFee()
{
$service = new Chain33Service();
return $service->getProperFee();
}
/**
* 获取coin地址下DAPP交易信息
* @param string $address
......
......@@ -14,4 +14,63 @@ class CoinPlatform extends BaseActiveRecord
{
return '{{%coin_platform}}';
}
/**
* 获取钱包信息列表
*
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
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()];
}
}
public function updateOne($params)
{
$params = array_filter($params, function ($value) {
if (null === $value) {
return false;
}
return true;
});
if (isset($params['id']) && !empty($params['id'])) {
$coin = self::findOne(['id' => $params['id']]);
if ($coin === null) {
return ['code' => 1, 'msg' => '币种不存在'];
}
unset($params['id']);
}
$coin->setAttributes($params, false);
try {
return (bool)$coin->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
}
......@@ -313,6 +313,11 @@ class Chain33Service
return $this->send(['height' => $height], 'Chain33.GetBlockHash');
}
public function getProperFee($params = [])
{
return $this->send($params, 'Chain33.GetProperFee');
}
public function getTxByAddr($addr, $flag, $count, $direction, $height, $index)
{
$params = [
......
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