Commit 9529ea23 authored by shajiaiming's avatar shajiaiming

fix

parent cf41cb88
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace api\controllers; namespace api\controllers;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\AirDrop;
use common\models\psources\CoinAirDropTrade; use common\models\psources\CoinAirDropTrade;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use Yii; use Yii;
...@@ -10,16 +11,42 @@ use Yii; ...@@ -10,16 +11,42 @@ use Yii;
class AirDropController extends BaseController class AirDropController extends BaseController
{ {
public function actionApply()
{
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
$model = new AirDrop();
$model->setScenario(AirDrop::SCENARIOS_CREATE);
if ($model->load($data, '') && $model->save()) {
goto doEnd;
}
$this->msg = $model->errors;
if (empty($this->msg)) {
$this->msg = 'Validation failed.';
}
$service = new Chain33Service();
$result = $service->chainQuery('ticket', 'MinerSourceList', $data['miner_address']);
echo json_encode($result);exit;
$this->code = -1;
goto doEnd;
}
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
public function actionGameTrade() public function actionGameTrade()
{ {
$coins_address = Yii::$app->request->post('coins_address', ''); $coins_address = Yii::$app->request->post('coins_address', '');
if(empty($coins_address)){ if (empty($coins_address)) {
return ['code' => -1, 'msg' => '参数不能为空']; return ['code' => -1, 'msg' => '参数不能为空'];
} }
$coinTokenTransfer = CoinAirDropTrade::find()->where(['coins_address' => $coins_address, 'type' => CoinAirDropTrade::TYPE_GAME])->one(); $coinTokenTransfer = CoinAirDropTrade::find()->where(['coins_address' => $coins_address, 'type' => CoinAirDropTrade::TYPE_GAME])->one();
if($coinTokenTransfer){ if ($coinTokenTransfer) {
return ['code' => -1, 'data' => null, 'msg' => 'record already exists']; return ['code' => -1, 'data' => null, 'msg' => 'record already exists'];
} }
...@@ -29,8 +56,8 @@ class AirDropController extends BaseController ...@@ -29,8 +56,8 @@ class AirDropController extends BaseController
$note = ''; $note = '';
$service = new Chain33Service(); $service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($coins_address, $amount, $fee, $note, $execer); $createRawTransaction = $service->createRawTransaction($coins_address, $amount, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){ if (0 != $createRawTransaction['code']) {
$msg = $createRawTransaction['msg']; $msg = $createRawTransaction['msg'];
$code = -1; $code = -1;
goto doEnd; goto doEnd;
...@@ -41,7 +68,7 @@ class AirDropController extends BaseController ...@@ -41,7 +68,7 @@ class AirDropController extends BaseController
$expire = '1m'; $expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire); $signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){ if (0 != $signRawTx['code']) {
$msg = $signRawTx['msg']; $msg = $signRawTx['msg'];
$code = -1; $code = -1;
goto doEnd; goto doEnd;
...@@ -49,7 +76,7 @@ class AirDropController extends BaseController ...@@ -49,7 +76,7 @@ class AirDropController extends BaseController
$sign_str = $signRawTx['result']; $sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str); $result = $service->sendTransaction($sign_str);
if(0 != $result['code']){ if (0 != $result['code']) {
$msg = $result['msg']; $msg = $result['msg'];
$code = -1; $code = -1;
goto doEnd; goto doEnd;
...@@ -72,16 +99,16 @@ class AirDropController extends BaseController ...@@ -72,16 +99,16 @@ class AirDropController extends BaseController
public function actionGameTradeUpdate() public function actionGameTradeUpdate()
{ {
$coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2 ,'msg' => '0'])->limit(30)->all(); $coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2, 'msg' => '0'])->limit(30)->all();
foreach ($coinAirDropTrade as $val){ foreach ($coinAirDropTrade as $val) {
$fee = 100000; $fee = 100000;
$amount = 1 * 1e8; $amount = 1 * 1e8;
$execer = 'coins'; $execer = 'coins';
$note = ''; $note = '';
$service = new Chain33Service(); $service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer); $createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){ if (0 != $createRawTransaction['code']) {
continue; continue;
} }
...@@ -90,13 +117,13 @@ class AirDropController extends BaseController ...@@ -90,13 +117,13 @@ class AirDropController extends BaseController
$expire = '1m'; $expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire); $signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){ if (0 != $signRawTx['code']) {
continue; continue;
} }
$sign_str = $signRawTx['result']; $sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str); $result = $service->sendTransaction($sign_str);
if(0 != $result['code']){ if (0 != $result['code']) {
continue; continue;
} }
$currentModel = CoinAirDropTrade::findOne($val->id); $currentModel = CoinAirDropTrade::findOne($val->id);
...@@ -112,17 +139,17 @@ class AirDropController extends BaseController ...@@ -112,17 +139,17 @@ class AirDropController extends BaseController
{ {
$coinAirDropTrade = CoinAirDropTrade::find()->where(['balance' => 0])->limit(60)->all(); $coinAirDropTrade = CoinAirDropTrade::find()->where(['balance' => 0])->limit(60)->all();
$address = []; $address = [];
foreach ($coinAirDropTrade as $val){ foreach ($coinAirDropTrade as $val) {
$address[] = $val->coins_address; $address[] = $val->coins_address;
} }
$service = new Chain33Service(); $service = new Chain33Service();
$execer = 'coins'; $execer = 'coins';
$result = $service->getBalance($address, $execer); $result = $service->getBalance($address, $execer);
if(0 == $result['code']){ if (0 == $result['code']) {
$result_balance = $result['result']; $result_balance = $result['result'];
foreach ($result_balance as $val){ foreach ($result_balance as $val) {
$coinAirDropTrade = CoinAirDropTrade::find()->where(['coins_address' => $val['addr']])->one(); $coinAirDropTrade = CoinAirDropTrade::find()->where(['coins_address' => $val['addr']])->one();
if(empty($coinAirDropTrade)) continue; if (empty($coinAirDropTrade)) continue;
$coinAirDropTrade->balance = $val['balance']; $coinAirDropTrade->balance = $val['balance'];
$coinAirDropTrade->save(); $coinAirDropTrade->save();
} }
......
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class AirDrop extends CommonActiveRecord
{
const ISSUE_TOKEN = 'issue_token';
const REVOKE_TOKEN = 'revoke_token';
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%wallet_airdrop_apply}}';
}
public function rules()
{
return [
[['identifier', 'wallet_address', 'miner_address'], 'required'],
[['checked_times'], 'integer'],
[['identifier'], 'string', 'length' => [5, 50]],
[['wallet_address', 'miner_address'], 'string', 'length' => [10, 50]],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['identifier', 'miner_address'],
self:: SCENARIOS_UPDATE => ['wallet_address'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'identifier' => '树莓派编号',
'wallet_address' => '矿主地址',
'miner_address' => '矿工地址',
'checked_times' => '达标次数',
'create_time' => '开始时间',
'finish_time' => '结束时间'
];
}
}
\ 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