|
|
@@ -30,6 +30,7 @@ use IEXBase\TronAPI\Tron;
|
|
|
use Tron\Api;
|
|
|
use Tron\TRC20;
|
|
|
use Tron\TRX;
|
|
|
+use Web3\Personal;
|
|
|
use Web3\Web3;
|
|
|
use Web3p\EthereumUtil\Util;
|
|
|
|
|
|
@@ -44,7 +45,7 @@ class UsdtWalletService extends BaseService
|
|
|
protected $config = [];
|
|
|
protected $apiUrls = [
|
|
|
'usdt_trx2_transfer_log' => '/v1/accounts/%s/transactions/trc20?limit=%s&only_to=%s&only_from=%s&only_confirmed=true&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
|
|
|
- ];
|
|
|
+ ];
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
@@ -74,7 +75,7 @@ class UsdtWalletService extends BaseService
|
|
|
* 获取TRC2.0钱包地址
|
|
|
* @throws \Tron\Exceptions\TronErrorException
|
|
|
*/
|
|
|
- public function getTrxAddress()
|
|
|
+ public function getTrxAddress1()
|
|
|
{
|
|
|
$api = new Api(new Client(['base_uri' => $this->config['tron_api_url']]));
|
|
|
|
|
|
@@ -85,6 +86,18 @@ class UsdtWalletService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取TRC2.0钱包地址
|
|
|
+ * @throws \Tron\Exceptions\TronErrorException
|
|
|
+ */
|
|
|
+ public function getTrxAddress($userId = 0)
|
|
|
+ {
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url']]));
|
|
|
+
|
|
|
+ $trxWallet = new TRX($api);
|
|
|
+ $addressData = $trxWallet->generateAddress();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* trx 转账
|
|
|
* @param $from 转账账户
|
|
|
* @param $to 进账账户
|
|
|
@@ -92,7 +105,7 @@ class UsdtWalletService extends BaseService
|
|
|
* @throws \Tron\Exceptions\TransactionException
|
|
|
* @throws \Tron\Exceptions\TronErrorException
|
|
|
*/
|
|
|
- public function trxTransfer($from, $to, $amount)
|
|
|
+ public function trxTransfer($to, $amount)
|
|
|
{
|
|
|
if ($amount <= 0) {
|
|
|
$this->error = '2205';
|
|
|
@@ -105,23 +118,28 @@ class UsdtWalletService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
- $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'],'headers'=> $headers]));
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
$trxWallet = new TRX($api);
|
|
|
|
|
|
// 获取钱包参数
|
|
|
try {
|
|
|
- $fromData = MemberService::make()->getWallet($from, 'trc');
|
|
|
- $privateKey = isset($fromData['trc_wif']) ? $fromData['trc_wif'] : '';
|
|
|
- $hexAddress = isset($fromData['trc_hexaddress']) ? $fromData['trc_hexaddress'] : '';
|
|
|
- if (empty($privateKey) || empty($hexAddress)) {
|
|
|
+ $otcAddress = ConfigService::make()->getConfigByCode('trc_address');
|
|
|
+ $otcAddressPrivate = ConfigService::make()->getConfigByCode('trc_private_key');
|
|
|
+ if (empty($otcAddress) || empty($otcAddressPrivate)) {
|
|
|
$this->error = '2203';
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
$tron = new Tron();
|
|
|
+ // 获取平台钱包hex
|
|
|
+ $tron->setAddress($otcAddress);
|
|
|
+ $otcAddress = $tron->getAddress();
|
|
|
+
|
|
|
+
|
|
|
$tron->setAddress($to);
|
|
|
$toAddress = $tron->getAddress();
|
|
|
- $from = new \Tron\Address($from, $privateKey, $hexAddress);
|
|
|
+ $from = new \Tron\Address($otcAddress['base58'], $otcAddressPrivate, $otcAddress['hex']);
|
|
|
$to = new \Tron\Address($toAddress['base58'], '', $toAddress['hex']);
|
|
|
$result = $trxWallet->transfer($from, $to, $amount);
|
|
|
|
|
|
@@ -141,7 +159,7 @@ class UsdtWalletService extends BaseService
|
|
|
* @throws \Tron\Exceptions\TransactionException
|
|
|
* @throws \Tron\Exceptions\TronErrorException
|
|
|
*/
|
|
|
- public function usdtTrcTransfer($from, $to, $amount)
|
|
|
+ public function usdtTrcTransfer($to, $amount)
|
|
|
{
|
|
|
if ($amount <= 0) {
|
|
|
$this->error = '2205';
|
|
|
@@ -153,24 +171,29 @@ class UsdtWalletService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
- $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'],'headers'=> $headers]));
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
$trxWallet = new TRC20($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
|
|
|
// 获取钱包参数
|
|
|
try {
|
|
|
- $fromData = MemberService::make()->getWallet($from, 'trc');
|
|
|
- $privateKey = isset($fromData['trc_wif']) ? $fromData['trc_wif'] : '';
|
|
|
- $hexAddress = isset($fromData['trc_hexaddress']) ? $fromData['trc_hexaddress'] : '';
|
|
|
- if (empty($privateKey) || empty($hexAddress)) {
|
|
|
+
|
|
|
+ $otcAddress = ConfigService::make()->getConfigByCode('trc_address');
|
|
|
+ $otcAddressPrivate = ConfigService::make()->getConfigByCode('trc_private_key');
|
|
|
+ if (empty($otcAddress) || empty($otcAddressPrivate)) {
|
|
|
$this->error = '2203';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$tron = new Tron();
|
|
|
+ // 获取平台钱包hex
|
|
|
+ $tron->setAddress($otcAddress);
|
|
|
+ $otcAddress = $tron->getAddress();
|
|
|
+
|
|
|
+ // 获取收款钱包hex
|
|
|
$tron->setAddress($to);
|
|
|
$toAddress = $tron->getAddress();
|
|
|
- $from = new \Tron\Address($from, $privateKey, $hexAddress);
|
|
|
+ $from = new \Tron\Address($otcAddress['base58'], $otcAddressPrivate, $otcAddress['hex']);
|
|
|
$to = new \Tron\Address($toAddress['base58'], '', $toAddress['hex']);
|
|
|
$result = $trxWallet->transfer($from, $to, $amount);
|
|
|
return $result;
|
|
|
@@ -183,6 +206,141 @@ class UsdtWalletService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * usdt-trc2.0 归集
|
|
|
+ * @throws \Tron\Exceptions\TransactionException
|
|
|
+ * @throws \Tron\Exceptions\TronErrorException
|
|
|
+ */
|
|
|
+ public function usdtTrcTrigger($force = false)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (empty($this->config['tron_api_url'])) {
|
|
|
+ $this->error = '2206';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
+ $trcWallet = new TRC20($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
+ $trxWallet = new TRX($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
+
|
|
|
+ // 获取钱包参数
|
|
|
+ try {
|
|
|
+
|
|
|
+ $otcAddress = ConfigService::make()->getConfigByCode('trc_address');
|
|
|
+ $otcAddressPrivate = ConfigService::make()->getConfigByCode('trc_private_key');
|
|
|
+ $triggerMin = ConfigService::make()->getConfigByCode('trade_trigger_min');
|
|
|
+ $triggerTime = ConfigService::make()->getConfigByCode('trade_trigger_time');
|
|
|
+ $triggerFree = ConfigService::make()->getConfigByCode('trade_trigger_free');
|
|
|
+ $triggerFree = $triggerFree > 0 ? $triggerFree : 8;
|
|
|
+ $triggerMin = $triggerMin > 0 ? $triggerMin : 0.1;
|
|
|
+ $triggerTime = $triggerTime > 0 ? $triggerTime * 86400 : 86400;
|
|
|
+ if (empty($otcAddress) || empty($otcAddressPrivate)) {
|
|
|
+ $this->error = '2203';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $page = RedisService::get("caches:wallet:transferPage");
|
|
|
+ $page = $page ? $page : 1;
|
|
|
+
|
|
|
+ // 归集时间段为凌晨0点-5点
|
|
|
+ if ((date('H:i') >= '05:00') && !$force) {
|
|
|
+ $this->error = '不在归集时间段';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(RedisService::get("caches:wallet:triggerLock:{$page}")){
|
|
|
+ $this->error = '不要频繁操作,30秒后重试';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上锁
|
|
|
+ RedisService::set("caches:wallet:triggerLock:{$page}", 1, rand(10, 30));
|
|
|
+ $addrList = MemberService::make()->getTriggerAddressList($triggerMin, $page, 200);
|
|
|
+ var_dump($addrList);
|
|
|
+ if (empty($addrList)) {
|
|
|
+ RedisService::set("caches:wallet:transferPage", 1, 600);
|
|
|
+ $this->error = '1019';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 平台钱包地址
|
|
|
+ $count = 0;
|
|
|
+ $failedCount = 0;
|
|
|
+ $tron = new Tron();
|
|
|
+ $tron->setAddress($otcAddress);
|
|
|
+ $otcAddress = $tron->getAddress();
|
|
|
+ $otcAddressData = new \Tron\Address($otcAddress['base58'], $otcAddressPrivate, $otcAddress['hex']);
|
|
|
+ $cacheKey = "caches:wallet:trigger:";
|
|
|
+ foreach ($addrList as $v) {
|
|
|
+ try {
|
|
|
+ // 获取子钱包TRC-USDT余额
|
|
|
+ $userId = isset($v['user_id']) ? $v['user_id'] : 0;
|
|
|
+ $address = isset($v['trc_address']) ? $v['trc_address'] : '';
|
|
|
+ $addressPrivate = isset($v['trc_wif']) ? $v['trc_wif'] : '';
|
|
|
+ $triggerAddress = new \Tron\Address($address['base58'], $addressPrivate, $address['hex']);
|
|
|
+ // 可归集的USDT余额
|
|
|
+ $triggerUsdt = $trcWallet->balance($triggerAddress);
|
|
|
+
|
|
|
+ // USDT 余额低于归集金额,则不归集
|
|
|
+ if ($triggerUsdt < $triggerMin) {
|
|
|
+ $failedCount++;
|
|
|
+ $error = ['data' => $v, 'usdt' => $triggerUsdt, 'triggerMin' => $triggerMin, 'error' => '用户余额不足归集', 'date' => date('Y-m-d H:i:s')];
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:error", $error, 7200);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取子钱包TRX余额
|
|
|
+ $triggerTrx = $trxWallet->balance($triggerAddress);
|
|
|
+
|
|
|
+ // 获取平台钱包TRX余额
|
|
|
+ $otcTrxTotal = $trxWallet->balance($otcAddressData);
|
|
|
+
|
|
|
+ // 如果子钱包和平台钱包TRX余额不足手续费,则不归集
|
|
|
+ if ($triggerTrx < $triggerFree && $otcTrxTotal < $triggerFree) {
|
|
|
+ $failedCount++;
|
|
|
+ $error = ['data' => $v, 'usdt' => $triggerUsdt, 'triggerMin' => $triggerMin,'triggerTrx' => $triggerTrx, 'otcTrx' => $otcTrxTotal, 'error' => '平台钱包手续费不足', 'date' => date('Y-m-d H:i:s')];
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:error", $error, 7200);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果子钱包TRX不足手续费8个,平台TRX充足则自动充值后下次调用时归集
|
|
|
+ if ($triggerTrx < $triggerFree) {
|
|
|
+ $failedCount++;
|
|
|
+ $this->trxTransfer($otcAddress['base58']);
|
|
|
+ $error = ['data' => $v, 'usdt' => $triggerUsdt, 'triggerMin' => $triggerMin, 'triggerTrx' => $triggerTrx, 'error' => '归集钱包手续费不足,先充值', 'date' => date('Y-m-d H:i:s')];
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:catch", $error, 7200);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 满足归集条件处理
|
|
|
+ $result = $trxWallet->transfer($triggerAddress, $otcAddressData, $triggerUsdt);
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:result", ['data'=> $v,'result'=>$result,'msg'=>'归集已提交','date' => date('Y-m-d H:i:s')], 7200);
|
|
|
+ $count++;
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $failedCount++;
|
|
|
+ RedisService::set($cacheKey . "U_{$userId}:exception", ['data'=> $v,'msg'=>$exception->getMessage(),'date' => date('Y-m-d H:i:s')], 7200);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已经归集过
|
|
|
+ RedisService::set("caches:wallet:transferPage", $page + 1, 600);
|
|
|
+ if ($count > 0) {
|
|
|
+ return ['success' => $count, 'fail' => $failedCount];
|
|
|
+ } else {
|
|
|
+ $this->error = 1021;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $this->error = $exception->getMessage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 监听USDT-TRC2.0转账记录并进账
|
|
|
* @param $userId 用户ID
|
|
|
* @param $address 用户钱包地址
|
|
|
@@ -190,17 +348,17 @@ class UsdtWalletService extends BaseService
|
|
|
* @param int $limit 转账记录数,最新的
|
|
|
* @return array|false
|
|
|
*/
|
|
|
- public function getTrc20RechargeLog($userId, $address, $coinType= 1, $limit = 50)
|
|
|
+ public function getTrc20RechargeLog($userId, $address, $coinType = 1, $limit = 50)
|
|
|
{
|
|
|
- if($userId<=0 || empty($address)){
|
|
|
+ if ($userId <= 0 || empty($address)) {
|
|
|
$this->error = '1013';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'true','false');
|
|
|
- $headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
+ $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'true', 'false');
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
$result = curl_get($this->config['tron_api_url'] . $url, [], $headers, 10);
|
|
|
- $result = $result? json_decode($result, true) : [];
|
|
|
+ $result = $result ? json_decode($result, true) : [];
|
|
|
$datas = isset($result['data']) ? $result['data'] : [];
|
|
|
$status = isset($result['success']) ? $result['success'] : '';
|
|
|
if ($status != true || empty($datas)) {
|
|
|
@@ -210,31 +368,33 @@ class UsdtWalletService extends BaseService
|
|
|
|
|
|
$logs = [];
|
|
|
foreach ($datas as $v) {
|
|
|
- $amount = isset($v['value'])? intval($v['value']) : 0;
|
|
|
- $amount = moneyFormat($amount/1000000, 6);
|
|
|
- $time = isset($v['block_timestamp'])? intval($v['block_timestamp']) : 0;
|
|
|
- $txid = isset($v['transaction_id'])? $v['transaction_id'] : '';
|
|
|
- if(!CoinLogService::make()->checkExists('txid', $txid) && $time> time() - 6*3600){
|
|
|
- $balance = $this->memberModel->where(['id'=> $userId])->value('usdt_num');
|
|
|
+ $amount = isset($v['value']) ? intval($v['value']) : 0;
|
|
|
+ $amount = moneyFormat($amount / 1000000, 6);
|
|
|
+ $time = isset($v['block_timestamp']) ? intval($v['block_timestamp']) : 0;
|
|
|
+ $txid = isset($v['transaction_id']) ? $v['transaction_id'] : '';
|
|
|
+ if (!CoinLogService::make()->checkExists('txid', $txid) && $time > time() - 6 * 3600) {
|
|
|
+ $balance = $this->memberModel->where(['id' => $userId])->value('usdt_num');
|
|
|
$log = [
|
|
|
- 'user_id'=> $userId,
|
|
|
- 'change_type'=> 1,
|
|
|
- 'coin_type'=> $coinType,
|
|
|
- 'contact_type'=> 1,
|
|
|
- 'order_no'=> get_order_num('OT'),
|
|
|
- 'from_address'=> isset($v['from'])? $v['from'] : '',
|
|
|
- 'to_address'=> isset($v['to'])? $v['to'] : '',
|
|
|
- 'txid'=> $txid,
|
|
|
- 'num'=> $amount,
|
|
|
- 'balance'=> $balance,
|
|
|
- 'create_time'=> intval($time/1000),
|
|
|
- 'status'=> 1,
|
|
|
- 'mark'=> 1,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'change_type' => 1,
|
|
|
+ 'coin_type' => $coinType,
|
|
|
+ 'contact_type' => 1,
|
|
|
+ 'order_no' => get_order_num('OT'),
|
|
|
+ 'from_address' => isset($v['from']) ? $v['from'] : '',
|
|
|
+ 'to_address' => isset($v['to']) ? $v['to'] : '',
|
|
|
+ 'txid' => $txid,
|
|
|
+ 'num' => $amount,
|
|
|
+ 'balance' => $balance,
|
|
|
+ 'create_time' => intval($time / 1000),
|
|
|
+ 'status' => 1,
|
|
|
+ 'mark' => 1,
|
|
|
];
|
|
|
|
|
|
- if($this->memberModel->where(['id'=> $userId])->increment('usdt_num', $amount)){
|
|
|
+ if ($this->memberModel->where(['id' => $userId])->increment('usdt_num', $amount)) {
|
|
|
$logs[] = $log;
|
|
|
$this->coinModel->insert($log);
|
|
|
+
|
|
|
+ $this->memberModel->where(['id' => $userId])->increment('trc_usdt', $amount);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -251,17 +411,17 @@ class UsdtWalletService extends BaseService
|
|
|
* @param int $limit 转账记录数,最新的
|
|
|
* @return array|false
|
|
|
*/
|
|
|
- public function getTrc20TransferLog($userId, $address, $coinType= 1, $limit = 50)
|
|
|
+ public function getTrc20TransferLog($userId, $address, $coinType = 1, $limit = 50)
|
|
|
{
|
|
|
- if($userId<=0 || empty($address)){
|
|
|
+ if ($userId <= 0 || empty($address)) {
|
|
|
$this->error = '1013';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'false','true');
|
|
|
- $headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
+ $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'false', 'true');
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
$result = curl_get($this->config['tron_api_url'] . $url, [], $headers, 10);
|
|
|
- $result = $result? json_decode($result, true) : [];
|
|
|
+ $result = $result ? json_decode($result, true) : [];
|
|
|
$datas = isset($result['data']) ? $result['data'] : [];
|
|
|
$status = isset($result['success']) ? $result['success'] : '';
|
|
|
if ($status != true || empty($datas)) {
|
|
|
@@ -271,31 +431,33 @@ class UsdtWalletService extends BaseService
|
|
|
|
|
|
$logs = [];
|
|
|
foreach ($datas as $v) {
|
|
|
- $amount = isset($v['value'])? intval($v['value']) : 0;
|
|
|
- $amount = moneyFormat($amount/1000000, 6);
|
|
|
- $time = isset($v['block_timestamp'])? intval($v['block_timestamp']) : 0;
|
|
|
- $txid = isset($v['transaction_id'])? $v['transaction_id'] : '';
|
|
|
- if(!CoinLogService::make()->checkExists('txid', $txid) && $time> time() - 6*3600){
|
|
|
- $balance = $this->memberModel->where(['id'=> $userId])->value('usdt_num');
|
|
|
+ $amount = isset($v['value']) ? intval($v['value']) : 0;
|
|
|
+ $amount = moneyFormat($amount / 1000000, 6);
|
|
|
+ $time = isset($v['block_timestamp']) ? intval($v['block_timestamp']) : 0;
|
|
|
+ $txid = isset($v['transaction_id']) ? $v['transaction_id'] : '';
|
|
|
+ if (!CoinLogService::make()->checkExists('txid', $txid) && $time > time() - 6 * 3600) {
|
|
|
+ $balance = $this->memberModel->where(['id' => $userId])->value('usdt_num');
|
|
|
$log = [
|
|
|
- 'user_id'=> $userId,
|
|
|
- 'change_type'=> 2,
|
|
|
- 'coin_type'=> $coinType,
|
|
|
- 'contact_type'=> 1,
|
|
|
- 'order_no'=> get_order_num('OT'),
|
|
|
- 'from_address'=> isset($v['from'])? $v['from'] : '',
|
|
|
- 'to_address'=> isset($v['to'])? $v['to'] : '',
|
|
|
- 'txid'=> $txid,
|
|
|
- 'num'=> $amount,
|
|
|
- 'balance'=> $balance,
|
|
|
- 'create_time'=> intval($time/1000),
|
|
|
- 'status'=> 1,
|
|
|
- 'mark'=> 1,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'change_type' => 2,
|
|
|
+ 'coin_type' => $coinType,
|
|
|
+ 'contact_type' => 1,
|
|
|
+ 'order_no' => get_order_num('OT'),
|
|
|
+ 'from_address' => isset($v['from']) ? $v['from'] : '',
|
|
|
+ 'to_address' => isset($v['to']) ? $v['to'] : '',
|
|
|
+ 'txid' => $txid,
|
|
|
+ 'num' => $amount,
|
|
|
+ 'balance' => $balance,
|
|
|
+ 'create_time' => intval($time / 1000),
|
|
|
+ 'status' => 1,
|
|
|
+ 'mark' => 1,
|
|
|
];
|
|
|
|
|
|
- if($this->memberModel->where(['id'=> $userId])->decrement('usdt_num', $amount)){
|
|
|
+ if ($this->memberModel->where(['id' => $userId])->decrement('usdt_num', $amount)) {
|
|
|
$logs[] = $log;
|
|
|
$this->coinModel->insert($log);
|
|
|
+
|
|
|
+ $this->memberModel->where(['id' => $userId])->decrement('trc_usdt', $amount);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -307,10 +469,50 @@ class UsdtWalletService extends BaseService
|
|
|
* @param $address
|
|
|
* @return false|float|string
|
|
|
*/
|
|
|
+ public function getTrxBalance($address)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:wallet:balance:{$address}";
|
|
|
+ if (RedisService::get($cacheKey)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($address)) {
|
|
|
+ $this->error = '1018';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($this->config['tron_api_url'])) {
|
|
|
+ $this->error = '2206';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
+ $trxWallet = new TRX($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
+
|
|
|
+ $tron = new Tron();
|
|
|
+ $tron->setAddress($address);
|
|
|
+ $address = $tron->getAddress();
|
|
|
+ $address = new \Tron\Address($address['base58'], '', $address['hex']);
|
|
|
+ $result = $trxWallet->balance($address);
|
|
|
+
|
|
|
+ return $result ? floatval($result) : '0.00';
|
|
|
+
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $this->error = $exception->getMessage();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $address
|
|
|
+ * @return false|float|string
|
|
|
+ */
|
|
|
public function getUsdtByTrc20($address)
|
|
|
{
|
|
|
$cacheKey = "caches:wallet:balance:{$address}";
|
|
|
- if(RedisService::get($cacheKey)){
|
|
|
+ if (RedisService::get($cacheKey)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -325,8 +527,8 @@ class UsdtWalletService extends BaseService
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
- $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'],'headers'=> $headers]));
|
|
|
+ $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
+ $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
$trxWallet = new TRC20($api, ['contract_address' => $this->config['tron_contract_address'], 'decimals' => 6]);
|
|
|
|
|
|
$tron = new Tron();
|
|
|
@@ -335,9 +537,9 @@ class UsdtWalletService extends BaseService
|
|
|
$address = new \Tron\Address($address['base58'], '', $address['hex']);
|
|
|
$result = $trxWallet->balance($address);
|
|
|
|
|
|
- return $result? floatval($result) : '0.00';
|
|
|
+ return $result ? floatval($result) : '0.00';
|
|
|
|
|
|
- } catch (\Exception $exception){
|
|
|
+ } catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
return false;
|
|
|
}
|
|
|
@@ -405,17 +607,18 @@ class UsdtWalletService extends BaseService
|
|
|
|
|
|
public function getWebAddress($label = '1')
|
|
|
{
|
|
|
- $web3 = new Web3("https://cloudflare-eth.com");
|
|
|
- $web3->eth->personal->newAccount($label, function ($err, $account) use (&$newAccount) {
|
|
|
+ $personal = new Personal("https://cloudflare-eth.com");
|
|
|
+ $personal->batch(true);
|
|
|
+ $personal->listAccounts();
|
|
|
+ $personal->newAccount('123456');
|
|
|
+ $personal->provider->execute(function ($err, $data) {
|
|
|
if ($err !== null) {
|
|
|
- echo 'Error: ' . $err->getMessage();
|
|
|
+ // do something
|
|
|
return;
|
|
|
}
|
|
|
- $newAccount = $account;
|
|
|
- echo 'New account: ' . $account . PHP_EOL;
|
|
|
+ // do something
|
|
|
});
|
|
|
|
|
|
- var_dump($newAccount);
|
|
|
}
|
|
|
|
|
|
/**
|