Commit 6ea915a8 authored by shajiaiming's avatar shajiaiming

dapp logs

parent 270071b7
......@@ -9,7 +9,9 @@
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinAppVisitStatistics;
use common\models\psources\CoinDailyStatistics;
use common\models\psources\CoinDailyNumbers;
use common\models\psources\CoinDailyTimes;
use Yii;
class VisitStatisticsController extends BaseController
......@@ -21,18 +23,20 @@ class VisitStatisticsController extends BaseController
$identify = Yii::$app->request->get('identify', '');
$duration = Yii::$app->request->get('duration', '');
$address = Yii::$app->request->get('address', '');
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($dapp) || empty($identify) || empty($duration) || empty($address)){
if(empty($dapp) || empty($identify) || empty($duration) || empty($address) || empty($platform_id)){
return ['code' => -1,'data' => [], 'msg' => '缺少必要的参数'];
}
$isExistModel = CoinAppVisitStatistics::find()->where(['identify' => $identify])->one();
$isExistModel = CoinDailyStatistics::find()->where(['identify' => $identify, 'platform_id' => $platform_id])->one();
if(!$isExistModel) {
$model = new CoinAppVisitStatistics();
$model = new CoinDailyStatistics();
$model->dapp = $dapp;
$model->duration = $duration;
$model->address = $address;
$model->identify = $identify;
$model->platform_id = $platform_id;
$model->save();
return ['code' => 0,'data' => [], 'msg' => '数据记录插入成功'];
}
......@@ -43,4 +47,36 @@ class VisitStatisticsController extends BaseController
return ['code' => 0,'data' => [], 'msg' => '数据记录更新成功'];
}
}
public function actionDailyTimes()
{
$dapp = Yii::$app->request->get('dapp', '');
$address = Yii::$app->request->get('address', '');
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($dapp) || empty($address) || empty($platform_id)){
return ['code' => -1,'data' => [], 'msg' => '缺少必要的参数'];
}
$begin = date("Y-m-d",time())." 00:00:00";
$end = date("Y-m-d",time())." 23:59:59";
$isExist_coinDailyNumbers = CoinDailyNumbers::find()
->where(['dapp' => $dapp, 'address' => $address, 'platform_id' => $platform_id])
->andWhere(['between', 'create_time', $begin, $end])
->one();
if(!$isExist_coinDailyNumbers){
$model_coinDailyNumbers = new CoinDailyNumbers();
$model_coinDailyNumbers->setScenario(CoinDailyNumbers::SCENARIOS_CREATE);
$model_coinDailyNumbers->load(Yii::$app->request->get(),'');
$model_coinDailyNumbers->save();
}
$model_coinDailyTimes = new CoinDailyTimes();
$model_coinDailyTimes->setScenario(CoinDailyTimes::SCENARIOS_CREATE);
if($model_coinDailyTimes->load(Yii::$app->request->get(),'') && $model_coinDailyTimes->save()) {
return ['code' => 0,'data' => [], 'msg' => '数据记录插入成功'];
} else {
return ['code' => -1,'data' => [], 'msg' => current($model_coinDailyTimes->firstErrors)];
}
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
namespace backend\controllers;
use backend\models\Coin;
use common\service\chain33\Chain33Service;
use Yii;
use common\models\psources\CoinTransfer;
......@@ -66,17 +67,27 @@ class CoinTransferController extends BaseController
public function actionBatchTransfer()
{
$model = CoinTransfer::find()->where(['status' => 0])->limit(30)->all();
$model = CoinTransfer::find()->where(['hash' => '-----------------'])->limit(30)->all();
foreach ($model as $val){
echo $val->address."<br/>";
$id = $val->id;
$to = $val->address;
$amount = str_replace(" TSC", "", $val->amount) * 1e8;
#$amount = str_replace(" TSC", "", $val->amount) * 1e8;
$amount = $val->amount * 1e8;
$fee = 100000;
$note = '';
$execer = 'user.p.tschain.coins';
// $isExist = CoinTransfer::find()->where(['address' => $val->address, 'status' => 1])->one();
// if($isExist){
// $updateModel = CoinTransfer::findOne($val->id);
// $updateModel->hash = '-----------------';
// $updateModel->status = 1;
// $updateModel->save();
// continue;
// }
$service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($to, $amount, $fee, $note, $execer);
......@@ -89,6 +100,7 @@ class CoinTransferController extends BaseController
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
continue;
}
......
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinDailyNumbers extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_daily_numbers}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules() {
return [
[['dapp','address', 'platform_id'], 'required'],
[['platform_id'],'match','pattern'=>'/^[0-9]+$/','message' => '{attribute} 必须为数字'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['dapp', 'address', 'platform_id'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
......@@ -3,23 +3,10 @@
namespace common\models\psources;
use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
use Yii;
class CoinAppVisitStatistics extends BaseActiveRecord
class CoinDailyStatistics extends BaseActiveRecord
{
// public function behaviors()
// {
// return [
// [
// 'class' => TimestampBehavior::className(),
// 'createdAtAttribute' => 'created_at', // 自己根据数据库字段修改
// 'updatedAtAttribute' => 'updated_at', // 自己根据数据库字段修改
// 'value' => new Expression('NOW()'), // 自己根据数据库字段修改
// ]
// ];
// }
public static function getDb()
{
......@@ -28,7 +15,7 @@ class CoinAppVisitStatistics extends BaseActiveRecord
public static function tableName()
{
return '{{%coin_app_visit_statistics}}';
return '{{%coin_daily_statistics}}';
}
}
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinDailyTimes extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_daily_times}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules() {
return [
[['dapp','address', 'platform_id'], 'required'],
[['platform_id'],'match','pattern'=>'/^[0-9]+$/','message' => '{attribute} 必须为数字'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['dapp', 'address', 'platform_id'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
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