Commit a6595101 authored by rlgy's avatar rlgy

账单

parent 0687e53b
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-30
* Time: 下午3:09
*/
namespace api\controllers;
use common\models\pwallet\Bill;
use Yii;
use api\base\BaseController;
use api\job\BillJob;
class BillController extends BaseController
{
/**
* 插入交易记录
*/
public function actionInsert()
{
$post = Yii::$app->request->post();
$model = new Bill();
if ($model->load($post) && $model->validate()) {
$model->status = 0;
if ($model->save(false)) {
//加入队列
Yii::$app->queue->push(new BillJob(['id' => $model->id, 'txid' => $model->txid, 'chain' => $model->chain, 'from' => $model->from]));
return ['code' => 0, 'message' => 'succeed'];
}
} else {
return ['code' => -1, 'message' => '数据验证失败'];
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-30
* Time: 下午3:12
*/
namespace api\job;
use yii\base\BaseObject;
use yii\queue\JobInterface;
use yii\queue\Queue;
/**
* Class BillJob
*
* 处理账单队列数据
* @package api\job
*/
class BillJob extends BaseObject implements JobInterface
{
public $id;
public $chain;
public $txid;
public $from;
/**
* @param Queue $queue which pushed and is handling the job
* @return integer
*/
public function execute($queue)
{
//todo 查询交易状态, 更改状态
return 0;
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ return [
/**
* db config
*/
'db' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=manage',
'username' => 'root',
......@@ -19,14 +19,14 @@ return [
'charset' => 'utf8',
'tablePrefix' => 'gli_',
],
'db_pwallet' => [
'db_pwallet' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=api',
'username' => 'root',
'password' => '123456',
'charset' => 'utf8',
],
'cache' => [
'cache' => [
'class' => 'yii\redis\Cache',
'redis' => [
'hostname' => 'localhost',
......@@ -35,14 +35,26 @@ return [
'database' => 0,
],
],
'redis' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'password' => 'jlm123456',
'port' => 6379,
'database' => 1,
],
'uploader' => [
'redis-queue' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'password' => 'jlm123456',
'port' => 6379,
'database' => 2,
],
'queue' => [
'class' => \yii\queue\redis\Queue::class,
'redis' => 'redis-queue', // Redis connection component or its config
'channel' => 'queue', // Queue channel key
],
'uploader' => [
'class' => 'common\components\uploader\Uploader',
'baseuri' => 'http://127.0.0.1:8082/admin/upload',
'absolute' => dirname(dirname(__DIR__)) . '/backend/web/upload',
......
......@@ -80,6 +80,17 @@ return [
'port' => 6379,
'database' => 1,
],
'redis-queue' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 2,
],
'queue' => [
'class' => \yii\queue\redis\Queue::class,
'redis' => 'redis-queue', // Redis connection component or its config
'channel' => 'queue', // Queue channel key
],
'i18n' => [
'translations' => [
'*' => [
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-1
* Time: 下午5:13
*/
namespace common\models\pwallet;
use Yii;
use common\core\BaseActiveRecord;
class Bill extends BaseActiveRecord
{
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
*/
public static function getDb()
{
return Yii::$app->get('db_pwallet');
}
public function formName()
{
return '';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'txid' => 'HashId',
'chain' => '主链',
'coinname' => '币种',
'from' => '转出地址',
'to' => '转入地址',
'value' => '金额',
'fee' => '矿工费',
'status' => '状态',
'type' => '交易类型',
'height' => '区块高度',
'note' => '备注',
'blocktime' => '更新时间'
];
}
public function rules()
{
return [
[['txid', 'chain', 'coinname', 'from', 'to', 'value', 'fee', 'type'], 'required', 'message' => '{attribute} 不能为空'],
[['txid', 'from', 'to', 'note'], 'string', 'max' => 255],
[['chain', 'coinname'], 'string', 'max' => 32],
[['value', 'fee'], 'double'],
[['status', 'type'], 'number', 'max' => 2],
];
}
}
\ No newline at end of file
......@@ -19,7 +19,8 @@
"kartik-v/yii2-field-range": "*",
"kartik-v/yii2-date-range": "*",
"kartik-v/yii2-widget-fileinput": "*",
"yiisoft/yii2-redis": "~2.0.0"
"yiisoft/yii2-redis": "~2.0.0",
"yiisoft/yii2-queue": "~2.0"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
......
This diff is collapsed.
......@@ -9,7 +9,10 @@ $params = array_merge(
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'bootstrap' => [
'log',
'queue'
],
'controllerNamespace' => 'console\controllers',
'aliases' => [
'@bower' => '@vendor/bower-asset',
......
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