Commit 6f23d0d8 authored by shajiaiming's avatar shajiaiming

epc airdrop

parent 5079bede
...@@ -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\CoinAirDropTransfer;
use common\models\psources\CoinPlatformCoins; use common\models\psources\CoinPlatformCoins;
use Yii; use Yii;
...@@ -25,32 +26,42 @@ class PlatformCoinsController extends BaseController ...@@ -25,32 +26,42 @@ class PlatformCoinsController extends BaseController
$header = Yii::$app->request->headers; $header = Yii::$app->request->headers;
$deviceCode = $header['FZM-REQUEST-UUID'] ?? null; $deviceCode = $header['FZM-REQUEST-UUID'] ?? null;
if(empty($platform_id) || empty($coins_address) || empty($type)){ if (empty($platform_id) || empty($coins_address) || empty($type)) {
return ['code' => -1,'data' => null, 'msg' => '缺少必要的参数']; return ['code' => -1, 'data' => null, 'msg' => '缺少必要的参数'];
} }
if(empty($deviceCode)){ if (empty($deviceCode)) {
return ['code' => 0,'data' => null, 'msg' => '数据导入成功']; return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
}
$is_exist = true;
if (41 == $platform_id) {
$model = CoinPlatformCoins::find()->where(['platform_id' => $platform_id, 'deviceCode' => $deviceCode])->one();
if (!$model) {
$is_exist = false;
}
} }
$item_array = []; $item_array = [];
foreach($coins_address as $item){ $to_address = '';
foreach ($coins_address as $item) {
$platform_coins_arr = explode(',', $item); $platform_coins_arr = explode(',', $item);
$coin_name = $platform_coins_arr[0]; $coin_name = $platform_coins_arr[0];
$coins_address = $platform_coins_arr[1]; $coins_address = $platform_coins_arr[1];
if(empty($coin_name) || empty($coins_address)) continue; $to_address = $coins_address;
if (empty($coin_name) || empty($coins_address)) continue;
$isExistModel = CoinPlatformCoins::find()->where(['coins_name' => $coin_name, 'coins_address' => $coins_address, 'platform_id' => $platform_id])->one(); $isExistModel = CoinPlatformCoins::find()->where(['coins_name' => $coin_name, 'coins_address' => $coins_address, 'platform_id' => $platform_id])->one();
if(!empty($isExistModel) && empty($isExistModel->deviceCode)){ if (!empty($isExistModel) && empty($isExistModel->deviceCode)) {
$isExistModel->deviceCode = $deviceCode; $isExistModel->deviceCode = $deviceCode;
$isExistModel->save(); $isExistModel->save();
continue; continue;
} }
if(!empty($isExistModel) && strlen($isExistModel->deviceCode) > 0 && $isExistModel->deviceCode !== $deviceCode) { if (!empty($isExistModel) && strlen($isExistModel->deviceCode) > 0 && $isExistModel->deviceCode !== $deviceCode) {
$isExistModel->deviceCode = $deviceCode; $isExistModel->deviceCode = $deviceCode;
$isExistModel->save(); $isExistModel->save();
continue; continue;
}; };
if(!empty($isExistModel) && $isExistModel->deviceCode == $deviceCode) { if (!empty($isExistModel) && $isExistModel->deviceCode == $deviceCode) {
continue; continue;
}; };
$item_array[] = [ $item_array[] = [
...@@ -59,17 +70,30 @@ class PlatformCoinsController extends BaseController ...@@ -59,17 +70,30 @@ class PlatformCoinsController extends BaseController
$type, $type,
$deviceCode, $deviceCode,
$platform_id, $platform_id,
] ; ];
} }
if(empty($item_array)){ if (empty($item_array)) {
return ['code' => 0,'data' => null, 'msg' => '数据导入成功']; return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
} }
$result = CoinPlatformCoins::batchImport($item_array); $result = CoinPlatformCoins::batchImport($item_array);
if(!$result){ if (!$result) {
return ['code' => -1,'data' => null, 'msg' => '数据导入失败']; return ['code' => -1, 'data' => null, 'msg' => '数据导入失败'];
} }
return ['code' => 0,'data' => null, 'msg' => '数据导入成功'];
if (41 == $platform_id && false == $is_exist) {
$model = new CoinAirDropTransfer();
$model->txhash = '0';
$model->msg = '';
$model->to_address = $to_address;
$model->coin_name = 'EPC';
$model->amount = 0.001;
$model->origin = CoinAirDropTransfer::ORIGIN_API;
$model->type = CoinAirDropTransfer::TYPE_COINS;
$model->save();
}
return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
} }
} }
\ No newline at end of file
...@@ -269,13 +269,13 @@ class AirDropController extends Controller ...@@ -269,13 +269,13 @@ class AirDropController extends Controller
$amount = $val['amount'] * 1e8; $amount = $val['amount'] * 1e8;
$fee = 100000; $fee = 100000;
$note = ''; $note = '';
if (CoinAirDropTransfer::TYPE_COINS == $val['type']) { if (CoinAirDropTransfer::TYPE_COINS == $val['type'] && CoinAirDropTransfer::ORIGIN_IMPORT == $val['origin']) {
$node_params = Yii::$app->params['chain_parallel']['primary']; $node_params = Yii::$app->params['chain_parallel']['primary'];
$service = new Chain33Service($node_params); $service = new Chain33Service($node_params);
$execer = 'coins'; $execer = 'coins';
$createRawTransaction = $service->createRawTransaction($to, $amount, $fee, $note, $execer); $createRawTransaction = $service->createRawTransaction($to, $amount, $fee, $note, $execer);
} }
if (CoinAirDropTransfer::TYPE_TOKEN == $val['type']) { if (CoinAirDropTransfer::TYPE_TOKEN == $val['type'] && CoinAirDropTransfer::ORIGIN_IMPORT == $val['origin']) {
$node_params = Yii::$app->params['chain_parallel']['parallel']; $node_params = Yii::$app->params['chain_parallel']['parallel'];
$service = new Chain33Service($node_params); $service = new Chain33Service($node_params);
$execer = 'user.p.mall.token'; $execer = 'user.p.mall.token';
...@@ -283,8 +283,20 @@ class AirDropController extends Controller ...@@ -283,8 +283,20 @@ class AirDropController extends Controller
$tokenSymbol = $val['coin_name']; $tokenSymbol = $val['coin_name'];
$createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer); $createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer);
} }
if (CoinAirDropTransfer::TYPE_COINS == $val['type'] && CoinAirDropTransfer::ORIGIN_API == $val['origin']) {
$node_params = [
'scheme' => 'http',
'host' => '161.117.40.62',
'port' => 8901
];
$service = new Chain33Service($node_params);
$execer = 'user.p.ecopoolchain.coins';
$isToken = false;
$tokenSymbol = $val['coin_name'];
$createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer);
}
if (0 != $createRawTransaction['code']) { if (isset($createRawTransaction['code']) && 0 != $createRawTransaction['code']) {
$txhash = '0'; $txhash = '0';
$msg = $createRawTransaction['msg']; $msg = $createRawTransaction['msg'];
goto doEnd; goto doEnd;
......
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