Commit 3a260f2c authored by shajiaiming's avatar shajiaiming

Merge branch 'develop' into 'master'

Develop See merge request !3
parents 270071b7 bcaeeb80
<?php
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinPlatformCoins;
use Yii;
class PlatformCoinsController extends BaseController
{
/**
* 新增空投钱包
*
* @param string $platform_id
* @param string $platform_coins
* @return array
*/
public function actionIndex()
{
$platform_id = Yii::$app->request->post('platform_id', '');
$coins_address = Yii::$app->request->post('platform_coins', '');
$type = Yii::$app->request->post('type', '');
if(empty($platform_id) || empty($coins_address) || empty($type)){
return ['code' => -1,'data' => null, 'msg' => '缺少必要的参数'];
}
$item_array = [];
foreach($coins_address as $item){
$platform_coins_arr = explode(',', $item);
$coin_name = $platform_coins_arr[0];
$coins_address = $platform_coins_arr[1];
if(empty($coin_name) || empty($coins_address)) continue;
$isExistModel = CoinPlatformCoins::find()->where(['coins_address' => $coins_address, 'platform_id' => $platform_id])->one();
if($isExistModel) continue;
$item_array[] = [
$coin_name,
$coins_address,
$type,
$platform_id,
] ;
}
if(empty($item_array)){
return ['code' => -1,'data' => null, 'msg' => '数据重复插入'];
}
$result = CoinPlatformCoins::batchImport($item_array);
if(!$result){
return ['code' => -1,'data' => null, 'msg' => '数据导入失败'];
}
return ['code' => 0,'data' => null, 'msg' => '数据导入成功'];
}
}
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
namespace api\controllers; namespace api\controllers;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\CoinTokenTransfer;
use common\service\chain33\Chain33Service;
use Yii; use Yii;
...@@ -45,4 +47,80 @@ class TradeController extends BaseController ...@@ -45,4 +47,80 @@ class TradeController extends BaseController
} }
public function actionAddressIsExist()
{
$get = Yii::$app->request->get();
$to = $get['coin_address'] ?? '';
if(empty($to)){
return ['code' => -1, 'msg' => '参数不能为空'];
}
$coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one();
if(!$coinTokenTransfer){
return ['code' => 0, 'msg' => 'record does not exist'];
}
return ['code' => 1, 'msg' => 'record already exists'];
}
public function actionTokenTransfer()
{
$get = Yii::$app->request->get();
$to = $get['coin_address'] ?? '';
if(empty($to)){
return ['code' => -1, 'msg' => '参数不能为空'];
}
$coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one();
if($coinTokenTransfer){
return ['code' => -1, 'msg' => 'record already exists'];
}
$fee = 100000;
$amount = 1 * 1e8;
$note = '2050糖果';
$execer = 'user.p.youngplus.token';
$isToken = true;
$tokenSymbol = 'YPLUS';
$service = new Chain33Service();
$createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){
$msg = $createRawTransaction['msg'];
$code = -1;
goto doEnd;
}
$txHex = $createRawTransaction['result'];
$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2';
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
$msg = $signRawTx['msg'];
$code = -1;
goto doEnd;
}
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str);
if(0 != $result['code']){
$msg = $result['msg'];
$code = -1;
goto doEnd;
}
$code = 1;
$msg = $result['result'];
doEnd :
$coinTokenTransfer = new CoinTokenTransfer();
$coinTokenTransfer->coin_address = $to;
$coinTokenTransfer->msg = $msg;
$coinTokenTransfer->code = $code;
$coinTokenTransfer->save();
return ['code' => $code, 'msg' => $msg];
}
} }
\ No newline at end of file
...@@ -9,30 +9,48 @@ ...@@ -9,30 +9,48 @@
namespace api\controllers; namespace api\controllers;
use api\base\BaseController; 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 common\service\chain33\Chain33Service;
use Yii; use Yii;
class VisitStatisticsController extends BaseController class VisitStatisticsController extends BaseController
{ {
/**
* 单个DAPP停留时长
*
* @param string $dapp_name
* @param string $identify
* @param string $duration
* @param string $dapp_address
* @param string $coins_address
* @param string $platform_id
* @return array
*/
public function actionIndex() public function actionIndex()
{ {
$dapp_name = Yii::$app->request->get('dapp_name', '');
$dapp = Yii::$app->request->get('dapp', '');
$identify = Yii::$app->request->get('identify', ''); $identify = Yii::$app->request->get('identify', '');
$duration = Yii::$app->request->get('duration', ''); $duration = Yii::$app->request->get('duration', '');
$address = Yii::$app->request->get('address', ''); $dapp_address = Yii::$app->request->get('dapp_address', '');
$coins_address = Yii::$app->request->get('coins_address', '');
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($dapp) || empty($identify) || empty($duration) || empty($address)){ if(empty($dapp_name) || empty($identify) || empty($duration) || empty($dapp_address) || empty($coins_address) || empty($platform_id)){
return ['code' => -1,'data' => [], 'msg' => '缺少必要的参数']; 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) { if(!$isExistModel) {
$model = new CoinAppVisitStatistics(); $model = new CoinDailyStatistics();
$model->dapp = $dapp; $model->dapp_name = $dapp_name;
$model->dapp_address = $dapp_address;
$model->duration = $duration; $model->duration = $duration;
$model->address = $address;
$model->identify = $identify; $model->identify = $identify;
$model->coins_address = $coins_address;
$model->platform_id = $platform_id;
$model->save(); $model->save();
return ['code' => 0,'data' => [], 'msg' => '数据记录插入成功']; return ['code' => 0,'data' => [], 'msg' => '数据记录插入成功'];
} }
...@@ -43,4 +61,89 @@ class VisitStatisticsController extends BaseController ...@@ -43,4 +61,89 @@ class VisitStatisticsController extends BaseController
return ['code' => 0,'data' => [], 'msg' => '数据记录更新成功']; return ['code' => 0,'data' => [], 'msg' => '数据记录更新成功'];
} }
} }
/**
* 日打开/进入DAPP的个数/次数
*
* @param string $dapp_name
* @param string $dapp_address
* @param string $coins_address
* @param string $platform_id
* @return array
*/
public function actionDailyTimes()
{
$dapp_name = Yii::$app->request->get('dapp_name', '');
$dapp_address = Yii::$app->request->get('dapp_address', '');
$coins_address = Yii::$app->request->get('coins_address', '');
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($dapp_name) || empty($dapp_address) || empty($coins_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_name' => $dapp_name, 'dapp_address' => $dapp_address, 'coins_address' => $coins_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' => null, 'msg' => '数据记录插入成功'];
} else {
return ['code' => -1,'data' => null, 'msg' => current($model_coinDailyTimes->firstErrors)];
}
}
/**
* 获取coin地址下DAPP交易信息
*
* @param string $coins_address
* @return array
*/
public function actionDappResult()
{
$coins_address = Yii::$app->request->get('coins_address', '');
if(empty($coins_address)){
return ['code' => -1,'data' => [], 'msg' => '缺少必要的参数'];
}
$service = new Chain33Service();
$result = $service->getDappTradeResult($coins_address);
if( 0 !== $result['code']){
return ['code' => -1,'data' => [], 'msg' => $result['msg']];
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
return ['code' => -1,'data' => [], 'msg' => 'error'];
}
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'],true);
$betting_times = $resultJSON['betting_times'] ?? 0;
$betting_amount = $resultJSON['betting_amount'] ?? 0;
$earnings = $resultJSON['earnings'] ?? 0;
$data = [
'betting_times' => $betting_times,
'betting_amount' => $betting_amount,
'earnings' => $earnings
];
return ['code' => 0,'data' => $data, 'msg' => 'ok'];
}
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace backend\controllers; namespace backend\controllers;
use backend\models\Coin;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use Yii; use Yii;
use common\models\psources\CoinTransfer; use common\models\psources\CoinTransfer;
...@@ -66,17 +67,27 @@ class CoinTransferController extends BaseController ...@@ -66,17 +67,27 @@ class CoinTransferController extends BaseController
public function actionBatchTransfer() public function actionBatchTransfer()
{ {
$model = CoinTransfer::find()->where(['status' => 0])->limit(30)->all(); $model = CoinTransfer::find()->where(['hash' => '-----------------'])->limit(30)->all();
foreach ($model as $val){ foreach ($model as $val){
echo $val->address."<br/>"; echo $val->address."<br/>";
$id = $val->id; $id = $val->id;
$to = $val->address; $to = $val->address;
$amount = str_replace(" TSC", "", $val->amount) * 1e8; #$amount = str_replace(" TSC", "", $val->amount) * 1e8;
$amount = $val->amount * 1e8;
$fee = 100000; $fee = 100000;
$note = ''; $note = '';
$execer = 'user.p.tschain.coins'; $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(); $service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($to, $amount, $fee, $note, $execer); $createRawTransaction = $service->createRawTransaction($to, $amount, $fee, $note, $execer);
...@@ -89,6 +100,7 @@ class CoinTransferController extends BaseController ...@@ -89,6 +100,7 @@ class CoinTransferController 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;
} }
......
...@@ -45,8 +45,8 @@ class CoinAppVersion extends BaseActiveRecord ...@@ -45,8 +45,8 @@ class CoinAppVersion extends BaseActiveRecord
*/ */
public static function getLastStable($type = 1,$platform_id = 1) public static function getLastStable($type = 1,$platform_id = 1)
{ {
$max_version = self::find()->where(['type' => $type,'platform_id' => $platform_id])->max('version'); $max_version_code = self::find()->where(['type' => $type,'platform_id' => $platform_id])->max('version_code');
$data = self::find()->where(['type' => $type,'platform_id' => $platform_id,'version' => $max_version])->asArray()->one(); $data = self::find()->where(['type' => $type,'platform_id' => $platform_id,'version_code' => $max_version_code])->asArray()->one();
return $data; return $data;
} }
......
<?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_name','dapp_address', 'coins_address', 'platform_id'], 'required'],
[['platform_id'],'match','pattern'=>'/^[0-9]+$/','message' => '{attribute} 必须为数字'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['dapp_name','dapp_address', 'coins_address', 'platform_id'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
...@@ -3,23 +3,10 @@ ...@@ -3,23 +3,10 @@
namespace common\models\psources; namespace common\models\psources;
use common\core\BaseActiveRecord; use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
use Yii; 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() public static function getDb()
{ {
...@@ -28,7 +15,7 @@ class CoinAppVisitStatistics extends BaseActiveRecord ...@@ -28,7 +15,7 @@ class CoinAppVisitStatistics extends BaseActiveRecord
public static function tableName() 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_name','dapp_address', 'coins_address', 'platform_id'], 'required'],
[['platform_id'],'match','pattern'=>'/^[0-9]+$/','message' => '{attribute} 必须为数字'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['dapp_name','dapp_address', 'coins_address', 'platform_id'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinPlatformCoins extends BaseActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_platform_coins}}';
}
public function rules() {
return [
[['coins_name','coins_address', 'type', 'platform_id'], 'required'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['coins_name','coins_address', 'type', 'platform_id'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
/**
* 导入数据
*
* @param array $datas
* @return boolean
*/
public static function batchImport(array $datas)
{
if (!is_array($datas)) {
return false;
}
try {
$result = self::getDb()->createCommand()->batchInsert(self::tableName(), ['coins_name', 'coins_address', 'type', 'platform_id'], $datas)->execute();
return $result;
} catch (\Exception $e) {
}
return false;
}
}
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinTokenTransfer extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_token_transfer}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules() {
return [
[['coin_address','msg', 'code'], 'required'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['coin_address','msg', 'code'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
...@@ -63,6 +63,32 @@ class Chain33Service ...@@ -63,6 +63,32 @@ class Chain33Service
} }
/** /**
* 获取coin地址下DAPP交易信息
*
* @param string|array $address
* @return array
*/
public function getDappTradeResult($address)
{
$params = [
'execer' => 'wasm',
'funcName' => 'WasmGetContractTable',
'payload' => [
'contractName' => 'user.p.tschain.user.wasm.dice',
'items' => [
[
'tableName' => 'addrinfo',
'key' => 'addrinfo-' . $address
]
]
]
];
return $this->send($params);
}
/**
* 获取地址下的所有token资产 * 获取地址下的所有token资产
* *
* @param string|array $address * @param string|array $address
...@@ -130,6 +156,21 @@ class Chain33Service ...@@ -130,6 +156,21 @@ class Chain33Service
return $this->send($params, 'Chain33.SendToAddress'); return $this->send($params, 'Chain33.SendToAddress');
} }
public function createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer)
{
$params = [
"to" => $to,
"amount" => $amount,
"isToken" => $isToken,
"tokenSymbol" => $tokenSymbol,
"fee" => $fee,
"note" => $note,
"execer" => $execer,
];
return $this->send($params, 'Chain33.CreateRawTransaction');
}
public function createRawTransaction($to, $amount, $fee, $note,$execer) public function createRawTransaction($to, $amount, $fee, $note,$execer)
{ {
$params = [ $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